OSDN Git Service

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