@Override public Object getUserData(String key) { return node.getUserData(key); }
// XmlTest.java import java.io.ByteArrayInputStream; import java.io.InputStream; import org.w3c.dom.Document; import org.w3c.dom.Node; public class XmlTest { public static void main(final String[] args) throws Exception { String xmlString = "<foo>\n" + " <bar>\n" + " <moo>Hello World!</moo>\n" + " </bar>\n" + "</foo>"; InputStream is = new ByteArrayInputStream(xmlString.getBytes()); Document doc = PositionalXMLReader.readXML(is); is.close(); Node node = doc.getElementsByTagName("moo").item(0); System.out.println("Line number: " + node.getUserData("lineNumber")); } }
@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); } } } }
private int line(Node node) { XmlLocationData loc = (XmlLocationData) node.getUserData(XmlLocationData.LOCATION_DATA_KEY); return loc == null ? 0 : loc.getStartLine(); }
@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); } } } }
private int line(Node node) { XmlLocationData loc = (XmlLocationData) node.getUserData(XmlLocationData.LOCATION_DATA_KEY); return loc == null ? 0 : loc.getStartLine(); }
private int col(Node node) { XmlLocationData loc = (XmlLocationData) node.getUserData(XmlLocationData.LOCATION_DATA_KEY); return loc == null ? 0 : loc.getStartColumn(); }
@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); } } } }
private int col(Node node) { XmlLocationData loc = (XmlLocationData) node.getUserData(XmlLocationData.LOCATION_DATA_KEY); return loc == null ? 0 : loc.getStartColumn(); }
/** * Get the column number embedded in a node. * * @param node * the node * @return the column number, or -1 if none was embedded */ public static int getColumnNumber(Node node) { Integer col = (Integer) node.getUserData(LocationAwareDOMParser.COLUMN_NUMBER); return col == null ? -1 : col; } }
@Override public Object getElementUserData(final Element element, final String key) { Node currentNode = element; while (currentNode != null) { Object userData = currentNode.getUserData(key); if (userData != null) { return userData; } currentNode = currentNode.getParentNode(); } return null; }
@Override public void handle(short operation, String key, Object data, Node src, Node dst) { if (operation == NODE_IMPORTED || operation == NODE_CLONED) { dst.setUserData(METADATA_ANNOTATIONS_KEY, src.getUserData(METADATA_ANNOTATIONS_KEY), this); } } };
@Override public void handle(short operation, String key, Object data, Node src, Node dst) { if (operation == NODE_IMPORTED || operation == NODE_CLONED) { dst.setUserData(METADATA_ANNOTATIONS_KEY, src.getUserData(METADATA_ANNOTATIONS_KEY), this); } } };
/** * Retrieves the object associated to a key on a this node. The object * must first have been set to this node by calling * <code>setUserData</code> with the same key. * @param key The key the object is associated to. * @return Returns the <code>DOMObject</code> associated to the given key * on this node, or <code>null</code> if there was none. * @since DOM Level 3 */ public Object getUserData(String key) { return getOwnerDocument().getUserData( key); }
/** * Retrieves the object associated to a key on a this node. The object * must first have been set to this node by calling * <code>setUserData</code> with the same key. * @param key The key the object is associated to. * @return Returns the <code>DOMObject</code> associated to the given key * on this node, or <code>null</code> if there was none. * @since DOM Level 3 */ public Object getUserData(String key) { return getOwnerDocument().getUserData( key); }
/** * Retrieves the object associated to a key on a this node. The object * must first have been set to this node by calling * <code>setUserData</code> with the same key. * @param key The key the object is associated to. * @return Returns the <code>DOMObject</code> associated to the given key * on this node, or <code>null</code> if there was none. * @since DOM Level 3 */ public Object getUserData(String key) { return getOwnerDocument().getUserData( key); }
public Location getLocation() { try { Object o = getCurrentNode().getUserData("location"); if (o instanceof Location) { return (Location)o; } } catch (Throwable ex) { //ignore, probably not DOM level 3 } return super.getLocation(); }
public Location getLocation() { try { Object o = getCurrentNode().getUserData("location"); if (o instanceof Location) { return (Location)o; } } catch (Throwable ex) { //ignore, probably not DOM level 3 } return super.getLocation(); }
public Location getLocation() { try { Object o = getCurrentNode().getUserData("location"); if (o instanceof Location) { return (Location)o; } } catch (Throwable ex) { //ignore, probably not DOM level 3 } return super.getLocation(); }
public Location getLocation() { try { Object o = getCurrentNode().getUserData("location"); if (o instanceof Location) { return (Location)o; } } catch (Throwable ex) { //ignore, probably not DOM level 3 } return super.getLocation(); }