Search in sources :

Example 1 with InterningKXmlParser

use of org.javarosa.xform.util.InterningKXmlParser in project javarosa by opendatakit.

the class XFormParser method getXMLDocument.

/**
 * Uses xkml to parse the provided XML content, and then consolidates text elements.
 *
 * @param reader      the XML content provider
 * @param stringCache an optional string cache, whose presence will cause the use of
 *                    {@link InterningKXmlParser} rather than {@link KXmlParser}.
 * @return the parsed document
 * @throws IOException
 * @deprecated The InterningKXmlParser is not used.
 */
@Deprecated
public static Document getXMLDocument(Reader reader, CacheTable<String> stringCache) throws IOException {
    final CodeTimer ctParse = new CodeTimer("Reading XML and parsing with kXML2");
    Document doc = new Document();
    try {
        KXmlParser parser;
        if (stringCache != null) {
            parser = new InterningKXmlParser(stringCache);
        } else {
            parser = new KXmlParser();
        }
        parser.setInput(reader);
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
        doc.parse(parser);
    } catch (XmlPullParserException e) {
        String errorMsg = "XML Syntax Error at Line: " + e.getLineNumber() + ", Column: " + e.getColumnNumber() + "!";
        Std.err.println(errorMsg);
        Std.printStack(e);
        throw new XFormParseException(errorMsg);
    } catch (IOException e) {
        // CTS - 12/09/2012 - Stop swallowing IO Exceptions
        throw e;
    } catch (Exception e) {
        // #if debug.output==verbose || debug.output==exception
        String errorMsg = "Unhandled Exception while Parsing XForm";
        Std.err.println(errorMsg);
        Std.printStack(e);
        throw new XFormParseException(errorMsg);
    // #endif
    }
    try {
        reader.close();
    } catch (IOException e) {
        Std.out.println("Error closing reader");
        Std.printStack(e);
    }
    ctParse.logDone();
    final CodeTimer ctConsolidate = new CodeTimer("Consolidating text");
    XmlTextConsolidator.consolidateText(stringCache, doc.getRootElement());
    ctConsolidate.logDone();
    return doc;
}
Also used : KXmlParser(org.kxml2.io.KXmlParser) InterningKXmlParser(org.javarosa.xform.util.InterningKXmlParser) InterningKXmlParser(org.javarosa.xform.util.InterningKXmlParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) Document(org.kxml2.kdom.Document) CodeTimer(org.javarosa.core.util.CodeTimer) UnfullfilledRequirementsException(org.javarosa.xml.util.UnfullfilledRequirementsException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) InvalidStructureException(org.javarosa.xml.util.InvalidStructureException) XPathSyntaxException(org.javarosa.xpath.parser.XPathSyntaxException) IOException(java.io.IOException) PrototypeFactoryDeprecated(org.javarosa.core.util.externalizable.PrototypeFactoryDeprecated)

Aggregations

IOException (java.io.IOException)1 CodeTimer (org.javarosa.core.util.CodeTimer)1 PrototypeFactoryDeprecated (org.javarosa.core.util.externalizable.PrototypeFactoryDeprecated)1 InterningKXmlParser (org.javarosa.xform.util.InterningKXmlParser)1 InvalidStructureException (org.javarosa.xml.util.InvalidStructureException)1 UnfullfilledRequirementsException (org.javarosa.xml.util.UnfullfilledRequirementsException)1 XPathSyntaxException (org.javarosa.xpath.parser.XPathSyntaxException)1 KXmlParser (org.kxml2.io.KXmlParser)1 Document (org.kxml2.kdom.Document)1 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)1