This repository has been archived by the owner on Feb 3, 2023. It is now read-only.
/
MemoXmlExporter.java
73 lines (65 loc) · 2.4 KB
/
MemoXmlExporter.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
/**
* pdbconverter - Convert Palm PDB files into more common formats
*
* Copyright (C) 2009 Richard "Shred" Körber
* http://pdbconverter.shredzone.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.shredzone.pdbconverter.export;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import org.shredzone.commons.pdb.PdbDatabase;
import org.shredzone.commons.pdb.appinfo.CategoryAppInfo;
import org.shredzone.commons.pdb.record.MemoRecord;
/**
* Writes a {@link MemoRecord} database as a single XML file.
*
* @author Richard "Shred" Körber
*/
public class MemoXmlExporter extends AbstractExporter<MemoRecord, CategoryAppInfo> {
/**
* Writes the {@link MemoRecord} database XML to the given {@link OutputStream}.
*
* @param database
* {@link MemoRecord} {@link PdbDatabase} to write
* @param out
* {@link OutputStream} to write to
*/
@Override
public void export(PdbDatabase<MemoRecord, CategoryAppInfo> database, OutputStream out)
throws IOException {
XmlHelper xh = new XmlHelper();
xh.openXmlWriter(out, "memodb");
xh.writeDatabase(database);
xh.writeCategories(database);
xh.startElement("memos");
List<MemoRecord> records = database.getRecords();
for (int ix = 0; ix < records.size(); ix++) {
MemoRecord record = records.get(ix);
if (isAccepted(record)) {
xh.startElement("memo",
"id", ix,
"category", record.getCategoryIndex(),
"secret", record.isSecret()
);
xh.writeContent(record.getMemo());
xh.endElement();
}
}
xh.endElement();
xh.closeXmlWriter();
}
}