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

The following are Jave code examples for showing how to use getNextSibling() 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.
+ Save this method
Example 1
Project: openjdk-jdk10   File: KeyInfo.java   View Source Code Vote up 7 votes
/**
 * Searches the library wide KeyResolvers for public keys
 *
 * @return The public key contained in this Node.
 * @throws KeyResolverException
 */
PublicKey getPublicKeyFromStaticResolvers() throws KeyResolverException {
    Iterator<KeyResolverSpi> it = KeyResolver.iterator();
    while (it.hasNext()) {
        KeyResolverSpi keyResolver = it.next();
        keyResolver.setSecureValidation(secureValidation);
        Node currentChild = this.constructionElement.getFirstChild();
        String uri = this.getBaseURI();
        while (currentChild != null) {
            if (currentChild.getNodeType() == Node.ELEMENT_NODE) {
                for (StorageResolver storage : storageResolvers) {
                    PublicKey pk =
                        keyResolver.engineLookupAndResolvePublicKey(
                            (Element) currentChild, uri, storage
                        );

                    if (pk != null) {
                        return pk;
                    }
                }
            }
            currentChild = currentChild.getNextSibling();
        }
    }
    return null;
}
 
Example 2
Project: jdk8u-jdk   File: ITXtTest.java   View Source Code Vote up 6 votes
private static ITXtTest readFrom(File f) {
    try {
        ImageInputStream iis = ImageIO.createImageInputStream(f);
        ImageReader r = ImageIO.getImageReaders(iis).next();
        r.setInput(iis);

        IIOImage dst = r.readAll(0, null);

        // look for iTXt node
        IIOMetadata m = dst.getMetadata();
        Node root = m.getAsTree(m.getNativeMetadataFormatName());
        Node n = root.getFirstChild();
        while (n != null && !"iTXt".equals(n.getNodeName())) {
            n = n.getNextSibling();
        }
        if (n == null) {
            throw new RuntimeException("No iTXt node!");
        }
        ITXtTest t = ITXtTest.getFromNode((IIOMetadataNode)n);
        return t;
    } catch (Throwable e) {
        throw new RuntimeException("Reading test failed.", e);
    }
}
 
Example 3
Project: xitk   File: XmlUtil.java   View Source Code Vote up 6 votes
public static Element getFirstElementChild(Element element, String namespace,
        String localname) {
    ParamUtil.requireNonNull("element", element);
    ParamUtil.requireNonBlank("localname", localname);
    Node node = element.getFirstChild();
    if (node == null) {
        return null;
    }

    do {
        if (match(node, namespace, localname)) {
            return (Element) node;
        }
        node = node.getNextSibling();
    }
    while (node != null);
    return null;
}
 
Example 4
Project: OpenJSharp   File: TextImpl.java   View Source Code Vote up 6 votes
/**
 * Check if an EntityReference node has Text Only child nodes
 *
 * @param node
 * @return true - Contains text only children
 */
private boolean hasTextOnlyChildren(Node node) {

    Node child = node;

    if (child == null) {
        return false;
    }

    child = child.getFirstChild();
    while (child != null) {
        int type = child.getNodeType();

        if (type == Node.ENTITY_REFERENCE_NODE) {
            return hasTextOnlyChildren(child);
        }
        else if (type != Node.TEXT_NODE
                && type != Node.CDATA_SECTION_NODE
                && type != Node.ENTITY_REFERENCE_NODE) {
            return false;
        }
        child = child.getNextSibling();
    }
    return true;
}
 
Example 5
Project: alevin-svn2   File: XMLUtils.java   View Source Code Vote up 5 votes
/**
 * @param n
 *            The current XML node
 * @return The next sibling that is a {@link Node#ELEMENT_NODE}.
 */
public static Node nextElementNode(Node n) {
	if (isElementNode(n))
		n = n.getNextSibling();

	while (n != null && !isElementNode(n))
		n = n.getNextSibling();

	return n;
}
 
