Search in sources :

Example 6 with LocatorImpl

use of org.xml.sax.helpers.LocatorImpl in project robovm by robovm.

the class Locator2ImplTest method testLocatorImplLocator.

public void testLocatorImplLocator() {
    Locator2Impl inner = new Locator2Impl();
    inner.setPublicId(PUB);
    inner.setSystemId(SYS);
    inner.setLineNumber(ROW);
    inner.setColumnNumber(COL);
    inner.setEncoding(ENC);
    inner.setXMLVersion(XML);
    // Ordinary case
    Locator2Impl outer = new Locator2Impl(inner);
    assertEquals(PUB, outer.getPublicId());
    assertEquals(SYS, outer.getSystemId());
    assertEquals(ROW, outer.getLineNumber());
    assertEquals(COL, outer.getColumnNumber());
    assertEquals(ENC, outer.getEncoding());
    assertEquals(XML, outer.getXMLVersion());
    // Instance of old locator
    outer = new Locator2Impl(new LocatorImpl(inner));
    assertEquals(PUB, outer.getPublicId());
    assertEquals(SYS, outer.getSystemId());
    assertEquals(ROW, outer.getLineNumber());
    assertEquals(COL, outer.getColumnNumber());
    assertEquals(null, outer.getEncoding());
    assertEquals(null, outer.getXMLVersion());
    // No locator
    try {
        outer = new Locator2Impl(null);
        fail("NullPointerException expected");
    } catch (NullPointerException e) {
    // Expected
    }
}
Also used : LocatorImpl(org.xml.sax.helpers.LocatorImpl) Locator2Impl(org.xml.sax.ext.Locator2Impl)

Example 7 with LocatorImpl

use of org.xml.sax.helpers.LocatorImpl in project robovm by robovm.

the class DefaultHandlerTest method testFatalError.

public void testFatalError() {
    // Ordinary case
    try {
        h.fatalError(new SAXParseException("Foo", new LocatorImpl()));
        fail("SAXException expected");
    } catch (SAXException e) {
    // Expected
    }
    // No exception
    try {
        h.fatalError(null);
        fail("NullPointerException expected");
    } catch (SAXException e) {
        fail("NullPointerException expected");
    } catch (NullPointerException e) {
    // Expected
    }
}
Also used : SAXParseException(org.xml.sax.SAXParseException) LocatorImpl(org.xml.sax.helpers.LocatorImpl) SAXException(org.xml.sax.SAXException)

Example 8 with LocatorImpl

use of org.xml.sax.helpers.LocatorImpl in project robovm by robovm.

the class SAXParseExceptionTest method testSAXParseException_String_Locator_Exception.

public void testSAXParseException_String_Locator_Exception() {
    LocatorImpl l = new LocatorImpl();
    l.setPublicId(PUB);
    l.setSystemId(SYS);
    l.setLineNumber(ROW);
    l.setColumnNumber(COL);
    Exception c = new Exception();
    // Ordinary case
    SAXParseException e = new SAXParseException(ERR, l, c);
    assertEquals(ERR, e.getMessage());
    assertEquals(c, e.getException());
    assertEquals(PUB, e.getPublicId());
    assertEquals(SYS, e.getSystemId());
    assertEquals(ROW, e.getLineNumber());
    assertEquals(COL, e.getColumnNumber());
    // No message
    e = new SAXParseException(null, l, c);
    assertNull(e.getMessage());
    assertEquals(c, e.getException());
    assertEquals(PUB, e.getPublicId());
    assertEquals(SYS, e.getSystemId());
    assertEquals(ROW, e.getLineNumber());
    assertEquals(COL, e.getColumnNumber());
    // No locator
    e = new SAXParseException(ERR, null, c);
    assertEquals(ERR, e.getMessage());
    assertEquals(c, e.getException());
    assertNull(e.getPublicId());
    assertNull(e.getSystemId());
    assertEquals(-1, e.getLineNumber());
    assertEquals(-1, e.getColumnNumber());
    // No cause
    e = new SAXParseException(ERR, l, null);
    assertEquals(ERR, e.getMessage());
    assertNull(e.getException());
    assertEquals(PUB, e.getPublicId());
    assertEquals(SYS, e.getSystemId());
    assertEquals(ROW, e.getLineNumber());
    assertEquals(COL, e.getColumnNumber());
}
Also used : SAXParseException(org.xml.sax.SAXParseException) LocatorImpl(org.xml.sax.helpers.LocatorImpl) SAXParseException(org.xml.sax.SAXParseException)

Example 9 with LocatorImpl

use of org.xml.sax.helpers.LocatorImpl in project j2objc by google.

the class DocumentBuilderImpl method parse.

