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

The following examples show how to use org.w3c.dom.Node#getUserData() . These examples are extracted from open source projects. 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
/**
 * 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
Source Project: buck   File: XmlUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static SourceFilePosition getSourceFilePosition(Node node) {
    SourceFile sourceFile = (SourceFile) node.getUserData(SOURCE_FILE_USER_DATA_KEY);
    if (sourceFile == null) {
        sourceFile = SourceFile.UNKNOWN;
    }
    return new SourceFilePosition(sourceFile, PositionXmlParser.getPosition(node));
}
 
Example 3
@Override
public void handle(short operation, String key, Object data,
        Node src, Node dst) {
   
    if (src != null && dst != null) {
        XmlLocationData locatonData = (XmlLocationData)
                src.getUserData(XmlLocationData.LOCATION_DATA_KEY);
       
        if (locatonData != null) {
            dst.setUserData(XmlLocationData.LOCATION_DATA_KEY,
                    locatonData, dataHandler);
        }
    }
}
 
Example 4
@Override
public void handle(short operation, String key, Object data,
        Node src, Node dst) {
   
    if (src != null && dst != null) {
        XmlLocationData locatonData = (XmlLocationData)
                src.getUserData(XmlLocationData.LOCATION_DATA_KEY);
       
        if (locatonData != null) {
            dst.setUserData(XmlLocationData.LOCATION_DATA_KEY,
                    locatonData, dataHandler);
        }
    }
}
 
Example 5
/**
 * 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 6
Source Project: cxf   File: OverlayW3CDOMStreamWriter.java    License: Apache License 2.0 5 votes vote down vote up
public void writeStartElement(String namespace, String local) throws XMLStreamException {
    isOverlaidStack.add(0, isOverlaid);
    if (isOverlaid) {
        Element nd = getCurrentNode();
        Node nd2;
        if (nd == null) {
            nd2 = getDocument().getDocumentElement();
        } else {
            nd2 = nd.getFirstChild();
        }
        while (nd2 != null) {
            Object userData = null;
            try {
                userData = nd2.getUserData("new");
            } catch (Throwable t) {
                //ignore - non DOM level 3
            }
            if (nd2.getNodeType() == Node.ELEMENT_NODE
                && local.equals(nd2.getLocalName())
                && namespace.equals(nd2.getNamespaceURI())
                && userData == null) {
                adjustOverlaidNode(nd2, "");
                setChild((Element)nd2, false);
                if (nd2.getFirstChild() == null) {
                    //optimize a case where we KNOW anything added cannot be an overlay
                    isOverlaid = false;
                    textOverlay = null;
                }
                return;
            }
            nd2 = nd2.getNextSibling();
        }
    }
    super.writeStartElement(namespace, local);
    isOverlaid = false;
    textOverlay = false;
}
 
Example 7
Source Project: cxf   File: OverlayW3CDOMStreamWriter.java    License: Apache License 2.0 5 votes vote down vote up
public void writeStartElement(String local) throws XMLStreamException {
    isOverlaidStack.add(0, isOverlaid);
    if (isOverlaid) {
        Element nd = getCurrentNode();
        Node nd2;
        if (nd == null) {
            nd2 = getDocument().getDocumentElement();
        } else {
            nd2 = nd.getFirstChild();
        }
        while (nd2 != null) {
            Object userData = null;
            try {
                userData = nd2.getUserData("new");
            } catch (Throwable t) {
                //ignore - non DOM level 3
            }
            if (nd2.getNodeType() == Node.ELEMENT_NODE
                && local.equals(nd2.getLocalName())
                && StringUtils.isEmpty(nd2.getNamespaceURI())
                && userData != null) {
                adjustOverlaidNode(nd2, null);
                setChild((Element)nd2, false);
                if (nd2.getFirstChild() == null) {
                    //optimize a case where we KNOW anything added cannot be an overlay
                    isOverlaid = false;
                    textOverlay = null;
                }
                return;
            }
            nd2 = nd2.getNextSibling();
        }
    }
    super.writeStartElement(local);
    isOverlaid = false;
    textOverlay = Boolean.FALSE;
}
 
Example 8
Source Project: phoebus   File: XMLUtil.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/** (Try to) obtain original line number in XML file for a node.
 *
 *  @param node Node in document
 *  @return Line number. Empty if not known.
 */
public static Optional<Integer> getLineNumber(final Node node)
{
    final Object info = node.getUserData(PositionalXMLReader.LINE_NUMBER);
    if (info instanceof Integer)
        return Optional.of((Integer)info);
    return Optional.empty();
}
 
Example 9
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 10
/**
 * Report the ending column where the provided node was read in
 * its source line.
 *
 * @param node the provided node
 * @return the column number, or null
 */
public static String getColumn (Node node)
{
    if (node == null) {
        return null;
    }

    return (String) node.getUserData(KEY_COLUMN);
}
 
Example 11
public static Integer getLineNumber(Node node)
{
    return (Integer) node.getUserData(LocationAwareContentHandler.LINE_NUMBER_KEY_NAME);
}
 
