Java Code Examples for org.dom4j.Element#nodeCount()

The following examples show how to use org.dom4j.Element#nodeCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XmlInputFieldsImportProgressDialog.java    From hop with Apache License 2.0 6 votes vote down vote up
private boolean childNode( Node node, IProgressMonitor monitor ) {
  boolean rc = false; // true: we found child nodes
  Element ce = (Element) node;
  // List child
  for ( int j = 0; j < ce.nodeCount(); j++ ) {
    Node cnode = ce.node( j );
    if ( !Utils.isEmpty( cnode.getName() ) ) {
      Element cce = (Element) cnode;
      if ( cce.nodeCount() > 1 ) {
        if ( childNode( cnode, monitor ) == false ) {
          // We do not have child nodes ...
          setNodeField( cnode, monitor );
          rc = true;
        }
      } else {
        setNodeField( cnode, monitor );
        rc = true;
      }
    }
  }
  return rc;
}
 
Example 2
Source File: Tools.java    From testing_platform with Apache License 2.0 6 votes vote down vote up
private static void read(Element e) {
    String result = "";
    if( !"".equals(targetPath) ){
        return ;
    }
    if (e.nodeCount() > 0) {
        Iterator<Element> it = e.elementIterator();
        while (it.hasNext()) {
            Element ele = it.next();
            if( "CSVDataSet".equals(ele.getName()) ){
                /*if("".equals(targetPath)){ //查到的第一个 CSVDataSet 保存到参数中,
                    targetPath = ele.getUniquePath();
                }*/
                targetPath = ele.getUniquePath();
            }
            read(ele);
        }
    }

}
 
Example 3
Source File: XMLInputFieldsImportProgressDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private boolean childNode( Node node, IProgressMonitor monitor ) {
  boolean rc = false; // true: we found child nodes
  Element ce = (Element) node;
  // List child
  for ( int j = 0; j < ce.nodeCount(); j++ ) {
    Node cnode = ce.node( j );
    if ( !Utils.isEmpty( cnode.getName() ) ) {
      Element cce = (Element) cnode;
      if ( cce.nodeCount() > 1 ) {
        if ( childNode( cnode, monitor ) == false ) {
          // We do not have child nodes ...
          setNodeField( cnode, monitor );
          rc = true;
        }
      } else {
        setNodeField( cnode, monitor );
        rc = true;
      }
    }
  }
  return rc;
}
 
Example 4
Source File: LoopNodesImportProgressDialog.java    From hop with Apache License 2.0 5 votes vote down vote up
private void addLoopXPath( Node node, IProgressMonitor monitor ) {
  Element ce = (Element) node;
  monitor.worked( 1 );
  // List child
  for ( int j = 0; j < ce.nodeCount(); j++ ) {
    if ( monitor.isCanceled() ) {
      return;
    }
    Node cnode = ce.node( j );

    if ( !Utils.isEmpty( cnode.getName() ) ) {
      Element cce = (Element) cnode;
      if ( !listpath.contains( cnode.getPath() ) ) {
        nr++;
        monitor.subTask( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.FetchNodes",
            String.valueOf( nr ) ) );
        monitor.subTask( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.AddingNode",
            cnode.getPath() ) );
        listpath.add( cnode.getPath() );
      }
      // let's get child nodes
      if ( cce.nodeCount() > 1 ) {
        addLoopXPath( cnode, monitor );
      }
    }
  }
}
 
Example 5
Source File: SiteServiceImpl.java    From studio with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private  Map<String, Object> createMap(Element element) {
	Map<String, Object> map = new HashMap<String, Object>();
	for ( int i = 0, size = element.nodeCount(); i < size; i++ ) {
		Node currentNode = element.node(i);
		if ( currentNode instanceof Element ) {
			Element currentElement = (Element)currentNode;
			String key = currentElement.getName();
			Object toAdd = null;
			if (currentElement.isTextOnly()) {
				 toAdd = currentElement.getStringValue();
			} else {
				toAdd = createMap(currentElement);
			}
			if (map.containsKey(key)) {
				Object value = map.get(key);
				List listOfValues = new ArrayList<Object>();
				if (value instanceof List) {
					listOfValues = (List<Object>)value;
				} else {
					listOfValues.add(value);
				}
				listOfValues.add(toAdd);
				map.put(key, listOfValues);
			} else {
				map.put(key, toAdd);
			}
		}
	}
	return map;
}
 
