From fb4ec297b0e6a555ece9166183f905068c89bf2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20R=C3=B8sdal?= Date: Sat, 4 Aug 2018 10:52:14 +0200 Subject: [PATCH] Add dependency to Apache Commons commons-text. Remove SimpleXMLParser.escapeXML. Deprecate SimpleXMLParser. --- README.md | 1 + openpdf/pom.xml | 6 +++ .../com/lowagie/text/pdf/SimpleBookmark.java | 8 ++-- .../text/pdf/SimpleNamedDestination.java | 7 +-- .../xml/simpleparser/SimpleXMLParser.java | 44 +------------------ 5 files changed, 18 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 032b9a650..e5369d552 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ https://groups.google.com/d/forum/openpdf ### Required: ### + - Apache Commons Text - RxJava - PDFRenderer - DOM4j diff --git a/openpdf/pom.xml b/openpdf/pom.xml index c027fbabf..90507c352 100644 --- a/openpdf/pom.xml +++ b/openpdf/pom.xml @@ -14,9 +14,15 @@ 1.60 2.2.0 + 1.4 + + org.apache.commons + commons-text + ${commons-text.version} + io.reactivex.rxjava2 rxjava diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/SimpleBookmark.java b/openpdf/src/main/java/com/lowagie/text/pdf/SimpleBookmark.java index c5adf7ec1..33010746e 100755 --- a/openpdf/src/main/java/com/lowagie/text/pdf/SimpleBookmark.java +++ b/openpdf/src/main/java/com/lowagie/text/pdf/SimpleBookmark.java @@ -66,6 +66,8 @@ import com.lowagie.text.xml.simpleparser.IanaEncodings; import com.lowagie.text.xml.simpleparser.SimpleXMLDocHandler; import com.lowagie.text.xml.simpleparser.SimpleXMLParser; +import org.apache.commons.text.StringEscapeUtils; + /** * Bookmark processing in a simple way. It has some limitations, mainly the only * action types supported are GoTo, GoToR, URI and Launch. @@ -597,14 +599,14 @@ else if (key.equals("Kids")) { String value = (String) entry.getValue(); if (key.equals("Named") || key.equals("NamedN")) value = SimpleNamedDestination.escapeBinaryString(value); - out.write(SimpleXMLParser.escapeXML(value, onlyASCII)); + out.write(StringEscapeUtils.escapeXml11(value)); out.write("\" "); } } out.write(">"); if (title == null) title = ""; - out.write(SimpleXMLParser.escapeXML(title, onlyASCII)); + out.write(StringEscapeUtils.escapeXml11(title)); if (kids != null) { out.write("\n"); exportToXMLNode(kids, out, indent + 1, onlyASCII); @@ -658,7 +660,7 @@ public static void exportToXML(List list, OutputStream out, String encoding, boo */ public static void exportToXML(List list, Writer wrt, String encoding, boolean onlyASCII) throws IOException { wrt.write("\n\n"); exportToXMLNode(list, wrt, 1, onlyASCII); wrt.write("\n"); diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/SimpleNamedDestination.java b/openpdf/src/main/java/com/lowagie/text/pdf/SimpleNamedDestination.java index be30c2dc3..3b8eb0bc2 100755 --- a/openpdf/src/main/java/com/lowagie/text/pdf/SimpleNamedDestination.java +++ b/openpdf/src/main/java/com/lowagie/text/pdf/SimpleNamedDestination.java @@ -62,6 +62,7 @@ import com.lowagie.text.xml.simpleparser.IanaEncodings; import com.lowagie.text.xml.simpleparser.SimpleXMLDocHandler; import com.lowagie.text.xml.simpleparser.SimpleXMLParser; +import org.apache.commons.text.StringEscapeUtils; /** * @@ -134,16 +135,16 @@ public static void exportToXML(HashMap names, OutputStream out, String encoding, */ public static void exportToXML(HashMap names, Writer wrt, String encoding, boolean onlyASCII) throws IOException { wrt.write("\n\n"); for (Iterator it = names.entrySet().iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry)it.next(); String key = (String)entry.getKey(); String value = (String)entry.getValue(); wrt.write(" "); - wrt.write(SimpleXMLParser.escapeXML(escapeBinaryString(key), onlyASCII)); + wrt.write(StringEscapeUtils.escapeXml11(escapeBinaryString(key))); wrt.write("\n"); } wrt.write("\n"); diff --git a/openpdf/src/main/java/com/lowagie/text/xml/simpleparser/SimpleXMLParser.java b/openpdf/src/main/java/com/lowagie/text/xml/simpleparser/SimpleXMLParser.java index bb06246e3..6d2d5c961 100644 --- a/openpdf/src/main/java/com/lowagie/text/xml/simpleparser/SimpleXMLParser.java +++ b/openpdf/src/main/java/com/lowagie/text/xml/simpleparser/SimpleXMLParser.java @@ -102,6 +102,7 @@ * *

*/ +@Deprecated public final class SimpleXMLParser { /** possible states */ private final static int UNKNOWN = 0; @@ -650,48 +651,7 @@ public static void parse(SimpleXMLDocHandler doc,Reader r) throws IOException { parse(doc, null, r, false); } - /** - * Escapes a string with the appropriated XML codes. - * @param s the string to be escaped - * @param onlyASCII codes above 127 will always be escaped with &#nn; if true - * @return the escaped string - */ - public static String escapeXML(String s, boolean onlyASCII) { - char cc[] = s.toCharArray(); - int len = cc.length; - StringBuffer sb = new StringBuffer(); - for (int k = 0; k < len; ++k) { - int c = cc[k]; - switch (c) { - case '<': - sb.append("<"); - break; - case '>': - sb.append(">"); - break; - case '&': - sb.append("&"); - break; - case '"': - sb.append("""); - break; - case '\'': - sb.append("'"); - break; - default: - if ((c == 0x9) || (c == 0xA) || (c == 0xD) - || ((c >= 0x20) && (c <= 0xD7FF)) - || ((c >= 0xE000) && (c <= 0xFFFD)) - || ((c >= 0x10000) && (c <= 0x10FFFF))) { - if (onlyASCII && c > 127) - sb.append("&#").append(c).append(';'); - else - sb.append((char)c); - } - } - } - return sb.toString(); - } + /** * Returns the IANA encoding name that is auto-detected from * the bytes specified, with the endian-ness of that encoding where appropriate.