@Test public void testLocation() { String XML = "<?xml version='1.0' ?>" + "<!DOCTYPE root [\n" + "<!ENTITY intEnt 'internal'>\n" + "<!ENTITY extParsedEnt SYSTEM 'url:dummy'>\n" + "<!NOTATION notation PUBLIC 'notation-public-id'>\n" + "<!NOTATION notation2 SYSTEM 'url:dummy'>\n" + "<!ENTITY extUnparsedEnt SYSTEM 'url:dummy2' NDATA notation>\n" + "]>\n" + "<root />"; try { XMLEventReader er = getReader(XML); XMLEvent evt = er.nextEvent(); // StartDocument Location loc1 = evt.getLocation(); System.out.println("Location 1: " + loc1.getLineNumber() + "," + loc1.getColumnNumber()); evt = er.nextEvent(); // DTD // loc1 should not change so its line number should still be 1 Assert.assertTrue(loc1.getLineNumber() == 1); Location loc2 = evt.getLocation(); System.out.println("Location 2: " + loc2.getLineNumber() + "," + loc2.getColumnNumber()); evt = er.nextEvent(); // root System.out.println("Location 1: " + loc1.getLineNumber() + "," + loc1.getColumnNumber()); Assert.assertTrue(loc1.getLineNumber() == 1); Assert.assertTrue(loc2.getLineNumber() == 7); } catch (Exception e) { Assert.fail(e.getMessage()); } }
public void report(String message, String errorType, Object relatedInformation, Location location) throws XMLStreamException { if (errorHandler != null) { try { errorHandler.warning(new SAXParseException(message, this)); } catch (SAXException e) { XMLStreamException e2 = new XMLStreamException(e.getMessage()); e2.initCause(e); throw e2; } } }
private static Locator toLocation(XMLStreamReader xsr) { LocatorImpl loc = new LocatorImpl(); Location in = xsr.getLocation(); loc.setSystemId(in.getSystemId()); loc.setPublicId(in.getPublicId()); loc.setLineNumber(in.getLineNumber()); loc.setColumnNumber(in.getColumnNumber()); return loc; }
private Map<URI, Policy> unmarshal(final XMLEventReader reader, final StartElement parentElement) throws PolicyException { XMLEvent event = null; while (reader.hasNext()) { try { event = reader.peek(); switch (event.getEventType()) { case XMLStreamConstants.START_DOCUMENT: case XMLStreamConstants.COMMENT: reader.nextEvent(); break; case XMLStreamConstants.CHARACTERS: processCharacters(event.asCharacters(), parentElement, map); reader.nextEvent(); break; case XMLStreamConstants.END_ELEMENT: processEndTag(event.asEndElement(), parentElement); reader.nextEvent(); return map; case XMLStreamConstants.START_ELEMENT: final StartElement element = event.asStartElement(); processStartTag(element, parentElement, reader, map); break; case XMLStreamConstants.END_DOCUMENT: return map; default: throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0087_UNKNOWN_EVENT(event))); } } catch (XMLStreamException e) { final Location location = event == null ? null : event.getLocation(); throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0088_FAILED_PARSE(location)), e); } } return map; }
private Locator getLocator(XMLStreamReader reader) { Location location = reader.getLocation(); LocatorImpl loc = new LocatorImpl(); loc.setSystemId(location.getSystemId()); loc.setLineNumber(location.getLineNumber()); return loc; }
public Location getCurrentLocation() { if (docLocator != null) { return new SAXLocation(docLocator); } else { return null; } }
Location convertToStaxLocation(final XMLLocator location){ return new Location(){ public int getColumnNumber(){ return location.getColumnNumber(); } public int getLineNumber(){ return location.getLineNumber(); } public String getPublicId(){ return location.getPublicId(); } public String getSystemId(){ return location.getLiteralSystemId(); } public int getCharacterOffset(){ return location.getCharacterOffset(); } public String getLocationURI(){ return ""; } }; }
protected void init(String encoding, String version, boolean standalone,Location loc) { setEventType(XMLStreamConstants.START_DOCUMENT); this.fEncodingScheam = encoding; this.fVersion = version; this.fStandalone = standalone; if (encoding != null && !encoding.equals("")) this.fEncodingSchemeSet = true; else { this.fEncodingSchemeSet = false; this.fEncodingScheam = "UTF-8"; } this.fLocation = loc; }
void setLocation(Location loc){ if (loc == null) { fLocation = nowhere; } else { fLocation = loc; } }
LocationImpl(Location loc){ systemId = loc.getSystemId(); publicId = loc.getPublicId(); lineNo = loc.getLineNumber(); colNo = loc.getColumnNumber(); charOffset = loc.getCharacterOffset(); }
@Test public void testSetLocation() { XMLEventFactory factory = XMLEventFactory.newInstance(); Location loc = new MyLocation(); factory.setLocation(loc); XMLEvent event = factory.createComment("some comment"); Assert.assertEquals(event.getLocation().getLineNumber(), 15); }
protected DTDImpl(Location location, String body, Object impl, List notations, List entities) { super(location); this.body = body; this.impl = impl; this.notations = notations; this.entities = entities; }
protected NotationDeclarationImpl(Location location, String name, String publicId, String systemId) { super(location); this.name = name; this.publicId = publicId; this.systemId = systemId; }
protected StartDocumentImpl(Location location, String systemId, String encoding, String xmlVersion, boolean xmlStandalone, boolean standaloneDeclared, boolean encodingDeclared) { super(location); this.systemId = systemId; this.encoding = encoding; this.xmlVersion = xmlVersion; this.xmlStandalone = xmlStandalone; this.standaloneDeclared = standaloneDeclared; this.encodingDeclared = encodingDeclared; }
public static void main(String[] args) throws Exception { if (args.length == 0) { throw new Exception("XML file name should be specified as the first command line argument"); } File xmlFile = new File(args[0]); // // instantiate the factory // XMLInputFactory factory = XMLInputFactory.newInstance(); // // configure the factory // // // get the parser // XMLEventReader reader = factory.createXMLEventReader(new FileReader(xmlFile)); // // iterate, and also manage location // while(reader.hasNext()) { XMLEvent e = reader.nextEvent(); Location location = e.getLocation(); System.out.println( "[" + location.getLineNumber() + ":" + location.getColumnNumber() + "]: " + e.toString()); } }
protected NamespaceImpl(Location location, String prefix, String uri, boolean specified) { super(location); this.prefix = prefix; this.uri = uri; this.specified = specified; }
public void printLocations(String path, ArrayList<Location> locations) throws FileNotFoundException { //print location list to file FileOutputStream fos; fos = new FileOutputStream(path,true); PrintStream ps = new PrintStream(fos); for(Location l:locations){ ps.println(l.toString()); } ps.flush(); ps.close(); }
public void printLocations(String path, ArrayList<Location> locations) { if(debugPrint == false) { return; } //print location list to console for(Location l:locations){ System.out.println(l.toString()); } }
@Override public Location getLocation() { return new Location() { @Override public int getCharacterOffset() { return 0; } @Override public int getColumnNumber() { return 0; } @Override public int getLineNumber() { return 0; } @Override public String getPublicId() { return null; } @Override public String getSystemId() { return null; } }; }
@Override public Location getLocation() { return new Location() { @Override public int getLineNumber() { return -1; } @Override public int getColumnNumber() { return -1; } @Override public int getCharacterOffset() { return -1; } @Override public String getPublicId() { return null; } @Override public String getSystemId() { return null; } }; }
protected EntityDeclarationImpl(Location location, String publicId, String systemId, String name, String notationName, String replacementText, String baseUri) { super(location); this.publicId = publicId; this.systemId = systemId; this.name = name; this.notationName = notationName; this.replacementText = replacementText; this.baseUri = baseUri; }
private void handleDtd() throws SAXException { if (getLexicalHandler() != null) { javax.xml.stream.Location location = this.reader.getLocation(); getLexicalHandler().startDTD(null, location.getPublicId(), location.getSystemId()); } if (getLexicalHandler() != null) { getLexicalHandler().endDTD(); } }
public static XMLReadException wrap(RuntimeException cause, Location location) { if (cause instanceof XMLReadException) { return (XMLReadException) cause; } else { return new XMLReadException(cause, location); } }
private void handleDtd() throws SAXException { if (getLexicalHandler() != null) { javax.xml.stream.Location location = reader.getLocation(); getLexicalHandler().startDTD(null, location.getPublicId(), location.getSystemId()); } if (getLexicalHandler() != null) { getLexicalHandler().endDTD(); } }
protected CharactersImpl(Location location, String data, boolean whitespace, boolean cdata, boolean ignorableWhitespace) { super(location); this.data = data; this.whitespace = whitespace; this.cdata = cdata; this.ignorableWhitespace = ignorableWhitespace; }
protected StartElementImpl(Location location, QName name, List attributes, List namespaces, NamespaceContext namespaceContext) { super(location); this.name = name; this.attributes = attributes; this.namespaces = namespaces; this.namespaceContext = namespaceContext; }