diff options
author | Jeremias Maerki <jeremias@apache.org> | 2006-01-05 14:00:50 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2006-01-05 14:00:50 +0000 |
commit | ee938b7c2361df5ad4629ba6f90d84c74b5278a5 (patch) | |
tree | 06b9ce3be1edcc596306656ee316d15858012917 /src/java/org/apache/fop | |
parent | 49ee2648a31a64069ca7bfdf7d4a97a9cd0ce5f2 (diff) | |
download | xmlgraphics-fop-ee938b7c2361df5ad4629ba6f90d84c74b5278a5.tar.gz xmlgraphics-fop-ee938b7c2361df5ad4629ba6f90d84c74b5278a5.zip |
Bugzilla #38135:
Added support for RFC 2397 "data" URLs.
Submitted by: Richard Wheeldon <richardw.at.geoquip-rnd.demon.co.uk>
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@366184 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop')
-rw-r--r-- | src/java/org/apache/fop/apps/FOURIResolver.java | 32 |
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)); + } + } } |