OSDN Git Service

Altered save logic to use JTidy instead of manually messing with the XML structure.
authorRandy Baumgarte <randy@fbn.cx>
Thu, 2 Sep 2010 18:19:35 +0000 (14:19 -0400)
committerRandy Baumgarte <randy@fbn.cx>
Tue, 14 Sep 2010 10:23:27 +0000 (06:23 -0400)
.classpath
lib/jtidy-r938.jar [new file with mode: 0644]
src/cx/fbn/nevernote/evernote/EnmlConverter.java

index b839928..51308c4 100644 (file)
@@ -10,5 +10,6 @@
        <classpathentry kind="var" path="QTJAMBI_API_JAR"/>\r
        <classpathentry kind="var" path="QTJAMBI_PLATFORM_JAR"/>\r
        <classpathentry kind="lib" path="D:/repository/nevernote/nevernote/lib/commons-lang-2.4.jar"/>\r
+       <classpathentry kind="lib" path="D:/repository/nevernote/nevernote/lib/jtidy-r938.jar"/>\r
        <classpathentry kind="output" path="bin"/>\r
 </classpath>\r
diff --git a/lib/jtidy-r938.jar b/lib/jtidy-r938.jar
new file mode 100644 (file)
index 0000000..efde902
Binary files /dev/null and b/lib/jtidy-r938.jar differ
index ca23846..8b37bca 100644 (file)
 */\r
 package cx.fbn.nevernote.evernote;\r
 \r
+import java.io.ByteArrayInputStream;\r
+import java.io.ByteArrayOutputStream;\r
 import java.io.File;\r
 import java.util.ArrayList;\r
 import java.util.List;\r
 \r
+import org.w3c.tidy.Tidy;\r
+\r
 import cx.fbn.nevernote.Global;\r
 import cx.fbn.nevernote.utilities.ApplicationLogger;\r
 import cx.fbn.nevernote.xml.XMLCleanup;\r
@@ -87,10 +91,17 @@ public class EnmlConverter {
                // any problems found.\r
                \r
                XMLNoteRepair repair = new XMLNoteRepair();\r
-               logger.log(logger.HIGH, "Checking XML Structure");\r
-               newContent = repair.parse(newContent, false);\r
-               logger.log(logger.HIGH, "Check complete");\r
-               \r
+//             logger.log(logger.HIGH, "Checking XML Structure");\r
+//             newContent = repair.parse(newContent, false);\r
+//             logger.log(logger.HIGH, "Check complete");\r
+       \r
+               Tidy tidy = new Tidy();\r
+               tidy.setXmlTags(true);\r
+               byte html[] = newContent.getBytes();\r
+               ByteArrayInputStream is = new ByteArrayInputStream(html);\r
+               ByteArrayOutputStream os = new ByteArrayOutputStream();\r
+               tidy.parse(is, os);\r
+               newContent = os.toString();\r
 \r
                // If the repair above returned null, then the XML is foobar.\r
                // We are done here.\r