xmlgraphics-fop-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 31580] New: - fo:external-graphic does not work when src is an image URL which is in a jar-file
Date Thu, 07 Oct 2004 13:00:22 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=31580>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=31580

fo:external-graphic  does not work when src is an image URL which is in a jar-file

           Summary: fo:external-graphic  does not work when src is an image
                    URL which is in a jar-file
           Product: Fop
           Version: 0.20.5
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: images
        AssignedTo: fop-dev@xml.apache.org
        ReportedBy: h.wu@eurodata.de


Hi!

I found a problem when using url instead of file for fo:external-graphic's 
src paramater (FOP is 0.20.5 distribution). for example,

<fo:external-graphic height="15pt" width="180pt">
	<xsl:attribute name="src">url('/my/image/image.gif')</xsl:attribute>
</fo:external-graphic>


it will work with the following changes in class 
org.apache.fop.image.FopImageFactory.java

...

// Try to find the image as a class-resource first (for instance in a jar-
file)...
        try {
            imgIS = FopImageFactory.class.getResourceAsStream(href);
            absoluteURL = FopImageFactory.class.getResource(href);
        } catch (Exception e) {
        }

        if (imgIS == null) {
            try {
                // try url as complete first, this can cause
                // a problem with relative uri's if there is an
                // image relative to where fop is run and relative
                // to the base dir of the document
                try {
                    absoluteURL = new URL(href);
                } catch (MalformedURLException mue) {
                    // if the href contains onl a path then file is assumed
                    absoluteURL = new URL("file:" + href);
                }
                imgIS = absoluteURL.openStream();
            } catch (MalformedURLException e_context) {
                throw new FopImageException("Error with image URL: "
                    + e_context.getMessage());
            } catch (Exception e) {
                // maybe relative
                URL baseURL = Configuration.getBaseURL();

                if (baseURL == null) {
                    throw new FopImageException("Error with image URL: "
                        + e.getMessage()
                        + " and no base URL is specified");
                }

                try {
                    /*
                     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 <hier_part> syntax.

                        The URL class does not implement this work around, so 
we do.
                     */

                    String scheme = baseURL.getProtocol() + ":";
                    System.out.println("scheme " + scheme);
                    if (href.startsWith(scheme)) {
                        href = href.substring(scheme.length());
                    }
                    System.out.println("href after " + href);
                    absoluteURL = new URL(baseURL, href);
                } catch (MalformedURLException e_context) {
                    throw new FopImageException("Invalid Image URL - error on 
relative URL : "
                        + e_context.getMessage());
                }
            }
        }


        // If not, check image type
        ImageReader imgReader = null;
...

Mime
View raw message