aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/util
diff options
context:
space:
mode:
authorGlenn Adams <gadams@apache.org>2013-09-13 13:56:18 +0000
committerGlenn Adams <gadams@apache.org>2013-09-13 13:56:18 +0000
commit54eec84366117b4705a71810f1d1c87529c32ba5 (patch)
tree440e34d3633c5a176337dcd06b2d362e76d8d9e6 /src/java/org/apache/fop/util
parent119c49e73ecda40e92303c03231086eae61295df (diff)
downloadxmlgraphics-fop-54eec84366117b4705a71810f1d1c87529c32ba5.tar.gz
xmlgraphics-fop-54eec84366117b4705a71810f1d1c87529c32ba5.zip
FOP-2298: Enable support for PDF Transitions by defining low-level mechanism to augment /Catalog and /Page dictionaries.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1522934 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/util')
-rw-r--r--src/java/org/apache/fop/util/GenerationHelperContentHandler.java13
-rw-r--r--src/java/org/apache/fop/util/XMLUtil.java31
2 files changed, 43 insertions, 1 deletions
diff --git a/src/java/org/apache/fop/util/GenerationHelperContentHandler.java b/src/java/org/apache/fop/util/GenerationHelperContentHandler.java
index 64fabbc8a..68970a7f2 100644
--- a/src/java/org/apache/fop/util/GenerationHelperContentHandler.java
+++ b/src/java/org/apache/fop/util/GenerationHelperContentHandler.java
@@ -35,6 +35,7 @@ public class GenerationHelperContentHandler extends DelegatingContentHandler {
private static final Attributes EMPTY_ATTS = new AttributesImpl();
private String mainNamespace;
+ private Object contentHandlerContext;
/**
* Main constructor. If the given handler also implements any of the EntityResolver,
@@ -42,10 +43,12 @@ public class GenerationHelperContentHandler extends DelegatingContentHandler {
* @param handler the SAX content handler to delegate all calls to
* @param mainNamespace the main namespace used for generated XML content when abbreviated
* ContentHandler calls are used.
+ * @param contentHandlerContext additional content handler context state
*/
- public GenerationHelperContentHandler(ContentHandler handler, String mainNamespace) {
+ public GenerationHelperContentHandler(ContentHandler handler, String mainNamespace, Object contentHandlerContext) {
super(handler);
this.mainNamespace = mainNamespace;
+ this.contentHandlerContext = contentHandlerContext;
}
/**
@@ -66,6 +69,14 @@ public class GenerationHelperContentHandler extends DelegatingContentHandler {
}
/**
+ * Returns the context object (may be null).
+ * @return the context object
+ */
+ public Object getContentHandlerContext() {
+ return this.contentHandlerContext;
+ }
+
+ /**
* Convenience method to generate a startElement SAX event.
* @param localName the local name of the element
* @param atts the attributes
diff --git a/src/java/org/apache/fop/util/XMLUtil.java b/src/java/org/apache/fop/util/XMLUtil.java
index 24c75922c..3f815e59e 100644
--- a/src/java/org/apache/fop/util/XMLUtil.java
+++ b/src/java/org/apache/fop/util/XMLUtil.java
@@ -300,4 +300,35 @@ public final class XMLUtil implements XMLConstants {
}
}
+ /**
+ * Escape '<', '>' and '&' using NCRs.
+ * @param unescaped string
+ * @return escaped string
+ */
+ public static String escape(String unescaped) {
+ int needsEscape = 0;
+ for (int i = 0, n = unescaped.length(); i < n; ++i) {
+ char c = unescaped.charAt(i);
+ if ((c == '<') || (c == '>') || (c == '&')) {
+ ++needsEscape;
+ }
+ }
+ if (needsEscape > 0) {
+ StringBuffer sb = new StringBuffer(unescaped.length() + 6 * needsEscape);
+ for (int i = 0, n = unescaped.length(); i < n; ++i) {
+ char c = unescaped.charAt(i);
+ if ((c == '<') || (c == '>') || (c == '&')) {
+ sb.append("&#x");
+ sb.append(Integer.toString(c, 16));
+ sb.append(';');
+ } else {
+ sb.append(c);
+ }
+ }
+ return sb.toString();
+ } else {
+ return unescaped;
+ }
+ }
+
}