Search in sources :

Example 16 with KXmlParser

use of org.kxml2.io.KXmlParser in project platform_frameworks_base by android.

the class LayoutParserWrapperTest method getParserFromString.

private static LayoutParserWrapper getParserFromString(String layoutContent) throws XmlPullParserException {
    XmlPullParser parser = new KXmlParser();
    parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
    parser.setInput(new StringReader(layoutContent));
    return new LayoutParserWrapper(parser);
}
Also used : KXmlParser(org.kxml2.io.KXmlParser) XmlPullParser(org.xmlpull.v1.XmlPullParser) StringReader(java.io.StringReader)

Example 17 with KXmlParser

use of org.kxml2.io.KXmlParser in project platform_frameworks_base by android.

the class ExpatPerformanceTest method runJavaPullParser.

private void runJavaPullParser() throws XmlPullParserException, IOException {
    XmlPullParser pullParser;
    long start = System.currentTimeMillis();
    pullParser = new KXmlParser();
    pullParser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
    pullParser.setInput(newInputStream(), "UTF-8");
    withPullParser(pullParser);
    long elapsed = System.currentTimeMillis() - start;
    Log.i(TAG, "java pull parser: " + elapsed + "ms");
}
Also used : KXmlParser(org.kxml2.io.KXmlParser) XmlPullParser(org.xmlpull.v1.XmlPullParser)

Example 18 with KXmlParser

use of org.kxml2.io.KXmlParser in project android_frameworks_base by ParanoidAndroid.

the class ExpatPerformanceTest method runJavaPullParser.

private void runJavaPullParser() throws XmlPullParserException, IOException {
    XmlPullParser pullParser;
    long start = System.currentTimeMillis();
    pullParser = new KXmlParser();
    pullParser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
    pullParser.setInput(newInputStream(), "UTF-8");
    withPullParser(pullParser);
    long elapsed = System.currentTimeMillis() - start;
    Log.i(TAG, "java pull parser: " + elapsed + "ms");
}
Also used : KXmlParser(org.kxml2.io.KXmlParser) XmlPullParser(org.xmlpull.v1.XmlPullParser)

Example 19 with KXmlParser

use of org.kxml2.io.KXmlParser in project android_frameworks_base by ParanoidAndroid.

the class ParserFactory method create.

private static XmlPullParser create(InputStream stream, String name, long size) throws XmlPullParserException {
    KXmlParser parser = instantiateParser(name);
    stream = readAndClose(stream, name, size);
    parser.setInput(stream, ENCODING);
    return parser;
}
Also used : KXmlParser(org.kxml2.io.KXmlParser)

Example 20 with KXmlParser

use of org.kxml2.io.KXmlParser in project robovm by robovm.

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

KXmlParser (org.kxml2.io.KXmlParser)32 XmlPullParser (org.xmlpull.v1.XmlPullParser)14 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)14 StringReader (java.io.StringReader)8 IOException (java.io.IOException)6 URL (java.net.URL)3 URLConnection (java.net.URLConnection)3 DocumentImpl (org.apache.harmony.xml.dom.DocumentImpl)3 DocumentType (org.w3c.dom.DocumentType)3 SAXParseException (org.xml.sax.SAXParseException)3 LocatorImpl (org.xml.sax.helpers.LocatorImpl)3 XmlAttribute (com.intellij.psi.xml.XmlAttribute)2 XmlFile (com.intellij.psi.xml.XmlFile)2 XmlTag (com.intellij.psi.xml.XmlTag)2 InputStreamReader (java.io.InputStreamReader)2 TreeSet (java.util.TreeSet)2 VisibleForTesting (com.android.annotations.VisibleForTesting)1 PsiElement (com.intellij.psi.PsiElement)1 StringWriter (java.io.StringWriter)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1