-
Notifications
You must be signed in to change notification settings - Fork 0
/
RvlXMLExport.java
98 lines (88 loc) · 2.93 KB
/
RvlXMLExport.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package net.sf.gnukeyring.export;
import net.sf.gnukeyring.KeyringEntry;
import net.sf.gnukeyring.KeyringLibrary;
import java.io.*;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
/**
* The Revelation XML export for a keyring database.
* a fork of XMLExport.java
*/
public class RvlXMLExport extends Export {
public RvlXMLExport() {
}
public void export() throws IOException {
writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
writer.write("<revelationdata version=\"0.4.11\" dataversion=\"1\">\n");
exportEntries();
writer.write("</revelationdata>\n");
writer.close();
}
public String xmlencode(String str) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
switch (c) {
case '&':
sb.append("&");
break;
case '<':
sb.append("<");
break;
case '>':
sb.append(">");
break;
default:
sb.append(c);
}
}
return sb.toString();
}
public void exportEntries() throws IOException {
List entries = keylib.getEntries();
Set categories= keylib.getCategories();
Date now = new Date();
String nowString = String.valueOf((long)(now.getTime()/1000L));
for (Iterator i = categories.iterator(); i.hasNext(); ) {
Object o = i.next();
if (o != null) {
String c = o.toString();
writer.write("<entry type=\"folder\">\n");
writer.write(" <name>"+xmlencode(c)+"</name>\n");
writer.write(" <description></description>\n");
writer.write(" <updated>"+nowString+"</updated>\n");
for (Iterator j = entries.iterator(); j.hasNext(); ) {
KeyringEntry entry = (KeyringEntry) j.next();
String category = (String) entry.getCategory();
if (category.equals(c)) {
writer.write(" <entry type=\"generic\">\n");
writer.write(" <name>"+xmlencode(entry.getName())+"</name>\n");
String account = (String) entry.getField("Account");
String password = (String) entry.getField("Password");
Date changed = (Date) entry.getField("Changed");
String notes = (String) entry.getField("Notes");
if (notes != null) {
if ((password !=null) && notes.equals(password)) {
writer.write(" <description></description>\n");
} else {
writer.write(" <description>"+xmlencode(notes)+"</description>\n");
}
}
if (changed != null) {
String updated = String.valueOf((long)(changed.getTime()/1000L));
writer.write(" <updated>"+updated+"</updated>\n");
}
if (account != null)
writer.write(" <field id=\"generic-username\">"+xmlencode(account)+"</field>\n");
if (password != null)
writer.write(" <field id=\"generic-password\">"+xmlencode(password)+"</field>\n");
writer.write(" </entry>\n");
}
}
}
writer.write("</entry>\n");
}
}
}