private void handleStartDocument(final XMLEvent event) throws SAXException { _sax.setDocumentLocator(new Locator2() { public int getColumnNumber() { return event.getLocation().getColumnNumber(); } public int getLineNumber() { return event.getLocation().getLineNumber(); } public String getPublicId() { return event.getLocation().getPublicId(); } public String getSystemId() { return event.getLocation().getSystemId(); } public String getXMLVersion(){ return version; } public String getEncoding(){ return encoding; } }); _sax.startDocument(); }
private void handleStartDocument() throws SAXException { _sax.setDocumentLocator(new Locator2() { public int getColumnNumber() { return staxStreamReader.getLocation().getColumnNumber(); } public int getLineNumber() { return staxStreamReader.getLocation().getLineNumber(); } public String getPublicId() { return staxStreamReader.getLocation().getPublicId(); } public String getSystemId() { return staxStreamReader.getLocation().getSystemId(); } public String getXMLVersion() { return staxStreamReader.getVersion(); } public String getEncoding() { return staxStreamReader.getEncoding(); } }); _sax.startDocument(); }
@Test public void testStartElement() throws SAXException { handler.startDocument(); Locator2 locator = Mockito.mock(Locator2.class); handler.setDocumentLocator(locator); Mockito.when(locator.getLineNumber()).thenReturn(1); Mockito.when(locator.getColumnNumber()).thenReturn(7); handler.startElement("", "", "element", new AttributesImpl()); assertEquals(1, handler.getElementStack().size()); Element element = handler.getElementStack().pop(); DocumentLocation location = (DocumentLocation) element.getUserData("location"); assertEquals(1, location.getLineNumber()); assertEquals(7, location.getColumnNumber()); }
@Test public void testEndElement() throws SAXException { handler.startDocument(); Locator2 locator = Mockito.mock(Locator2.class); handler.setDocumentLocator(locator); Mockito.when(locator.getLineNumber()).thenReturn(1); Mockito.when(locator.getColumnNumber()).thenReturn(7); handler.startElement("", "", "element", new AttributesImpl()); assertEquals(1, handler.getElementStack().size()); Mockito.when(locator.getEncoding()).thenReturn("UTF-8"); handler.endElement("", "", "element"); assertEquals(0, handler.getElementStack().size()); Document document = handler.getDocument(); Node node = document.getDocumentElement(); DocumentLocation location = (DocumentLocation) node.getUserData("location"); assertEquals(1, location.getLineNumber()); assertEquals(7, location.getColumnNumber()); }
@Test public void testAddText() throws SAXException { char[] test = "test".toCharArray(); handler.startDocument(); Locator2 locator = Mockito.mock(Locator2.class); handler.setDocumentLocator(locator); Mockito.when(locator.getLineNumber()).thenReturn(1); Mockito.when(locator.getColumnNumber()).thenReturn(7); handler.startElement("", "", "element", new AttributesImpl()); handler.characters(test, 0, test.length); handler.addText(); Stack<Element> elements = handler.getElementStack(); Node parent = elements.pop(); NodeList childNodes = parent.getChildNodes(); assertEquals(1, childNodes.getLength()); assertEquals("test", childNodes.item(0).getTextContent()); }
private void setDocumentInfo() { //try to set document version if (locator == null) return; try{ _document.setXmlVersion(((Locator2)locator).getXMLVersion()); }catch(ClassCastException e){} }
protected void setDocumentInfo() { if (m_locator == null) return; try{ String strVersion = ((Locator2)m_locator).getXMLVersion(); if (strVersion != null) setVersion(strVersion); /*String strEncoding = ((Locator2)m_locator).getEncoding(); if (strEncoding != null) setEncoding(strEncoding); */ }catch(ClassCastException e){} }
@Override public void setDocumentLocator(Locator locator) { if (locator instanceof Locator2) { Locator2 locator2 = (Locator2) locator; properties.setEL("encoding", locator2.getEncoding()); } }
@Override public void setDocumentLocator(Locator locator) { if (locator instanceof Locator2) { Locator2 locator2 = (Locator2) locator; root.put("encoding", locator2.getEncoding()); } }
public void setDocumentLocator (@Nullable final Locator aLocator) { if (m_bTrackPosition) { m_aLocator = aLocator; _updatePosition ("setLocator"); if (aLocator instanceof Locator2) { m_sSourceXMLVersion = ((Locator2) aLocator).getXMLVersion (); m_sSourceXMLEncoding = ((Locator2) aLocator).getEncoding (); } } }
private void handleStartDocument(final XMLEvent event) throws SAXException { if (event.isStartDocument()) { StartDocument startDocument = (StartDocument) event; String xmlVersion = startDocument.getVersion(); if (StringUtils.hasLength(xmlVersion)) { this.xmlVersion = xmlVersion; } if (startDocument.encodingSet()) { this.encoding = startDocument.getCharacterEncodingScheme(); } } if (getContentHandler() != null) { final Location location = event.getLocation(); getContentHandler().setDocumentLocator(new Locator2() { public int getColumnNumber() { return (location != null ? location.getColumnNumber() : -1); } public int getLineNumber() { return (location != null ? location.getLineNumber() : -1); } public String getPublicId() { return (location != null ? location.getPublicId() : null); } public String getSystemId() { return (location != null ? location.getSystemId() : null); } public String getXMLVersion() { return xmlVersion; } public String getEncoding() { return encoding; } }); getContentHandler().startDocument(); } }
private void handleStartDocument() throws SAXException { if (XMLStreamConstants.START_DOCUMENT == this.reader.getEventType()) { String xmlVersion = this.reader.getVersion(); if (StringUtils.hasLength(xmlVersion)) { this.xmlVersion = xmlVersion; } this.encoding = this.reader.getCharacterEncodingScheme(); } if (getContentHandler() != null) { final Location location = this.reader.getLocation(); getContentHandler().setDocumentLocator(new Locator2() { public int getColumnNumber() { return (location != null ? location.getColumnNumber() : -1); } public int getLineNumber() { return (location != null ? location.getLineNumber() : -1); } public String getPublicId() { return (location != null ? location.getPublicId() : null); } public String getSystemId() { return (location != null ? location.getSystemId() : null); } public String getXMLVersion() { return xmlVersion; } public String getEncoding() { return encoding; } }); getContentHandler().startDocument(); if (this.reader.standaloneSet()) { setStandalone(this.reader.isStandalone()); } } }
public DocumentLocatorImpl(Locator locator) { this.locator = locator; if (locator instanceof Locator2) { locator2 = (Locator2) locator; } }
/** * Receive a Locator object for document events. */ @Override public void setDocumentLocator(Locator locator) { this.locator = locator; if (locator instanceof Locator2) { this.locator2 = (Locator2) locator; } }
private void encodeHeader() throws IOException { encodeHeader((locator instanceof Locator2)?((Locator2)locator).getEncoding():null, isStandAlone, (locator instanceof Locator2)?((Locator2)locator).getXMLVersion():null, unparsedEntities, notations ); }
public void setLocator(Locator locator) { fLocator = locator; if (locator instanceof Locator2 || locator == null) { fLocator2 = (Locator2) locator; } }