@ -11,6 +11,7 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException ;
import java.io.FileWriter ;
import java.io.IOException ;
import java.text.SimpleDateFormat ;
import java.util.regex.Matcher ;
import java.util.regex.Pattern ;
@ -18,7 +19,9 @@ public class XmlBackup {
private static final String PROTOCOL = "protocol" ;
private static final String ADDRESS = "address" ;
private static final String CONTACT_NAME = "contact_name" ;
private static final String DATE = "date" ;
private static final String READABLE_DATE = "readable_date" ;
private static final String TYPE = "type" ;
private static final String SUBJECT = "subject" ;
private static final String BODY = "body" ;
@ -29,6 +32,8 @@ public class XmlBackup {
private static final String SC_TOA = "sc_toa" ;
private static final String LOCKED = "locked" ;
private static final SimpleDateFormat dateFormatter = new SimpleDateFormat ( "EEE, dd MMM yyyy HH:mm:ss z" ) ;
private final XmlPullParser parser ;
public XmlBackup ( String path ) throws XmlPullParserException , FileNotFoundException {
@ -62,7 +67,9 @@ public class XmlBackup {
if ( attributeName . equals ( PROTOCOL ) ) item . protocol = Integer . parseInt ( parser . getAttributeValue ( i ) ) ;
else if ( attributeName . equals ( ADDRESS ) ) item . address = parser . getAttributeValue ( i ) ;
else if ( attributeName . equals ( CONTACT_NAME ) ) item . contactName = parser . getAttributeValue ( i ) ;
else if ( attributeName . equals ( DATE ) ) item . date = Long . parseLong ( parser . getAttributeValue ( i ) ) ;
else if ( attributeName . equals ( READABLE_DATE ) ) item . readableDate = parser . getAttributeValue ( i ) ;
else if ( attributeName . equals ( TYPE ) ) item . type = Integer . parseInt ( parser . getAttributeValue ( i ) ) ;
else if ( attributeName . equals ( SUBJECT ) ) item . subject = parser . getAttributeValue ( i ) ;
else if ( attributeName . equals ( BODY ) ) item . body = parser . getAttributeValue ( i ) ;
@ -80,7 +87,9 @@ public class XmlBackup {
public static class XmlBackupItem {
private int protocol ;
private String address ;
private String contactName ;
private long date ;
private String readableDate ;
private int type ;
private String subject ;
private String body ;
@ -90,12 +99,14 @@ public class XmlBackup {
public XmlBackupItem ( ) { }
public XmlBackupItem ( int protocol , String address , long date , int type , String subject ,
String body, String serviceCenter , int read , int status )
public XmlBackupItem ( int protocol , String address , String contactName , long date , int type ,
String subject, String body, String serviceCenter , int read , int status )
{
this . protocol = protocol ;
this . address = address ;
this . contactName = contactName ;
this . date = date ;
this . readableDate = dateFormatter . format ( date ) ;
this . type = type ;
this . subject = subject ;
this . body = body ;
@ -112,10 +123,18 @@ public class XmlBackup {
return address ;
}
public String getContactName ( ) {
return contactName ;
}
public long getDate ( ) {
return date ;
}
public String getReadableDate ( ) {
return readableDate ;
}
public int getType ( ) {
return type ;
}
@ -172,7 +191,9 @@ public class XmlBackup {
stringBuilder . append ( OPEN_TAG_SMS ) ;
appendAttribute ( stringBuilder , PROTOCOL , item . getProtocol ( ) ) ;
appendAttribute ( stringBuilder , ADDRESS , escapeXML ( item . getAddress ( ) ) ) ;
appendAttribute ( stringBuilder , CONTACT_NAME , item . getContactName ( ) ) ;
appendAttribute ( stringBuilder , DATE , item . getDate ( ) ) ;
appendAttribute ( stringBuilder , READABLE_DATE , item . getReadableDate ( ) ) ;
appendAttribute ( stringBuilder , TYPE , item . getType ( ) ) ;
appendAttribute ( stringBuilder , SUBJECT , escapeXML ( item . getSubject ( ) ) ) ;
appendAttribute ( stringBuilder , BODY , escapeXML ( item . getBody ( ) ) ) ;