Search in sources :

Example 21 with XmlPullParserFactory

use of org.xmlpull.v1.XmlPullParserFactory in project processdash by dtuma.

the class XmlParamDataPersisterV1 method getTextToPersistImpl.

private String getTextToPersistImpl(Map postedData) throws IOException {
    XmlSerializer ser = null;
    try {
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        ser = factory.newSerializer();
    } catch (XmlPullParserException xppe) {
        throw new RuntimeException("Couldn't obtain xml serializer", xppe);
    }
    try {
        if (generateWhitespace)
            ser.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
    } catch (Exception e) {
    }
    StringWriter out = new StringWriter();
    ser.setOutput(out);
    ser.startDocument("utf-16", Boolean.TRUE);
    ser.flush();
    out.getBuffer().setLength(0);
    ser.startTag(null, TOP_TAG);
    // in "_ALL".  This simplifies our work.
    if (lenientPostedDataMode)
        addMissingALLParams(postedData);
    postedData = EditedPageDataParser.filterParamMap(postedData, new TreeMap(), null, "_ALL", false, true);
    writeParamList(ser, postedData);
    ser.endTag(null, TOP_TAG);
    ser.endDocument();
    return out.toString();
}
Also used : XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) StringWriter(java.io.StringWriter) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) TreeMap(java.util.TreeMap) IOException(java.io.IOException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) SAXException(org.xml.sax.SAXException) XmlSerializer(org.xmlpull.v1.XmlSerializer)

Example 22 with XmlPullParserFactory

use of org.xmlpull.v1.XmlPullParserFactory in project processdash by dtuma.

the class TimeLogWriter method write.

public static void write(Writer out, Iterator timeLogEntries, boolean close) throws IOException {
    XmlSerializer ser = null;
    try {
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        ser = factory.newSerializer();
    } catch (XmlPullParserException xppe) {
        throw new RuntimeException("Couldn't obtain xml serializer", xppe);
    }
    ser.setOutput(out);
    ser.startDocument(ENCODING, null);
    ser.ignorableWhitespace(NEWLINE);
    ser.startTag(null, DOC_ROOT_ELEM);
    ser.ignorableWhitespace(NEWLINE);
    try {
        while (timeLogEntries.hasNext()) writeTimeLogEntry(ser, (TimeLogEntry) timeLogEntries.next());
    } catch (IONoSuchElementException ionsee) {
        throw ionsee.getIOException();
    }
    ser.endTag(null, DOC_ROOT_ELEM);
    ser.ignorableWhitespace(NEWLINE);
    ser.endDocument();
    if (close)
        out.close();
    else
        out.flush();
}
Also used : XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) XmlSerializer(org.xmlpull.v1.XmlSerializer)

Example 23 with XmlPullParserFactory

use of org.xmlpull.v1.XmlPullParserFactory in project processdash by dtuma.

the class DataExporterXMLv1 method writeDataElements.

private void writeDataElements(Writer out, HashTree sorted) throws IOException {
    XmlSerializer xml = null;
    try {
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        xml = factory.newSerializer();
    } catch (XmlPullParserException xppe) {
        throw new RuntimeException("Couldn't obtain xml serializer", xppe);
    }
    // we need to write our header manually, because we need to specify
    // XML version 1.1
    out.write(DATA_XML_HEADER + NEWLINE + NEWLINE);
    xml.setOutput(out);
    xml.startTag(null, DATA_ELEM);
    xml.ignorableWhitespace(NEWLINE);
    writeDataElementsForNode(xml, sorted, 0);
    xml.endTag(null, DATA_ELEM);
    xml.ignorableWhitespace(NEWLINE);
    xml.endDocument();
    out.flush();
}
Also used : XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) XmlSerializer(org.xmlpull.v1.XmlSerializer)

Example 24 with XmlPullParserFactory

use of org.xmlpull.v1.XmlPullParserFactory in project coursera-android by aporter.

the class XMLResponseHandler method handleResponse.

@Override
public List<String> handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
    try {
        // Create the Pull Parser
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        XmlPullParser xpp = factory.newPullParser();
        // Set the Parser's input to be the XML document in the HTTP Response
        xpp.setInput(new InputStreamReader(response.getEntity().getContent()));
        // Get the first Parser event and start iterating over the XML document 
        int eventType = xpp.getEventType();
        while (eventType != XmlPullParser.END_DOCUMENT) {
            if (eventType == XmlPullParser.START_TAG) {
                startTag(xpp.getName());
            } else if (eventType == XmlPullParser.END_TAG) {
                endTag(xpp.getName());
            } else if (eventType == XmlPullParser.TEXT) {
                text(xpp.getText());
            }
            eventType = xpp.next();
        }
        return mResults;
    } catch (XmlPullParserException e) {
    }
    return null;
}
Also used : XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) InputStreamReader(java.io.InputStreamReader) XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 25 with XmlPullParserFactory

use of org.xmlpull.v1.XmlPullParserFactory in project android-maps-utils by googlemaps.

the class KmlLayer method createXmlParser.

/**
     * Creates a new XmlPullParser to allow for the KML file to be parsed
     *
     * @param stream InputStream containing KML file
     * @return XmlPullParser containing the KML file
     * @throws XmlPullParserException if KML file cannot be parsed
     */
private static XmlPullParser createXmlParser(InputStream stream) throws XmlPullParserException {
    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    factory.setNamespaceAware(true);
    XmlPullParser parser = factory.newPullParser();
    parser.setInput(stream, null);
    return parser;
}
Also used : XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) XmlPullParser(org.xmlpull.v1.XmlPullParser)

Aggregations

XmlPullParserFactory (org.xmlpull.v1.XmlPullParserFactory)40 XmlPullParser (org.xmlpull.v1.XmlPullParser)28 IOException (java.io.IOException)15 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)15 InputStream (java.io.InputStream)11 StringReader (java.io.StringReader)7 InputStreamReader (java.io.InputStreamReader)6 XmlSerializer (org.xmlpull.v1.XmlSerializer)5 XmlResourceParser (android.content.res.XmlResourceParser)4 IOException2 (hudson.util.IOException2)4 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 HashMap (java.util.HashMap)3 Reader (java.io.Reader)2 Iterator (java.util.Iterator)2 ParseConfigurationFileException (org.litepal.exceptions.ParseConfigurationFileException)2 PackageManager (android.content.pm.PackageManager)1 Resources (android.content.res.Resources)1 NonNull (android.support.annotation.NonNull)1 VisibleForTesting (android.support.annotation.VisibleForTesting)1