OSDN Git Service

Add check for length = 0 on recognition in highlight checking.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / xml / NoteFormatter.java
index 191a827..d513322 100644 (file)
@@ -34,7 +34,8 @@ public class NoteFormatter {
        private final ApplicationLogger logger;\r
        private final DatabaseConnection conn;\r
        public boolean resourceError = false;\r
        private final ApplicationLogger logger;\r
        private final DatabaseConnection conn;\r
        public boolean resourceError = false;\r
-       public boolean readOnly = false;\r
+       public boolean readOnly = false; \r
+       public boolean inkNote = false;\r
        public boolean addHighlight = true;\r
        private Note currentNote;\r
        private String currentNoteGuid;\r
        public boolean addHighlight = true;\r
        private Note currentNote;\r
        private String currentNoteGuid;\r
@@ -53,11 +54,12 @@ public class NoteFormatter {
        public void setNote(Note note, boolean pdfPreview) {\r
                currentNote = note;\r
                this.pdfPreview = pdfPreview;\r
        public void setNote(Note note, boolean pdfPreview) {\r
                currentNote = note;\r
                this.pdfPreview = pdfPreview;\r
-               if (note != null)\r
-                       currentNoteGuid = note.getGuid();\r
-               else\r
-                       currentNoteGuid = null;\r
                readOnly = false;\r
                readOnly = false;\r
+               currentNoteGuid = null;\r
+               if (note != null) {\r
+                       currentNoteGuid = note.getGuid();\r
+                       readOnly = conn.getNotebookTable().isReadOnly(note.getNotebookGuid());\r
+               } \r
                resourceError = false;\r
        }\r
        \r
                resourceError = false;\r
        }\r
        \r
@@ -130,6 +132,8 @@ public class NoteFormatter {
                \r
                // Get the recognition XML that tells where to hilight on the image\r
                Resource recoResource = conn.getNoteTable().noteResourceTable.getNoteResourceRecognition(resGuid);\r
                \r
                // Get the recognition XML that tells where to hilight on the image\r
                Resource recoResource = conn.getNoteTable().noteResourceTable.getNoteResourceRecognition(resGuid);\r
+               if (recoResource.getRecognition().getBody() == null || recoResource.getRecognition().getBody().length == 0)\r
+                       return;\r
                QByteArray recoData = new QByteArray(recoResource.getRecognition().getBody());\r
                String xml = recoData.toString();\r
                \r
                QByteArray recoData = new QByteArray(recoResource.getRecognition().getBody());\r
                String xml = recoData.toString();\r
                \r
@@ -170,7 +174,12 @@ public class NoteFormatter {
                                        \r
                                        // Check to see if this word matches something we were searching for.\r
                                        for (int k=0; k<enSearch.hilightWords.size(); k++) {\r
                                        \r
                                        // Check to see if this word matches something we were searching for.\r
                                        for (int k=0; k<enSearch.hilightWords.size(); k++) {\r
-                                               if (enSearch.hilightWords.get(k).equalsIgnoreCase(text))\r
+                                               String searchWord = enSearch.hilightWords.get(k).toLowerCase();\r
+                                               if (searchWord.startsWith("*"))\r
+                                                       searchWord = searchWord.substring(1);\r
+                                               if (searchWord.endsWith("*"))\r
+                                                       searchWord = searchWord.substring(0,searchWord.length()-1);\r
+                                               if (text.toLowerCase().contains(searchWord))\r
                                                        p2.drawRect(x,y,w,h);                           \r
                                        }\r
                                }\r
                                                        p2.drawRect(x,y,w,h);                           \r
                                        }\r
                                }\r
@@ -203,8 +212,10 @@ public class NoteFormatter {
                Resource r = null;\r
                if (resGuid != null)\r
                        r = conn.getNoteTable().noteResourceTable.getNoteResource(resGuid,true);\r
                Resource r = null;\r
                if (resGuid != null)\r
                        r = conn.getNoteTable().noteResourceTable.getNoteResource(resGuid,true);\r
-                       if (r==null || r.getData() == null || r.getData().getBody().length == 0)\r
-                               resourceError = true;;\r
+                       if (r==null || r.getData() == null || r.getData().getBody().length == 0) {\r
+                               resourceError = true;\r
+                               readOnly = true;\r
+                       }\r
                        if (r!= null && r.getData() != null && r.getData().getBody().length > 0) {\r
                                tfile.open(new QIODevice.OpenMode(QIODevice.OpenModeFlag.WriteOnly));\r
                                QByteArray binData = new QByteArray(r.getData().getBody());\r
                        if (r!= null && r.getData() != null && r.getData().getBody().length > 0) {\r
                                tfile.open(new QIODevice.OpenMode(QIODevice.OpenModeFlag.WriteOnly));\r
                                QByteArray binData = new QByteArray(r.getData().getBody());\r
@@ -358,7 +369,7 @@ public class NoteFormatter {
     private void modifyApplicationTags(QDomDocument doc, QDomElement docElem, QDomElement enmedia, QDomAttr hash, String appl) {\r
        logger.log(logger.HIGH, "Entering NeverNote.modifyApplicationTags");\r
        if (appl.equalsIgnoreCase("vnd.evernote.ink")) {\r
     private void modifyApplicationTags(QDomDocument doc, QDomElement docElem, QDomElement enmedia, QDomAttr hash, String appl) {\r
        logger.log(logger.HIGH, "Entering NeverNote.modifyApplicationTags");\r
        if (appl.equalsIgnoreCase("vnd.evernote.ink")) {\r
-               readOnly = true;\r
+               inkNote = true;\r
            if (buildInkNote(doc, docElem, enmedia, hash, appl))\r
                return;\r
        }\r
            if (buildInkNote(doc, docElem, enmedia, hash, appl))\r
                return;\r
        }\r
@@ -498,6 +509,7 @@ public class NoteFormatter {
                        todo.setAttribute("unchecked","");\r
                todo.setAttribute("value", checked);\r
                todo.setAttribute("onClick", "value=checked;window.jambi.contentChanged(); ");\r
                        todo.setAttribute("unchecked","");\r
                todo.setAttribute("value", checked);\r
                todo.setAttribute("onClick", "value=checked;window.jambi.contentChanged(); ");\r
+               todo.setAttribute("onMouseOver", "style.cursor='hand'");\r
                todo.setTagName("input");\r
                logger.log(logger.HIGH, "Leaving NeverNote.modifyTodoTags");\r
     }\r
                todo.setTagName("input");\r
                logger.log(logger.HIGH, "Leaving NeverNote.modifyTodoTags");\r
     }\r