Java Code Examples for org.w3c.dom.Node.getChildNodes()

The following are Jave code examples for showing how to use getChildNodes() of the org.w3c.dom.Node class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: generator_mybatis   File: MyBatisGeneratorConfigurationParser.java   Source Code and License Vote up 8 votes
protected void parseConnectionFactory(Context context, Node node) {
    ConnectionFactoryConfiguration connectionFactoryConfiguration = new ConnectionFactoryConfiguration();

    context.setConnectionFactoryConfiguration(connectionFactoryConfiguration);

    Properties attributes = parseAttributes(node);
    String type = attributes.getProperty("type"); //$NON-NLS-1$

    if (stringHasValue(type)) {
        connectionFactoryConfiguration.setConfigurationType(type);
    }

    NodeList nodeList = node.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node childNode = nodeList.item(i);

        if (childNode.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }

        if ("property".equals(childNode.getNodeName())) { //$NON-NLS-1$
            parseProperty(connectionFactoryConfiguration, childNode);
        }
    }
}
 
Example 2
Project: OpenJSharp   File: ExsltBase.java   Source Code and License Vote up 7 votes
/**
 * Return the string value of a Node
 *
 * @param n The Node.
 * @return The string value of the Node
 */
protected static String toString(Node n)
{
  if (n instanceof DTMNodeProxy)
       return ((DTMNodeProxy)n).getStringValue();
  else
  {
    String value = n.getNodeValue();
    if (value == null)
    {
      NodeList nodelist = n.getChildNodes();
      StringBuffer buf = new StringBuffer();
      for (int i = 0; i < nodelist.getLength(); i++)
      {
        Node childNode = nodelist.item(i);
        buf.append(toString(childNode));
      }
      return buf.toString();
    }
    else
      return value;
  }
}
 
Example 3
Project: oscm   File: KeySelectorFactory.java   Source Code and License Vote up 7 votes
public KeySelector newKeySelector(Node nodeSignature)
        throws DigitalSignatureValidationException {

    Node nodeKeyinfo = getKeyInfoNode(nodeSignature);
    if (nodeKeyinfo == null) {
        throw new DigitalSignatureValidationException(
                "No KeyInfo element found in SAML assertion");
    }

    NodeList children = nodeKeyinfo.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node node = children.item(i);
        if (SamlXmlTags.NODE_KEY_VALUE.equals(node.getLocalName())) {
            return new KeyValueKeySelector();
        } else if (SamlXmlTags.NODE_X509DATA.equals(node.getLocalName())) {
            return new X509KeySelector(keystore);
        }
    }

    throw new DigitalSignatureValidationException(
            "Only RSA/DSA KeyValue and are X509Data supported");
}
 
Example 4
Project: generator_mybatis   File: IbatorConfigurationParser.java   Source Code and License Vote up 7 votes
private void parseIbatorPlugin(Context context, Node node) {
    PluginConfiguration pluginConfiguration = new PluginConfiguration();

    context.addPluginConfiguration(pluginConfiguration);

    Properties attributes = parseAttributes(node);
    String type = attributes.getProperty("type"); //$NON-NLS-1$

    pluginConfiguration.setConfigurationType(type);

    NodeList nodeList = node.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node childNode = nodeList.item(i);

        if (childNode.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }

        if ("property".equals(childNode.getNodeName())) { //$NON-NLS-1$
            parseProperty(pluginConfiguration, childNode);
        }
    }
}
 
Example 5
Project: org.mybatis.generator.core-1.3.5   File: MyBatisGeneratorConfigurationParser.java   Source Code and License Vote up 7 votes
protected void parseJavaTypeResolver(Context context, Node node) {
    JavaTypeResolverConfiguration javaTypeResolverConfiguration = new JavaTypeResolverConfiguration();

    context.setJavaTypeResolverConfiguration(javaTypeResolverConfiguration);

    Properties attributes = parseAttributes(node);
    String type = attributes.getProperty("type"); //$NON-NLS-1$

    if (stringHasValue(type)) {
        javaTypeResolverConfiguration.setConfigurationType(type);
    }

    NodeList nodeList = node.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node childNode = nodeList.item(i);

        if (childNode.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }

        if ("property".equals(childNode.getNodeName())) { //$NON-NLS-1$
            parseProperty(javaTypeResolverConfiguration, childNode);
        }
    }
}
 
