Search in sources :

Example 66 with XmlPullParserFactory

use of org.xmlpull.v1.XmlPullParserFactory in project violations-plugin by jenkinsci.

the class ParseXML method parse.

/**
 * Parse an xml file using a parser object.
 * @param xmlFile the file to parse.
 * @param xmlParser the parser object.
 * @throws IOException if there is a problem.
 */
public static void parse(File xmlFile, AbstractParser xmlParser) throws IOException {
    InputStream in = null;
    boolean seenException = false;
    try {
        in = new FileInputStream(xmlFile);
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        factory.setNamespaceAware(true);
        XmlPullParser parser = factory.newPullParser();
        parser.setInput(new XmlReader(in));
        xmlParser.setParser(parser);
        xmlParser.execute();
    } catch (IOException ex) {
        seenException = true;
        throw ex;
    } catch (Exception ex) {
        seenException = true;
        throw new IOException2(ex);
    } finally {
        CloseUtil.close(in, seenException);
    }
}
Also used : XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) XmlPullParser(org.xmlpull.v1.XmlPullParser) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) IOException2(hudson.util.IOException2)

Example 67 with XmlPullParserFactory

use of org.xmlpull.v1.XmlPullParserFactory in project Java by bottleleung.

the class XmlManager method getXmlParser.

/**
 * ��ȡXML������
 * @param fileName	��Ҫ������xml�ļ�·�����ļ�����������׺�������׺ͳһ��plist,�б�Ҫ���޸ģ�
 * @param encode	�ַ�������
 * @return
 */
public static XmlPullParser getXmlParser(String fileName, String encode) {
    try {
        // ��ô��� xml �ļ��� XmlResourceParser ����
        // XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), Thread.currentThread().getContextClassLoader().getClass());
        factory.setNamespaceAware(true);
        XmlPullParser xml = factory.newPullParser();
        xml.setInput(new FileInputStream(fileName + ".plist"), encode);
        return xml;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) XmlPullParser(org.xmlpull.v1.XmlPullParser) FileInputStream(java.io.FileInputStream)

Example 68 with XmlPullParserFactory

use of org.xmlpull.v1.XmlPullParserFactory in project wigle-wifi-wardriving by wiglenet.

the class KmlParserTest method createParser.

public XmlPullParser createParser(int res) throws Exception {
    InputStream stream = getInstrumentation().getContext().getResources().openRawResource(res);
    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    factory.setNamespaceAware(true);
    XmlPullParser parser = factory.newPullParser();
    parser.setInput(stream, null);
    parser.next();
    return parser;
}
Also used : XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) InputStream(java.io.InputStream) XmlPullParser(org.xmlpull.v1.XmlPullParser)

Example 69 with XmlPullParserFactory

use of org.xmlpull.v1.XmlPullParserFactory in project android_device_mediatek_common by MediatekDevs.

the class MtkEccList method parseEccList.

/**
 * Parse Ecc List From XML File
 *
 * @param none.
 * @return none.
 * @hide
 */
