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

The following are Jave code examples for showing how to use getUserData() 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: javaide   File: MergerXmlUtils.java   Source Code and License Vote up 6 votes
/**
 * Extracts the origin {@link File} that {@link #parseDocument(File, IMergerLog,
 * ManifestMerger)} added to the XML document or the string added by
 *
 * @param xmlNode Any node from a document returned by {@link #parseDocument(File, IMergerLog,
 *              ManifestMerger)}.
 * @return The {@link File} object used to create the document or null.
 */
@Nullable
static String extractXmlFilename(@Nullable Node xmlNode) {
    if (xmlNode != null && xmlNode.getNodeType() != Node.DOCUMENT_NODE) {
        xmlNode = xmlNode.getOwnerDocument();
    }
    if (xmlNode != null) {
        Object data = xmlNode.getUserData(DATA_ORIGIN_FILE);
        if (data instanceof File) {
            return ((File) data).getPath();
        }
        data = xmlNode.getUserData(DATA_FILE_NAME);
        if (data instanceof String) {
            return (String) data;
        }
    }

    return null;
}
 
Example 2
Project: camel-language-server   File: ParserFileHelper.java   Source Code and License Vote up 6 votes
private Node findElementAtLine(int line, Node node) {
	if(CAMEL_NODES_TAG.contains(node.getNodeName())) {
		return node;
	}
	NodeList childNodes = node.getChildNodes();
	for (int i = 0; i < childNodes.getLength(); i++) {
		Node childNode = childNodes.item(i);
		String nodeLineStart = (String)childNode.getUserData(XmlLineNumberParser.LINE_NUMBER);
		String nodeLineEnd = (String)childNode.getUserData(XmlLineNumberParser.LINE_NUMBER_END);
		// -1 is due to Camel XMLLineParser which is starting index at 1 although LSP is starting at 0
		if (nodeLineStart != null && nodeLineEnd != null && isBetween(line, Integer.parseInt(nodeLineStart) - 1, Integer.parseInt(nodeLineEnd) - 1)) {
			return findElementAtLine(line, childNode);
		}
	}
	return null;
}
 
Example 3
Project: openjdk-jdk10   File: SOAPDocumentImpl.java   Source Code and License Vote up 6 votes
public void registerChildNodes(Node parentNode, boolean deep) {
    if (parentNode.getUserData(SAAJ_NODE) == null) {
        if (parentNode instanceof Element) {
            ElementFactory.createElement(this, (Element) parentNode);
        } else if (parentNode instanceof CharacterData) {
            switch (parentNode.getNodeType()) {
                case CDATA_SECTION_NODE:
                    new CDATAImpl(this, (CharacterData) parentNode);
                    break;
                case COMMENT_NODE:
                    new SOAPCommentImpl(this, (CharacterData) parentNode);
                    break;
                case TEXT_NODE:
                    new SOAPTextImpl(this, (CharacterData) parentNode);
                    break;
            }
        }
    }
    if (deep) {
        NodeList nodeList = parentNode.getChildNodes();
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node nextChild = nodeList.item(i);
            registerChildNodes(nextChild, true);
        }
    }
}
 
Example 4
Project: alvisnlp   File: XMLWriter2ForINIST.java   Source Code and License Vote up 5 votes
private static final Element getElement(Node node) {
    for (Node n = node; n != null; n = n.getParentNode()) {
        Object result = node.getUserData(ELEMENT_USER_DATA);
        if (result != null) {
            return (Element) result;
        }
    }
    return null;
}
 
Example 5
Project: alvisnlp   File: XMLWriter.java   Source Code and License Vote up 5 votes
private static final Element getElement(Node node) {
	for (Node n = node; n != null; n = n.getParentNode()) {
		Object result = node.getUserData(ELEMENT_USER_DATA);
		if (result != null)
			return (Element) result;
	}
	return null;
}
 
