From ee938b7c2361df5ad4629ba6f90d84c74b5278a5 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Thu, 5 Jan 2006 14:00:50 +0000 Subject: [PATCH] Bugzilla #38135: Added support for RFC 2397 "data" URLs. Submitted by: Richard Wheeldon git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@366184 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/fop/apps/FOURIResolver.java | 32 +++++++++++-- status.xml | 3 ++ .../external-graphic_rfc2397.xml | 48 +++++++++++++++++++ 3 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 test/layoutengine/standard-testcases/external-graphic_rfc2397.xml 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 RFC 2397 + */ + private Source parseDataURI(String href) { + int commaPos = href.indexOf(','); + // header is of the form data:[][;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)); + } + } } diff --git a/status.xml b/status.xml index a0a333cb0..7ef2d56fe 100644 --- a/status.xml +++ b/status.xml @@ -27,6 +27,9 @@ + + Added support for RFC2397 "data" URLs. + Bugfix: Certain border styles could lead to a NullPointerException. diff --git a/test/layoutengine/standard-testcases/external-graphic_rfc2397.xml b/test/layoutengine/standard-testcases/external-graphic_rfc2397.xml new file mode 100644 index 000000000..7466a6e35 --- /dev/null +++ b/test/layoutengine/standard-testcases/external-graphic_rfc2397.xml @@ -0,0 +1,48 @@ + + + + + +

+ This test checks external-graphics with RFC2397 "data" URLs. +

+
+ + + + + + + + + + Image referenced by RFC 2397 "data" URL: + + EOG + + EOF + + + + + + + + + + +
-- 2.39.5