Java Code Examples for org.xmlpull.mxp1.MXParser#setFeature()

The following examples show how to use org.xmlpull.mxp1.MXParser#setFeature() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChatTranscripts.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: ConversationHistoryPlugin.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * 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())) {
                EntityBareJid jid = JidCreate.entityBareFromUnescapedOrThrowUnchecked(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);
    }
}
 
Example 3
Source File: PhonebookManager.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example 4
Source File: LogManagerImpl.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example 5
Source File: VCardManager.java    From Spark with Apache License 2.0 4 votes vote down vote up
/**
 * Initialize VCardManager.
 */
public VCardManager() {

    // Register providers
    ProviderManager.addExtensionProvider( JabberAvatarExtension.ELEMENT_NAME, JabberAvatarExtension.NAMESPACE, new JabberAvatarExtension.Provider() );
    ProviderManager.addExtensionProvider( VCardUpdateExtension.ELEMENT_NAME, VCardUpdateExtension.NAMESPACE, new VCardUpdateExtension.Provider() );

    // Initialize parser
    parser = new MXParser();

    try {
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
    }
    catch (XmlPullParserException e) {
        Log.error(e);
    }

    imageFile = new File(SparkManager.getUserDirectory(), "personal.png");

    // Initialize vCard.
    personalVCard = new VCard();
    personalVCardAvatar = null;
    personalVCardHash = null;

    // Set VCard Storage
    vcardStorageDirectory = new File(SparkManager.getUserDirectory(), "vcards");
    vcardStorageDirectory.mkdirs();

    // Set the current user directory.
    contactsDir = new File(SparkManager.getUserDirectory(), "contacts");
    contactsDir.mkdirs();

    initializeUI();

    // Intercept all presence packets being sent and append vcard information.
    StanzaFilter presenceFilter = new StanzaTypeFilter(Presence.class);
    SparkManager.getConnection().addPacketInterceptor( stanza -> {
        Presence newPresence = (Presence)stanza;
        VCardUpdateExtension update = new VCardUpdateExtension();
        JabberAvatarExtension jax = new JabberAvatarExtension();

        ExtensionElement updateExt = newPresence.getExtension(update.getElementName(), update.getNamespace());
        ExtensionElement jabberExt = newPresence.getExtension(jax.getElementName(), jax.getNamespace());

        if (updateExt != null) {
            newPresence.removeExtension(updateExt);
        }

        if (jabberExt != null) {
            newPresence.removeExtension(jabberExt);
        }

        if (personalVCard != null) {

            if ( personalVCardAvatar == null )
            {
                personalVCardAvatar = personalVCard.getAvatar();
            }
            if (personalVCardAvatar != null && personalVCardAvatar.length > 0) {
                if ( personalVCardHash == null )
                {
                    personalVCardHash = personalVCard.getAvatarHash();
                }
                update.setPhotoHash(personalVCardHash);
                jax.setPhotoHash(personalVCardHash);

                newPresence.addExtension(update);
                newPresence.addExtension(jax);
            }
        }
    }, presenceFilter);

    editor = new VCardEditor();

    // Start Listener
    startQueueListener();
}