More work on Google mail notifications (work in progress)

cusax-fix
Emil Ivov 17 years ago
parent 6a695ab928
commit 4378a0945c

@ -6,8 +6,11 @@
*/
package net.java.sip.communicator.impl.protocol.jabber.extensions.mailnotification;
import java.io.*;
import java.util.*;
import org.xmlpull.v1.*;
/**
* This class represents the "mail-thread-info" element the Google use in their
* mail notifications to deliver detailed thread information.
@ -21,6 +24,27 @@ public class MailThreadInfo
*/
public static final String ELEMENT_NAME = "mail-thread-info";
/**
* The name of the XML tag element containing the list of all senders.
*/
public static final String SENDERS_ELEMENT_NAME = "senders";
/**
* The name of the XML tag element containing a pipe separated list of
* labels assigned to this thread.
*/
public static final String LABELS_ELEMENT_NAME = "labels";
/**
* The name of the XML tag element containing the thread subject.
*/
public static final String SUBJECT_ELEMENT_NAME = "subject";
/**
* The name of the XML tag element containing a snippet of the thread.
*/
public static final String SNIPPET_ELEMENT_NAME = "snippet";
/**
* Contains the list of senders that have participated in this thread.
*/
@ -91,6 +115,11 @@ public class MailThreadInfo
*/
public class Sender
{
/**
* The name of the XML tag element containing information for an
* individual sender and represented by this class.
*/
public static final String ELEMENT_NAME = "sender";
/**
* The email address of the sender.
*/
@ -315,4 +344,85 @@ protected void setSnippet(String snippet)
{
this.snippet = snippet;
}
/**
* Creates and initializes a <tt>MailThreadInfo</tt> instance according to
* the details that come with the parser.
*
* @param parser the parse that we are to read the <tt>MailThreadInfo</tt>
* from.
*
* @return the newly created <tt>MailThreadInfo</tt> instance.
*
* @throws XmlPullParserException if something goes wrong while parsing
* the document.
* @throws NumberFormatException in case we fail to parse any of the
* elements that we expect to be numerical.
* @throws IOException in case reading the input xml fails.
*/
public static MailThreadInfo parse(XmlPullParser parser)
throws XmlPullParserException, NumberFormatException, IOException
{
MailThreadInfo info = new MailThreadInfo();
//we start by parsing the thread tag itself which should look something
//like this:
// <mail-thread-info tid='1172320964060972012' participation='1'
// messages='28' date='1118012394209'
// url='http://mail.google.com/mail?view=cv'>
info.setTid(parser.getAttributeValue("", "tid"));
info.setParticipation( Integer.parseInt(
parser.getAttributeValue("", "participation")));
info.setMessageCount( Integer.parseInt(
parser.getAttributeValue("", "messages")));
info.setDate( Long.parseLong(
parser.getAttributeValue("", "date")));
info.setURL( parser.getAttributeValue("", "url"));
//now parse the rest of the message
int eventType = parser.next();
while(eventType != XmlPullParser.END_TAG)
{
if (eventType == XmlPullParser.START_TAG)
{
String name = parser.getName();
if(SENDERS_ELEMENT_NAME.equals(name))
{
//senders
info.parseSenders(parser);
}
else if( LABELS_ELEMENT_NAME.equals(name))
{
//labels
info.setLabels(parser.nextText());
}
else if( SUBJECT_ELEMENT_NAME.equals(name))
{
//subject
info.setSubject(parser.nextText());
}
else if( SNIPPET_ELEMENT_NAME.equals(name))
{
//snippet
info.setSnippet(parser.nextText());
}
}
eventType = parser.next();
}
return info;
}
/**
* Parses a list of senders for this thread.
* @param parser
*/
private void parseSenders(XmlPullParser parser)
{
// TODO Auto-generated method stub
}
}

@ -203,46 +203,6 @@ public String getUrl()
return url;
}
/**
* Specifies the sender of a mail referred to by this URL.
*
* @param
*/
public void setSender(String sender)
{
this.sender = sender;
}
/**
* Set the subject of the last mail
*
* @param subject the subjet of the email String
*/
public void setSubject(String subject)
{
this.subject = subject;
}
/**
* Return the sender of the last mail
*
* @return the sender of the email String
*/
public String getSender()
{
return this.sender;
}
/**
* Return the subject of the last mail
*
* @return the subject of the email String
*/
public String getSubject()
{
return this.subject;
}
/**
* Adds a thread info element to the list of threads that this
* <tt>MailboxIQ</tt> is referring to.

@ -55,37 +55,32 @@ public IQ parseIQ(final XmlPullParser parser) throws Exception
mailboxIQ.setUrl(parser.getAttributeValue("", "url"));
boolean done = false;
while(!done)
int eventType = parser.next();
while(eventType != XmlPullParser.END_TAG)
{
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG)
{
String name = parser.getName();
if(MailThreadInfo.ELEMENT_NAME.equals(name))
{
//parse mail thread information
MailThreadInfo thread = MailThreadInfo.parse(parser);
mailboxIQ.addThread(thread);
}
}
else if (eventType == XmlPullParser.END_TAG)
{
if (parser.getName().equals("field"))
{
done = true;
}
}
else
{
if(logger.isTraceEnabled())
{
logger.trace("xml parser returned eventType=" + eventType);
logger.trace("parser="+parser);
logger.trace("parser="+parser.getText());
}
}
eventType = parser.next();
}
int eventType = 1;
eventType = 1;
String name = null;
if (eventType == XmlPullParser.START_TAG)
{
@ -104,8 +99,8 @@ else if (eventType == XmlPullParser.END_TAG)
if ( "1".equals(
parser.getAttributeValue("","originator")))
{
mailboxIQ.setSender(parser.
getAttributeValue("", "address"));
//mailboxIQ.setSender(parser.
// getAttributeValue("", "address"));
}
}
}
@ -116,7 +111,7 @@ else if (eventType == XmlPullParser.END_TAG)
if ("subject".equals(name))
{
name = parser.nextText();
mailboxIQ.setSubject(name);
//mailboxIQ.setSubject(name);
}
}
}

Loading…
Cancel
Save