Example 6
Project: jdk8u-jdk   File: KeyInfo.java   View Source Code Vote up 5 votes
/**
 * Searches the library wide KeyResolvers for Private keys
 *
 * @return the private key contained in this KeyInfo
 * @throws KeyResolverException
 */
PrivateKey getPrivateKeyFromStaticResolvers() throws KeyResolverException {
    Iterator<KeyResolverSpi> it = KeyResolver.iterator();
    while (it.hasNext()) {
        KeyResolverSpi keyResolver = it.next();
        keyResolver.setSecureValidation(secureValidation);

        Node currentChild = this.constructionElement.getFirstChild();
        String uri = this.getBaseURI();
        while (currentChild != null)      {
            if (currentChild.getNodeType() == Node.ELEMENT_NODE) {
                // not using StorageResolvers at the moment
                // since they cannot return private keys
                PrivateKey pk =
                    keyResolver.engineLookupAndResolvePrivateKey(
                        (Element) currentChild, uri, null
                    );

                if (pk != null) {
                    return pk;
                }
            }
            currentChild = currentChild.getNextSibling();
        }
    }
    return null;
}
 
Example 7
Project: OpenJSharp   File: IIOMetadataNode.java   View Source Code Vote up 5 votes
private void getElementsByTagName(String name, List l) {
    if (nodeName.equals(name)) {
        l.add(this);
    }

    Node child = getFirstChild();
    while (child != null) {
        ((IIOMetadataNode)child).getElementsByTagName(name, l);
        child = child.getNextSibling();
    }
}
 
Example 8
Project: Tarski   File: mxObjectCodec.java   View Source Code Vote up 5 votes
/**
 * Decodec all children of the given node using decodeChild.
 */
protected void decodeChildren(mxCodec dec, Node node, Object obj) {
  Node child = node.getFirstChild();

  while (child != null) {
    if (child.getNodeType() == Node.ELEMENT_NODE && !processInclude(dec, child, obj)) {
      decodeChild(dec, child, obj);
    }

    child = child.getNextSibling();
  }
}
 
Example 9
Project: OpenJSharp   File: XMLUtils.java   View Source Code Vote up 5 votes
/**
 * Method getFullTextChildrenFromElement
 *
 * @param element
 * @return the string of children
 */
public static String getFullTextChildrenFromElement(Element element) {
    StringBuilder sb = new StringBuilder();

    Node child = element.getFirstChild();
    while (child != null) {
        if (child.getNodeType() == Node.TEXT_NODE) {
            sb.append(((Text)child).getData());
        }
        child = child.getNextSibling();
    }

    return sb.toString();
}
 
Example 10
Project: PackagePlugin   File: DomWriter.java   View Source Code Vote up 5 votes
protected void write(Element node) throws ShellException {
    printWriter.print('<');
    printWriter.print(node.getNodeName());
    Attr attrs[] = sortAttributes(node.getAttributes());
    for (int i = 0; i < attrs.length; i++) {
        Attr attr = attrs[i];
        printWriter.print(' ');
        printWriter.print(attr.getNodeName());
        printWriter.print("=\""); //$NON-NLS-1$
        normalizeAndPrint(attr.getNodeValue(), true);
        printWriter.print('"');
    }
    
    if (node.getChildNodes().getLength() == 0) {
        printWriter.print(" />"); //$NON-NLS-1$
        printWriter.flush();
    } else {
        printWriter.print('>');
        printWriter.flush();

        Node child = node.getFirstChild();
        while (child != null) {
            writeAnyNode(child);
            child = child.getNextSibling();
        }

        printWriter.print("</"); //$NON-NLS-1$
        printWriter.print(node.getNodeName());
        printWriter.print('>');
        printWriter.flush();
    }
}
 
