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);
}
}
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);
}
}
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;
}
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;
}
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);
}
}
Aggregations