Bläddra i källkod

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
tags/fop-0_92-beta
Jeremias Maerki 18 år sedan
förälder
incheckning
ee938b7c23

+ 29
- 3
src/java/org/apache/fop/apps/FOURIResolver.java Visa fil

@@ -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));
}
}
}

+ 3
- 0
status.xml Visa fil

@@ -27,6 +27,9 @@

<changes>
<release version="FOP Trunk">
<action context="Code" dev="JM" type="add" fixes-bug="38132" due-to="Richard Wheeldon">
Added support for RFC2397 "data" URLs.
</action>
<action context="Code" dev="JM" type="fix" fixes-bug="38132">
Bugfix: Certain border styles could lead to a NullPointerException.
</action>

+ 48
- 0
test/layoutengine/standard-testcases/external-graphic_rfc2397.xml
Filskillnaden har hållits tillbaka eftersom den är för stor
Visa fil


Laddar…
Avbryt
Spara