Example 11
Project: openjdk-jdk10   File: PngCreationTimeTest.java   View Source Code Vote up 5 votes
public static void testMergeStandardTree() {
    // Merge a standard metadata tree and inspect creation time
    if (pngMetadata != null) {
        try {
            IIOMetadataNode root = createStandardMetadataNodeTree();

            /*
             * Merge the standard metadata tree created. The data should
             * correctly reflect in the native tree
             */
            pngMetadata.mergeTree("javax_imageio_1.0", root);
            Node keyNode = findNode(pngMetadata.getAsTree("javax_imageio_png_1.0"),
                    "tEXtEntry");
            // Last text entry would contain the merged information
            while (keyNode != null && keyNode.getNextSibling() != null) {
                keyNode = keyNode.getNextSibling();
            }

            if (keyNode != null) {
                // Query the attributes of the node and check for the value
                NamedNodeMap attrMap = keyNode.getAttributes();
                String attrValue = attrMap.getNamedItem("value")
                                          .getNodeValue();
                if (!attrValue.contains("2016")) {
                    // Throw exception. Incorrect year value observed
                    throw new RuntimeException("Test Failed: Incorrect"
                            + " creation time value observed.");
                }
            } else {
                // Throw exception.
                reportExceptionAndFail("Test Failed: Image creation"
                        + " time doesn't exist in metadata.");
            }
        } catch (IOException ex) {
            // Throw exception.
            reportExceptionAndFail("Test Failed: While executing"
                    + " mergeTree on metadata.");
        }
    }
}
 
Example 12
Project: openjdk-jdk10   File: XMLUtils.java   View Source Code Vote up 5 votes
/**
 * @param sibling
 * @param nodeName
 * @param number
 * @return nodes with the constraint
 */
public static Element selectDsNode(Node sibling, String nodeName, int number) {
    while (sibling != null) {
        if (Constants.SignatureSpecNS.equals(sibling.getNamespaceURI())
            && sibling.getLocalName().equals(nodeName)) {
            if (number == 0){
                return (Element)sibling;
            }
            number--;
        }
        sibling = sibling.getNextSibling();
    }
    return null;
}
 
Example 13
Project: jdk8u-jdk   File: XMLUtils.java   View Source Code Vote up 5 votes
/**
 * @param sibling
 * @param nodeName
 * @param number
 * @return nodes with the constrain
 */
public static Element selectXencNode(Node sibling, String nodeName, int number) {
    while (sibling != null) {
        if (EncryptionConstants.EncryptionSpecNS.equals(sibling.getNamespaceURI())
            && sibling.getLocalName().equals(nodeName)) {
            if (number == 0){
                return (Element)sibling;
            }
            number--;
        }
        sibling = sibling.getNextSibling();
    }
    return null;
}
 
Example 14
Project: sstore-soft   File: ParsedUpdateStmt.java   View Source Code Vote up 5 votes
void parseCondition(Node conditionNode, Database db) {
    Node exprNode = conditionNode.getFirstChild();
    while ((exprNode != null) && (exprNode.getNodeType() != Node.ELEMENT_NODE))
        exprNode = exprNode.getNextSibling();
    if (exprNode == null)
        return;
    where = parseExpressionTree(exprNode, db);
    ExpressionUtil.assignLiteralConstantTypesRecursively(where);
    ExpressionUtil.assignOutputValueTypesRecursively(where);
}
 
Example 15
Project: jdk8u-jdk   File: KeyInfo.java   View Source Code Vote up 5 votes
/**
 * Searches the per-KeyInfo KeyResolvers for secret keys
 *
 * @return the secret key contained in this KeyInfo
 * @throws KeyResolverException
 */

