public void parseElement(Element element, ElementNode treeNode) { for (Iterator elementIterator = element.elementIterator(); elementIterator.hasNext(); ) { Object childElementObject = elementIterator.next(); if (childElementObject instanceof Element) { Element childElement = (Element) childElementObject; ElementNode childTreeNode = new ElementNode(); treeNode.add(childTreeNode); parseAttribute(childElement, childTreeNode); parseElement(childElement, childTreeNode); } } }
public void parseAttribute(Element element, ElementNode treeNode) { HashMap userObject = null; for (Iterator attributeIterator = element.attributeIterator(); attributeIterator.hasNext(); ) { Attribute attribute = (Attribute) attributeIterator.next(); String attributeName = attribute.getName().trim(); String attributeText = attribute.getText().trim(); if (attributeName.equals(indexTag)) { treeNode.setIndex(Integer.parseInt(attributeText)); } else if (attributeName.equals(nameTag)) { treeNode.setName(attributeText); } else if (attributeName.equals(textTag)) { treeNode.setText(attributeText); } else if (attributeName.equals(iconTag)) { String iconName = attributeText + (iconExtensionName != null ? iconExtensionName : ""); switch (iconFolderMode) { case ICON_FOLDER_MODE_SWING: treeNode.setIcon(IconFactory.getSwingIcon(iconName)); break; case ICON_FOLDER_MODE_CONTEXT: treeNode.setIcon(IconFactory.getContextIcon(iconName)); break; case ICON_FOLDER_MODE_FULL: treeNode.setIcon(IconFactory.getIcon(iconName)); break; default: treeNode.setIcon(IconFactory.getContextIcon(iconName)); break; } } else if (attributeName.equals(toolTipTextTag)) { treeNode.setToolTipText(attributeText); } else if (attributeName.equals(classTag)) { if (userObject == null) { userObject = new HashMap(); treeNode.setUserObject(userObject); } Object instance = null; try { instance = Class.forName(attributeText).newInstance(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } userObject.put(classTag, instance); } else { if (userObject == null) { userObject = new HashMap(); treeNode.setUserObject(userObject); } userObject.put(attributeName, attributeText); } if (treeNode.getText() == null && treeNode.getName() != null) { treeNode.setText(treeNode.getName()); } if (treeNode.getToolTipText() == null && treeNode.getName() != null) { treeNode.setToolTipText(treeNode.getName()); } } }