/** * Create an HTML tree view. * @param root The nodes at the root of the tree * (the nodes are wrapped in an Html node that is never seen * because it's the root, but this makes all downstream processing * super-simple because every tree node is then a {@link Node}, * not sometimes a {@link NodeList} at the root). */ public HtmlTreeModel (NodeList root) { mTreeListeners = new ArrayList (); // for simplicity we encapsulate the nodelist in a Html tag mRoot = new Html (); mRoot.setChildren (root); }
/** * Make flat clone of just this one node. No nesting * * @param node Node to clone * @return cloned version of node */ public static Node flatClone(Node node) { if (node == null) return null; Node newNode = cloneOnlyNode(node, null); newNode.setChildren(new NodeList()); if (newNode instanceof Tag) { ((Tag) newNode).setEndTag(null); } return newNode; }
/** * Make flat clone of just this one node. No nesting * * @param node Node to clone * @return cloned version of node */ public static Node flatClone(Node node) { if (node == null) return null; Node newNode = cloneOnlyNode(node, null); newNode.setChildren(new NodeList()); if (newNode instanceof Tag) { ((Tag) newNode).setEndTag(null); } return newNode; }
/** * Add a child to the given tag. * @param parent The parent tag. * @param child The child node. */ protected void addChild (Tag parent, Node child) { if (null == parent.getChildren ()) parent.setChildren (new NodeList ()); child.setParent (parent); parent.getChildren ().add (child); }
private static NodeList deepClone(NodeList tree, Node clonedParent) { NodeList newNodeList = new NodeList(); for (int i = 0; i < tree.size(); i++) { Node node = tree.elementAt(i); Node newNode = cloneOnlyNode(node, clonedParent); newNodeList.add(newNode); if (node.getChildren() != null) { newNode.setChildren(deepClone(node.getChildren(), newNode)); } } return newNodeList; }
private static NodeList deepClone(NodeList tree, Node clonedParent) { NodeList newNodeList = new NodeList(); for (int i = 0; i < tree.size(); i++) { Node node = tree.elementAt(i); Node newNode = cloneOnlyNode(node, clonedParent); newNodeList.add(newNode); if (node.getChildren() != null) { newNode.setChildren(deepClone(node.getChildren(), newNode)); } } return newNodeList; }
if (null != content) tag.setChildren (new NodeList (content)); content.setParent (tag);
if (null != content) tag.setChildren (new NodeList (content)); content.setParent (tag);