/** * This method is called for the end tag of the root document tag. If there are name spaces, they * would have been defined in this tag. Insert them in the front of the attribute list. * * @throws XmlPullParserException */ private void addNamespaces(int depth) throws XmlPullParserException { TagNode tag = (TagNode) mDocumentTag; AttributeList attrList = tag.getAttrList(); int nsStart = mParser.getNamespaceCount(depth - 1); int nsEnd = mParser.getNamespaceCount(depth); for (int i = nsEnd - 1; i >= nsStart; i--) { Attribute attr = buildNS(i); attrList.insert(attr); } } // addNamespaces
/** * Build a tag node. Note that a tag node always has an AttributeList object, even if there is no * attribute list. This wastes some memory, but in theory should make the tree processing more * regular, since it can always be assumed that this object exits. */ private TagNode buildTagNode() { String name = mParser.getName(); // String prefix = mParser.getPrefix(); String prefix = null; String namespace = mParser.getNamespace(); TagNode tag = new TagNode(name, prefix, namespace); AttributeList attrList = new AttributeList(); int numAttr = mParser.getAttributeCount(); for (int i = 0; i < numAttr; i++) { Attribute attr = buildAttr(i); attrList.append(attr); } // for tag.setAttrList(attrList); return tag; } // buildTagNode
public void extend(TemplateDocument doc, FragmentList f, boolean normalize) throws BehaviorInstantiationException { ParentNode extended; if (extendedTag == null) { extended = extendedDocument; } else { extended = extendedTag; } ArrayList<TemplateNode> children = doc.getChildren(); for (TemplateNode node : children) { if (node instanceof Tag) { Tag tag = (Tag) node; Tag overriden = null; Attribute overrides = tag.getDynamicAttribute( new DynamicAttributeKey(Cambridge.DefaultNamespaceURI, "a", "overrides")); if (overrides != null) { overriden = extendedDocument.locateTag(overrides.getValue()); } else { Attribute id = tag.getAttribute("id"); if (id == null && tag.isDynamic()) { id = tag.getAttribute(tag.getNameSpace(), "id"); } if (id != null) { overriden = extended.getElementById(id.getValue()); } } if (overriden != null) { overriden.getParent().replaceChild((TemplateNode) overriden, (TemplateNode) tag); } } else if (node instanceof SetDirective) { int index = 0; if (extended == extendedDocument && extendedDocument.getChildren().size() > 0 && extendedDocument.getChildren().get(0) instanceof ExtendsDirective) { index = 1; } extended.insertChild(index, node); } } if (extendedDocument.getChildren().size() > 0 && extendedDocument.getChildren().get(0) instanceof ExtendsDirective) { ((ExtendsDirective) extendedDocument.getChildren().get(0)).extend(extendedDocument, f, false); } if (normalize) { if (extendedTag != null) { extendedTag.normalize(extendedDocument, f); } else { f.addAll(extendedDocument.normalize()); } } }
public void addAttribute(String name, String value) { current.addAttribute(name, value); }
@Override public String toString() { return root.toString(); }
public void addBeside(String sibling) { TagNode siblingNode = new TagNode(sibling); parent.add(siblingNode); current = siblingNode; }
public void addBelow(String node) { TagNode childNode = new TagNode(node); current.add(childNode); parent = current; current = childNode; }