private static void parseEccList() {
    mCustomizedEccList.clear();
    // Parse GSM ECC list
    try {
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        XmlPullParser parser = factory.newPullParser();
        if (parser == null) {
            Rlog.d(LOG_TAG, "XmlPullParserFactory.newPullParser() return null");
            return;
        }
        FileReader fileReader = new FileReader(EccEntry.ECC_LIST_PATH);
        parser.setInput(fileReader);
        int eventType = parser.getEventType();
        EccEntry record = null;
        while (eventType != XmlPullParser.END_DOCUMENT) {
            switch(eventType) {
                case XmlPullParser.START_TAG:
                    if (parser.getName().equals(EccEntry.ECC_ENTRY_TAG)) {
                        record = new EccEntry();
                        int attrNum = parser.getAttributeCount();
                        for (int i = 0; i < attrNum; ++i) {
                            String name = parser.getAttributeName(i);
                            String value = parser.getAttributeValue(i);
                            if (name.equals(EccEntry.ECC_ATTR))
                                record.setEcc(value);
                            else if (name.equals(EccEntry.CATEGORY_ATTR))
                                record.setCategory(value);
                            else if (name.equals(EccEntry.CONDITION_ATTR))
                                record.setCondition(value);
                        }
                    }
                    break;
                case XmlPullParser.END_TAG:
                    if (parser.getName().equals(EccEntry.ECC_ENTRY_TAG) && record != null)
                        mCustomizedEccList.add(record);
                    break;
            }
            eventType = parser.next();
        }
        fileReader.close();
        if (sIsCtaSet) {
            String[] emergencyCTAList = { "120", "122", "110", "119" };
            for (String emergencyNum : emergencyCTAList) {
                record = new EccEntry();
                record.setEcc(emergencyNum);
                record.setCategory("0");
                record.setCondition(EccEntry.ECC_FOR_MMI);
                boolean bFound = false;
                int nIndex = 0;
                for (EccEntry eccEntry : mCustomizedEccList) {
                    String ecc = eccEntry.getEcc();
                    if (ecc.equals(emergencyNum)) {
                        bFound = true;
                        Rlog.d(LOG_TAG, "[parseEccList]" + "CTA ecc match customized ecc list, ecc=" + ecc);
                        break;
                    }
                    nIndex++;
                }
                if (bFound)
                    mCustomizedEccList.set(nIndex, record);
                else
                    mCustomizedEccList.add(record);
            }
        }
    } catch (XmlPullParserException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) XmlPullParser(org.xmlpull.v1.XmlPullParser) FileReader(java.io.FileReader) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Example 70 with XmlPullParserFactory

use of org.xmlpull.v1.XmlPullParserFactory in project KeepScore by nolanlawson.

the class GamesBackupSerializer method readGamesBackupSummary.

/**
 * Don't read the entire file; just read the game count and other basic, summarized information.
 *
 * @param backupFilename
 * @return
 */
@SuppressWarnings("incomplete-switch")
public static GamesBackupSummary readGamesBackupSummary(Uri uri, Format format, ContentResolver contentResolver) {
    GamesBackupSummary result = new GamesBackupSummary();
    int infoReceived = 0;
    try {
        XmlPullParser parser = null;
        BufferedReader reader = null;
        int parserEvent = -1;
        try {
            XmlPullParserFactory parserFactory = XmlPullParserFactory.newInstance();
            parser = parserFactory.newPullParser();
            InputStream inputStream = contentResolver.openInputStream(uri);
            if (format == Format.GZIP) {
                // new, gzipped format
                inputStream = new GZIPInputStream(inputStream);
            }
            reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 0x1000);
            parser.setInput(reader);
            parserEvent = parser.getEventType();
            Tag tag = null;
            String text = null;
            while (parserEvent != XmlPullParser.END_DOCUMENT) {
                parserEvent = parser.next();
                switch(parserEvent) {
                    case XmlPullParser.START_TAG:
                        tag = Tag.valueOf(parser.getName());
                        break;
                    case XmlPullParser.TEXT:
                        text = parser.getText();
                        break;
                    case XmlPullParser.END_TAG:
                        switch(tag) {
                            case gameCount:
                                result.setGameCount(Integer.parseInt(text));
                                infoReceived++;
                                break;
                            case version:
                                result.setVersion(Integer.parseInt(text));
                                infoReceived++;
                                if (result.getVersion() < VERSION_TWO) {
                                    // no automatic vs. manual distinction in version one
                                    result.setAutomatic(false);
                                    infoReceived++;
                                }
                                if (result.getVersion() < VERSION_THREE) {
                                    // filename not stored in XML file itself until version three
                                    result.setFilename(uri.getLastPathSegment());
                                    infoReceived++;
                                }
                                break;
                            case automatic:
                                result.setAutomatic(Boolean.parseBoolean(text));
                                infoReceived++;
                                break;
                            case dateBackupSaved:
                                result.setDateSaved(Long.parseLong(text));
                                infoReceived++;
                                break;
                            case backupFilename:
                                result.setFilename(text);
                                infoReceived++;
                                break;
                        }
                        break;
                }
                if (infoReceived == 5) {
                    // this is all the info required to create a summary
                    return result;
                }
            }
        } finally {
            if (reader != null) {
                reader.close();
            }
        }
    } catch (NumberFormatException e) {
        log.e(e, "unexpected exception for " + uri);
        throw new RuntimeException(e);
    } catch (IOException e) {
        log.e(e, "unexpected exception for " + uri);
        throw new RuntimeException(e);
    } catch (XmlPullParserException e) {
        log.e(e, "unexpected exception for " + uri);
        throw new RuntimeException(e);
    }
    throw new RuntimeException("failed to find summary for " + uri);
}
Also used : InputStreamReader(java.io.InputStreamReader) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) XmlPullParser(org.xmlpull.v1.XmlPullParser) IOException(java.io.IOException) GZIPInputStream(java.util.zip.GZIPInputStream) XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) BufferedReader(java.io.BufferedReader) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Aggregations

XmlPullParserFactory (org.xmlpull.v1.XmlPullParserFactory)71 XmlPullParser (org.xmlpull.v1.XmlPullParser)56 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)30 IOException (java.io.IOException)24 InputStream (java.io.InputStream)16 InputStreamReader (java.io.InputStreamReader)10 StringReader (java.io.StringReader)10 FileInputStream (java.io.FileInputStream)8 XmlSerializer (org.xmlpull.v1.XmlSerializer)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 File (java.io.File)5 XmlResourceParser (android.content.res.XmlResourceParser)4 IOException2 (hudson.util.IOException2)4 BufferedReader (java.io.BufferedReader)4 Reader (java.io.Reader)4 Map (java.util.Map)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 StringWriter (java.io.StringWriter)2