Example 6
Project: ccpa   File: TreeOptimizer.java   Source Code and License Vote up 7 votes
private static boolean variableNotUsed(Node root, Node variable)
{
	if (root.getNodeName().equals("value"))
	{
		if (root.isEqualNode(variable))
			return false;
		else
			return true;
	}

	NodeList statements = root.getChildNodes();
	for (int i = 0; i < statements.getLength(); i++)
	{
		Node statement = statements.item(i);
		if (!statement.getNodeName().equals("uses"))
		    if (!variableNotUsed(statement,variable))
		    {
		    	return false;
		    }
	}
	return true;
}
 
Example 7
Project: MybatisGeneatorUtil   File: MyBatisGeneratorConfigurationParser.java   Source Code and License Vote up 6 votes
protected void parseCommentGenerator(Context context, Node node) {
    CommentGeneratorConfiguration commentGeneratorConfiguration = new CommentGeneratorConfiguration();

    context.setCommentGeneratorConfiguration(commentGeneratorConfiguration);

    Properties attributes = parseAttributes(node);
    String type = attributes.getProperty("type"); //$NON-NLS-1$

    if (stringHasValue(type)) {
        commentGeneratorConfiguration.setConfigurationType(type);
    }

    NodeList nodeList = node.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node childNode = nodeList.item(i);

        if (childNode.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }

        if ("property".equals(childNode.getNodeName())) { //$NON-NLS-1$
            parseProperty(commentGeneratorConfiguration, childNode);
        }
    }
}
 
Example 8
Project: whackpad   File: XmlProcessor.java   Source Code and License Vote up 6 votes
private void addTextNodesToRemoveAndTrim(List<Node> toRemove, Node node) {
    if (node instanceof Text) {
        Text text = (Text)node;
        boolean BUG_369394_IS_VALID = false;
        if (!BUG_369394_IS_VALID) {
            text.setData(text.getData().trim());
        } else {
            if (text.getData().trim().length() == 0) {
                text.setData("");
            }
        }
        if (text.getData().length() == 0) {
            toRemove.add(node);
        }
    }
    if (node.getChildNodes() != null) {
        for (int i=0; i<node.getChildNodes().getLength(); i++) {
            addTextNodesToRemoveAndTrim(toRemove, node.getChildNodes().item(i));
        }
    }
}
 
Example 9
Project: jdk8u-jdk   File: JPEGMetadata.java   Source Code and License Vote up 5 votes
void setFromMarkerSequenceNode(Node markerSequenceNode)
    throws IIOInvalidTreeException{

    NodeList children = markerSequenceNode.getChildNodes();
    // for all the children, add a marker segment
    for (int i = 0; i < children.getLength(); i++) {
        Node node = children.item(i);
        String childName = node.getNodeName();
        if (childName.equals("dqt")) {
            markerSequence.add(new DQTMarkerSegment(node));
        } else if (childName.equals("dht")) {
            markerSequence.add(new DHTMarkerSegment(node));
        } else if (childName.equals("dri")) {
            markerSequence.add(new DRIMarkerSegment(node));
        } else if (childName.equals("com")) {
            markerSequence.add(new COMMarkerSegment(node));
        } else if (childName.equals("app14Adobe")) {
            markerSequence.add(new AdobeMarkerSegment(node));
        } else if (childName.equals("unknown")) {
            markerSequence.add(new MarkerSegment(node));
        } else if (childName.equals("sof")) {
            markerSequence.add(new SOFMarkerSegment(node));
        } else if (childName.equals("sos")) {
            markerSequence.add(new SOSMarkerSegment(node));
        } else {
            throw new IIOInvalidTreeException("Invalid "
                + (isStream ? "stream " : "image ") + "child: "
                + childName, node);
        }
    }
}
 
Example 10
Project: geomapapp   File: PathUtil.java   Source Code and License Vote up 5 votes
private static List<Node> getElements(Node node, String elementName) {
	List<Node> list = new LinkedList<Node>();
	NodeList nodeList = node.getChildNodes();
	for (int i = 0; i < nodeList.getLength(); i++) {
		if (nodeList.item(i).getNodeName().equals(elementName)
				&& nodeList.item(i).getNodeType() == Node.ELEMENT_NODE) {
			list.add(nodeList.item(i));
		}	
	}
	return list;
}
 
Example 11
Project: geomapapp   File: ParseBRG.java   Source Code and License Vote up 5 votes
private static String getText(Node node) {
	NodeList nodeList = node.getChildNodes();
	for (int i = 0; i < nodeList.getLength(); i++) {
		if (nodeList.item(i).getNodeName().equals("#text") ||
				nodeList.item(i).getNodeName().equals("#cdata-section"))
		{
			return nodeList.item(i).getNodeValue();
		}
	}
	return null;
}
 
