OSDN Git Service

Cleanup compiler warning messages and alter backup & restore to handle new database...
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / xml / ExportData.java
index 2c36707..effdcb6 100644 (file)
@@ -24,11 +24,14 @@ import java.util.HashMap;
 import java.util.List;\r
 \r
 import com.evernote.edam.type.Data;\r
 import java.util.List;\r
 \r
 import com.evernote.edam.type.Data;\r
+import com.evernote.edam.type.LinkedNotebook;\r
 import com.evernote.edam.type.Note;\r
 import com.evernote.edam.type.NoteAttributes;\r
 import com.evernote.edam.type.Notebook;\r
 import com.evernote.edam.type.Note;\r
 import com.evernote.edam.type.NoteAttributes;\r
 import com.evernote.edam.type.Notebook;\r
+import com.evernote.edam.type.Publishing;\r
 import com.evernote.edam.type.Resource;\r
 import com.evernote.edam.type.SavedSearch;\r
 import com.evernote.edam.type.Resource;\r
 import com.evernote.edam.type.SavedSearch;\r
+import com.evernote.edam.type.SharedNotebook;\r
 import com.evernote.edam.type.Tag;\r
 import com.trolltech.qt.core.QByteArray;\r
 import com.trolltech.qt.core.QFile;\r
 import com.evernote.edam.type.Tag;\r
 import com.trolltech.qt.core.QByteArray;\r
 import com.trolltech.qt.core.QFile;\r