SecretKey getSecretKeyFromInternalResolvers() throws KeyResolverException {
    for (KeyResolverSpi keyResolver : internalKeyResolvers) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "Try " + keyResolver.getClass().getName());
        }
        keyResolver.setSecureValidation(secureValidation);
        Node currentChild = this.constructionElement.getFirstChild();
        String uri = this.getBaseURI();
        while (currentChild != null)      {
            if (currentChild.getNodeType() == Node.ELEMENT_NODE) {
                for (StorageResolver storage : storageResolvers) {
                    SecretKey sk =
                        keyResolver.engineLookupAndResolveSecretKey(
                            (Element) currentChild, uri, storage
                        );

                    if (sk != null) {
                        return sk;
                    }
                }
            }
            currentChild = currentChild.getNextSibling();
        }
    }

    return null;
}
 
Example 16
Project: QN-ACTR-Release   File: XMLReader.java   View Source Code Vote up 4 votes
/**
 * Parse router section
 * @param section router section
 * @param model data structure
 * @param key station's key
 */
protected static void parseRouter(Element section, CommonModel model, Object key) {
	Element parameter = (Element) section.getElementsByTagName(XML_E_PARAMETER).item(0);
	Map<String, Node> routing = parseParameterRefclassArray(parameter);
	Object[] classNames = routing.keySet().toArray();
	String className;

	// Creates a Map of Name --> Routing Strategy if needed
	if (engineToGuiRouting == null) {
		engineToGuiRouting = new TreeMap<String, RoutingStrategy>();
		RoutingStrategy[] allRS = RoutingStrategy.findAll();
		for (RoutingStrategy element : allRS) {
			engineToGuiRouting.put(element.getClass().getName(), element);
		}
	}

	Object[] routStratKeys = engineToGuiRouting.keySet().toArray();
	for (Object className2 : classNames) {
		className = ((Element) routing.get(className2)).getAttribute(XML_A_SUBPARAMETER_CLASSPATH);
		// Searches all available routing strategy to find the one saved
		for (Object routStratKey : routStratKeys) {
			if (className.equals(engineToGuiRouting.get(routStratKey).getClassPath())) {
				model.setRoutingStrategy(key, classes.get(className2), engineToGuiRouting.get(routStratKey).clone());
			}
		}

		// Treat particular case of Empirical (Probabilities) Routing
		RoutingStrategy rs = (RoutingStrategy) model.getRoutingStrategy(key, classes.get(className2));
		if (rs instanceof ProbabilityRouting) {
			// Creates a Vector of all empirical entris. Could not be done automaticly
			// for the above problem with array (see parseParameterRefclassArray)
			Vector<Node> entries = new Vector<Node>();
			// Finds EntryArray node
			Node entryArray = routing.get(className2).getFirstChild();
			while (entryArray.getNodeType() != Node.ELEMENT_NODE || !entryArray.getNodeName().equals(XML_E_SUBPARAMETER)) {
				entryArray = entryArray.getNextSibling();
			}
			// Now finds every empirical entry
			Node child = entryArray.getFirstChild();
			while (child != null) {
				// Find first subParameter element
				while (child != null && (child.getNodeType() != Node.ELEMENT_NODE || !child.getNodeName().equals(XML_E_SUBPARAMETER))) {
					child = child.getNextSibling();
				}
				if (child != null) {
					entries.add(child);
					child = child.getNextSibling();
				}
			}
			// For each empirical entry get station name and probability
			for (int j = 0; j < entries.size(); j++) {
				NodeList values = ((Element) entries.get(j)).getElementsByTagName(XML_E_SUBPARAMETER);
				String stationName = findText(((Element) values.item(0)).getElementsByTagName(XML_E_PARAMETER_VALUE).item(0));
				Double probability = Double.valueOf(findText(((Element) values.item(1)).getElementsByTagName(XML_E_PARAMETER_VALUE).item(0)));
				// Now puts the tuple stationName -> probability into a Map, then adds it
				// to empiricalRouting Map. This is needed as at this
				// point we don't have all station's key so will be adjusted latelly
				Map<String, Double> tmp = new TreeMap<String, Double>();
				tmp.put(stationName, probability);
				// Put into empiricalRouting a pair of station key and class key and map with
				// station names instead of station key
				empiricalRouting.put(new Object[] { key, classes.get(className2) }, tmp);
			}
		}
	}
}
 
