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.haulmont.cuba.core.app.EntitySnapshotManager.java
License:Apache License
protected void replaceInXmlTree(Element element, Map<Class, Class> classMapping) { for (int i = 0; i < element.nodeCount(); i++) { Node node = element.node(i); if (node instanceof Element) { Element childElement = (Element) node; replaceClasses(childElement, classMapping); replaceInXmlTree(childElement, classMapping); }//from ww w .j av a 2 s .com } }
From source file:com.smartwork.im.utils.XMLWriter.java
License:Open Source License
/** Outputs the content of the given element. If whitespace trimming is * enabled then all adjacent text nodes are appended together before * the whitespace trimming occurs to avoid problems with multiple * text nodes being created due to text content that spans parser buffers * in a SAX parser.//from ww w . j a v a 2 s. co m */ protected void writeElementContent(Element element) throws IOException { boolean trim = format.isTrimText(); boolean oldPreserve = preserve; if (trim) { //verify we have to before more expensive test preserve = isElementSpacePreserved(element); trim = !preserve; } if (trim) { // concatenate adjacent text nodes together // so that whitespace trimming works properly Text lastTextNode = null; StringBuilder buffer = null; boolean textOnly = true; for (int i = 0, size = element.nodeCount(); i < size; i++) { Node node = element.node(i); if (node instanceof Text) { if (lastTextNode == null) { lastTextNode = (Text) node; } else { if (buffer == null) { buffer = new StringBuilder(lastTextNode.getText()); } buffer.append(((Text) node).getText()); } } else { if (!textOnly && format.isPadText()) { writer.write(PAD_TEXT); } textOnly = false; if (lastTextNode != null) { if (buffer != null) { writeString(buffer.toString()); buffer = null; } else { writeString(lastTextNode.getText()); } lastTextNode = null; if (format.isPadText()) { writer.write(PAD_TEXT); } } writeNode(node); } } if (lastTextNode != null) { if (!textOnly && format.isPadText()) { writer.write(PAD_TEXT); } if (buffer != null) { writeString(buffer.toString()); buffer = null; } else { writeString(lastTextNode.getText()); } lastTextNode = null; } } else { Node lastTextNode = null; for (int i = 0, size = element.nodeCount(); i < size; i++) { Node node = element.node(i); if (node instanceof Text) { writeNode(node); lastTextNode = node; } else { if ((lastTextNode != null) && format.isPadText()) { writer.write(PAD_TEXT); } writeNode(node); if ((lastTextNode != null) && format.isPadText()) { writer.write(PAD_TEXT); } lastTextNode = null; } } } preserve = oldPreserve; }
From source file:com.taobao.sqlautoreview.XmlToSQL.java
License:Open Source License
/** * SQL MAP,SQL// www .j a va 2 s .c om * * @throws DocumentException */ private void readSqlMap() throws DocumentException { Element root; if (sqlmapfilename == null) return; try { Document dom = loadXml(sqlmapfilename); root = dom.getRootElement(); if (root == null) { logger.error("can not find sql map file xml root node,sqlautoreview program exit."); return; } } catch (FileNotFoundException e) { logger.error("the sql-map-file don't exist,please check the path."); return; } // SQL dealInclude(root); //Element Element sqlElement = null; // int max_loop_count = 0; //SQL String real_sql; //SQL String commentString = ""; // for (int i = 0; i < root.nodeCount(); i++) { //,100000, max_loop_count++; if (max_loop_count > 100000) { logger.error( "the sql map file has more than 100000 sqls.Sql reveiw exit. Please check the sql map file."); break; } Node node = root.node(i); if (node instanceof Element) { sqlElement = (Element) node; } else { continue; } //SQL:select,update,delete,insert if (sqlElement.getName().equals("select") || sqlElement.getName().equals("update") || sqlElement.getName().equals("delete") || sqlElement.getName().equals("insert")) { real_sql = formatSql(getRealSQL(sqlElement)); //SQL real_sql = preDealSql(real_sql); logger.info("java class id=" + sqlElement.attributeValue("id") + " sql=" + real_sql); //, real_sql = real_sql.replace("'", "''"); //sql_xml String sql_xml = sqlElement.asXML(); sql_xml = sql_xml.replace("'", "''"); //SQL MAPcomment if (root.node(i - 1) != null && root.node(i - 1) instanceof Comment) { commentString = root.node(i - 1).asXML(); commentString = commentString.replace("'", "''"); } // wsdb.insertDB(sqlmap_file_id, sqlElement.attributeValue("id"), sql_xml, real_sql, commentString); } commentString = ""; } }
From source file:com.thinkberg.moxo.dav.PropPatchHandler.java
License:Apache License
private void setProperty(Element root, FileObject object, Element el) { List propList = el.elements(); for (Object propElObject : propList) { Element propEl = (Element) propElObject; for (int i = 0; i < propEl.nodeCount(); i++) { propEl.node(i).detach(); }//from w w w . j av a 2 s. c o m root.add(propEl.detach()); } }
From source file:com.webarch.common.io.xml.XMLEditor.java
License:Apache License
public static int indexOf(Element rootElement, Node child) { int index = -1; for (int i = 0; i < rootElement.nodeCount(); i++) { if (rootElement.node(i).equals(child)) { index = i;/*from www .j a va2s . co m*/ } } return index; }
From source file:com.webarch.common.io.xml.XMLEditor.java
License:Apache License
public void insertElement(final Element parent, final Node child, int index) { final List childs = new ArrayList(); for (int i = 0; i < parent.nodeCount(); i++) { childs.add(parent.node(i)); }/*from www . j a v a2 s . c o m*/ childs.add(index, child); parent.setContent(childs); }
From source file:com.xpn.xwiki.pdf.impl.PdfExportImpl.java
License:Open Source License
/** * Recursively inline the computed style that applies to a DOM Element into the {@code style} attribute of that * Element.//from w w w . j a va 2 s. co m * * @param element the Element whose style should be inlined */ private void applyInlineStyle(Element element) { for (int i = 0; i < element.nodeCount(); i++) { org.dom4j.Node node = element.node(i); if (node instanceof CSSStylableElement) { CSSStylableElement styleElement = (CSSStylableElement) node; CSSStyleDeclaration style = styleElement.getComputedStyle(); if (style != null && StringUtils.isNotEmpty(style.getCssText())) { styleElement.addAttribute("style", styleElement.getComputedStyle().getCssText()); } } if (node instanceof Element) { applyInlineStyle((Element) node); } } }
From source file:com.zimbra.common.soap.DomUtil.java
License:Open Source License
/** * return the first child element in the specified element, or null * if it has no children./*from w ww . j av a 2 s.c o m*/ * @param e * @return */ public static Element firstChild(Element e) { for (int i = 0; i < e.nodeCount(); i++) { if (e.node(i) instanceof Element) return (Element) e.node(i); } return null; }
From source file:edu.umd.cs.marmoset.utilities.ParseWebXml.java
License:Apache License
public static ParseWebXml parse(String webXmlFileName) throws FileNotFoundException, DocumentException { File file = new File(webXmlFileName); FileInputStream fis = new FileInputStream(file); SAXReader reader = new SAXReader(); Document document = reader.read(fis); ParseWebXml webXml = new ParseWebXml(); Element root = document.getRootElement(); for (Iterator<?> ii = root.elementIterator("servlet-mapping"); ii.hasNext();) { Element elt = (Element) ii.next(); //System.out.print("name: " +elt.getName()); String urlPattern = null; String servletName = null; for (int jj = 0; jj < elt.nodeCount(); jj++) { Node node = elt.node(jj); if (node.getName() == null) continue; if (node.getName().equals(SERVLET_NAME)) { servletName = node.getText().trim(); if (webXml.tryToMapServlet(servletName, urlPattern)) break; } else if (node.getName().equals(SERVLET_URL_PATTERN)) { urlPattern = node.getText().trim(); if (webXml.tryToMapServlet(servletName, urlPattern)) break; }//from w w w. java 2 s .c o m } //System.out.println(" is mapped thusly: " +servletName +" => "+ urlPattern); } for (Iterator<?> ii = root.elementIterator("filter-mapping"); ii.hasNext();) { Element elt = (Element) ii.next(); //System.out.print("name: " +elt.getName()); String filterName = null; String urlPattern = null; for (int jj = 0; jj < elt.nodeCount(); jj++) { Node node = elt.node(jj); if (node.getName() == null) continue; if (node.getName().equals(FILTER_NAME)) { filterName = node.getText().trim(); if (webXml.tryToCreateFilter(filterName, urlPattern)) break; } else if (node.getName().equals(FILTER_URL_PATTERN)) { urlPattern = node.getText().trim(); if (webXml.tryToCreateFilter(filterName, urlPattern)) break; } } //System.out.println(" is mapped thusly: " +filterName+ " => "+ urlPattern); } return webXml; }
From source file:meddle.RString.java
License:Open Source License
public void treeWalk(Element element) { for (int i = 0, size = element.nodeCount(); i < size; i++) { Node node = element.node(i); if (node == null) continue; if (node instanceof Element) { treeWalk((Element) node); } else {//w w w . j a va 2s . com if (node.getParent() == null) continue; Util.debug(node.getParent().getName() + "\t" + node.getText()); String term = node.getParent().getName() + "=" + node.getText(); xmlTerms.add(term); } } }