OSDN Git Service

effdcb690d517d3c43e4a1576e8dec7f912e2bb7
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / xml / ExportData.java
1 /*\r
2  * This file is part of NeverNote \r
3  * Copyright 2009 Randy Baumgarte\r
4  * \r
5  * This file may be licensed under the terms of of the\r
6  * GNU General Public License Version 2 (the ``GPL'').\r
7  *\r
8  * Software distributed under the License is distributed\r
9  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either\r
10  * express or implied. See the GPL for the specific language\r
11  * governing rights and limitations.\r
12  *\r
13  * You should have received a copy of the GPL along with this\r
14  * program. If not, go to http://www.gnu.org/licenses/gpl.html\r
15  * or write to the Free Software Foundation, Inc.,\r
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
17  *\r
18 */\r
19 \r
20 package cx.fbn.nevernote.xml;\r
21 \r
22 import java.util.ArrayList;\r
23 import java.util.HashMap;\r
24 import java.util.List;\r
25 \r
26 import com.evernote.edam.type.Data;\r
27 import com.evernote.edam.type.LinkedNotebook;\r
28 import com.evernote.edam.type.Note;\r
29 import com.evernote.edam.type.NoteAttributes;\r
30 import com.evernote.edam.type.Notebook;\r
31 import com.evernote.edam.type.Publishing;\r
32 import com.evernote.edam.type.Resource;\r
33 import com.evernote.edam.type.SavedSearch;\r
34 import com.evernote.edam.type.SharedNotebook;\r
35 import com.evernote.edam.type.Tag;\r
36 import com.trolltech.qt.core.QByteArray;\r
37 import com.trolltech.qt.core.QFile;\r
38 import com.trolltech.qt.core.QIODevice;\r
39 import com.trolltech.qt.xml.QXmlStreamWriter;\r
40 \r
41 import cx.fbn.nevernote.Global;\r
42 import cx.fbn.nevernote.sql.DatabaseConnection;\r
43 import cx.fbn.nevernote.utilities.ApplicationLogger;\r
44 import cx.fbn.nevernote.utilities.Pair;\r
45 \r
46 public class ExportData {\r
47         \r
48         private List<Notebook>                                          notebooks;\r
49         private final HashMap<String,String>            localNotebooks;\r
50         private final HashMap<String,String>            dirtyNotebooks;\r
51         private final ApplicationLogger                         logger;\r
52         \r
53         private List<SavedSearch>                                       searches;\r
54         private List<LinkedNotebook>                            linkedNotebooks;\r
55         private List<SharedNotebook>                            sharedNotebooks;\r
56         private final HashMap<String,String>            dirtySearches;\r
57 \r
58         private List<Tag>                                                       tags;\r
59         private final HashMap<String,String>            dirtyTags;\r
60 \r
61         private final HashMap<String, String>           exportableNotebooks;\r
62         private final HashMap<String, String>           exportableTags;\r
63         private List<Note>                                                      notes;\r
64         private final HashMap<String,String>            dirtyNotes;\r
65         private final HashMap<String,String>            dirtyLinkedNotebooks;\r
66         private final HashMap<Long,String>                      dirtySharedNotebooks;\r
67         private HashMap<String,Integer>                         titleColors;\r
68         private final boolean                                           fullBackup;\r
69         private final DatabaseConnection                        conn;\r
70         private QXmlStreamWriter                                        writer;         \r
71         \r
72         private String                                                          errorMessage;\r
73         public int                                                                      lastError;\r
74         \r
75         public ExportData(DatabaseConnection conn2, boolean full) {\r
76                 conn = conn2;\r
77                 logger = new ApplicationLogger("export.log");\r
78                 notebooks = new ArrayList<Notebook>();\r
79                 tags = new ArrayList<Tag>();\r
80                 notes = new ArrayList<Note>();\r
81                 sharedNotebooks = new ArrayList<SharedNotebook>();\r
82                 linkedNotebooks = new ArrayList<LinkedNotebook>();\r
83                 dirtyNotebooks = new HashMap<String,String>();\r
84                 localNotebooks = new HashMap<String,String>();\r
85                 dirtyLinkedNotebooks = new HashMap<String,String>();\r
86                 dirtySharedNotebooks = new HashMap<Long,String>();\r
87                 dirtyTags = new HashMap<String,String>();\r
88                 fullBackup = full;\r
89                 \r
90                 dirtyNotes = new HashMap<String, String>();\r
91                 dirtySearches = new HashMap<String, String>();\r
92                 searches = new ArrayList<SavedSearch>();\r
93                 \r
94                 exportableNotebooks = new HashMap<String, String>();\r
95                 exportableTags = new HashMap<String, String>();\r
96         }\r
97         \r
98         \r
99         public ExportData(DatabaseConnection conn2, boolean full, List<String> guids) {\r
100                 conn = conn2;\r
101                 logger = new ApplicationLogger("export.log");\r
102                 notebooks = new ArrayList<Notebook>();\r
103                 tags = new ArrayList<Tag>();\r
104                 notes = new ArrayList<Note>();\r
105                 for (int i=0; i<guids.size(); i++) {\r
106                         notes.add(conn.getNoteTable().getNote(guids.get(i), true, true, true, true, true));\r
107                 }\r
108                 dirtyNotebooks = new HashMap<String,String>();\r
109                 localNotebooks = new HashMap<String,String>();\r
110                 dirtyTags = new HashMap<String,String>();\r
111                 fullBackup = full;\r
112                 \r
113                 dirtyNotes = new HashMap<String, String>();\r
114                 dirtyLinkedNotebooks = new HashMap<String,String>();\r
115                 dirtySharedNotebooks = new HashMap<Long,String>();\r
116                 dirtySearches = new HashMap<String, String>();\r
117                 searches = new ArrayList<SavedSearch>();\r
118                 \r
119                 exportableNotebooks = new HashMap<String, String>();\r
120                 exportableTags = new HashMap<String, String>();\r
121         }\r
122         \r
123         \r
124         public void exportData(String filename) {\r
125                 \r
126         notebooks = conn.getNotebookTable().getAll();           \r
127         tags = conn.getTagTable().getAll();\r
128         List<Notebook> books = conn.getNotebookTable().getAllLocal();\r
129         for (int i=0; i<books.size(); i++) {\r
130                 localNotebooks.put(books.get(i).getGuid(), "");\r
131         }\r
132         \r
133         books = conn.getNotebookTable().getDirty();\r
134         for (int i=0; i<books.size(); i++) {\r
135                 dirtyNotebooks.put(books.get(i).getGuid(), "");\r
136         }\r
137 \r
138         List<Tag> d= conn.getTagTable().getDirty();\r
139         for (int i=0; i<d.size(); i++) {\r
140                 dirtyTags.put(d.get(i).getGuid(), "");\r
141         }\r
142         \r
143         if (fullBackup)\r
144                 notes = conn.getNoteTable().getAllNotes();\r
145         \r
146         List<Note> dn = conn.getNoteTable().getDirty();\r
147         for (int i=0; i<dn.size(); i++) {\r
148                 dirtyNotes.put(dn.get(i).getGuid(), "");\r
149         }\r
150         \r
151         List<Pair<String,Integer>> tColors = conn.getNoteTable().getNoteTitleColors();\r
152         titleColors = new HashMap<String,Integer>();\r
153         for (int i=0; i<tColors.size(); i++) {\r
154                 titleColors.put(tColors.get(i).getFirst(), tColors.get(i).getSecond());\r
155         }\r
156         \r
157         searches = conn.getSavedSearchTable().getAll();\r
158         \r
159         List<SavedSearch> ds = conn.getSavedSearchTable().getDirty();\r
160         for (int i=0; i<ds.size(); i++) {\r
161                 dirtySearches.put(ds.get(i).getGuid(), "");\r
162         }\r
163                 \r
164         linkedNotebooks = conn.getLinkedNotebookTable().getAll();\r
165         List<String> dln = conn.getLinkedNotebookTable().getDirtyGuids();\r
166         for (int i=0; i<dln.size(); i++) {\r
167                 dirtyLinkedNotebooks.put(dln.get(i), "");\r
168         }\r
169         \r
170         sharedNotebooks = conn.getSharedNotebookTable().getAll();\r
171         List<Long> dsn = conn.getSharedNotebookTable().getDirtyIds();\r
172         for (int i=0; i<dsn.size(); i++) {\r
173                 dirtySharedNotebooks.put(dsn.get(i), "");\r
174         }\r
175                 \r
176                 lastError = 0;\r
177                 errorMessage = "";\r
178                 QFile xmlFile = new QFile(filename);\r
179                 if (!xmlFile.open(QIODevice.OpenModeFlag.WriteOnly, QIODevice.OpenModeFlag.Truncate)) {\r
180                         lastError = 16;\r
181                         errorMessage = "Cannot open file.";\r
182                 }\r
183                         \r
184                 writer = new QXmlStreamWriter(xmlFile); \r
185                 writer.setAutoFormatting(true);\r
186                 writer.setCodec("UTF-8");\r
187                 writer.writeStartDocument();\r
188                 writer.writeDTD("<!DOCTYPE NeverNote-Export>");\r
189                 writer.writeStartElement("nevernote-export");\r
190                 writer.writeAttribute("version", "0.95");\r
191                 if (fullBackup)\r
192                         writer.writeAttribute("exportType", "backup");\r
193                 else\r
194                         writer.writeAttribute("exportType", "export");                  \r
195                 writer.writeAttribute("application", "NeverNote");\r
196                 writer.writeAttribute("applicationVersion", Global.version);\r
197                 if (fullBackup) {\r
198                         writer.writeStartElement("Synchronization");\r
199                         long sequenceDate = conn.getSyncTable().getLastSequenceDate();\r
200                         int number = conn.getSyncTable().getUpdateSequenceNumber();\r
201                         createTextNode("UpdateSequenceNumber", new Long(number).toString());\r
202                         createTextNode("LastSequenceDate", new Long(sequenceDate).toString());\r
203                         writer.writeEndElement();\r
204                 }\r
205                 \r
206                 for (int i=0; i<notes.size(); i++) {\r
207                         String guid = notes.get(i).getGuid();\r
208                         logger.log(logger.EXTREME, "Getting note " +guid +" : " +notes.get(i).getTitle());\r
209                         Note note = conn.getNoteTable().getNote(guid, true, true, true, true, true);\r
210                         logger.log(logger.EXTREME, "Writing note XML");\r
211                         writeNote(note);\r
212                 }\r
213                 \r
214                 writeNotebooks();\r
215                 writeTags();\r
216                 writeSavedSearches();\r
217                 writeLinkedNotebooks();\r
218                 writeSharedNotebooks();\r
219 \r
220                 \r
221                 writer.writeEndElement();\r
222                 writer.writeEndDocument();\r
223 \r
224                 \r
225                 \r
226                 writer.dispose();\r
227 \r
228                 \r
229                 xmlFile.close();\r
230                 xmlFile.dispose();\r
231 \r
232         }\r
233         \r
234         \r
235         private void writeSavedSearches() {\r
236                 if (!fullBackup)\r
237                         return;\r
238                 for (int i=0; i<searches.size(); i++) {\r
239                         writer.writeStartElement("SavedSearch");\r
240                         createTextNode("Guid", searches.get(i).getGuid());\r
241                         createTextNode("Name", searches.get(i).getName());\r
242                         createTextNode("Query", searches.get(i).getQuery());\r
243                         createTextNode("Format", new Integer(searches.get(i).getFormat().getValue()).toString());\r
244                         if (dirtySearches.containsKey(searches.get(i).getGuid()))\r
245                                 createTextNode("Dirty","true");\r
246                         else\r
247                                 createTextNode("Dirty","false");\r
248                         writer.writeEndElement();\r
249                 }\r
250         }\r
251         \r
252         \r
253         private void writeLinkedNotebooks() {\r
254                 if (!fullBackup)\r
255                         return;\r
256                 for (int i=0; i<linkedNotebooks.size(); i++) {\r
257                         writer.writeStartElement("LinkedNotebook");\r
258                         createTextNode("Guid", linkedNotebooks.get(i).getGuid());\r
259                         createTextNode("ShardID", linkedNotebooks.get(i).getShardId());\r
260                         createTextNode("ShareKey", linkedNotebooks.get(i).getShareKey());\r
261                         createTextNode("ShareName", linkedNotebooks.get(i).getShareName());\r
262                         createTextNode("Uri", linkedNotebooks.get(i).getUri());\r
263                         createTextNode("Username", linkedNotebooks.get(i).getUsername());\r
264                         createTextNode("UpdateSequenceNumber", new Long(linkedNotebooks.get(i).getUpdateSequenceNum()).toString());\r
265                         if (dirtyLinkedNotebooks.containsKey(linkedNotebooks.get(i).getGuid()))\r
266                                 createTextNode("Dirty", "true");\r
267                         else\r
268                                 createTextNode("Dirty", "false");\r
269                         writer.writeEndElement();\r
270                 }\r
271         }\r
272 \r
273                 \r
274         \r
275         private void writeSharedNotebooks() {\r
276                 if (!fullBackup)\r
277                         return;\r
278                 for (int i=0; i<linkedNotebooks.size(); i++) {\r
279                         writer.writeStartElement("SharedNotebook");\r
280                         createTextNode("Id", new Long(sharedNotebooks.get(i).getId()).toString());\r
281                         createTextNode("Userid", new Integer(sharedNotebooks.get(i).getUserId()).toString());\r
282                         createTextNode("Email", sharedNotebooks.get(i).getEmail());\r
283                         createTextNode("NotebookGuid", sharedNotebooks.get(i).getNotebookGuid());\r
284                         createTextNode("ShareKey", sharedNotebooks.get(i).getShareKey());\r
285                         createTextNode("Username", sharedNotebooks.get(i).getUsername());\r
286                         createTextNode("ServiceCreated", new Long(sharedNotebooks.get(i).getServiceCreated()).toString());\r
287                         if (dirtySharedNotebooks.containsKey(sharedNotebooks.get(i).getId()))\r
288                                 createTextNode("Dirty", "true");\r
289                         else\r
290                                 createTextNode("Dirty", "false");\r
291                         writer.writeEndElement();\r
292                 }\r
293         }\r
294 \r
295 \r
296         \r
297         private void writeNote(Note note) {\r
298                 \r
299                 writer.writeStartElement("Note");\r
300                 createTextNode("Guid", note.getGuid());\r
301                 createTextNode("UpdateSequenceNumber", new Long(note.getUpdateSequenceNum()).toString());\r
302                 createTextNode("Title", note.getTitle());\r
303                 createTextNode("Created", new Long(note.getCreated()).toString());\r
304                 createTextNode("Updated", new Long(note.getUpdated()).toString());\r
305                 createTextNode("Deleted", new Long(note.getDeleted()).toString());\r
306                 createTextNode("Active", new Boolean(note.isActive()).toString());\r
307                 createTextNode("NotebookGuid", note.getNotebookGuid());\r
308                 if (dirtyNotes.containsKey(note.getGuid()))\r
309                         createTextNode("Dirty", "true");\r
310                 else\r
311                         createTextNode("Dirty", "false");\r
312                 if (titleColors.containsKey(note.getGuid()))\r
313                         createTextNode("TitleColor", new String(titleColors.get(note.getGuid()).toString()));\r
314                 exportableNotebooks.put(note.getNotebookGuid(), "");\r
315                 \r
316                 if (note.getTagGuidsSize() > 0) {\r
317                         writer.writeStartElement("NoteTags");\r
318                         for (int i=0; i<note.getTagGuidsSize(); i++) {\r
319                                 createTextNode("Guid", note.getTagGuids().get(i));\r
320                                 exportableTags.put(note.getTagGuids().get(i), "");\r
321                         }\r
322                         writer.writeEndElement();\r
323                 }\r
324                 \r
325                 NoteAttributes noteAttributes = note.getAttributes();\r
326                 if (noteAttributes != null) {\r
327                         writer.writeStartElement("NoteAttributes");\r
328                         createTextNode("Author", noteAttributes.getAuthor());\r
329                         createTextNode("Source", noteAttributes.getSource());\r
330                         createTextNode("SourceApplication", noteAttributes.getSourceApplication());\r
331                         createTextNode("SourceURL", noteAttributes.getSourceURL());\r
332                         createTextNode("Altitude", new Double(noteAttributes.getAltitude()).toString());\r
333                         createTextNode("Longitude", new Double(noteAttributes.getLongitude()).toString());\r
334                         createTextNode("Latitude", new Double(noteAttributes.getLatitude()).toString());\r
335                         createTextNode("SubjectDate", new Long(noteAttributes.getSubjectDate()).toString());\r
336                         writer.writeEndElement();\r
337                 }\r
338                 \r
339 //              writeResources(conn.getNoteTable().noteResourceTable.getNoteResources(note.getGuid(), true));\r
340                 writeResources(note.getResources());\r
341                 \r
342                 logger.log(logger.EXTREME, "Writing content");\r
343                 writer.writeStartElement("Content");\r
344                 writer.writeCDATA(conn.getNoteTable().getNoteContentBinary(note.getGuid()));\r
345                 writer.writeEndElement();\r
346                 writer.writeEndElement();\r
347         }\r
348 \r
349         \r
350         private void writeResources(List<Resource> resourceTable) {\r
351                 Resource resource;\r
352                 if (resourceTable.size() == 0)\r
353                         return;\r
354                 for (int i=0; i<resourceTable.size(); i++) {\r
355                         resource = resourceTable.get(i);\r
356                         writer.writeStartElement("NoteResource");\r
357                         createTextNode("Guid", resource.getGuid());\r
358                         createTextNode("NoteGuid", resource.getNoteGuid());\r
359                         createTextNode("UpdateSequenceNumber", new Integer(resource.getUpdateSequenceNum()).toString());\r
360                         createTextNode("Mime", resource.getMime());\r
361                         createTextNode("Duration", new Integer(resource.getDuration()).toString());\r
362                         createTextNode("Height", new Integer(resource.getHeight()).toString());\r
363                         createTextNode("Width", new Integer(resource.getWidth()).toString());\r
364                         logger.log(logger.EXTREME, "Checking for data node");\r
365                         if (resource.getData() != null)\r
366                                 writeDataNode("Data", resource.getData());\r
367                         logger.log(logger.EXTREME, "Checking for alternate data node");\r
368                         if (resource.getAlternateData() != null)\r
369                                 writeDataNode("AlternateData", resource.getAlternateData());\r
370                         logger.log(logger.EXTREME, "Checking for recognition");\r
371                         if (resource.getRecognition() != null)\r
372                                 writeRecognitionNode("Recognition", resource.getRecognition());\r
373                         if (resource.isActive())\r
374                                 createTextNode("Active", "true");\r
375                         else\r
376                                 createTextNode("Active", "false");\r
377                                 logger.log(logger.EXTREME, "Checking resource attributes");\r
378                         if (resource.getAttributes() != null) {\r
379                                 writer.writeStartElement("NoteResourceAttribute");\r
380                                 createTextNode("CameraMake", resource.getAttributes().getCameraMake());\r
381                                 createTextNode("CameraModel", resource.getAttributes().getCameraModel());\r
382                                 createTextNode("FileName", resource.getAttributes().getFileName());\r
383                                 createTextNode("RecoType", resource.getAttributes().getRecoType());\r
384                                 createTextNode("SourceURL", resource.getAttributes().getSourceURL());\r
385                                 createTextNode("Altitude", new Double(resource.getAttributes().getAltitude()).toString());\r
386                                 createTextNode("Longitude", new Double(resource.getAttributes().getLongitude()).toString());\r
387                                 createTextNode("Latitude", new Double(resource.getAttributes().getLatitude()).toString());\r
388                                 createTextNode("Timestamp", new Long(resource.getAttributes().getTimestamp()).toString());\r
389                                 if (resource.getAttributes().isAttachment())\r
390                                         createTextNode("Attachment", "true");\r
391                                 else    \r
392                                         createTextNode("Attachment", "false");\r
393                                 if (resource.getAttributes().isClientWillIndex())\r
394                                         createTextNode("ClientWillIndex", "true");\r
395                                 else\r
396                                         createTextNode("ClientWillIndex", "false");\r
397                                 writer.writeEndElement();\r
398                         }\r
399                         writer.writeEndElement();\r
400                 }\r
401                 logger.log(logger.EXTREME, "Ending resource node");\r
402 //              writer.writeEndElement();\r
403         }\r
404         \r
405         \r
406         private void writeDataNode(String name, Data data) {\r
407                 writer.writeStartElement(name);\r
408                 createTextNode("Size", new Integer(data.getSize()).toString());\r
409                 if (data.getBody() != null && data.getBody().length > 0)\r
410                         createBinaryNode("Body", new QByteArray(data.getBody()).toHex().toString());\r
411                 else\r
412                         createBinaryNode("Body", "");\r
413                 if (data.getBodyHash() != null && data.getBodyHash().length > 0)\r
414                         createTextNode("BodyHash", new QByteArray(data.getBodyHash()).toHex().toString());\r
415                 else\r
416                         createTextNode("BodyHash", "");\r
417                 writer.writeEndElement();               \r
418         }\r
419 \r
420         \r
421         \r
422         \r
423         private void writeRecognitionNode(String name, Data data) {\r
424                 writer.writeStartElement(name);\r
425                 createTextNode("Size", new Integer(data.getSize()).toString());\r
426                 if (data.getBody() != null && data.getBody().length > 0) {\r
427                         writer.writeStartElement("Body");\r
428                         writer.writeCDATA(new QByteArray(data.getBody()).toString());\r
429 //                      writer.writeCDATA(new QByteArray(data.getBody()).toHex().toString());\r
430                         writer.writeEndElement();\r
431                 }  else\r
432                         createBinaryNode("Body", "");\r
433                 \r
434                 if (data.getBodyHash() != null && data.getBodyHash().length > 0)\r
435                         createTextNode("BodyHash", new QByteArray(data.getBodyHash()).toHex().toString());\r
436                 else\r
437                         createTextNode("BodyHash", "");\r
438                 writer.writeEndElement();               \r
439         }\r
440 \r
441         \r
442         private void writeNotebooks() {\r
443                 for (int i=0; i<notebooks.size(); i++) {\r
444                         if (exportableNotebooks.containsKey(notebooks.get(i).getGuid()) || fullBackup) {\r
445                                 writer.writeStartElement("Notebook");\r
446                                 createTextNode("Guid", notebooks.get(i).getGuid());\r
447                                 createTextNode("Name", notebooks.get(i).getName());\r
448                                 createTextNode("UpdateSequenceNumber", new Long(notebooks.get(i).getUpdateSequenceNum()).toString());\r
449                                 if (notebooks.get(i).isDefaultNotebook())\r
450                                         createTextNode("DefaultNotebook", "true");\r
451                                 else\r
452                                         createTextNode("DefaultNotebook", "false");\r
453                                 createTextNode("ServiceCreated", new Long(notebooks.get(i).getServiceCreated()).toString());\r
454                                 createTextNode("ServiceUpdated", new Long(notebooks.get(i).getServiceUpdated()).toString());\r
455                                 if (localNotebooks.containsKey(notebooks.get(i).getGuid()))\r
456                                         createTextNode("Local","true");\r
457                                 else\r
458                                         createTextNode("Local","false");\r
459                                 if (dirtyNotebooks.containsKey(notebooks.get(i).getGuid()))\r
460                                         createTextNode("Dirty","true");\r
461                                 else\r
462                                         createTextNode("Dirty","false");\r
463                                 if (conn.getNotebookTable().isReadOnly(notebooks.get(i).getGuid()))\r
464                                         createTextNode("ReadOnly", "true");\r
465                                 else\r
466                                         createTextNode("ReadOnly", "false");\r
467                                 if (notebooks.get(i).getPublishing() != null) {\r
468                                         Publishing p = notebooks.get(i).getPublishing();\r
469                                         createTextNode("PublishingPublicDescription", p.getPublicDescription());\r
470                                         createTextNode("PublishingUri", p.getUri());\r
471                                         createTextNode("PublishingOrder", new Integer(p.getOrder().getValue()).toString());\r
472                                         if (p.isAscending())\r
473                                                 createTextNode("PublishingAscending", "true");\r
474                                         else\r
475                                                 createTextNode("PublishingAscending", "false");\r
476                                 }\r
477                                 QByteArray b = conn.getNotebookTable().getIconAsByteArray(notebooks.get(i).getGuid());\r
478                                 if (b != null) \r
479                                         createBinaryNode("Icon", b.toHex().toString());\r
480                                 if (notebooks.get(i).getStack() != null && !notebooks.get(i).getStack().trim().equals(""))\r
481                                         createTextNode("Stack", notebooks.get(i).getStack());\r
482                                 writer.writeEndElement();       \r
483                         }\r
484                 }\r
485         }\r
486 \r
487 \r
488         private void writeTags() {\r
489                 for (int i=0; i<tags.size(); i++) {\r
490                         if (exportableTags.containsKey(tags.get(i).getGuid()) || fullBackup) {\r
491                                 writer.writeStartElement("Tag");\r
492                                 createTextNode("Guid", tags.get(i).getGuid());\r
493                                 createTextNode("Name", tags.get(i).getName());\r
494                                 createTextNode("ParentGuid", tags.get(i).getParentGuid());\r
495                                 createTextNode("UpdateSequenceNumber", new Long(tags.get(i).getUpdateSequenceNum()).toString());\r
496                                 if (dirtyTags.containsKey(tags.get(i).getGuid()))\r
497                                         createTextNode("Dirty","true");\r
498                                 else\r
499                                         createTextNode("Dirty","false");\r
500                                 writer.writeEndElement();       \r
501                         }\r
502                 }\r
503         }\r
504         \r
505         \r
506         private void createTextNode(String nodeName, String value) {\r
507                 if (value == null)\r
508                         value = "";\r
509                 writer.writeTextElement(nodeName, value);\r
510                 return;\r
511         }\r
512 \r
513         private void createBinaryNode(String nodeName, String value) {\r
514                 if (value == null)\r
515                         value = "";\r
516                 logger.log(logger.EXTREME, "Writing binary node");\r
517                 writer.writeStartElement(nodeName);\r
518 /*              int i=0;\r
519                 for (; i<value.length(); i+=80) \r
520                 {\r
521                         writer.writeCharacters("\n"+value.substring(i,i+80));\r
522                 }\r
523                 writer.writeCharacters("\n"+value.substring(i)+"\n");\r
524 */              writer.writeCharacters(value);\r
525                 writer.writeEndElement();\r
526                 return;\r
527         }\r
528 \r
529         \r
530         public String getErrorMessage() {\r
531                 return errorMessage;\r
532         }\r
533         \r
534         \r
535 }\r