Search in sources :

Example 26 with Document

use of org.kxml2.kdom.Document in project javarosa by opendatakit.

the class XFormParser method restoreDataModel.

public static FormInstance restoreDataModel(Document doc, Class restorableType) {
    Restorable r = (restorableType != null ? (Restorable) PrototypeFactory.getInstance(restorableType) : null);
    Element e = doc.getRootElement();
    TreeElement te = buildInstanceStructure(e, null, buildNamespacesMap(e), null);
    FormInstance dm = new FormInstance(te);
    loadNamespaces(e, dm);
    if (r != null) {
        RestoreUtils.templateData(r, dm, null);
    }
    loadInstanceData(e, te, null);
    return dm;
}
Also used : TreeElement(org.javarosa.core.model.instance.TreeElement) AbstractTreeElement(org.javarosa.core.model.instance.AbstractTreeElement) Element(org.kxml2.kdom.Element) IFormElement(org.javarosa.core.model.IFormElement) FormInstance(org.javarosa.core.model.instance.FormInstance) Restorable(org.javarosa.core.model.util.restorable.Restorable) TreeElement(org.javarosa.core.model.instance.TreeElement) AbstractTreeElement(org.javarosa.core.model.instance.AbstractTreeElement)

Example 27 with Document

use of org.kxml2.kdom.Document in project javarosa by opendatakit.

the class XFormSerializer method getStream.

public static ByteArrayOutputStream getStream(Document doc) {
    KXmlSerializer serializer = new KXmlSerializer();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(bos);
    try {
        serializer.setOutput(dos, null);
        doc.write(serializer);
        serializer.flush();
        return bos;
    } catch (Exception e) {
        Std.printStack(e);
        return null;
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) KXmlSerializer(org.kxml2.io.KXmlSerializer) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 28 with Document

use of org.kxml2.kdom.Document in project javarosa by opendatakit.

the class ElementParser method instantiateParser.

/**
 * Prepares a parser that will be used by the element parser, configuring relevant
 * parameters and setting it to the appropriate point in the document.
 *
 * @param stream A stream which is reading the XML content
 *               of the document.
 * @throws IOException If the stream cannot be read for any reason
 *                     other than invalid XML Structures.
 */
public static KXmlParser instantiateParser(InputStream stream) throws IOException {
    KXmlParser parser = new KXmlParser();
    try {
        parser.setInput(stream, "UTF-8");
        parser.setFeature(KXmlParser.FEATURE_PROCESS_NAMESPACES, true);
        // Point to the first available tag.
        parser.next();
        return parser;
    } catch (XmlPullParserException e) {
        // TODO Auto-generated catch block
        Logger.exception("Element Parser", e);
        throw new IOException(e.getMessage());
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
        throw new IOException(e.getMessage());
    }
}
Also used : KXmlParser(org.kxml2.io.KXmlParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)18 KXmlParser (org.kxml2.io.KXmlParser)12 Document (org.kxml2.kdom.Document)11 Element (org.kxml2.kdom.Element)11 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)11 ParsingException (org.opendatakit.briefcase.model.ParsingException)8 File (java.io.File)6 URL (java.net.URL)6 ArrayList (java.util.ArrayList)6 KXmlSerializer (org.kxml2.io.KXmlSerializer)6 FileNotFoundException (java.io.FileNotFoundException)5 InputStreamReader (java.io.InputStreamReader)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 InputStream (java.io.InputStream)4 MalformedURLException (java.net.MalformedURLException)4 FileSystemException (org.opendatakit.briefcase.model.FileSystemException)4 MetadataUpdateException (org.opendatakit.briefcase.model.MetadataUpdateException)4 MediaFile (org.opendatakit.briefcase.util.ServerFetcher.MediaFile)4 FileInputStream (java.io.FileInputStream)3 OutputStreamWriter (java.io.OutputStreamWriter)3