Example 12
Source Project: org.hl7.fhir.core   File: XmlParser.java    License: Apache License 2.0 4 votes vote down vote up
private int col(Node node) {
XmlLocationData loc = node == null ? null : (XmlLocationData) node.getUserData(XmlLocationData.LOCATION_DATA_KEY);
return loc == null ? 0 : loc.getStartColumn();
}
 
Example 13
@Override
public Object evaluate(@SuppressWarnings("rawtypes") List args) throws XPathFunctionException
{
    int frameIdx = ((Double) args.get(0)).intValue();
    NodeList arg1 = (NodeList) args.get(1);
    String nodeText = XmlUtil.nodeListToString(arg1);
    LOG.fine("persist(" + frameIdx + ", " + nodeText + ")");

    for (int i = 0; i < arg1.getLength(); i++)
    {
        Node node = arg1.item(i);
        if (xpathResultMatch != null)
        {
            if (!node.toString().matches(xpathResultMatch))
            {
                continue;
            }
        }
        // Everything passed for this Node. Start creating XmlTypeReferenceModel for it.
        int lineNumber = (int) node.getUserData(
                    LocationAwareContentHandler.LINE_NUMBER_KEY_NAME);
        int columnNumber = (int) node.getUserData(
                    LocationAwareContentHandler.COLUMN_NUMBER_KEY_NAME);

        GraphService<XmlTypeReferenceModel> fileLocationService = new GraphService<>(
                    event.getGraphContext(),
                    XmlTypeReferenceModel.class);
        XmlTypeReferenceModel fileLocation = fileLocationService.create();
        String sourceSnippit = XmlUtil.nodeToString(node);
        fileLocation.setSourceSnippit(sourceSnippit);
        fileLocation.setLineNumber(lineNumber);
        fileLocation.setColumnNumber(columnNumber);
        fileLocation.setLength(node.toString().length());
        fileLocation.setFile(xml);
        fileLocation.setXpath(xpathString);
        GraphService<NamespaceMetaModel> metaModelService = new GraphService<>(
                    event.getGraphContext(),
                    NamespaceMetaModel.class);
        for (Map.Entry<String, String> namespace : namespaces.entrySet())
        {
            NamespaceMetaModel metaModel = metaModelService.create();
            metaModel.setSchemaLocation(namespace.getKey());
            metaModel.setSchemaLocation(namespace.getValue());
            metaModel.addXmlResource(xml);
            fileLocation.addNamespace(metaModel);
        }
        resultLocations.add(fileLocation);

        evaluationStrategy.modelSubmissionRejected();
        evaluationStrategy.modelMatched();

        if (fileNameValidator.getFileNamePattern() != null && !fileNameValidator.getFileNamePattern().parse(xml.getFileName()).submit(event, context))
        {
            evaluationStrategy.modelSubmissionRejected();
            continue;
        }

        for (Map.Entry<String, String> entry : paramMatchCache.getVariables().entrySet())
        {
            Parameter<?> param = store.get(entry.getKey());
            String value = entry.getValue();
            if (!evaluationStrategy.submitValue(param, value))
            {
                evaluationStrategy.modelSubmissionRejected();
                return false;
            }
        }
        evaluationStrategy.modelSubmitted(fileLocation);
        evaluationStrategy.modelMatched();
    }

    return true;
}
 
Example 14
Source Project: org.hl7.fhir.core   File: XmlParser.java    License: Apache License 2.0 4 votes vote down vote up
private int col(Node node) {
XmlLocationData loc = (XmlLocationData) node.getUserData(XmlLocationData.LOCATION_DATA_KEY);
return loc == null ? 0 : loc.getStartColumn();
}
 
Example 15
Source Project: org.hl7.fhir.core   File: XmlParser.java    License: Apache License 2.0 4 votes vote down vote up
private int col(Node node) {
XmlLocationData loc = (XmlLocationData) node.getUserData(XmlLocationData.LOCATION_DATA_KEY);
return loc == null ? 0 : loc.getStartColumn();
}
 
Example 16
Source Project: org.hl7.fhir.core   File: XmlParser.java    License: Apache License 2.0 4 votes vote down vote up
private int line(Node node) {
	XmlLocationData loc = (XmlLocationData) node.getUserData(XmlLocationData.LOCATION_DATA_KEY);
	return loc == null ? 0 : loc.getStartLine();
}
 
Example 17
Source Project: org.hl7.fhir.core   File: XmlParser.java    License: Apache License 2.0 4 votes vote down vote up
private int col(Node node) {
	XmlLocationData loc = (XmlLocationData) node.getUserData(XmlLocationData.LOCATION_DATA_KEY);
	return loc == null ? 0 : loc.getStartColumn();
}
 
Example 18
Source Project: astor   File: XmlNode.java    License: GNU General Public License v2.0 4 votes vote down vote up
private static XmlNode getUserData(Node node) {
    if (DOM_LEVEL_3) {
        return (XmlNode)node.getUserData(USER_DATA_XMLNODE_KEY);
    }
    return null;
}
 
Example 19
private boolean isVersion25() {
  Node node = document.getFirstChild();
  String versionString = (String) node.getUserData("version");
  return "2.5".equals(versionString);
}
 
Example 20
/**
 * 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);
}