aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/org/apache')
-rw-r--r--src/java/org/apache/fop/apps/FOURIResolver.java32
1 files changed, 29 insertions, 3 deletions
diff --git a/src/java/org/apache/fop/apps/FOURIResolver.java b/src/java/org/apache/fop/apps/FOURIResolver.java
index 5a72e2d12..068951464 100644
--- a/src/java/org/apache/fop/apps/FOURIResolver.java
+++ b/src/java/org/apache/fop/apps/FOURIResolver.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2005 The Apache Software Foundation.
+ * Copyright 2005-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,10 +14,11 @@
* limitations under the License.
*/
-/* $Id: $ */
+/* $Id$ */
package org.apache.fop.apps;
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
@@ -28,6 +29,9 @@ import javax.xml.transform.stream.StreamSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+// base64 support for "data" urls
+import org.apache.batik.util.Base64DecodeStream;
+
/**
* Provides FOP specific URI resolution.
* This is the default URIResolver {@link FOUserAgent} will use unless overidden.
@@ -70,6 +74,8 @@ public class FOURIResolver
} catch (MalformedURLException mfue) {
log.error("Could not convert filename to URL: " + mfue.getMessage(), mfue);
}
+ } else if (href.startsWith("data:")) {
+ return parseDataURI(href);
} else {
URL baseURL = toBaseURL(base);
if (baseURL == null) {
@@ -151,5 +157,25 @@ public class FOURIResolver
}
return null;
}
-
+
+ /**
+ * Parses inline data URIs as generated by MS Word's XML export and FO stylesheet.
+ * @see <a href="http://www.ietf.org/rfc/rfc2397">RFC 2397</a>
+ */
+ private Source parseDataURI(String href) {
+ int commaPos = href.indexOf(',');
+ // header is of the form data:[<mediatype>][;base64]
+ String header = href.substring(0, commaPos);
+ String data = href.substring(commaPos + 1);
+ if (header.endsWith(";base64")) {
+ byte[] bytes = data.getBytes();
+ ByteArrayInputStream encodedStream = new ByteArrayInputStream(bytes);
+ Base64DecodeStream decodedStream = new Base64DecodeStream(encodedStream);
+ return new StreamSource(decodedStream);
+ } else {
+ //Note that this is not quite the full story here. But since we are only interested
+ //in base64-encoded binary data, the next line will probably never be called.
+ return new StreamSource(new java.io.StringReader(data));
+ }
+ }
}