@@ -48,6 +51,8 @@ public class ExportData {
        private final ApplicationLogger                         logger;\r
        \r
        private List<SavedSearch>                                       searches;\r
        private final ApplicationLogger                         logger;\r
        \r
        private List<SavedSearch>                                       searches;\r
+       private List<LinkedNotebook>                            linkedNotebooks;\r
+       private List<SharedNotebook>                            sharedNotebooks;\r
        private final HashMap<String,String>            dirtySearches;\r
 \r
        private List<Tag>                                                       tags;\r
        private final HashMap<String,String>            dirtySearches;\r
 \r
        private List<Tag>                                                       tags;\r
@@ -57,7 +62,9 @@ public class ExportData {
        private final HashMap<String, String>           exportableTags;\r
        private List<Note>                                                      notes;\r
        private final HashMap<String,String>            dirtyNotes;\r
        private final HashMap<String, String>           exportableTags;\r
        private List<Note>                                                      notes;\r
        private final HashMap<String,String>            dirtyNotes;\r
-       private HashMap<String,Integer>         titleColors;\r
+       private final HashMap<String,String>            dirtyLinkedNotebooks;\r
+       private final HashMap<Long,String>                      dirtySharedNotebooks;\r
+       private HashMap<String,Integer>                         titleColors;\r
        private final boolean                                           fullBackup;\r
        private final DatabaseConnection                        conn;\r
        private QXmlStreamWriter                                        writer;         \r
        private final boolean                                           fullBackup;\r
        private final DatabaseConnection                        conn;\r
        private QXmlStreamWriter                                        writer;         \r
@@ -71,8 +78,12 @@ public class ExportData {
                notebooks = new ArrayList<Notebook>();\r
                tags = new ArrayList<Tag>();\r
                notes = new ArrayList<Note>();\r
                notebooks = new ArrayList<Notebook>();\r
                tags = new ArrayList<Tag>();\r
                notes = new ArrayList<Note>();\r
+               sharedNotebooks = new ArrayList<SharedNotebook>();\r
+               linkedNotebooks = new ArrayList<LinkedNotebook>();\r
                dirtyNotebooks = new HashMap<String,String>();\r
                localNotebooks = new HashMap<String,String>();\r
                dirtyNotebooks = new HashMap<String,String>();\r
                localNotebooks = new HashMap<String,String>();\r
+               dirtyLinkedNotebooks = new HashMap<String,String>();\r
+               dirtySharedNotebooks = new HashMap<Long,String>();\r
                dirtyTags = new HashMap<String,String>();\r
                fullBackup = full;\r
                \r
                dirtyTags = new HashMap<String,String>();\r
                fullBackup = full;\r
                \r
@@ -100,6 +111,8 @@ public class ExportData {
                fullBackup = full;\r
                \r
                dirtyNotes = new HashMap<String, String>();\r
                fullBackup = full;\r
                \r
                dirtyNotes = new HashMap<String, String>();\r
+               dirtyLinkedNotebooks = new HashMap<String,String>();\r
+               dirtySharedNotebooks = new HashMap<Long,String>();\r
                dirtySearches = new HashMap<String, String>();\r
                searches = new ArrayList<SavedSearch>();\r
                \r
                dirtySearches = new HashMap<String, String>();\r
                searches = new ArrayList<SavedSearch>();\r
                \r
@@ -148,7 +161,17 @@ public class ExportData {
                dirtySearches.put(ds.get(i).getGuid(), "");\r
        }\r
                \r
                dirtySearches.put(ds.get(i).getGuid(), "");\r
        }\r
                \r
-               \r
+       linkedNotebooks = conn.getLinkedNotebookTable().getAll();\r
+       List<String> dln = conn.getLinkedNotebookTable().getDirtyGuids();\r
+       for (int i=0; i<dln.size(); i++) {\r
+               dirtyLinkedNotebooks.put(dln.get(i), "");\r
+       }\r
+       \r
+       sharedNotebooks = conn.getSharedNotebookTable().getAll();\r
+       List<Long> dsn = conn.getSharedNotebookTable().getDirtyIds();\r
+       for (int i=0; i<dsn.size(); i++) {\r
+               dirtySharedNotebooks.put(dsn.get(i), "");\r
+       }\r
                \r
                lastError = 0;\r
                errorMessage = "";\r
                \r
                lastError = 0;\r
                errorMessage = "";\r
@@ -164,7 +187,7 @@ public class ExportData {
                writer.writeStartDocument();\r
                writer.writeDTD("<!DOCTYPE NeverNote-Export>");\r
                writer.writeStartElement("nevernote-export");\r
                writer.writeStartDocument();\r
                writer.writeDTD("<!DOCTYPE NeverNote-Export>");\r
                writer.writeStartElement("nevernote-export");\r
-               writer.writeAttribute("version", "0.86");\r
+               writer.writeAttribute("version", "0.95");\r
                if (fullBackup)\r
                        writer.writeAttribute("exportType", "backup");\r
                else\r
                if (fullBackup)\r
                        writer.writeAttribute("exportType", "backup");\r
                else\r
@@ -191,6 +214,8 @@ public class ExportData {
                writeNotebooks();\r
                writeTags();\r
                writeSavedSearches();\r
                writeNotebooks();\r
                writeTags();\r
                writeSavedSearches();\r
+               writeLinkedNotebooks();\r
+               writeSharedNotebooks();\r
 \r
                \r
                writer.writeEndElement();\r
 \r
                \r
                writer.writeEndElement();\r
@@ -224,8 +249,51 @@ public class ExportData {
                }\r
        }\r
        \r
                }\r
        }\r
        \r
+       \r
+       private void writeLinkedNotebooks() {\r
+               if (!fullBackup)\r
+                       return;\r
+               for (int i=0; i<linkedNotebooks.size(); i++) {\r
+                       writer.writeStartElement("LinkedNotebook");\r
+                       createTextNode("Guid", linkedNotebooks.get(i).getGuid());\r
+                       createTextNode("ShardID", linkedNotebooks.get(i).getShardId());\r
+                       createTextNode("ShareKey", linkedNotebooks.get(i).getShareKey());\r
+                       createTextNode("ShareName", linkedNotebooks.get(i).getShareName());\r
+                       createTextNode("Uri", linkedNotebooks.get(i).getUri());\r
+                       createTextNode("Username", linkedNotebooks.get(i).getUsername());\r
+                       createTextNode("UpdateSequenceNumber", new Long(linkedNotebooks.get(i).getUpdateSequenceNum()).toString());\r
+                       if (dirtyLinkedNotebooks.containsKey(linkedNotebooks.get(i).getGuid()))\r
+                               createTextNode("Dirty", "true");\r
+                       else\r
+                               createTextNode("Dirty", "false");\r
+                       writer.writeEndElement();\r
+               }\r
+       }\r
+\r
                \r
        \r
                \r
        \r
+       private void writeSharedNotebooks() {\r
+               if (!fullBackup)\r
+                       return;\r
+               for (int i=0; i<linkedNotebooks.size(); i++) {\r
+                       writer.writeStartElement("SharedNotebook");\r
+                       createTextNode("Id", new Long(sharedNotebooks.get(i).getId()).toString());\r
+                       createTextNode("Userid", new Integer(sharedNotebooks.get(i).getUserId()).toString());\r
+                       createTextNode("Email", sharedNotebooks.get(i).getEmail());\r
+                       createTextNode("NotebookGuid", sharedNotebooks.get(i).getNotebookGuid());\r
+                       createTextNode("ShareKey", sharedNotebooks.get(i).getShareKey());\r
+                       createTextNode("Username", sharedNotebooks.get(i).getUsername());\r
+                       createTextNode("ServiceCreated", new Long(sharedNotebooks.get(i).getServiceCreated()).toString());\r
+                       if (dirtySharedNotebooks.containsKey(sharedNotebooks.get(i).getId()))\r
+                               createTextNode("Dirty", "true");\r
+                       else\r
+                               createTextNode("Dirty", "false");\r
+                       writer.writeEndElement();\r
+               }\r
+       }\r
+\r
+\r
+       \r
        private void writeNote(Note note) {\r
                \r
                writer.writeStartElement("Note");\r
        private void writeNote(Note note) {\r
                \r
                writer.writeStartElement("Note");\r
@@ -392,6 +460,25 @@ public class ExportData {
                                        createTextNode("Dirty","true");\r
                                else\r
                                        createTextNode("Dirty","false");\r
                                        createTextNode("Dirty","true");\r
                                else\r
                                        createTextNode("Dirty","false");\r
+                               if (conn.getNotebookTable().isReadOnly(notebooks.get(i).getGuid()))\r
+                                       createTextNode("ReadOnly", "true");\r
+                               else\r
+                                       createTextNode("ReadOnly", "false");\r
+                               if (notebooks.get(i).getPublishing() != null) {\r
+                                       Publishing p = notebooks.get(i).getPublishing();\r
+                                       createTextNode("PublishingPublicDescription", p.getPublicDescription());\r
+                                       createTextNode("PublishingUri", p.getUri());\r
+                                       createTextNode("PublishingOrder", new Integer(p.getOrder().getValue()).toString());\r
+                                       if (p.isAscending())\r
+                                               createTextNode("PublishingAscending", "true");\r
+                                       else\r
+                                               createTextNode("PublishingAscending", "false");\r
+                               }\r
+                               QByteArray b = conn.getNotebookTable().getIconAsByteArray(notebooks.get(i).getGuid());\r
+                               if (b != null) \r
+                                       createBinaryNode("Icon", b.toHex().toString());\r
+                               if (notebooks.get(i).getStack() != null && !notebooks.get(i).getStack().trim().equals(""))\r
+                                       createTextNode("Stack", notebooks.get(i).getStack());\r
                                writer.writeEndElement();       \r
                        }\r
                }\r
                                writer.writeEndElement();       \r
                        }\r
                }\r