Example 17
Project: openjdk-jdk10   File: GIFWritableStreamMetadata.java   View Source Code Vote up 4 votes
protected void mergeNativeTree(Node root) throws IIOInvalidTreeException {
    Node node = root;
    if (!node.getNodeName().equals(nativeMetadataFormatName)) {
        fatal(node, "Root must be " + nativeMetadataFormatName);
    }

    node = node.getFirstChild();
    while (node != null) {
        String name = node.getNodeName();

        if (name.equals("Version")) {
            version = getStringAttribute(node, "value", null,
                                         true, versionStrings);
        } else if (name.equals("LogicalScreenDescriptor")) {
            /* NB: At the moment we use empty strings to support undefined
             * integer values in tree representation.
             * We need to add better support for undefined/default values
             * later.
             */
            logicalScreenWidth = getIntAttribute(node,
                                                 "logicalScreenWidth",
                                                 UNDEFINED_INTEGER_VALUE,
                                                 true,
                                                 true, 1, 65535);

            logicalScreenHeight = getIntAttribute(node,
                                                  "logicalScreenHeight",
                                                  UNDEFINED_INTEGER_VALUE,
                                                  true,
                                                  true, 1, 65535);

            colorResolution = getIntAttribute(node,
                                              "colorResolution",
                                              UNDEFINED_INTEGER_VALUE,
                                              true,
                                              true, 1, 8);

            pixelAspectRatio = getIntAttribute(node,
                                               "pixelAspectRatio",
                                               0, true,
                                               true, 0, 255);
        } else if (name.equals("GlobalColorTable")) {
            int sizeOfGlobalColorTable =
                getIntAttribute(node, "sizeOfGlobalColorTable",
                                true, 2, 256);
            if (sizeOfGlobalColorTable != 2 &&
               sizeOfGlobalColorTable != 4 &&
               sizeOfGlobalColorTable != 8 &&
               sizeOfGlobalColorTable != 16 &&
               sizeOfGlobalColorTable != 32 &&
               sizeOfGlobalColorTable != 64 &&
               sizeOfGlobalColorTable != 128 &&
               sizeOfGlobalColorTable != 256) {
                fatal(node,
                      "Bad value for GlobalColorTable attribute sizeOfGlobalColorTable!");
            }

            backgroundColorIndex = getIntAttribute(node,
                                                   "backgroundColorIndex",
                                                   0, true,
                                                   true, 0, 255);

            sortFlag = getBooleanAttribute(node, "sortFlag", false, true);

            globalColorTable = getColorTable(node, "ColorTableEntry",
                                             true, sizeOfGlobalColorTable);
        } else {
            fatal(node, "Unknown child of root node!");
        }

        node = node.getNextSibling();
    }
}
 
Example 18
Project: L2J-Global   File: DocumentBase.java   View Source Code Vote up 4 votes
protected Condition parseCondition(Node n, Object template)
{
	while ((n != null) && (n.getNodeType() != Node.ELEMENT_NODE))
	{
		n = n.getNextSibling();
	}
	
	Condition condition = null;
	if (n != null)
	{
		switch (n.getNodeName().toLowerCase())
		{
			case "and":
			{
				condition = parseLogicAnd(n, template);
				break;
			}
			case "or":
			{
				condition = parseLogicOr(n, template);
				break;
			}
			case "not":
			{
				condition = parseLogicNot(n, template);
				break;
			}
			case "player":
			{
				condition = parsePlayerCondition(n, template);
				break;
			}
			case "target":
			{
				condition = parseTargetCondition(n, template);
				break;
			}
			case "using":
			{
				condition = parseUsingCondition(n);
				break;
			}
			case "game":
			{
				condition = parseGameCondition(n);
				break;
			}
		}
	}
	return condition;
}
 