Example 6
Project: convertigo-engine   File: Sequence.java   Source Code and License Vote up 5 votes
private static Node cloneNodeWithUserData(Node node, boolean recurse) {
	if (node != null) {
		Object node_output = node.getUserData(Step.NODE_USERDATA_OUTPUT);

		Node clonedNode = node.cloneNode(false);
		clonedNode.setUserData(Step.NODE_USERDATA_OUTPUT, node_output, null);
		
		if (node.getNodeType() == Node.ELEMENT_NODE) {
			// attributes
			NamedNodeMap attributeMap = clonedNode.getAttributes();
			for (int i=0; i< attributeMap.getLength(); i++) {
				Node clonedAttribute = attributeMap.item(i);
				String attr_name = clonedAttribute.getNodeName();
				Object attr_output = ((Element)node).getAttributeNode(attr_name).getUserData(Step.NODE_USERDATA_OUTPUT);
				clonedAttribute.setUserData(Step.NODE_USERDATA_OUTPUT, attr_output, null);
			}
			
			// recurse on element child nodes only
			if (recurse && node.hasChildNodes()) {
				NodeList list = node.getChildNodes();
				for (int i=0; i<list.getLength(); i++) {
					Node clonedChild = cloneNodeWithUserData(list.item(i), recurse);
					if (clonedChild != null) {
						clonedNode.appendChild(clonedChild);
					}
				}
			}
		}
		
		return clonedNode;
	}
	return null;
}
 
Example 7
Project: javaide   File: MergerXmlUtils.java   Source Code and License Vote up 5 votes
/**
 * Extracts the line number that {@link #findLineNumbers} added to the XML nodes.
 *
 * @param xmlNode Any node from a document returned by {@link #parseDocument(File, IMergerLog,
 *                ManifestMerger)}.
 * @return The line number if found or 0.
 */
static int extractLineNumber(@Nullable Node xmlNode) {
    if (xmlNode != null) {
        Object data = xmlNode.getUserData(DATA_LINE_NUMBER);
        if (data instanceof Integer) {
            return ((Integer) data).intValue();
        }
    }

    return 0;
}
 
Example 8
Project: openjdk-jdk10   File: SOAPDocumentImpl.java   Source Code and License Vote up 5 votes
private javax.xml.soap.Node find(Node node, boolean required) {
    if (node == null) {
        return null;
    }
    if (node instanceof javax.xml.soap.Node) {
        return (javax.xml.soap.Node) node;
    }
    final javax.xml.soap.Node found = (javax.xml.soap.Node) node.getUserData(SAAJ_NODE);
    if (found == null && required) {
        throw new IllegalArgumentException(MessageFormat.format("Cannot find SOAP wrapper for element {0}", node));
    }
    return found;
}
 
Example 9
Project: HL4A   File: XmlNode.java   Source Code and License Vote up 4 votes
private static XmlNode getUserData(Node node) {
    if (DOM_LEVEL_3) {
        return (XmlNode)node.getUserData(USER_DATA_XMLNODE_KEY);
    }
    return null;
}
 
Example 10
Project: whackpad   File: XmlNode.java   Source Code and License Vote up 4 votes
private static XmlNode getUserData(Node node) {
    if (DOM_LEVEL_3) {
        return (XmlNode)node.getUserData(USER_DATA_XMLNODE_KEY);
    }
    return null;
}
 
Example 11
Project: hybris-integration-intellij-idea-plugin   File: ValidateContextImpl.java   Source Code and License Vote up 4 votes
public T get(@NotNull final Node node) {
    //noinspection unchecked
    return (T) node.getUserData(this.myName);
}
 
Example 12
Project: openjdk-jdk10   File: SOAPDocumentImpl.java   Source Code and License Vote up 3 votes
/**
 * Insert a mapping information for {@link org.w3c.dom.Node} - {@link javax.xml.soap.Node}.
 *
 * In SAAJ, elements in DOM are expected to be interfaces of SAAJ, on the other hand in JDKs Xerces,
 * they are casted to internal impl classes. After removal of SAAJ dependency
 * to JDKs internal classes elements in DOM can never be both of them.
 *
 * @param node SAAJ wrapper node for w3c DOM node
 */
public void register(javax.xml.soap.Node node) {
    final Node domElement = getDomNode(node);
    if (domElement.getUserData(SAAJ_NODE) != null) {
        throw new IllegalStateException("Element " + domElement.getNodeName()
                + " is already registered");
    }
    domElement.setUserData(SAAJ_NODE, node, null);
}
 
Example 13
Project: javaide   File: MergerXmlUtils.java   Source Code and License Vote up 2 votes
/**
 * Returns the file associated with the given specific node, if any.
 * Note that this will not search upwards for parent nodes; it returns a
 * file associated with this specific node, if any.
 */
@Nullable
public static File getFileFor(@NonNull Node node) {
    return (File) node.getUserData(DATA_ORIGIN_FILE);
}