Example 6
Source File: LoopNodesImportProgressDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private void addLoopXPath( Node node, IProgressMonitor monitor ) {
  Element ce = (Element) node;
  monitor.worked( 1 );
  // List child
  for ( int j = 0; j < ce.nodeCount(); j++ ) {
    if ( monitor.isCanceled() ) {
      return;
    }
    Node cnode = ce.node( j );

    if ( !Utils.isEmpty( cnode.getName() ) ) {
      Element cce = (Element) cnode;
      if ( !listpath.contains( cnode.getPath() ) ) {
        nr++;
        monitor.subTask( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.FetchNodes",
            String.valueOf( nr ) ) );
        monitor.subTask( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.AddingNode",
            cnode.getPath() ) );
        listpath.add( cnode.getPath() );
      }
      // let's get child nodes
      if ( cce.nodeCount() > 1 ) {
        addLoopXPath( cnode, monitor );
      }
    }
  }
}
 
Example 7
Source File: RESTUtil.java    From rest-client with Apache License 2.0 4 votes vote down vote up
/**
* 
* @Title: xmlTree 
* @Description: To generate a XML tree 
* @param @param e
* @param @param layer
* @param @param sb 
* @return void
* @throws
 */
public static void xmlTree(Element e, int layer, StringBuilder sb)
{
    if (e.nodeCount() <= 0)
    {
        return;
    }

    String spaces = "    ";
    String vertLine = "│   ";
    String line = RESTConst.LINE;
    String type = RESTConst.UNKNOWN;
    String indent = dup(layer, spaces);

    layer++;
    if (layer <= 0)
    {
        line = "   ";
    }

    @SuppressWarnings("unchecked")
    List<Element> es = e.elements();
    for (Element ce : es)
    {
        indent = dup(layer, spaces);
        if (layer >= 2)
        {
            indent = dup(1, spaces) + dup(layer - 1, vertLine);
        }

        if (!ce.elements().isEmpty() || ce.attributeCount() > 0)
        {
            type = Object.class.getSimpleName();
        }
        else if (StringUtils.isNotEmpty(ce.getText()) && StringUtils.isNumeric(ce.getStringValue()))
        {
            type = Number.class.getSimpleName();
        }
        else
        {
            type = String.class.getSimpleName();
        }

        /* Element */
        sb.append(indent).append(line)
          .append(ce.getName()).append(" [")
          .append(type.toLowerCase())
          .append("]").append(lines(1));

        /* Attributes */
        if (ce.attributeCount() > 0)
        {
            indent = dup(layer + 1, spaces);
            if (layer + 1 >= 2)
            {
                indent = dup(1, spaces) + dup(layer, vertLine);
            }

            @SuppressWarnings("unchecked")
            List<Attribute> as = ce.attributes();
            for (Attribute a : as)
            {
                if (StringUtils.isNotEmpty(ce.getText()) && StringUtils.isNumeric(a.getValue()))
                {
                    type = Number.class.getSimpleName();
                }
                else
                {
                    type = String.class.getSimpleName();
                }
                
                sb.append(indent).append(RESTConst.LINE)
                  .append(a.getName()).append(" [")
                  .append(type.toLowerCase())
                  .append("]").append(lines(1));
            }
        }

        xmlTree(ce, layer, sb);
    }
}
 
Example 8
Source File: LowercaseTableNames.java    From unitime with Apache License 2.0 4 votes vote down vote up
protected void writeElement(Element element) throws IOException {
    int size = element.nodeCount();
    String qualifiedName = element.getQualifiedName();

    writePrintln();
    indent();

    writer.write("<");
    writer.write(qualifiedName);

    boolean textOnly = true;

    for (int i = 0; i < size; i++) {
        Node node = element.node(i);
        if (node instanceof Element) {
            textOnly = false;
        } else if (node instanceof Comment) {
            textOnly = false;
        }
    }

    writeAttributes(element);

    lastOutputNodeType = Node.ELEMENT_NODE;

    if (size <= 0) {
        writeEmptyElementClose(qualifiedName);
    } else {
        writer.write(">");

        if (textOnly) {
            // we have at least one text node so lets assume
            // that its non-empty
            writeElementContent(element);
        } else {
        	if (element.attributeCount() > 3)
        		writePrintln();
            // we know it's not null or empty from above
            ++indentLevel;

            writeElementContent(element);

            --indentLevel;

            writePrintln();
            indent();
        }

        writer.write("</");
        writer.write(qualifiedName);
        writer.write(">");
    }
   	if (element.attributeCount() > 2 && indentLevel > 0)
   		writePrintln();

    lastOutputNodeType = Node.ELEMENT_NODE;
}
 
Example 9
Source File: XmlUtil.java    From fixflow with Apache License 2.0 2 votes vote down vote up
public static boolean hasChild(Element element) {

		return element.nodeCount() > 0;

	}