From c12d48dc9442ef12ea246f81dc335362138f080d Mon Sep 17 00:00:00 2001 From: Christian Geisert Date: Mon, 9 Dec 2002 00:58:47 +0000 Subject: [PATCH] Fixed resolution of relative URLs in FopImageFactory with IBM JDK PR: 14949 Submitted by: Manuel Mall git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/fop-0_20_2-maintain@195743 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 2 ++ src/org/apache/fop/image/FopImageFactory.java | 27 +++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index f19928896..f31b0eeed 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,7 @@ ============================================================================== Done since 0.20.4 release +- Fixed resolution of relative URLs in FopImageFactory with IBM JDK + Submitted by: Manuel Mall (see bug #14948) - Fixed infinite loop when page-height="auto" (Oleg Tkachenko) - Fix embedding of Adobe Type 1 fonts. PFB file encoded in PC format were not decoded prior to embedding. This may explain error messages with diff --git a/src/org/apache/fop/image/FopImageFactory.java b/src/org/apache/fop/image/FopImageFactory.java index 19794d223..dedc17c9d 100644 --- a/src/org/apache/fop/image/FopImageFactory.java +++ b/src/org/apache/fop/image/FopImageFactory.java @@ -97,9 +97,32 @@ public class FopImageFactory { } try { - absoluteURL = new URL(baseURL, absoluteURL.getFile()); + /* + This piece of code is based on the following statement in RFC2396 section 5.2: + + 3) If the scheme component is defined, indicating that the reference + starts with a scheme name, then the reference is interpreted as an + absolute URI and we are done. Otherwise, the reference URI's + scheme is inherited from the base URI's scheme component. + + Due to a loophole in prior specifications [RFC1630], some parsers + allow the scheme name to be present in a relative URI if it is the + same as the base URI scheme. Unfortunately, this can conflict + with the correct parsing of non-hierarchical URI. For backwards + compatibility, an implementation may work around such references + by removing the scheme if it matches that of the base URI and the + scheme is known to always use the syntax. + + The URL class does not implement this work around, so we do. + */ + + String scheme = baseURL.getProtocol() + ":"; + if (href.startsWith(scheme)) { + href = href.substring(scheme.length()); + } + absoluteURL = new URL(baseURL, href); + System.out.println("baseURL=" + baseURL.toString() + " href=" + href + " absoluteURL=" + absoluteURL.toString()); } catch (MalformedURLException e_context) { - // pb context url throw new FopImageException("Invalid Image URL - error on relative URL : " + e_context.getMessage()); } -- 2.39.5