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

The following are Jave code examples for showing how to use setUserData() 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: convertigo-engine   File: Sequence.java   Source Code and License Vote up 6 votes
private static Node setOutputUserData(Node node, Object value, boolean recurse) {
	if (node != null) {
		// set output mode as userdata (element or attribute)
		node.setUserData(Step.NODE_USERDATA_OUTPUT, value, null);
		
		// recurse on element child nodes only
		if (node.getNodeType() == Node.ELEMENT_NODE) {
			if (recurse && node.hasChildNodes()) {
				NodeList list = node.getChildNodes();
				for (int i=0; i<list.getLength(); i++) {
					setOutputUserData(list.item(i), value, recurse);
				}
			}
		}
	}
	return node;
}
 
Example 2
Project: javaide   File: MergerXmlUtils.java   Source Code and License Vote up 6 votes
/**
 * This is a CRUDE INEXACT HACK to decorate the DOM with some kind of line number
 * information for elements. It's inexact because by the time we get the DOM we
 * already have lost all the information about whitespace between attributes.
 * <p/>
 * Also we don't even try to deal with \n vs \r vs \r\n insanity. This only counts
 * the \n occurring in text nodes to determine line advances, which is clearly flawed.
 * <p/>
 * However it's good enough for testing, and we'll replace it by a PositionXmlParser
 * once it's moved into com.android.util.
 */
private static int findLineNumbers(Node node, int line) {
    for (; node != null; node = node.getNextSibling()) {
        node.setUserData(DATA_LINE_NUMBER, Integer.valueOf(line), null /*handler*/);

        if (node.getNodeType() == Node.TEXT_NODE) {
            String text = node.getNodeValue();
            if (text.length() > 0) {
                for (int pos = 0; (pos = text.indexOf('\n', pos)) != -1; pos++) {
                    ++line;
                }
            }
        }

        Node child = node.getFirstChild();
        if (child != null) {
            line = findLineNumbers(child, line);
        }
    }
    return line;
}
 
Example 3
Project: openjdk-jdk10   File: SOAPDocumentImpl.java   Source Code and License Vote up 6 votes
@Override
public org.w3c.dom.Node importNode(Node importedNode, boolean deep)
    throws DOMException {
    Node domNode = getDomNode(importedNode);
    final Node newNode = document.importNode(domNode, deep);

    if (importedNode instanceof javax.xml.soap.Node) {
        Node newSoapNode = createSoapNode(importedNode.getClass(), newNode);
        newNode.setUserData(SAAJ_NODE, newSoapNode, null);
        if (deep && importedNode.hasChildNodes()) {
            NodeList childNodes = importedNode.getChildNodes();
            for (int i = 0; i < childNodes.getLength(); i++) {
                registerChildNodes(childNodes.item(i), deep);
            }
        }
        return newSoapNode;
    }

    registerChildNodes(newNode, deep);
    return findIfPresent(newNode);
}
 
Example 4
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 5
Project: javaide   File: MergerXmlUtils.java   Source Code and License Vote up 5 votes
public static void setSource(@NonNull Node node, @NonNull File source) {
    //noinspection ConstantConditions
    for (; node != null; node = node.getNextSibling()) {
        short nodeType = node.getNodeType();
        if (nodeType == Node.ELEMENT_NODE
                || nodeType == Node.COMMENT_NODE
                || nodeType == Node.DOCUMENT_NODE
                || nodeType == Node.CDATA_SECTION_NODE) {
            node.setUserData(DATA_ORIGIN_FILE, source, null);
        }
        Node child = node.getFirstChild();
        setSource(child, source);
    }
}
 
Example 6
Project: HL4A   File: XmlNode.java   Source Code and License Vote up 4 votes
private static void setUserData(Node node, XmlNode wrap) {
    if (DOM_LEVEL_3) {
        node.setUserData(USER_DATA_XMLNODE_KEY, wrap, wrap.events);
    }
}
 
Example 7
Project: whackpad   File: XmlNode.java   Source Code and License Vote up 4 votes
private static void setUserData(Node node, XmlNode wrap) {
    if (DOM_LEVEL_3) {
        node.setUserData(USER_DATA_XMLNODE_KEY, wrap, wrap.events);
    }
}
 
Example 8
Project: javaide   File: MergerXmlUtils.java   Source Code and License Vote up 4 votes
/**
 * Sets the file associated with the given node, if any
 */
public static void setFileFor(Node node, File file) {
    node.setUserData(MergerXmlUtils.DATA_ORIGIN_FILE, file, null);
}
 
Example 9
Project: hybris-integration-intellij-idea-plugin   File: ValidateContextImpl.java   Source Code and License Vote up 4 votes
public void put(@NotNull final Node node, final T value) {
    node.setUserData(this.myName, value, null);
}
 
Example 10
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);
}