@Override
public Document parse(InputSource source) throws SAXException, IOException {
    if (source == null) {
        throw new IllegalArgumentException("source == null");
    }
    String namespaceURI = null;
    String qualifiedName = null;
    DocumentType doctype = null;
    String inputEncoding = source.getEncoding();
    String systemId = source.getSystemId();
    DocumentImpl document = new DocumentImpl(dom, namespaceURI, qualifiedName, doctype, inputEncoding);
    document.setDocumentURI(systemId);
    KXmlParser parser = new KXmlParser();
    try {
        parser.keepNamespaceAttributes();
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, namespaceAware);
        if (source.getByteStream() != null) {
            parser.setInput(source.getByteStream(), inputEncoding);
        } else if (source.getCharacterStream() != null) {
            parser.setInput(source.getCharacterStream());
        } else if (systemId != null) {
            URL url = new URL(systemId);
            URLConnection urlConnection = url.openConnection();
            urlConnection.connect();
            // TODO: if null, extract the inputEncoding from the Content-Type header?
            parser.setInput(urlConnection.getInputStream(), inputEncoding);
        } else {
            throw new SAXParseException("InputSource needs a stream, reader or URI", null);
        }
        if (parser.nextToken() == XmlPullParser.END_DOCUMENT) {
            throw new SAXParseException("Unexpected end of document", null);
        }
        parse(parser, document, document, XmlPullParser.END_DOCUMENT);
        parser.require(XmlPullParser.END_DOCUMENT, null, null);
    } catch (XmlPullParserException ex) {
        if (ex.getDetail() instanceof IOException) {
            throw (IOException) ex.getDetail();
        }
        if (ex.getDetail() instanceof RuntimeException) {
            throw (RuntimeException) ex.getDetail();
        }
        LocatorImpl locator = new LocatorImpl();
        locator.setPublicId(source.getPublicId());
        locator.setSystemId(systemId);
        locator.setLineNumber(ex.getLineNumber());
        locator.setColumnNumber(ex.getColumnNumber());
        SAXParseException newEx = new SAXParseException(ex.getMessage(), locator);
        if (errorHandler != null) {
            errorHandler.error(newEx);
        }
        throw newEx;
    } finally {
        IoUtils.closeQuietly(parser);
    }
    return document;
}
Also used : KXmlParser(org.kxml2.io.KXmlParser) SAXParseException(org.xml.sax.SAXParseException) DocumentType(org.w3c.dom.DocumentType) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) LocatorImpl(org.xml.sax.helpers.LocatorImpl) IOException(java.io.IOException) DocumentImpl(org.apache.harmony.xml.dom.DocumentImpl) URL(java.net.URL) URLConnection(java.net.URLConnection)

Example 10 with LocatorImpl

use of org.xml.sax.helpers.LocatorImpl in project XobotOS by xamarin.

the class DocumentBuilderImpl method parse.

@Override
public Document parse(InputSource source) throws SAXException, IOException {
    if (source == null) {
        throw new IllegalArgumentException("source == null");
    }
    String namespaceURI = null;
    String qualifiedName = null;
    DocumentType doctype = null;
    String inputEncoding = source.getEncoding();
    String systemId = source.getSystemId();
    DocumentImpl document = new DocumentImpl(dom, namespaceURI, qualifiedName, doctype, inputEncoding);
    document.setDocumentURI(systemId);
    KXmlParser parser = new KXmlParser();
    try {
        parser.keepNamespaceAttributes();
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, namespaceAware);
        if (source.getByteStream() != null) {
            parser.setInput(source.getByteStream(), inputEncoding);
        } else if (source.getCharacterStream() != null) {
            parser.setInput(source.getCharacterStream());
        } else if (systemId != null) {
            URL url = new URL(systemId);
            URLConnection urlConnection = url.openConnection();
            urlConnection.connect();
            // TODO: if null, extract the inputEncoding from the Content-Type header?
            parser.setInput(urlConnection.getInputStream(), inputEncoding);
        } else {
            throw new SAXParseException("InputSource needs a stream, reader or URI", null);
        }
        if (parser.nextToken() == XmlPullParser.END_DOCUMENT) {
            throw new SAXParseException("Unexpected end of document", null);
        }
        parse(parser, document, document, XmlPullParser.END_DOCUMENT);
        parser.require(XmlPullParser.END_DOCUMENT, null, null);
    } catch (XmlPullParserException ex) {
        if (ex.getDetail() instanceof IOException) {
            throw (IOException) ex.getDetail();
        }
        if (ex.getDetail() instanceof RuntimeException) {
            throw (RuntimeException) ex.getDetail();
        }
        LocatorImpl locator = new LocatorImpl();
        locator.setPublicId(source.getPublicId());
        locator.setSystemId(systemId);
        locator.setLineNumber(ex.getLineNumber());
        locator.setColumnNumber(ex.getColumnNumber());
        SAXParseException newEx = new SAXParseException(ex.getMessage(), locator);
        if (errorHandler != null) {
            errorHandler.error(newEx);
        }
        throw newEx;
    } finally {
        IoUtils.closeQuietly(parser);
    }
    return document;
}
Also used : KXmlParser(org.kxml2.io.KXmlParser) SAXParseException(org.xml.sax.SAXParseException) DocumentType(org.w3c.dom.DocumentType) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) LocatorImpl(org.xml.sax.helpers.LocatorImpl) IOException(java.io.IOException) DocumentImpl(org.apache.harmony.xml.dom.DocumentImpl) URL(java.net.URL) URLConnection(java.net.URLConnection)

Aggregations

LocatorImpl (org.xml.sax.helpers.LocatorImpl)23 SAXParseException (org.xml.sax.SAXParseException)7 SAXException (org.xml.sax.SAXException)6 SchemaLocationFilter (com.sun.xml.bind.marshaller.SchemaLocationFilter)4 MarshalException (javax.xml.bind.MarshalException)4 IOException (java.io.IOException)3 URL (java.net.URL)3 URLConnection (java.net.URLConnection)3 DocumentImpl (org.apache.harmony.xml.dom.DocumentImpl)3 KXmlParser (org.kxml2.io.KXmlParser)3 DocumentType (org.w3c.dom.DocumentType)3 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)3 Locator (org.xml.sax.Locator)2 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Properties (java.util.Properties)1 XMLEventReader (javax.xml.stream.XMLEventReader)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 XMLEvent (javax.xml.stream.events.XMLEvent)1