List of usage examples for org.dom4j Element nodeCount
int nodeCount();
Node
instances that this branch contains. From source file:com.globalsight.everest.tm.util.ttx.TtxToTmx.java
License:Apache License
/** * Finds TTX formatting elements (DF).//from w w w.ja va2 s . com */ private void findDfElements(ArrayList p_result, Element p_element) { for (int i = 0, max = p_element.nodeCount(); i < max; i++) { Node child = (Node) p_element.node(i); if (child instanceof Element) { findDfElements(p_result, (Element) child); } } String name = p_element.getName(); if (name.equals(Ttx.DF)) { p_result.add(p_element); } }
From source file:com.globalsight.everest.tm.util.ttx.TtxToTmx.java
License:Apache License
/** * Finds TTX/TMX unknown tag elements (UT). *///from ww w .j a v a 2 s . com private void findUtElements(ArrayList p_result, Element p_element) { for (int i = 0, max = p_element.nodeCount(); i < max; i++) { Node child = (Node) p_element.node(i); if (child instanceof Element) { findUtElements(p_result, (Element) child); } } String name = p_element.getName(); if (name.equals(Ttx.UT)) { p_result.add(p_element); } }
From source file:com.globalsight.ling.docproc.DiplomatWordCounter.java
License:Apache License
private void findSubElements(ArrayList p_result, Element p_element) { // Depth-first traversal: add embedded <sub> to the list first. for (int i = 0, max = p_element.nodeCount(); i < max; i++) { Node child = (Node) p_element.node(i); if (child instanceof Element) { findSubElements(p_result, (Element) child); }//from ww w.java 2 s.c o m } if (p_element.getName().equals(DiplomatNames.Element.SUB)) { p_result.add(p_element); } }
From source file:com.globalsight.terminology.indexer.Writer.java
License:Apache License
private void getIndexableText(Element p_root, ArrayList p_result) { if (p_root == null || p_root.nodeCount() == 0) { return;//from w w w.j ava 2 s. c o m } List elements = p_root.elements(); for (int i = 0, max = elements.size(); i < max; i++) { Element elem = (Element) elements.get(i); String name = elem.getName(); Element field = null; String type = null; if (name.equals("descripGrp")) { getIndexableText(elem, p_result); } else if (name.equals("sourceGrp")) { getIndexableText(elem, p_result); } else if (name.equals("noteGrp")) { getIndexableText(elem, p_result); } else if (name.equals("descrip")) { field = elem; type = field.attributeValue("type"); } else if (name.equals("source")) { field = elem; type = "source"; } else if (name.equals("note")) { field = elem; type = "note"; } if (field == null || type == null) { continue; } if (isIndexableField(type)) { p_result.add(EntryUtils.getInnerText(field)); } } }
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 w ww .ja va 2s . c om*/ } }
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 w ww. ja va 2 s . c om */ 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//from w ww. j a v a 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 ww . j a va2 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 w ww .j a v a 2 s .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 w ww . ja v a2s.c o m*/ } childs.add(index, child); parent.setContent(childs); }