Granted some account/identity keys their own XML element (export)

This commit is contained in:
cketti 2011-03-30 06:37:10 +02:00
parent 8850915987
commit 70f9a7b852
2 changed files with 61 additions and 16 deletions

View File

@ -55,11 +55,17 @@ public class Account implements BaseAccount {
private static final String DEFAULT_QUOTE_PREFIX = ">";
private static final boolean DEFAULT_REPLY_AFTER_QUOTE = false;
public static final String ACCOUNT_DESCRIPTION_KEY = "description";
public static final String IDENTITY_NAME_KEY = "name";
public static final String IDENTITY_EMAIL_KEY = "email";
public static final String IDENTITY_DESCRIPTION_KEY = "description";
public static final Set<String> IDENTITY_KEYS = new HashSet<String>();
static {
IDENTITY_KEYS.add("name");
IDENTITY_KEYS.add("email");
IDENTITY_KEYS.add("description");
IDENTITY_KEYS.add(IDENTITY_NAME_KEY);
IDENTITY_KEYS.add(IDENTITY_EMAIL_KEY);
IDENTITY_KEYS.add(IDENTITY_DESCRIPTION_KEY);
IDENTITY_KEYS.add("signatureUse");
IDENTITY_KEYS.add("signature");
IDENTITY_KEYS.add("replyTo");
@ -1036,11 +1042,11 @@ public class Account implements BaseAccount {
boolean gotOne = false;
do {
gotOne = false;
String name = prefs.getString(mUuid + ".name." + ident, null);
String email = prefs.getString(mUuid + ".email." + ident, null);
String name = prefs.getString(mUuid + "." + IDENTITY_NAME_KEY + "." + ident, null);
String email = prefs.getString(mUuid + "." + IDENTITY_EMAIL_KEY + "." + ident, null);
boolean signatureUse = prefs.getBoolean(mUuid + ".signatureUse." + ident, true);
String signature = prefs.getString(mUuid + ".signature." + ident, null);
String description = prefs.getString(mUuid + ".description." + ident, null);
String description = prefs.getString(mUuid + "." + IDENTITY_DESCRIPTION_KEY + "." + ident, null);
final String replyTo = prefs.getString(mUuid + ".replyTo." + ident, null);
if (email != null) {
Identity identity = new Identity();
@ -1078,13 +1084,13 @@ public class Account implements BaseAccount {
boolean gotOne = false;
do {
gotOne = false;
String email = prefs.getString(mUuid + ".email." + ident, null);
String email = prefs.getString(mUuid + "." + IDENTITY_EMAIL_KEY + "." + ident, null);
if (email != null) {
editor.remove(mUuid + ".name." + ident);
editor.remove(mUuid + ".email." + ident);
editor.remove(mUuid + "." + IDENTITY_NAME_KEY + "." + ident);
editor.remove(mUuid + "." + IDENTITY_EMAIL_KEY + "." + ident);
editor.remove(mUuid + ".signatureUse." + ident);
editor.remove(mUuid + ".signature." + ident);
editor.remove(mUuid + ".description." + ident);
editor.remove(mUuid + "." + IDENTITY_DESCRIPTION_KEY + "." + ident);
editor.remove(mUuid + ".replyTo." + ident);
gotOne = true;
}
@ -1097,11 +1103,11 @@ public class Account implements BaseAccount {
int ident = 0;
for (Identity identity : identities) {
editor.putString(mUuid + ".name." + ident, identity.getName());
editor.putString(mUuid + ".email." + ident, identity.getEmail());
editor.putString(mUuid + "." + IDENTITY_NAME_KEY + "." + ident, identity.getName());
editor.putString(mUuid + "." + IDENTITY_EMAIL_KEY + "." + ident, identity.getEmail());
editor.putBoolean(mUuid + ".signatureUse." + ident, identity.getSignatureUse());
editor.putString(mUuid + ".signature." + ident, identity.getSignature());
editor.putString(mUuid + ".description." + ident, identity.getDescription());
editor.putString(mUuid + "." + IDENTITY_DESCRIPTION_KEY + "." + ident, identity.getDescription());
editor.putString(mUuid + ".replyTo." + ident, identity.getReplyTo());
ident++;
}

View File

@ -43,6 +43,9 @@ public class StorageExporter {
private static final String NAME_ATTRIBUTE = "name";
private static final String VALUE_ELEMENT = "value";
private static final String KEY_ATTRIBUTE = "key";
private static final String NAME_ELEMENT = "name";
private static final String EMAIL_ELEMENT = "email";
private static final String DESCRIPTION_ELEMENT = "description";
public static String exportToFile(Context context, boolean includeGlobals,
@ -169,6 +172,13 @@ public class StorageExporter {
serializer.startTag(null, ACCOUNT_ELEMENT);
serializer.attribute(null, UUID_ATTRIBUTE, accountUuid);
String name = (String) prefs.get(accountUuid + "." + Account.ACCOUNT_DESCRIPTION_KEY);
if (name != null) {
serializer.startTag(null, NAME_ELEMENT);
serializer.text(name);
serializer.endTag(null, NAME_ELEMENT);
}
serializer.startTag(null, SETTINGS_ELEMENT);
for (Map.Entry<String, ? extends Object> entry : prefs.entrySet()) {
String key = entry.getKey();
@ -176,11 +186,13 @@ public class StorageExporter {
String[] comps = key.split("\\.");
if (comps.length >= 2) {
String keyUuid = comps[0];
if (!keyUuid.equals(accountUuid)) {
String secondPart = comps[1];
if (!keyUuid.equals(accountUuid)
|| Account.ACCOUNT_DESCRIPTION_KEY.equals(secondPart)) {
continue;
}
if (comps.length == 3) {
String secondPart = comps[1];
String thirdPart = comps[2];
if (Account.IDENTITY_KEYS.contains(secondPart)) {
@ -242,6 +254,28 @@ public class StorageExporter {
String identity, Map<String, ? extends Object> prefs) throws IOException {
serializer.startTag(null, IDENTITY_ELEMENT);
String name = (String) prefs.get(accountUuid + "." + Account.IDENTITY_NAME_KEY +
"." + identity);
serializer.startTag(null, NAME_ELEMENT);
serializer.text(name);
serializer.endTag(null, NAME_ELEMENT);
String email = (String) prefs.get(accountUuid + "." + Account.IDENTITY_EMAIL_KEY +
"." + identity);
serializer.startTag(null, EMAIL_ELEMENT);
serializer.text(email);
serializer.endTag(null, EMAIL_ELEMENT);
String description = (String) prefs.get(accountUuid + "." +
Account.IDENTITY_DESCRIPTION_KEY + "." + identity);
if (description != null) {
serializer.startTag(null, DESCRIPTION_ELEMENT);
serializer.text(description);
serializer.endTag(null, DESCRIPTION_ELEMENT);
}
serializer.startTag(null, SETTINGS_ELEMENT);
for (Map.Entry<String, ? extends Object> entry : prefs.entrySet()) {
String key = entry.getKey();
String value = entry.getValue().toString();
@ -251,7 +285,10 @@ public class StorageExporter {
String identityKey = comps[1];
String identityIndex = comps[2];
if (!keyUuid.equals(accountUuid) || !identityIndex.equals(identity)
|| !Account.IDENTITY_KEYS.contains(identityKey)) {
|| !Account.IDENTITY_KEYS.contains(identityKey)
|| Account.IDENTITY_NAME_KEY.equals(identityKey)
|| Account.IDENTITY_EMAIL_KEY.equals(identityKey)
|| Account.IDENTITY_DESCRIPTION_KEY.equals(identityKey)) {
continue;
}
} else {
@ -264,6 +301,8 @@ public class StorageExporter {
serializer.text(value);
serializer.endTag(null, VALUE_ELEMENT);
}
serializer.endTag(null, SETTINGS_ELEMENT);
serializer.endTag(null, IDENTITY_ELEMENT);
}