Example 12
Project: OpenJSharp   File: DTMNodeProxy.java   Source Code and License Vote up 5 votes
/**
 *
 * @param tagname
 *
 *
 * @see org.w3c.dom.Document
 */
@Override
public final NodeList getElementsByTagName(String tagname)
{
     Vector listVector = new Vector();
     Node retNode = dtm.getNode(node);
     if (retNode != null)
     {
       boolean isTagNameWildCard = "*".equals(tagname);
       if (DTM.ELEMENT_NODE == retNode.getNodeType())
       {
         NodeList nodeList = retNode.getChildNodes();
         for (int i = 0; i < nodeList.getLength(); i++)
         {
           traverseChildren(listVector, nodeList.item(i), tagname,
                            isTagNameWildCard);
         }
       } else if (DTM.DOCUMENT_NODE == retNode.getNodeType()) {
         traverseChildren(listVector, dtm.getNode(node), tagname,
                          isTagNameWildCard);
       }
     }
     int size = listVector.size();
     NodeSet nodeSet = new NodeSet(size);
     for (int i = 0; i < size; i++)
     {
       nodeSet.addNode((Node) listVector.elementAt(i));
     }
     return (NodeList) nodeSet;
}
 
Example 13
Project: oscm   File: XMLConverter.java   Source Code and License Vote up 5 votes
/**
 * Returns the last child node with the provided name if existing.
 * 
 * @param parentNode
 *            the node to find the wanted child in
 * @param nodeName
 *            the wanted child node name
 * @return the matching child node or <code>null</code> if not found
 */
public static Node getLastChildNode(Node parentNode, String nodeName) {
    NodeList childNodes = parentNode.getChildNodes();
    Node node = null;
    for (int index = 0; index < childNodes.getLength(); index++) {
        if (nodeName.equals(childNodes.item(index).getNodeName())) {
            node = childNodes.item(index);
        }
    }
    return node;
}
 
Example 14
Project: geomapapp   File: XML_Layer.java   Source Code and License Vote up 5 votes
private static Node getElement(Node node, String elementName) {
	NodeList nodeList = node.getChildNodes();
	for (int i = 0; i < nodeList.getLength(); i++) {
		if (nodeList.item(i).getNodeName().equals(elementName)
				&& nodeList.item(i).getNodeType() == Node.ELEMENT_NODE)
			return nodeList.item(i);
	}
	return null;
}
 
Example 15
Project: PackagePlugin   File: AbatorConfigurationParser.java   Source Code and License Vote up 5 votes
private void parseSqlMapGenerator(AbatorContext abatorContext, Node node) {
    SqlMapGeneratorConfiguration sqlMapGeneratorConfiguration = new SqlMapGeneratorConfiguration();

    abatorContext
            .setSqlMapGeneratorConfiguration(sqlMapGeneratorConfiguration);

    Properties attributes = parseAttributes(node);
    String type = attributes.getProperty("type"); //$NON-NLS-1$
    String targetPackage = attributes.getProperty("targetPackage"); //$NON-NLS-1$
    String targetProject = attributes.getProperty("targetProject"); //$NON-NLS-1$

    if (StringUtility.stringHasValue(type)) {
        sqlMapGeneratorConfiguration.setConfigurationType(type);
    }

    sqlMapGeneratorConfiguration.setTargetPackage(targetPackage);
    sqlMapGeneratorConfiguration.setTargetProject(targetProject);

    NodeList nodeList = node.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node childNode = nodeList.item(i);

        if (childNode.getNodeType() != 1) {
            continue;
        }

        if ("property".equals(childNode.getNodeName())) { //$NON-NLS-1$
            parseProperty(sqlMapGeneratorConfiguration, childNode);
        }
    }
}
 
Example 16
Project: jaffa-framework   File: PatternGenerator.java   Source Code and License Vote up 4 votes
/**
 * Create source files based on the contents of an XML file
 * @param tempFileName the temporary file to be parsed, whose contents will
 *                     determine which files get created.
 * @param context contains information needed for processing, including
 *                information from WebMacro.properties and PatternGenerator
 *                properties.
 * @throws PatternGeneratorException
 * @throws ParserConfigurationException
 * @throws SAXException
 * @throws IOException
 * @throws WebMacroException
 * @throws SourceDecomposerException
 */
