1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-25 00:58:50 -05:00

Use constants for element names and attributes in XML export code

This commit is contained in:
cketti 2011-03-30 00:21:15 +02:00
parent fbe1b26f24
commit 77f7303aa2

View File

@ -24,6 +24,15 @@ import com.fsck.k9.helper.Utility;
public class StorageExporter { public class StorageExporter {
private static final String EXPORT_FILENAME = "settings.k9s"; private static final String EXPORT_FILENAME = "settings.k9s";
private static final String ROOT_ELEMENT = "k9settings";
private static final String VERSION_ATTRIBUTE = "version";
private static final String SETTINGS_ELEMENT = "settings";
private static final String ACCOUNTS_ELEMENT = "accounts";
private static final String ACCOUNT_ELEMENT = "account";
private static final String UUID_ATTRIBUTE = "uuid";
private static final String VALUE_ELEMENT = "value";
private static final String KEY_ATTRIBUTE = "key";
public static String exportToFile(Context context, boolean includeGlobals, public static String exportToFile(Context context, boolean includeGlobals,
Set<String> accountUuids, String encryptionKey) Set<String> accountUuids, String encryptionKey)
@ -65,9 +74,8 @@ public class StorageExporter {
// Output with indentation // Output with indentation
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
// Root tag serializer.startTag(null, ROOT_ELEMENT);
serializer.startTag(null, "k9settings"); serializer.attribute(null, VERSION_ATTRIBUTE, "x");
serializer.attribute(null, "version", "x");
Log.i(K9.LOG_TAG, "Exporting preferences"); Log.i(K9.LOG_TAG, "Exporting preferences");
@ -85,18 +93,18 @@ public class StorageExporter {
Map<String, ? extends Object> prefs = storage.getAll(); Map<String, ? extends Object> prefs = storage.getAll();
if (includeGlobals) { if (includeGlobals) {
serializer.startTag(null, "settings"); serializer.startTag(null, SETTINGS_ELEMENT);
writeSettings(serializer, prefs); writeSettings(serializer, prefs);
serializer.endTag(null, "settings"); serializer.endTag(null, SETTINGS_ELEMENT);
} }
serializer.startTag(null, "accounts"); serializer.startTag(null, ACCOUNTS_ELEMENT);
for (String accountUuid : accountUuids) { for (String accountUuid : accountUuids) {
writeAccount(serializer, accountUuid, prefs); writeAccount(serializer, accountUuid, prefs);
} }
serializer.endTag(null, "accounts"); serializer.endTag(null, ACCOUNTS_ELEMENT);
serializer.endTag(null, "k9settings"); serializer.endTag(null, ROOT_ELEMENT);
serializer.endDocument(); serializer.endDocument();
serializer.flush(); serializer.flush();
@ -115,18 +123,18 @@ public class StorageExporter {
// Skip account entries // Skip account entries
continue; continue;
} }
serializer.startTag(null, "value"); serializer.startTag(null, VALUE_ELEMENT);
serializer.attribute(null, "key", key); serializer.attribute(null, KEY_ATTRIBUTE, key);
serializer.text(value); serializer.text(value);
serializer.endTag(null, "value"); serializer.endTag(null, VALUE_ELEMENT);
} }
} }
private static void writeAccount(XmlSerializer serializer, String accountUuid, private static void writeAccount(XmlSerializer serializer, String accountUuid,
Map<String, ? extends Object> prefs) throws IOException { Map<String, ? extends Object> prefs) throws IOException {
serializer.startTag(null, "account"); serializer.startTag(null, ACCOUNT_ELEMENT);
serializer.attribute(null, "uuid", accountUuid); serializer.attribute(null, UUID_ATTRIBUTE, accountUuid);
for (Map.Entry<String, ? extends Object> entry : prefs.entrySet()) { for (Map.Entry<String, ? extends Object> entry : prefs.entrySet()) {
String key = entry.getKey(); String key = entry.getKey();
String value = entry.getValue().toString(); String value = entry.getValue().toString();
@ -144,11 +152,11 @@ public class StorageExporter {
// Strip account UUID from key // Strip account UUID from key
String keyPart = key.substring(comps[0].length() + 1); String keyPart = key.substring(comps[0].length() + 1);
serializer.startTag(null, "value"); serializer.startTag(null, VALUE_ELEMENT);
serializer.attribute(null, "key", keyPart); serializer.attribute(null, KEY_ATTRIBUTE, keyPart);
serializer.text(value); serializer.text(value);
serializer.endTag(null, "value"); serializer.endTag(null, VALUE_ELEMENT);
} }
serializer.endTag(null, "account"); serializer.endTag(null, ACCOUNT_ELEMENT);
} }
} }