Example 19
Project: openjdk-jdk10   File: XMLUtils.java   View Source Code Vote up 4 votes
/**
 * This is the work horse for {@link #circumventBug2650}.
 *
 * @param node
 * @see <A HREF="http://nagoya.apache.org/bugzilla/show_bug.cgi?id=2650">
 * Namespace axis resolution is not XPath compliant </A>
 */
@SuppressWarnings("fallthrough")
private static void circumventBug2650internal(Node node) {
    Node parent = null;
    Node sibling = null;
    final String namespaceNs = Constants.NamespaceSpecNS;
    do {
        switch (node.getNodeType()) {
        case Node.ELEMENT_NODE :
            Element element = (Element) node;
            if (!element.hasChildNodes()) {
                break;
            }
            if (element.hasAttributes()) {
                NamedNodeMap attributes = element.getAttributes();
                int attributesLength = attributes.getLength();

                for (Node child = element.getFirstChild(); child!=null;
                    child = child.getNextSibling()) {

                    if (child.getNodeType() != Node.ELEMENT_NODE) {
                        continue;
                    }
                    Element childElement = (Element) child;

                    for (int i = 0; i < attributesLength; i++) {
                        Attr currentAttr = (Attr) attributes.item(i);
                        if (!namespaceNs.equals(currentAttr.getNamespaceURI())) {
                            continue;
                        }
                        if (childElement.hasAttributeNS(namespaceNs,
                                                        currentAttr.getLocalName())) {
                            continue;
                        }
                        childElement.setAttributeNS(namespaceNs,
                                                    currentAttr.getName(),
                                                    currentAttr.getNodeValue());
                    }
                }
            }
        case Node.ENTITY_REFERENCE_NODE :
        case Node.DOCUMENT_NODE :
            parent = node;
            sibling = node.getFirstChild();
            break;
        }
        while ((sibling == null) && (parent != null)) {
            sibling = parent.getNextSibling();
            parent = parent.getParentNode();
        }
        if (sibling == null) {
            return;
        }

        node = sibling;
        sibling = node.getNextSibling();
    } while (true);
}
 
Example 20
Project: openjdk-jdk10   File: DOM3TreeWalker.java   View Source Code Vote up 4 votes
/**
 * Perform a pre-order traversal non-recursive style.
 *
 * Note that TreeWalker assumes that the subtree is intended to represent
 * a complete (though not necessarily well-formed) document and, during a
 * traversal, startDocument and endDocument will always be issued to the
 * SAX listener.
 *
 * @param pos Node in the tree where to start traversal
 *
 * @throws TransformerException
 */
public void traverse(Node pos) throws org.xml.sax.SAXException {
    this.fSerializer.startDocument();

    // Determine if the Node is a DOM Level 3 Core Node.
    if (pos.getNodeType() != Node.DOCUMENT_NODE) {
        Document ownerDoc = pos.getOwnerDocument();
        if (ownerDoc != null
            && ownerDoc.getImplementation().hasFeature("Core", "3.0")) {
            fIsLevel3DOM = true;
        }
    } else {
        if (((Document) pos)
            .getImplementation()
            .hasFeature("Core", "3.0")) {
            fIsLevel3DOM = true;
        }
    }

    if (fSerializer instanceof LexicalHandler) {
        fLexicalHandler = ((LexicalHandler) this.fSerializer);
    }

    if (fFilter != null)
        fWhatToShowFilter = fFilter.getWhatToShow();

    Node top = pos;

    while (null != pos) {
        startNode(pos);

        Node nextNode = null;

        nextNode = pos.getFirstChild();

        while (null == nextNode) {
            endNode(pos);

            if (top.equals(pos))
                break;

            nextNode = pos.getNextSibling();

            if (null == nextNode) {
                pos = pos.getParentNode();

                if ((null == pos) || (top.equals(pos))) {
                    if (null != pos)
                        endNode(pos);

                    nextNode = null;

                    break;
                }
            }
        }

        pos = nextNode;
    }
    this.fSerializer.endDocument();
}