List of usage examples for org.dom4j Element node
Node node(int index) throws IndexOutOfBoundsException;
Node
at the specified index position. From source file:com.cladonia.xml.XMLFormatter.java
License:Mozilla Public License
protected Node writePreservedElementContent(Element element) throws IOException { if (DEBUG)/*from w ww . j a v a 2 s. c o m*/ System.out.println("XMLFormatter.writePreservedElementContent( " + element + ")"); Node previousNode = null; boolean previousTrim = format.isTrimText(); boolean previousWrapText = wrapText; format.setTrimText(false); wrapText = false; for (int i = 0, size = element.nodeCount(); i < size; i++) { Node node = element.node(i); Node nextNode = null; if (i + 1 < size) { nextNode = element.node(i + 1); } if (node instanceof Text) { String text = node.getText(); // previous node was an empty element-node <element/> writeString(text); } else { writePreservedNode(node); } previousNode = node; } format.setTrimText(previousTrim); wrapText = previousWrapText; return previousNode; }
From source file:com.cladonia.xngreditor.actions.ToolsAddNodeToNamespaceAction.java
License:Open Source License
/** * Walk through the document tree and change the attributes if they are the selected ones * /* ww w . j a v a2 s. co m*/ * @param document the exchanger document * @param attributeList the list of attributes that match the xpath result * @param newNs the new namespace for the nodes * @throws Exception */ public void treeWalk(Element element, List attributeList, Namespace newNs) throws Exception { for (int i = 0, size = element.nodeCount(); i < size; i++) { Node node = element.node(i); if (node instanceof Element) { //if it's an element XElement e = (XElement) node; if (e.attributeCount() > 0) { //and it has attributes List attList = e.attributes(); for (int cnt = 0; cnt < attList.size(); ++cnt) { //for each attribute XAttribute newAtt = (XAttribute) attList.get(cnt); int fcnt = findInList(newAtt, attributeList); if (fcnt > -1) { //if the attribute matches the one we are looking for //replace it with the new qname String name = newAtt.getName(); String value = newAtt.getValue(); Namespace ns = newNs; attList.set(cnt, new XAttribute(new QName(name, ns), value)); //now remove it from the attributeList to speed up the next searches attributeList.remove(fcnt); } } } treeWalk((Element) node, attributeList, newNs); } } }
From source file:com.cladonia.xngreditor.actions.ToolsCapitalizeAction.java
License:Open Source License
private void iterateTree(Element element, boolean capitalizeElements, boolean capitalizeAttributes, boolean capitalizeElementsAndAttributes) throws Exception { for (int i = 0, size = element.nodeCount(); i < size; i++) { Node oldNode = element.node(i); if (oldNode instanceof Element) { XElement oldElement = (XElement) oldNode; if (((capitalizeAttributes) || (capitalizeElementsAndAttributes)) && (oldElement.attributeCount() > 0)) { oldElement.setAttributes(this.capitalizeAttributes(oldElement)); }//from w ww. j av a 2 s . co m //capitalize the element if (((capitalizeElements) || (capitalizeElementsAndAttributes)) && (oldElement.getName() != null)) { String name = oldElement.getName(); name = capitalizeString(name); Namespace ns = oldElement.getNamespace(); oldElement.setQName(new QName(name, ns)); } iterateTree(oldElement, capitalizeElements, capitalizeAttributes, capitalizeElementsAndAttributes); } } }
From source file:com.cladonia.xngreditor.actions.ToolsDeCapitalizeAction.java
License:Open Source License
/** * Iterate through the tree to decapitalize elements and attributes based on the flags * @param element the element the method is working on * @param deCapitalizeElements flag as to whether to decapitalize elements * @param deCapitalizeAttributes flag as to whether to decapitalize attributes * @param deCapitalizeElementsAndAttributes flag as to whether to decapitalize elements and attributes * @throws Exception/*from ww w.ja va2 s . c o m*/ */ private void iterateTree(Element element, boolean deCapitalizeElements, boolean deCapitalizeAttributes, boolean deCapitalizeElementsAndAttributes) throws Exception { for (int i = 0, size = element.nodeCount(); i < size; i++) { Node oldNode = element.node(i); if (oldNode instanceof Element) { XElement oldElement = (XElement) oldNode; if ((deCapitalizeAttributes) || (deCapitalizeElementsAndAttributes)) { oldElement.setAttributes(this.deCapitalizeAttributes(oldElement)); } //DeCapitalize the element if (((deCapitalizeElements) || (deCapitalizeElementsAndAttributes)) && (oldElement.getName() != null)) { String name = oldElement.getName(); name = deCapitalizeString(name); Namespace ns = oldElement.getNamespace(); oldElement.setQName(new QName(name, ns)); } iterateTree(oldElement, deCapitalizeElements, deCapitalizeAttributes, deCapitalizeElementsAndAttributes); } } }
From source file:com.cladonia.xngreditor.actions.ToolsLowercaseAction.java
License:Open Source License
private void iterateTree(Element element, boolean lowercaseElements, boolean lowercaseAttributes, boolean lowercaseElementsAndAttributes) throws Exception { for (int i = 0, size = element.nodeCount(); i < size; i++) { Node oldNode = element.node(i); if (oldNode instanceof Element) { XElement oldElement = (XElement) oldNode; if ((lowercaseAttributes) || (lowercaseElementsAndAttributes)) { oldElement.setAttributes(this.lowercaseAttributes(oldElement)); }// w w w . ja va 2 s . c o m //Lowercase the element if (((lowercaseElements) || (lowercaseElementsAndAttributes)) && (oldElement.getName() != null)) { String name = oldElement.getName(); name = lowercaseString(name); Namespace ns = oldElement.getNamespace(); oldElement.setQName(new QName(name, ns)); } iterateTree(oldElement, lowercaseElements, lowercaseAttributes, lowercaseElementsAndAttributes); } } }
From source file:com.cladonia.xngreditor.actions.ToolsMoveNSToFirstUsedAction.java
License:Open Source License
private Vector iterateTree(XElement root, Element element, Vector allNamespaces) throws Exception { for (int i = 0, size = element.nodeCount(); i < size; i++) { Node oldNode = element.node(i); if (oldNode instanceof Element) { XElement oldElement = (XElement) oldNode; this.removeNamespacesFromElement(oldElement); iterateTree(root, oldElement, allNamespaces); }/*w w w . jav a 2 s . co m*/ } //return the vector of namespaces return (allNamespaces); }
From source file:com.cladonia.xngreditor.actions.ToolsSetNodeValueAction.java
License:Open Source License
/** * Walk through the document tree and change the attributes if they are the selected ones * //from w ww . jav a2 s .co m * @param document the exchanger document * @param attributeList the list of attributes that match the xpath result * @param value the new value for the nodes * @throws Exception */ private void treeWalk(Element element, List attributeList, String value) throws Exception { for (int i = 0, size = element.nodeCount(); i < size; i++) { Node node = element.node(i); if (node instanceof Element) { //if it's an element XElement e = (XElement) node; if (e.attributeCount() > 0) { //and it has attributes List attList = e.attributes(); for (int cnt = 0; cnt < attList.size(); ++cnt) { //for each attribute XAttribute newAtt = (XAttribute) attList.get(cnt); int fcnt = findInList(newAtt, attributeList); if (fcnt > -1) { //if the attribute matches the one we are looking for //replace it with the new qname String name = newAtt.getName(); String oldValue = newAtt.getValue(); Namespace ns = newAtt.getNamespace(); attList.set(cnt, new XAttribute(new QName(name, ns), value)); //now remove it from the attributeList to speed up the next searches attributeList.remove(fcnt); } } } treeWalk((Element) node, attributeList, value); } } }
From source file:com.cladonia.xngreditor.actions.ToolsSortNodeAction.java
License:Open Source License
private Vector treeWalk(Element element, List nodeList, Vector nodes) throws Exception { for (int i = 0, size = element.nodeCount(); i < size; i++) { Node node = element.node(i); //search to see if this node is in the nodelist for (int cnt = 0; cnt < nodeList.size(); ++cnt) { if (node == (Node) nodeList.get(cnt)) { //make sure it doesn't already exist in the nodes vector boolean wasFound = false; for (int icnt = 0; icnt < nodes.size(); ++icnt) { if (node == ((NodeInfo) nodes.get(icnt)).getNode()) { wasFound = true; }//from ww w . jav a 2 s.c o m } if (!wasFound) { //set this to the next id Element parent = node.getParent(); int index = parent.indexOf(node); NodeInfo ni = new NodeInfo(originalCounter, parent, node, index); nodes.add(ni); originalCounter++; } } } if (node instanceof Element) { treeWalk((Element) node, nodeList, nodes); } } return (nodes); }
From source file:com.cladonia.xngreditor.actions.ToolsUppercaseAction.java
License:Open Source License
/** * Iterate through the tree and uppercase each node depending on the flags * @param element the element node/*from w w w .jav a 2 s.c o m*/ * @param uppercaseElements uppercase elements flag * @param uppercaseAttributes uppercase attributes flag * @param uppercaseElementsAndAttributes uppercase elements and attributes flag * @throws Exception */ private void iterateTree(Element element, boolean uppercaseElements, boolean uppercaseAttributes, boolean uppercaseElementsAndAttributes) throws Exception { for (int i = 0, size = element.nodeCount(); i < size; i++) { Node oldNode = element.node(i); if (oldNode instanceof Element) { XElement oldElement = (XElement) oldNode; if ((uppercaseAttributes) || (uppercaseElementsAndAttributes)) { oldElement.setAttributes(this.uppercaseAttributes(oldElement)); } //Uppercase the element if (((uppercaseElements) || (uppercaseElementsAndAttributes)) && (oldElement.getName() != null)) { String name = oldElement.getName(); name = uppercaseString(name); Namespace ns = oldElement.getNamespace(); oldElement.setQName(new QName(name, ns)); } iterateTree(oldElement, uppercaseElements, uppercaseAttributes, uppercaseElementsAndAttributes); } } }
From source file:com.doculibre.constellio.services.ConnectorManagerServicesImpl.java
License:Open Source License
@Override public String getConfigFormSnippet(ConnectorManager connectorManager, String connectorType, String connectorName, Locale locale) { Element xml;//from ww w. j a v a2 s . com Map<String, String> paramsMap = new HashMap<String, String>(); paramsMap.put(ServletUtil.QUERY_PARAM_LANG, locale.getLanguage()); if (connectorName == null) { // New connector paramsMap.put(ServletUtil.XMLTAG_CONNECTOR_TYPE, connectorType); xml = ConnectorManagerRequestUtils.sendGet(connectorManager, "/getConfigForm", paramsMap); } else { // Existing connector paramsMap.put(ServletUtil.XMLTAG_CONNECTOR_NAME, connectorName); xml = ConnectorManagerRequestUtils.sendGet(connectorManager, "/getConnectorConfigToEdit", paramsMap); } Element formSnippet = xml.element(ServletUtil.XMLTAG_CONFIGURE_RESPONSE) .element(ServletUtil.XMLTAG_FORM_SNIPPET); CDATA cdata = (CDATA) formSnippet.node(0); String configFormSnippetText = cdata.getStringValue(); return configFormSnippetText; }