req, $econf->doc->dom, $out_node); } function process_node($econf, $in_node, $out_node) { for ($child = $in_node->firstChild; $child !== NULL; $child = $next_sibling) { switch ($child->nodeType) { case XML_ELEMENT_NODE: $next_sibling = process_element($econf, $child, $out_node); break; case XML_TEXT_NODE: case XML_CDATA_SECTION_NODE: case XML_PI_NODE: case XML_ENTITY_REF_NODE: process_node_copy($econf, $child, $out_node); $next_sibling = $child->nextSibling; break; case XML_COMMENT_NODE: case XML_DOCUMENT_TYPE_NODE: # Do not copy comments; doctype already copied. $next_sibling = $child->nextSibling; break; default: throw new DocumentException ('Unknown document node type "'.$child->nodeType.'"'); } } } function process_node_copy($econf, $from_node, $to_node) { if ($econf->x_access) { $node_copy = document_of($to_node)->importNode($from_node, TRUE); $to_node->appendChild($node_copy); } } function process_element($econf, $in_elm, $out_node) { $econf = clone $econf; $next_sibling = process_element_with_new_conf($econf, $in_elm, $out_node); $econf->pre_destruct(); return $next_sibling; } function process_element_with_new_conf($econf, $in_elm, $out_node) { $next_sibling = $in_elm->nextSibling; $econf->notice_html_ns($in_elm); prepare_undo($econf, $in_elm); store_template($econf, $in_elm); process_once_attribute($econf, $in_elm); process_instance__attribute($econf, $in_elm); process_login_attribute($econf, $in_elm); process_access_attributes($econf, $in_elm); if (is_access($econf, $in_elm)) { process_configuration_attributes($econf, $in_elm); $new_elm = process_new_attribute($econf, $in_elm, $out_node); if ($new_elm !== NULL) { if ($in_elm->parentNode === NULL) { return $new_elm; } $next_sibling = $in_elm->nextSibling; } process_del_attribute($econf, $in_elm); if ($in_elm->parentNode === NULL) { return $next_sibling; } process_ed_attribute_1($econf, $in_elm); if ($in_elm->namespaceURI !== W2ML_NS) { process_non_w2ml_element($econf, $in_elm, $out_node); } else { process_w2ml_element($econf, $in_elm, $out_node); if ($in_elm->parentNode === NULL) { return $next_sibling; } } } elseif (is_template_ed_access($econf, $in_elm)) { process_node($econf, $in_elm, $out_node); } process_once_attribute_2($econf, $in_elm); process_next_attribute($econf, $in_elm); finish_undo($econf, $in_elm); return $next_sibling; } function is_access($econf, $in_elm) { return is_x_access($econf) && is_template_ed_access($econf, $in_elm); } function is_template_ed_access($econf, $in_elm) { $ed = get_w2ml_attribute_value($in_elm, 'ed'); return !($ed === 'new' && !$econf->n_access) && !($ed === 'del' && !$econf->d_access); } function is_x_access($econf) { return $econf->x_access; } function process_non_w2ml_element($econf, $in_elm, $out_node) { dup_non_w2ml_element($in_elm, $out_node); $econf->notice_out_element($out_node->lastChild); process_node($econf, $in_elm, $out_node->lastChild); process_text_attributes($econf, $in_elm, $out_node->lastChild); process_ed_attribute_2($econf, $in_elm, $out_node->lastChild); process_template_attributes_2($econf, $in_elm, $out_node->lastChild); } function dup_non_w2ml_element($in_elm, $out_node) { # Note the hack from http://ch.php.net/manual/en/domdocument.importnode.php: # we import recursively a unrecursively cloned element. Benefit: we get the element # with its attributes, including namespace declarations (!), but not its children. $new_elm = document_of($out_node)->importNode($in_elm->cloneNode(FALSE), TRUE); remove_attributes_of_ns($new_elm, W2ML_NS); $out_node->appendChild($new_elm); } function process_w2ml_element($econf, $in_elm, $out_node) { $receptacle = document_of($out_node)->createElementNS(NULL, 'DUMMY'); $out_node->appendChild($receptacle); dispatch_w2ml_element($econf, $in_elm, $receptacle); if ($in_elm->parentNode !== NULL) { process_text_attributes($econf, $in_elm, $receptacle); dispatch_late_w2ml_element($econf, $in_elm, $receptacle); } if ($receptacle->parentNode !== NULL) { remove_node_shallow($receptacle); } } function dispatch_w2ml_element($econf, $in_elm, $out_elm) { switch ($in_elm->localName) { case 'g': case 'once': case 'output': case 'res': case 'user': case 'name': case 'password': case 'group': case 'undo': process_node($econf, $in_elm, $out_elm); break; case 'year': process_year_element($econf, $in_elm, $out_elm); break; case 'month': process_month_element($econf, $in_elm, $out_elm); break; case 'day': process_day_element($econf, $in_elm, $out_elm); break; case 'ampm': process_ampm_element($econf, $in_elm, $out_elm); break; case 'hour': process_hour_element($econf, $in_elm, $out_elm); break; case 'minute': process_minute_element($econf, $in_elm, $out_elm); break; case 'second': process_second_element($econf, $in_elm, $out_elm); break; case 'tz': process_tz_element($econf, $in_elm, $out_elm); break; case 'time': process_time_element($econf, $in_elm, $out_elm); break; case 'sleep': process_sleep_element($econf, $in_elm, $out_elm); break; case 'counter': process_counter_element($econf, $in_elm, $out_elm); break; case 'next': process_next_element($econf, $in_elm); break; case 'v': process_v_element($econf, $in_elm, $out_elm); break; case 'del': process_del_element($econf, $in_elm); break; case 'include': process_clude_element($econf, $in_elm, $out_elm); break; case 'outclude': process_clude_element($econf, $in_elm, $out_elm); break; case 'backclude': process_backclude_element($econf, $in_elm, $out_elm); break; case 'fdel': case 'fcopy': case 'fren': case 'fsave': case 'ok': case 'ko': case 'a': log_error('Unimplemented W2ML element "'.$in_elm->localName.'"', $econf->log); process_node($econf, $in_elm, $out_elm); break; default: log_error('Unknown W2ML element "'.$in_elm->localName.'"', $econf->log); process_node($econf, $in_elm, $out_elm); } } function dispatch_late_w2ml_element($econf, $in_elm, $out_elm) { switch ($in_elm->localName) { case 'once': process_once_element($econf, $in_elm); break; case 'output': process_output_element($econf, $in_elm, $out_elm); break; case 'res': process_res_element($econf, $in_elm, $out_elm); break; } } function post_process($req, $in_doc, $out_doc) { add_ed_browser_support($req, $out_doc); } ?>