private void generateSourceFiles(String tempFileName, Context context)
        throws PatternGeneratorException, ParserConfigurationException,
               SAXException, IOException, WebMacroException,
               SourceDecomposerException {
    // parse the tempFileName.. Force XML validation
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);
    DocumentBuilder parser = factory.newDocumentBuilder();
    parser.setEntityResolver(new DefaultEntityResolver());
    parser.setErrorHandler(new DefaultErrorHandler());
    Document document = parser.parse(tempFileName);

    // check for Prerequisites
    // @todo : this currently only supports java files..
    // Need to enhance this logic to support other files too !!
    String preReqErrLog = null;
    Node preReq = document.getElementsByTagName(XML_PREREQUESITES).item(0);
    NodeList classes = preReq.getChildNodes();
    if (classes != null) {
        for (int i = 0; i < classes.getLength(); i++) {
            Node clazz = classes.item(i);
            if (clazz.getNodeType() == Node.ELEMENT_NODE) {
                String requiredClassName = XmlHelper.getTextTrim(clazz);
                try {
                    Class.forName(requiredClassName);
                } catch (ClassNotFoundException e) {
                    if (preReqErrLog == null) {
                        preReqErrLog = "";
                    }
                    preReqErrLog += "Error: PreRequesite Class " +
                                    requiredClassName + " not found\n";
                }
            }
        }
    }
    if (preReqErrLog != null) {
        writeMessage(m_auditFile, preReqErrLog, true);
        throw new PatternGeneratorException(preReqErrLog);
    }
    processComponents(context, document);
}
 
Example 17
Project: fb2parser   File: TitleInfo.java   Source Code and License Vote up 4 votes
TitleInfo(Document document) {
    NodeList description = document.getElementsByTagName("title-info");
    for (int item = 0; item < description.getLength(); item++) {
        NodeList map = description.item(item).getChildNodes();
        for (int index = 0; index < map.getLength(); index++) {
            Node node = map.item(index);
            switch (node.getNodeName()) {
                case "sequence":
                    sequence = new Sequence(node);
                    break;
                case "coverpage":
                    NodeList images = node.getChildNodes();
                    for (int image = 0; image < images.getLength(); image++) {
                        if (images.item(image).getNodeName().equals("image")) {
                            coverPage.add(new Image(images.item(image)));
                        }
                    }
                    break;
                case "annotation":
                    this.annotation = new Annotation(node);
                    break;
                case "date":
                    date = node.getTextContent();
                    break;
                case "author":
                    NodeList authorsList = node.getChildNodes();
                    authors.add(new Author(authorsList));
                    break;
                case "translator":
                    NodeList translatorsList = node.getChildNodes();
                    translators.add(new Author(translatorsList));
                    break;
                case "keywords":
                    keywords.add(node.getTextContent());
                    break;
                case "genre":
                    genre.add(node.getTextContent());
                    break;
                case "book-title":
                    bookTitle = node.getTextContent();
                    break;
                case "lang":
                    lang = node.getTextContent();
                    break;
                case "src-lang":
                    srcLang = node.getTextContent();
                    break;
            }
        }
    }
}
 
Example 18
Project: openjdk-jdk10   File: JPEGMetadata.java   Source Code and License Vote up 4 votes
/**
 * Merge the given DHT node into the marker sequence.  If there already
 * exist DHT marker segments in the sequence, then each table in the
 * node replaces the first table, in any DHT segment, with the same
 * table class and table id.  If none of the existing DHT segments contain
 * a table with the same class and id, then the table is added to the last
 * existing DHT segment.
 * If there are no DHT segments, then a new one is created and added
 * as follows:
 * If there are DQT segments, the new DHT segment is inserted immediately
 * following the last DQT segment.
 * If there are no DQT segments, the new DHT segment is inserted before
 * an SOF segment, if there is one.
 * If there is no SOF segment, the new DHT segment is inserted before
 * the first SOS segment, if there is one.
 * If there is no SOS segment, the new DHT segment is added to the end
 * of the sequence.
 */
