本文整理汇总了Java中org.xml.sax.ext.Locator2类的典型用法代码示例。如果您正苦于以下问题:Java Locator2类的具体用法?Java Locator2怎么用?Java Locator2使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Locator2类属于org.xml.sax.ext包,在下文中一共展示了Locator2类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleStartDocument
import org.xml.sax.ext.Locator2; //导入依赖的package包/类
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();
}
示例2: handleStartDocument
import org.xml.sax.ext.Locator2; //导入依赖的package包/类
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();
}
示例3: testStartElement
import org.xml.sax.ext.Locator2; //导入依赖的package包/类
@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());
}
示例4: testEndElement
import org.xml.sax.ext.Locator2; //导入依赖的package包/类
@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());
}
示例5: testAddText
import org.xml.sax.ext.Locator2; //导入依赖的package包/类
@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());
}
示例6: setDocumentInfo
import org.xml.sax.ext.Locator2; //导入依赖的package包/类
private void setDocumentInfo() {
//try to set document version
if (locator == null) return;
try{
_document.setXmlVersion(((Locator2)locator).getXMLVersion());
}catch(ClassCastException e){}
}
示例7: setDocumentInfo
import org.xml.sax.ext.Locator2; //导入依赖的package包/类
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){}
}
示例8: setDocumentLocator
import org.xml.sax.ext.Locator2; //导入依赖的package包/类
@Override
public void setDocumentLocator(Locator locator) {
if (locator instanceof Locator2) {
Locator2 locator2 = (Locator2) locator;
properties.setEL("encoding", locator2.getEncoding());
}
}
示例9: setDocumentLocator
import org.xml.sax.ext.Locator2; //导入依赖的package包/类
@Override
public void setDocumentLocator(Locator locator) {
if (locator instanceof Locator2) {
Locator2 locator2 = (Locator2) locator;
root.put("encoding", locator2.getEncoding());
}
}
示例10: setDocumentLocator
import org.xml.sax.ext.Locator2; //导入依赖的package包/类
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 ();
}
}
}
示例11: handleStartDocument
import org.xml.sax.ext.Locator2; //导入依赖的package包/类
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();
}
}
示例12: handleStartDocument
import org.xml.sax.ext.Locator2; //导入依赖的package包/类
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());
}
}
}
示例13: DocumentLocatorImpl
import org.xml.sax.ext.Locator2; //导入依赖的package包/类
public DocumentLocatorImpl(Locator locator)
{
this.locator = locator;
if (locator instanceof Locator2)
{
locator2 = (Locator2) locator;
}
}
示例14: setDocumentLocator
import org.xml.sax.ext.Locator2; //导入依赖的package包/类
/**
* Receive a Locator object for document events.
*/
@Override
public void setDocumentLocator(Locator locator) {
this.locator = locator;
if (locator instanceof Locator2) {
this.locator2 = (Locator2) locator;
}
}
示例15: encodeHeader
import org.xml.sax.ext.Locator2; //导入依赖的package包/类
private void encodeHeader() throws IOException {
encodeHeader((locator instanceof Locator2)?((Locator2)locator).getEncoding():null,
isStandAlone,
(locator instanceof Locator2)?((Locator2)locator).getXMLVersion():null,
unparsedEntities, notations
);
}