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()); } } }
protected void restoreTree() { Pair<ElementNode, List<ElementNode>> selection = storeSelection(); DefaultMutableTreeNode root = getRootNode(); if (!myShowClasses || myContainerNodes.isEmpty()) { List<ParentNode> otherObjects = new ArrayList<ParentNode>(); Enumeration<ParentNode> children = getRootNodeChildren(); ParentNode newRoot = new ParentNode( null, new MemberChooserObjectBase(getAllContainersNodeName()), new Ref<Integer>(0)); while (children.hasMoreElements()) { final ParentNode nextElement = children.nextElement(); if (nextElement instanceof ContainerNode) { final ContainerNode containerNode = (ContainerNode) nextElement; Enumeration<MemberNode> memberNodes = containerNode.children(); List<MemberNode> memberNodesList = new ArrayList<MemberNode>(); while (memberNodes.hasMoreElements()) { memberNodesList.add(memberNodes.nextElement()); } for (MemberNode memberNode : memberNodesList) { newRoot.add(memberNode); } } else { otherObjects.add(nextElement); } } replaceChildren(root, otherObjects); sortNode(newRoot, myComparator); if (newRoot.children().hasMoreElements()) root.add(newRoot); } else { Enumeration<ParentNode> children = getRootNodeChildren(); while (children.hasMoreElements()) { ParentNode allClassesNode = children.nextElement(); Enumeration<MemberNode> memberNodes = allClassesNode.children(); ArrayList<MemberNode> arrayList = new ArrayList<MemberNode>(); while (memberNodes.hasMoreElements()) { arrayList.add(memberNodes.nextElement()); } Collections.sort(arrayList, myComparator); for (MemberNode memberNode : arrayList) { myNodeToParentMap.get(memberNode).add(memberNode); } } replaceChildren(root, myContainerNodes); } myTreeModel.nodeStructureChanged(root); defaultExpandTree(); restoreSelection(selection); }
private static void sortNode(ParentNode node, final Comparator<ElementNode> sortComparator) { ArrayList<MemberNode> arrayList = new ArrayList<MemberNode>(); Enumeration<MemberNode> children = node.children(); while (children.hasMoreElements()) { arrayList.add(children.nextElement()); } Collections.sort(arrayList, sortComparator); replaceChildren(node, arrayList); }
@Override void toXML(XMLStreamWriter xmlWriter) throws XMLStreamException { xmlWriter.writeStartElement(getNamespacePrefix(), getLocalName(), getNamespaceURI()); // write attribute values for (int i = 0; i < getAttributeCount(); i++) { getAttribute(i).toXML(xmlWriter); } super.toXML(xmlWriter); xmlWriter.writeEndElement(); }