Search in sources :

Example 1 with MXParser

use of org.xmlpull.mxp1.MXParser in project Spark by igniterealtime.

the class LogManagerImpl method loadCallHistory.

/**
 * Reads in the transcript file using the Xml Pull Parser.
 */
private void loadCallHistory() {
    File historyFile = getHistoryFile();
    if (!historyFile.exists()) {
        return;
    }
    // Otherwise load
    try {
        final MXParser parser = new MXParser();
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
        BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(historyFile), "UTF-8"));
        parser.setInput(in);
        boolean done = false;
        while (!done) {
            int eventType = parser.next();
            if (eventType == XmlPullParser.START_TAG && "call".equals(parser.getName())) {
                calls.add(getHistoryCall(parser));
            } else if (eventType == XmlPullParser.END_TAG && "calls".equals(parser.getName())) {
                done = true;
            }
        }
        in.close();
    } catch (Exception e) {
        Log.error(e);
    }
}
Also used : MXParser(org.xmlpull.mxp1.MXParser) SmackException(org.jivesoftware.smack.SmackException) XMPPException(org.jivesoftware.smack.XMPPException)

Example 2 with MXParser

use of org.xmlpull.mxp1.MXParser in project Spark by igniterealtime.

the class ConversationHistoryPlugin method loadPreviousHistory.

/**
 * Loads the previous history.
 */
private void loadPreviousHistory() {
    if (!conFile.exists()) {
        return;
    }
    // Otherwise load it.
    try {
        final MXParser parser = new MXParser();
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
        BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(conFile), "UTF-8"));
        parser.setInput(in);
        boolean done = false;
        while (!done) {
            int eventType = parser.next();
            if (eventType == XmlPullParser.START_TAG && "user".equals(parser.getName())) {
                String jid = XmppStringUtils.parseBareJid(parser.nextText());
                historyList.add(jid);
            } else if (eventType == XmlPullParser.END_TAG && "conversations".equals(parser.getName())) {
                done = true;
            }
        }
        in.close();
    } catch (Exception e) {
        Log.error(e);
    }
}
Also used : MXParser(org.xmlpull.mxp1.MXParser)

Example 3 with MXParser

use of org.xmlpull.mxp1.MXParser in project Spark by igniterealtime.

the class ChatTranscripts method getTranscript.

/**
 * Reads in the transcript file using the Xml Pull Parser.
 *
 * @param transcriptFile the transcript file to read.
 * @return the ChatTranscript.
 */
public static ChatTranscript getTranscript(File transcriptFile) {
    final ChatTranscript transcript = new ChatTranscript();
    if (!transcriptFile.exists()) {
        return transcript;
    }
    try {
        final MXParser parser = new MXParser();
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
        BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(transcriptFile), "UTF-8"));
        parser.setInput(in);
        boolean done = false;
        while (!done) {
            int eventType = parser.next();
            if (eventType == XmlPullParser.START_TAG && "message".equals(parser.getName())) {
                transcript.addHistoryMessage(getHistoryMessage(parser));
            } else if (eventType == XmlPullParser.END_TAG && "transcript".equals(parser.getName())) {
                done = true;
            }
        }
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return transcript;
}
Also used : InputStreamReader(java.io.InputStreamReader) MXParser(org.xmlpull.mxp1.MXParser) BufferedReader(java.io.BufferedReader) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) ParseException(java.text.ParseException)

Example 4 with MXParser

use of org.xmlpull.mxp1.MXParser in project ecf by eclipse.

the class SimpleDirectoryPersistentCache method restoreInfoFromFile.

/**
 * Tries to restore an DiscoverInfo packet from a file.
 *
 * @param file
 * @return
 * @throws IOException
 */
private static DiscoverInfo restoreInfoFromFile(File file) throws IOException {
    DataInputStream dis = new DataInputStream(new FileInputStream(file));
    String fileContent = null;
    String id;
    String from;
    String to;
    try {
        fileContent = dis.readUTF();
    } finally {
        dis.close();
    }
    if (fileContent == null)
        return null;
    Reader reader = new StringReader(fileContent);
    XmlPullParser parser;
    try {
        parser = new MXParser();
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
        parser.setInput(reader);
    } catch (XmlPullParserException xppe) {
        xppe.printStackTrace();
        return null;
    }
    DiscoverInfo iqPacket;
    IQProvider provider = new DiscoverInfoProvider();
    // Parse the IQ, we only need the id
    try {
        parser.next();
        id = parser.getAttributeValue("", "id");
        from = parser.getAttributeValue("", "from");
        to = parser.getAttributeValue("", "to");
        parser.next();
    } catch (XmlPullParserException e1) {
        return null;
    }
    try {
        iqPacket = (DiscoverInfo) provider.parseIQ(parser);
    } catch (Exception e) {
        return null;
    }
    iqPacket.setPacketID(id);
    iqPacket.setFrom(from);
    iqPacket.setTo(to);
    iqPacket.setType(IQ.Type.RESULT);
    return iqPacket;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.packet.DiscoverInfo) MXParser(org.xmlpull.mxp1.MXParser) DiscoverInfoProvider(org.jivesoftware.smackx.provider.DiscoverInfoProvider) StringReader(java.io.StringReader) XmlPullParser(org.xmlpull.v1.XmlPullParser) Reader(java.io.Reader) StringReader(java.io.StringReader) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IQProvider(org.jivesoftware.smack.provider.IQProvider)

Example 5 with MXParser

use of org.xmlpull.mxp1.MXParser in project Spark by igniterealtime.

the class PhonebookManager method loadPhonebook.

/**
 * Reads in the transcript file using the Xml Pull Parser.
 */
private void loadPhonebook() {
    File bookFile = getPhonebookFile();
    if (!bookFile.exists()) {
        return;
    }
    // Otherwise load
    try {
        final MXParser parser = new MXParser();
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
        BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(bookFile), "UTF-8"));
        parser.setInput(in);
        boolean done = false;
        while (!done) {
            int eventType = parser.next();
            if (eventType == XmlPullParser.START_TAG && "entry".equals(parser.getName())) {
                phonenumbers.add(getBookEntry(parser));
            } else if (eventType == XmlPullParser.END_TAG && "book".equals(parser.getName())) {
                done = true;
            }
        }
        in.close();
    } catch (Exception e) {
        Log.error(e);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) MXParser(org.xmlpull.mxp1.MXParser) BufferedReader(java.io.BufferedReader) File(java.io.File) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException)

Aggregations

MXParser (org.xmlpull.mxp1.MXParser)8 FileInputStream (java.io.FileInputStream)3 IOException (java.io.IOException)3 XmlPullParser (org.xmlpull.v1.XmlPullParser)3 BufferedReader (java.io.BufferedReader)2 InputStreamReader (java.io.InputStreamReader)2 IQ (org.jivesoftware.smack.packet.IQ)2 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)2 DataInputStream (java.io.DataInputStream)1 File (java.io.File)1 InputStream (java.io.InputStream)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ParseException (java.text.ParseException)1 SmackException (org.jivesoftware.smack.SmackException)1 XMPPException (org.jivesoftware.smack.XMPPException)1 ExtensionElementProvider (org.jivesoftware.smack.provider.ExtensionElementProvider)1 IQProvider (org.jivesoftware.smack.provider.IQProvider)1