private void mergeDHTNode(Node node) throws IIOInvalidTreeException {
    // First collect any existing DQT nodes into a local list
    ArrayList<DHTMarkerSegment> oldDHTs = new ArrayList<>();
    Iterator<MarkerSegment> iter = markerSequence.iterator();
    while (iter.hasNext()) {
        MarkerSegment seg = iter.next();
        if (seg instanceof DHTMarkerSegment) {
            oldDHTs.add((DHTMarkerSegment) seg);
        }
    }
    if (!oldDHTs.isEmpty()) {
        NodeList children = node.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            NamedNodeMap attrs = child.getAttributes();
            int childID = MarkerSegment.getAttributeValue(child,
                                                          attrs,
                                                          "htableId",
                                                          0, 3,
                                                          true);
            int childClass = MarkerSegment.getAttributeValue(child,
                                                             attrs,
                                                             "class",
                                                             0, 1,
                                                             true);
            DHTMarkerSegment dht = null;
            int tableIndex = -1;
            for (int j = 0; j < oldDHTs.size(); j++) {
                DHTMarkerSegment testDHT = oldDHTs.get(j);
                for (int k = 0; k < testDHT.tables.size(); k++) {
                    DHTMarkerSegment.Htable testTable = testDHT.tables.get(k);
                    if ((childID == testTable.tableID) &&
                        (childClass == testTable.tableClass)) {
                        dht = testDHT;
                        tableIndex = k;
                        break;
                    }
                }
                if (dht != null) break;
            }
            if (dht != null) {
                dht.tables.set(tableIndex, dht.getHtableFromNode(child));
            } else {
                dht = oldDHTs.get(oldDHTs.size()-1);
                dht.tables.add(dht.getHtableFromNode(child));
            }
        }
    } else {
        DHTMarkerSegment newGuy = new DHTMarkerSegment(node);
        int lastDQT = findMarkerSegmentPosition(DQTMarkerSegment.class, false);
        int firstSOF = findMarkerSegmentPosition(SOFMarkerSegment.class, true);
        int firstSOS = findMarkerSegmentPosition(SOSMarkerSegment.class, true);
        if (lastDQT != -1) {
            markerSequence.add(lastDQT+1, newGuy);
        } else if (firstSOF != -1) {
            markerSequence.add(firstSOF, newGuy);
        } else if (firstSOS != -1) {
            markerSequence.add(firstSOS, newGuy);
        } else {
            markerSequence.add(newGuy);
        }
    }
}
 
Example 19
Project: QN-ACTR-Release   File: WorkloadResultLoader.java   Source Code and License Vote up 4 votes
public int loadResult(ZipFile zf, NodeList resultNodeList, JwatSession session) throws IOException {
	int i, nclustLoaded = 0, numSave;
	Node tmpNode;
	Clustering tmpClust = null;
	String name, algo, numCluster, varSel;
	int varSelLst[];
	waSession = (WorkloadAnalysisSession) session;

	ArrayList resultList = new ArrayList();
	tmpNode = resultNodeList.item(0);
	numSave = Integer.parseInt(tmpNode.getAttributes().getNamedItem("num").getNodeValue());
	resultNodeList = tmpNode.getChildNodes();

	for (i = 0; i < resultNodeList.getLength(); i++) {
		tmpNode = resultNodeList.item(i);
		//System.out.println("Clustering:");
		if (tmpNode.getNodeType() == Node.ELEMENT_NODE) {
			algo = tmpNode.getAttributes().getNamedItem("algo").getNodeValue();
			//System.out.println("TIPO " + algo);

			name = tmpNode.getAttributes().getNamedItem("name").getNodeValue();
			//System.out.println("NOME " + name);

			numCluster = tmpNode.getAttributes().getNamedItem("numcluster").getNodeValue();
			//System.out.println("NUMCLUSTER " + numCluster);

			varSel = tmpNode.getAttributes().getNamedItem("varsel").getNodeValue();
			//System.out.println("VARSEL " + varSel);

			varSelLst = parseVarsSel(varSel);
			switch (Integer.parseInt(algo)) {
				case JWATConstants.KMEANS:
					tmpClust = loadKmeanResult(Integer.parseInt(numCluster), varSelLst, name + "_" + nclustLoaded + JwatSession.BINext, zf);
					break;
				case JWATConstants.FUZZYK:
					tmpClust = loadFuzzyResult(Integer.parseInt(numCluster), varSelLst, name + "_" + nclustLoaded + JwatSession.BINext, zf);
					break;

				default:
					System.out.println("ALGORITHM NOT DEFINED");
					break;
			}

			waSession.addClustering(tmpClust);
			nclustLoaded++;
		}

	}
	return nclustLoaded;
}
 
Example 20
Project: rest-jersey2-json-jwt-authentication   File: DbConfig.java   Source Code and License Vote up 3 votes
private static String getSingleElement( Element element, String tagName ) {
	Node tagNameNode = element.getElementsByTagName( tagName ).item(0);
	
	if( tagNameNode == null ) 
		return null;
	
	NodeList tagNameNodeChildren = tagNameNode.getChildNodes();
	
	if( tagNameNodeChildren == null || tagNameNodeChildren.getLength() == 0 )
		return null;
	
	return tagNameNodeChildren.item(0).getNodeValue().toLowerCase(); 
}