OSDN Git Service

Cleanup compiler warning messages and alter backup & restore to handle new database...
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / xml / ImportData.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 import java.util.Random;\r
26 \r
27 import com.evernote.edam.type.Data;\r
28 import com.evernote.edam.type.LinkedNotebook;\r
29 import com.evernote.edam.type.Note;\r
30 import com.evernote.edam.type.NoteAttributes;\r
31 import com.evernote.edam.type.NoteSortOrder;\r
32 import com.evernote.edam.type.Notebook;\r
33 import com.evernote.edam.type.Publishing;\r
34 import com.evernote.edam.type.Resource;\r
35 import com.evernote.edam.type.ResourceAttributes;\r
36 import com.evernote.edam.type.SavedSearch;\r
37 import com.evernote.edam.type.SharedNotebook;\r
38 import com.evernote.edam.type.Tag;\r
39 import com.trolltech.qt.core.QByteArray;\r
40 import com.trolltech.qt.core.QFile;\r
41 import com.trolltech.qt.core.QIODevice;\r
42 import com.trolltech.qt.gui.QIcon;\r
43 import com.trolltech.qt.gui.QImage;\r
44 import com.trolltech.qt.gui.QPixmap;\r
45 import com.trolltech.qt.xml.QXmlStreamAttributes;\r
46 import com.trolltech.qt.xml.QXmlStreamReader;\r
47 \r
48 import cx.fbn.nevernote.sql.DatabaseConnection;\r
49 import cx.fbn.nevernote.utilities.ApplicationLogger;\r
50 \r
51 public class ImportData {\r
52 \r
53         public int                                                      lastError;\r
54         private String                                          errorMessage;\r
55         private String                                          fileName;\r
56         DatabaseConnection                                      conn;\r
57         QXmlStreamReader                                        reader;\r
58         private Note                                            note;\r
59         private boolean                                         noteIsDirty;\r
60         private Notebook                                        notebook;\r
61         private boolean                                         notebookIsDirty;\r
62         private boolean                                         notebookIsLocal;\r
63         private boolean                                         notebookIsReadOnly;\r
64         private QIcon                                           notebookIcon;\r
65         private Tag                                                     tag;\r
66         private boolean                                         tagIsDirty;\r
67         private final HashMap<String,Integer>           titleColors;\r
68         private SavedSearch                                     search;\r
69         private boolean                                         searchIsDirty;\r
70         public int                                                      highUpdateSequenceNumber;\r
71         public long                                                     lastSequenceDate;\r
72         private final ApplicationLogger         logger;\r
73         private final boolean                           backup;\r
74         private String                                          notebookGuid;\r
75         private boolean                                         linkedNotebookIsDirty;\r
76         private boolean                                         sharedNotebookIsDirty;\r
77         private LinkedNotebook                          linkedNotebook;\r
78         private SharedNotebook                          sharedNotebook;\r
79         public final boolean                            importTags = false;\r
80         public final boolean                            importNotebooks = false;\r
81         private final HashMap<String,String>            noteMap;\r
82         \r
83         public ImportData(DatabaseConnection c, boolean full) {\r
84                 logger = new ApplicationLogger("import.log");\r
85                 backup = full;\r
86                 conn = c;\r
87                 titleColors = new HashMap<String,Integer>();\r
88                 noteMap = new HashMap<String,String>();\r
89         }\r
90         \r
91         public void importData(String f) {\r
92                 fileName = f;\r
93                 errorMessage = "";\r
94                                 \r
95                 lastError = 0;\r
96                 errorMessage = "";\r
97                 QFile xmlFile = new QFile(fileName);\r
98                 if (!xmlFile.open(QIODevice.OpenModeFlag.ReadOnly)) {\r
99                         lastError = 16;\r
100                         errorMessage = "Cannot open file.";\r
101                 }\r
102                         \r
103                 reader = new QXmlStreamReader(xmlFile); \r
104                 while (!reader.atEnd()) {\r
105                         reader.readNext();\r
106                         if (reader.hasError()) {\r
107                                 errorMessage = reader.errorString();\r
108                                 logger.log(logger.LOW, "************************* ERROR READING BACKUP " +reader.errorString());\r
109                                 lastError = 16;\r
110                                 return;\r
111                         }\r
112                         if (reader.name().equalsIgnoreCase("nevernote-export") && reader.isStartElement()) {\r
113                                 QXmlStreamAttributes attributes = reader.attributes();\r
114                                 String version = attributes.value("version");\r
115                                 String type = attributes.value("exportType");\r
116                                 String application = attributes.value("application");\r
117                                 if (!version.equalsIgnoreCase("0.85") && !version.equalsIgnoreCase("0.86")\r
118                                                 && !version.equalsIgnoreCase("0.95")) {\r
119                                         lastError = 1;\r
120                                         errorMessage = "Unknown backup version = " +version;\r
121                                         return;\r
122                                 }\r
123                                 if (!application.equalsIgnoreCase("NeverNote")) {\r
124                                         lastError = 2;\r
125                                         errorMessage = "This backup is from an unknown application = " +application;\r
126                                         return;\r
127                                 }\r
128                                 if (!type.equalsIgnoreCase("backup") && backup) {\r
129                                         lastError = 4;\r
130                                         errorMessage = "This is an export file, not a backup file";\r
131                                         return;\r
132                                 } \r
133                                 if (type.equalsIgnoreCase("export") && backup) {\r
134                                         lastError = 5;\r
135                                         errorMessage = "This is a backup file, not an export file";             \r
136                                         return;\r
137                                 }\r
138                                 \r
139                         }\r
140                         if (reader.name().equalsIgnoreCase("Synchronization") && reader.isStartElement() && backup) {\r
141                                 processSynchronizationNode();\r
142                                 conn.getSyncTable().setLastSequenceDate(lastSequenceDate);\r
143                         conn.getSyncTable().setUpdateSequenceNumber(highUpdateSequenceNumber);\r
144 //                              Global.setSequenceDate(lastSequenceDate);\r
145 //                      Global.setUpdateSequenceNumber(highUpdateSequenceNumber);\r
146                         }\r
147                         if (reader.name().equalsIgnoreCase("note") && reader.isStartElement()) {\r
148                                 processNoteNode();\r
149                                 if (backup)\r
150                                         conn.getNoteTable().addNote(note, noteIsDirty);\r
151                                 else {\r
152                                         note.setUpdateSequenceNum(0);\r
153                                         if (notebookGuid != null) \r
154                                                 note.setNotebookGuid(notebookGuid);\r
155                                         for (int i=0; i<note.getResourcesSize(); i++) {\r
156                                                 note.getResources().get(i).setUpdateSequenceNum(0);\r
157                                         }\r
158                                         conn.getNoteTable().addNote(note, true);\r
159                                 }\r
160                                 if (titleColors.containsKey(note.getGuid())) \r
161                                         conn.getNoteTable().setNoteTitleColor(note.getGuid(), titleColors.get(note.getGuid()));\r
162                         }\r
163                         if (reader.name().equalsIgnoreCase("notebook") && reader.isStartElement() && (backup || importNotebooks)) {\r
164                                 processNotebookNode();\r
165                         String existingGuid = conn.getNotebookTable().findNotebookByName(notebook.getName());\r
166                         if (existingGuid == null) {\r
167                                 conn.getNotebookTable().addNotebook(notebook, notebookIsDirty, notebookIsLocal);\r
168                         } else {\r
169                                 conn.getNotebookTable().updateNotebookGuid(existingGuid, notebook.getGuid());\r
170                                 conn.getNotebookTable().updateNotebook(notebook, notebookIsDirty);\r
171                         }\r
172                         conn.getNotebookTable().setIcon(notebook.getGuid(), notebookIcon, "PNG");\r
173                         conn.getNotebookTable().setReadOnly(notebook.getGuid(), notebookIsReadOnly);\r
174                         }\r
175                         if (reader.name().equalsIgnoreCase("tag") && reader.isStartElement() && (backup || importTags)) {\r
176                                 processTagNode();\r
177                                 String testGuid = conn.getTagTable().findTagByName(tag.getName());\r
178                         if (testGuid == null)\r
179                                 conn.getTagTable().addTag(tag, tagIsDirty);\r
180                         else {\r
181                                 conn.getTagTable().updateTagGuid(testGuid, tag.getGuid());\r
182                                 conn.getTagTable().updateTag(tag,tagIsDirty);\r
183                         }\r
184                         }\r
185                         if (reader.name().equalsIgnoreCase("savedsearch") && reader.isStartElement() && backup) {\r
186                                 processSavedSearchNode();\r
187                         conn.getSavedSearchTable().addSavedSearch(search, searchIsDirty);\r
188                         }\r
189                         if (reader.name().equalsIgnoreCase("LinkedNotebook") && reader.isStartElement() && backup) {\r
190                                 processLinkedNotebookNode();\r
191                         conn.getLinkedNotebookTable().addNotebook(linkedNotebook, linkedNotebookIsDirty);\r
192                         }\r
193                         if (reader.name().equalsIgnoreCase("SharedNotebook") && reader.isStartElement() && backup) {\r
194                                 processSharedNotebookNode();\r
195                         conn.getSharedNotebookTable().addNotebook(sharedNotebook, sharedNotebookIsDirty);\r
196                         }\r
197                 }\r
198                 xmlFile.close();\r
199         }\r
200         \r
201         \r
202         private void processNoteNode() {\r
203                 note = new Note();\r
204                 note.setResources(new ArrayList<Resource>());\r
205 \r
206                 boolean atEnd = false;\r
207                 while(!atEnd) {\r
208                         if (reader.isStartElement()) {\r
209                                 if (reader.name().equalsIgnoreCase("Guid")) { \r
210                                         note.setGuid(textValue());\r
211                                         if (!backup) {\r
212                                                 Random random1 = new Random();\r
213                                                 String newGuid = "IMP" +new Integer(random1.nextInt(1000)).toString();\r
214                                                 newGuid = newGuid+"-"+new Integer(random1.nextInt(1000)).toString();\r
215                                                 newGuid = newGuid+"-"+new Integer(random1.nextInt(1000)).toString();\r
216                                                 newGuid = newGuid+"-"+new Integer(random1.nextInt(1000)).toString();\r
217                                                 noteMap.put(note.getGuid(), newGuid);\r
218                                                 note.setGuid(newGuid);\r
219                                         } else \r
220                                                 noteMap.put(note.getGuid(), note.getGuid());\r
221                                 }\r
222                                 if (reader.name().equalsIgnoreCase("UpdateSequenceNumber")) \r
223                                         note.setUpdateSequenceNum(intValue());\r
224                                 if (reader.name().equalsIgnoreCase("Title")) \r
225                                         note.setTitle(textValue());\r
226                                 if (reader.name().equalsIgnoreCase("Created")) \r
227                                         note.setCreated(longValue());\r
228                                 if (reader.name().equalsIgnoreCase("Updated")) \r
229                                         note.setUpdated(longValue());\r
230                                 if (reader.name().equalsIgnoreCase("Deleted")) \r
231                                         note.setDeleted(longValue());\r
232                                 if (reader.name().equalsIgnoreCase("Active")) \r
233                                         note.setActive(booleanValue());\r
234                                 if (reader.name().equalsIgnoreCase("NotebookGuid") && (backup || importNotebooks)) \r
235                                         note.setNotebookGuid(textValue());\r
236                                 if (reader.name().equalsIgnoreCase("Content")) \r
237                                         note.setContent(textValue());\r
238                                 if (reader.name().equalsIgnoreCase("NoteTags") && (backup || importTags)) \r
239                                         note.setTagGuids(processNoteTagList());\r
240                                 if (reader.name().equalsIgnoreCase("NoteAttributes")) \r
241                                         note.setAttributes(processNoteAttributes());\r
242                                 if (reader.name().equalsIgnoreCase("NoteResource")) \r
243                                         note.getResources().add(processResource());\r
244                                 if (reader.name().equalsIgnoreCase("Dirty")) {\r
245                                         if (booleanValue())\r
246                                                 noteIsDirty=true;\r
247                                 }\r
248                                 if (reader.name().equalsIgnoreCase("TitleColor")) \r
249                                         titleColors.put(note.getGuid(), intValue());\r
250                         }\r
251                         reader.readNext();\r
252                         if (reader.name().equalsIgnoreCase("note") && reader.isEndElement())\r
253                                 atEnd = true;\r
254                 }\r
255                 \r
256                 return;\r
257                 \r
258         }       \r
259         private Resource processResource() {\r
260                 Resource resource = new Resource();\r
261                 boolean atEnd = false;\r
262                 boolean isDirty = false;\r
263                 while(!atEnd) {\r
264                         if (reader.isStartElement()) {\r
265                                 if (reader.name().equalsIgnoreCase("Guid")) \r
266                                         resource.setGuid(textValue());\r
267                                 if (!backup) {\r
268                                         Random random1 = new Random();\r
269                                         String newGuid = "IMP" +new Integer(random1.nextInt(1000)).toString();\r
270                                         newGuid = newGuid+"-"+new Integer(random1.nextInt(1000)).toString();\r
271                                         newGuid = newGuid+"-"+new Integer(random1.nextInt(1000)).toString();\r
272                                         newGuid = newGuid+"-"+new Integer(random1.nextInt(1000)).toString();\r
273                                         resource.setGuid(newGuid);\r
274                                 }\r
275                                 if (reader.name().equalsIgnoreCase("NoteGuid")) \r
276                                         resource.setNoteGuid(noteMap.get(textValue()));\r
277                                 if (reader.name().equalsIgnoreCase("UpdateSequenceNumber")) \r
278                                         resource.setUpdateSequenceNum(intValue());\r
279                                 if (reader.name().equalsIgnoreCase("Active")) \r
280                                         resource.setActive(booleanValue());\r
281                                 if (reader.name().equalsIgnoreCase("Mime")) \r
282                                         resource.setMime(textValue());\r
283                                 if (reader.name().equalsIgnoreCase("Duration")) \r
284                                         resource.setDuration(shortValue());\r
285                                 if (reader.name().equalsIgnoreCase("Height")) \r
286                                         resource.setHeight(shortValue());\r
287                                 if (reader.name().equalsIgnoreCase("Width")) \r
288                                         resource.setWidth(shortValue());\r
289                                 if (reader.name().equalsIgnoreCase("dirty")) \r
290                                         isDirty = booleanValue();\r
291                                 if (reader.name().equalsIgnoreCase("Data")) \r
292                                         resource.setData(processData("Data"));\r
293                                 if (reader.name().equalsIgnoreCase("AlternateData")) \r
294                                         resource.setAlternateData(processData("AlternateData"));\r
295                                 if (reader.name().equalsIgnoreCase("RecognitionData")) \r
296                                         resource.setRecognition(processData("NoteResourceAttribute"));\r
297                                 if (reader.name().equalsIgnoreCase("NoteResourceAttribute")) \r
298                                         resource.setAttributes(processResourceAttributes());\r
299                         }\r
300                         reader.readNext();\r
301                         if (reader.name().equalsIgnoreCase("noteresource") && reader.isEndElement())\r
302                                 atEnd = true;\r
303                 }\r
304                 \r
305                 conn.getNoteTable().noteResourceTable.saveNoteResource(resource, isDirty);\r
306 \r
307                 \r
308                 return resource;\r
309         }\r
310         \r
311         private Data processData(String nodeName) {\r
312                 Data data = new Data();\r
313                 boolean atEnd = false;\r
314                 while(!atEnd) {\r
315                         if (reader.isStartElement()) {\r
316                                 if (reader.name().equalsIgnoreCase("Size")) \r
317                                         data.setSize(intValue());\r
318                                 if (reader.name().equalsIgnoreCase("Body")) {\r
319                                         byte[] b = textValue().getBytes();   // data binary\r
320                                         QByteArray hexData = new QByteArray(b);\r
321                                         QByteArray binData = new QByteArray(QByteArray.fromHex(hexData));\r
322                                         data.setBody(binData.toByteArray());\r
323                                 }\r
324                                 if (reader.name().equalsIgnoreCase("BodyHash")) {\r
325                                         byte[] b = textValue().getBytes();   // data binary\r
326                                         QByteArray hexData = new QByteArray(b);\r
327                                         QByteArray binData = new QByteArray(QByteArray.fromHex(hexData));\r
328                                         data.setBodyHash(binData.toByteArray());\r
329                                 }\r
330 \r
331                                 reader.readNext();\r
332                                 if (reader.name().equalsIgnoreCase("data") && reader.isEndElement())\r
333                                         atEnd = true;\r
334                         }\r
335                         reader.readNext();\r
336                         if (reader.name().equalsIgnoreCase(nodeName) && reader.isEndElement())\r
337                                 atEnd = true;\r
338                 }\r
339                 return data;\r
340         }\r
341 \r
342         private ResourceAttributes processResourceAttributes() {\r
343                 ResourceAttributes attributes = new ResourceAttributes();\r
344                 boolean atEnd = false;\r
345                 while(!atEnd) {\r
346                         if (reader.isStartElement()) {\r
347                                 if (reader.name().equalsIgnoreCase("CameraMake")) \r
348                                         attributes.setCameraMake(textValue());          \r
349                                 if (reader.name().equalsIgnoreCase("CameraModel")) \r
350                                         attributes.setCameraModel(textValue());         \r
351                                 if (reader.name().equalsIgnoreCase("FileName")) \r
352                                         attributes.setFileName(textValue());            \r
353                                 if (reader.name().equalsIgnoreCase("RecoType")) \r
354                                         attributes.setRecoType(textValue());            \r
355                                 if (reader.name().equalsIgnoreCase("CameraModel")) \r
356                                         attributes.setCameraMake(textValue());          \r
357                                 if (reader.name().equalsIgnoreCase("SourceURL")) \r
358                                         attributes.setSourceURL(textValue());           \r
359                                 if (reader.name().equalsIgnoreCase("Altitude")) \r
360                                         attributes.setAltitude(doubleValue());          \r
361                                 if (reader.name().equalsIgnoreCase("Longitude")) \r
362                                         attributes.setLongitude(doubleValue());         \r
363                                 if (reader.name().equalsIgnoreCase("Latitude")) \r
364                                         attributes.setLatitude(doubleValue());          \r
365                                 if (reader.name().equalsIgnoreCase("Timestamp")) \r
366                                         attributes.setTimestamp(longValue());           \r
367                                 if (reader.name().equalsIgnoreCase("Attachment")) \r
368                                         attributes.setAttachment(booleanValue());               \r
369                                 if (reader.name().equalsIgnoreCase("ClientWillIndex")) \r
370                                         attributes.setClientWillIndex(booleanValue());          \r
371                         }\r
372                         reader.readNext();\r
373                         if (reader.name().equalsIgnoreCase("noteresourceattribute") && reader.isEndElement())\r
374                                 atEnd = true;\r
375                 }\r
376                 \r
377                 return attributes;\r
378         }\r
379 \r
380         \r
381         private List<String> processNoteTagList() {\r
382                 List<String> guidList = new ArrayList<String>();\r
383         \r
384 \r
385                 boolean atEnd = false;\r
386                 while(!atEnd) {                 \r
387                         if (reader.isStartElement()) {\r
388                                 if (reader.name().equalsIgnoreCase("guid")) \r
389                                         guidList.add(textValue());\r
390                         }\r
391                         reader.readNext();\r
392                         if (reader.name().equalsIgnoreCase("notetags") && reader.isEndElement())\r
393                                 atEnd = true;\r
394                 }\r
395                         return guidList;\r
396         }\r
397 \r
398 \r
399 \r
400         private NoteAttributes processNoteAttributes() {\r
401         NoteAttributes attributes = new NoteAttributes();\r
402         \r
403         boolean atEnd = false;\r
404         while(!atEnd) {\r
405                 if (reader.isStartElement()) {\r
406                         if (reader.name().equalsIgnoreCase("Author")) \r
407                                 attributes.setAuthor(textValue());\r
408                         if (reader.name().equalsIgnoreCase("SourceURL")) \r
409                                 attributes.setSourceURL(textValue());\r
410                         if (reader.name().equalsIgnoreCase("Source")) \r
411                                 attributes.setSource(textValue());\r
412                         if (reader.name().equalsIgnoreCase("SourceApplication")) \r
413                                 attributes.setSourceApplication(textValue());\r
414                         if (reader.name().equalsIgnoreCase("Altitude")) \r
415                                 attributes.setAltitude(doubleValue());\r
416                         if (reader.name().equalsIgnoreCase("Longitude")) \r
417                                 attributes.setLongitude(doubleValue());\r
418                         if (reader.name().equalsIgnoreCase("Latitude")) \r
419                                 attributes.setLatitude(doubleValue());\r
420                         if (reader.name().equalsIgnoreCase("SubjectDate")) \r
421                                 attributes.setSubjectDate(longValue());\r
422                 }\r
423                 reader.readNext();\r
424                 if (reader.name().equalsIgnoreCase("noteattributes") && reader.isEndElement())\r
425                         atEnd = true;\r
426         }\r
427         \r
428         return attributes;\r
429 }\r
430 \r
431         \r
432         private void processSynchronizationNode() {\r
433                 boolean atEnd = false;\r
434                 while(!atEnd) {\r
435                         if (reader.isStartElement()) {\r
436                                 if (reader.name().equalsIgnoreCase("UpdateSequenceNumber"))     \r
437                                         highUpdateSequenceNumber = intValue();\r
438                                 if (reader.name().equalsIgnoreCase("LastSequenceDate"))         \r
439                                         lastSequenceDate = longValue();\r
440                         }\r
441                         reader.readNext();\r
442                         if (reader.name().equalsIgnoreCase("synchronization") && reader.isEndElement())\r
443                                 atEnd = true;\r
444                 }               \r
445         }\r
446         \r
447         \r
448         private void processSavedSearchNode() {\r
449                 search = new SavedSearch();\r
450                 searchIsDirty = false;\r
451                 \r
452                 boolean atEnd = false;\r
453                 while(!atEnd) {\r
454                         if (reader.isStartElement()) {\r
455                                 if (reader.name().equalsIgnoreCase("Guid")) \r
456                                         search.setGuid(textValue());\r
457                                 if (reader.name().equalsIgnoreCase("Name")) \r
458                                         search.setName(textValue());\r
459                                 if (reader.name().equalsIgnoreCase("UpdateSequenceNumber")) \r
460                                         search.setUpdateSequenceNum(intValue());\r
461                                 if (reader.name().equalsIgnoreCase("Query")) \r
462                                         search.setQuery(textValue());\r
463                                 if (reader.name().equalsIgnoreCase("Dirty")) {\r
464                                         if (booleanValue())\r
465                                                 searchIsDirty = true;\r
466                                 }\r
467                         }\r
468                         reader.readNext();\r
469                         if (reader.name().equalsIgnoreCase("savedsearch") && reader.isEndElement())\r
470                                 atEnd = true;           }       \r
471                 return;\r
472         }\r
473         \r
474         \r
475         private void processLinkedNotebookNode() {\r
476                 linkedNotebook = new LinkedNotebook();\r
477                 linkedNotebookIsDirty = false;\r
478                 \r
479                 boolean atEnd = false;\r
480                 while(!atEnd) {\r
481                         if (reader.isStartElement()) {\r
482                                 if (reader.name().equalsIgnoreCase("Guid")) \r
483                                         linkedNotebook.setGuid(textValue());\r
484                                 if (reader.name().equalsIgnoreCase("ShardID")) \r
485                                         linkedNotebook.setShardId(textValue());\r
486                                 if (reader.name().equalsIgnoreCase("UpdateSequenceNumber")) \r
487                                         linkedNotebook.setUpdateSequenceNum(intValue());\r
488                                 if (reader.name().equalsIgnoreCase("ShareKey")) \r
489                                         linkedNotebook.setShareKey(textValue());\r
490                                 if (reader.name().equalsIgnoreCase("ShareName")) \r
491                                         linkedNotebook.setShareName(textValue());\r
492                                 if (reader.name().equalsIgnoreCase("Uri")) \r
493                                         linkedNotebook.setUri(textValue());\r
494                                 if (reader.name().equalsIgnoreCase("Username")) \r
495                                         linkedNotebook.setUsername(textValue());\r
496                                 if (reader.name().equalsIgnoreCase("Dirty")) {\r
497                                         if (booleanValue())\r
498                                                 linkedNotebookIsDirty = true;\r
499                                 }\r
500                         }\r
501                         reader.readNext();\r
502                         if (reader.name().equalsIgnoreCase("LinkedNotebook") && reader.isEndElement())\r
503                                 atEnd = true;           }       \r
504                 return;\r
505         }\r
506 \r
507 \r
508         private void processSharedNotebookNode() {\r
509                 sharedNotebook = new SharedNotebook();\r
510                 sharedNotebookIsDirty = false;\r
511                 \r
512                 boolean atEnd = false;\r
513                 while(!atEnd) {\r
514                         if (reader.isStartElement()) {\r
515                                 if (reader.name().equalsIgnoreCase("Id")) \r
516                                         sharedNotebook.setId(intValue());\r
517                                 if (reader.name().equalsIgnoreCase("Userid")) \r
518                                         sharedNotebook.setUserId(intValue());\r
519                                 if (reader.name().equalsIgnoreCase("Email")) \r
520                                         sharedNotebook.setEmail(textValue());\r
521                                 if (reader.name().equalsIgnoreCase("NotebookGuid")) \r
522                                         sharedNotebook.setNotebookGuid(textValue());\r
523                                 if (reader.name().equalsIgnoreCase("ShareKey")) \r
524                                         sharedNotebook.setShareKey(textValue());\r
525                                 if (reader.name().equalsIgnoreCase("Username")) \r
526                                         sharedNotebook.setUsername(textValue());\r
527                                 if (reader.name().equalsIgnoreCase("ServiceCreated")) \r
528                                         sharedNotebook.setServiceCreated(longValue());\r
529                                 if (reader.name().equalsIgnoreCase("Dirty")) {\r
530                                         if (booleanValue())\r
531                                                 sharedNotebookIsDirty = true;\r
532                                 }\r
533                         }\r
534                         reader.readNext();\r
535                         if (reader.name().equalsIgnoreCase("LinkedNotebook") && reader.isEndElement())\r
536                                 atEnd = true;           }       \r
537                 return;\r
538         }\r
539 \r
540         \r
541 \r
542         \r
543         private void processNotebookNode() {\r
544                 notebook = new Notebook();\r
545                 Publishing p = new Publishing();\r
546                 notebook.setPublishing(p);\r
547                 notebookIsDirty = false;\r
548                 notebookIsLocal = false;\r
549                 notebookIsReadOnly = false;\r
550                 notebookIcon = null;\r
551                 boolean atEnd = false;\r
552                 while(!atEnd) {\r
553                         if (reader.isStartElement()) {\r
554                                 if (reader.name().equalsIgnoreCase("Guid")) \r
555                                         notebook.setGuid(textValue());\r
556                                 if (reader.name().equalsIgnoreCase("Name")) \r
557                                         notebook.setName(textValue());\r
558                                 if (reader.name().equalsIgnoreCase("UpdateSequenceNumber")) \r
559                                         notebook.setUpdateSequenceNum(intValue());\r
560                                 if (reader.name().equalsIgnoreCase("ServiceCreated")) \r
561                                         notebook.setServiceCreated(longValue());\r
562                                 if (reader.name().equalsIgnoreCase("ServiceUpdated")) \r
563                                         notebook.setServiceUpdated(longValue());\r
564                                 if (reader.name().equalsIgnoreCase("DefaultNotebook")) {\r
565                                         notebook.setDefaultNotebook(booleanValue());\r
566                                 }\r
567                                 if (reader.name().equalsIgnoreCase("Dirty")) {\r
568                                         if (booleanValue())\r
569                                                 notebookIsDirty = true;\r
570                                 }\r
571                                 if (reader.name().equalsIgnoreCase("LocalNotebook")) {\r
572                                         if (booleanValue())\r
573                                                 notebookIsLocal = true;\r
574                                 }\r
575                                 if (reader.name().equalsIgnoreCase("ReadOnly")) {\r
576                                         if (booleanValue())\r
577                                                 notebookIsReadOnly = true;\r
578                                 }\r
579                                 if (reader.name().equalsIgnoreCase("PublishingPublicDescription")) {\r
580                                         notebook.getPublishing().setPublicDescription(textValue());\r
581                                 }\r
582                                 if (reader.name().equalsIgnoreCase("PublishingUri")) {\r
583                                         notebook.getPublishing().setUri(textValue());\r
584                                 }\r
585                                 if (reader.name().equalsIgnoreCase("PublishingOrder")) {\r
586                                         notebook.getPublishing().setOrder(NoteSortOrder.findByValue(intValue()));\r
587                                 }\r
588                                 if (reader.name().equalsIgnoreCase("ReadOnly")) {\r
589                                         if (booleanValue())\r
590                                                 notebookIsReadOnly = true;\r
591                                 }\r
592                                 if (reader.name().equalsIgnoreCase("PublishingAscending")) {\r
593                                         if (booleanValue())\r
594                                                 notebook.getPublishing().setAscending(true);\r
595                                         else\r
596                                                 notebook.getPublishing().setAscending(false);\r
597                                 }               \r
598                                 if (reader.name().equalsIgnoreCase("Icon")) {\r
599                                         byte[] b = textValue().getBytes();   // data binary\r
600                                         QByteArray hexData = new QByteArray(b);\r
601                                         QByteArray binData = new QByteArray(QByteArray.fromHex(hexData));\r
602                                         notebookIcon = new QIcon(QPixmap.fromImage(QImage.fromData(binData)));\r
603                                 }\r
604                                 if (reader.name().equalsIgnoreCase("Stack"))\r
605                                         notebook.setStack(textValue());\r
606                         }\r
607                         reader.readNext();\r
608                         if (reader.name().equalsIgnoreCase("notebook") && reader.isEndElement())\r
609                                 atEnd = true;\r
610                 }\r
611                 return;\r
612         }\r
613 \r
614         \r
615         \r
616         private void processTagNode() {\r
617                 tag = new Tag();\r
618                 tagIsDirty = false;\r
619                 boolean atEnd = false;\r
620                 while(!atEnd) {\r
621                         if (reader.isStartElement()) {                  \r
622                                 if (reader.name().equalsIgnoreCase("Guid")) \r
623                                         tag.setGuid(textValue());\r
624                                 if (reader.name().equalsIgnoreCase("Name")) \r
625                                         tag.setName(textValue());\r
626                                 if (reader.name().equalsIgnoreCase("UpdateSequenceNumber")) \r
627                                         tag.setUpdateSequenceNum(intValue());\r
628                                 if (reader.name().equalsIgnoreCase("ParentGuid")) \r
629                                         tag.setParentGuid(textValue());\r
630                                 if (reader.name().equalsIgnoreCase("Dirty")) {\r
631                                         if (booleanValue())\r
632                                                 tagIsDirty = true;\r
633                                 }\r
634                         }\r
635                         reader.readNext();\r
636                         if (reader.name().equalsIgnoreCase("tag") && reader.isEndElement())\r
637                                 atEnd = true;\r
638                 }\r
639                 return;\r
640         }\r
641         \r
642         \r
643         \r
644         \r
645         private String textValue() {\r
646                 return reader.readElementText();\r
647         }\r
648         private int intValue() {\r
649                 return new Integer(textValue());\r
650         }\r
651         private long longValue() {\r
652                 return new Long(textValue());\r
653         }\r
654         private double doubleValue() {\r
655                 return new Double(textValue());\r
656         }\r
657         private boolean booleanValue() {\r
658                 String value = textValue();\r
659                 if (value.equalsIgnoreCase("true"))\r
660                         return true;\r
661                 else\r
662                         return false;\r
663         }\r
664         private short shortValue() {\r
665                 return new Short(textValue());\r
666         }\r
667         \r
668         public void setNotebookGuid(String g) {\r
669                 notebookGuid = g;\r
670         }\r
671         \r
672         public String getErrorMessage() {\r
673                 return errorMessage;\r
674         }\r
675 }\r