E
Edward
I am trying to use Apache FOP to load images with data url into a PDF
using XSL-FO. My application has no trouble loading images when they
are loaded from a file or from a servlet generated image using
fo:external-graphic.
I have a requirement to generate these images without an external file
or servlet embedded in xsl-fo but with a string of Base64 data passed
as a parameter. I have not been able to get to this work. I have an
application that a former co-worker wrote that was able to accomplish
this and I have tried cloning their code but still cannot succeed in
this.
I see in the other application there is a line of code (which I added
to my application):
System.setProperty("java.protocol.handler.pkgs","org.apache.fop.util.protocols");
which I assume is used to tell FOP where to look for its protocols.
The other application also has added in two classes in a similar
package that looks like it was acquired from Apache (I added these
classes as well, in the same package):
org.apache.fop.util.protocols.data/Handler.java
org.apache.fop.util.protocols.data/RFC2397URLConnection.java
Within Handler is a variable that I assume defines the data protocol:
public static final String PROTOCOL = "data";
and within RFC2397URLConnection is a class:
public void connect() {
if (data != null) {
return;
}
ParsedURLDataProtocolHandler handler = new
ParsedURLDataProtocolHandler();
data = handler.parseURL(getURL().toString());
headerFields.put("content-type", data.contentType);
}
All well and good. But here is the rub, in my application this code
never gets called, while in the application that I am trying to copy it
does (verified by putting simple System.out.println's in the methods to
see when they are called).
Thinking that perhaps the other application had different libraries, I
deleted all of the common libraries from my application and added them
into mine, using the same classpath as the other (and triple checked to
make sure that fop.jar and batik.jar were the same). Also note that
for testing purposes the image is a simple hard-coded Base64 string
that I put in both applications to make sure that my problem was not
related to the way that the data was generated.
Note also that the working code runs as a standalone Java program while
my code is a servlet based web app running in WSAD and I have been
doing this testing in WSAD 5.0.0.
In both the working and non-working apps the external-graphics are
identical:
<fo:external-graphic
src="url('data:image/gif;base64,R0lGODdhMAAwAPAAAAAAAP///ywAAAAAMAAwAAAC8IyPqcvt3wCcDkiLc7C0qwyGHhSWpjQu5yqmCYsapyuvUUlvONmOZtfzgFzByTB10QgxOR0TqBQejhRNzOfkVJ+5YiUqrXF5Y5lKh/DeuNcP5yLWGsEbtLiOSpa/TPg7JpJHxyendzWTBfX0cxOnKPjgBzi4diinWGdkF8kjdfnycQZXZeYGejmJlZeGl9i2icVqaNVailT6F5iJ90m6mvuTS4OK05M0vDk0Q4XUtwvKOzrcd3iq9uisF81M1OIcR7lEewwcLp7tuNNkM3uNna3F2JQFo97Vriy/Xl4/f1cf5VWzXyym7PHhhx4dbgYKAAA7')"
height="3cm" width="3cm" />
Anybody have any idea what I am missing? Or can anyone point me to any
good FOP resources/forums? I have been searching and have not been
able to find any yet. I also cannot even find from where within
http://xmlgraphics.apache.org/fop/ that my ex-colleague even got the
org.apache.fop.util.protocols.data package or the
java.protocol.handler.pkgs code. Please help!
Thanks.
Edward
using XSL-FO. My application has no trouble loading images when they
are loaded from a file or from a servlet generated image using
fo:external-graphic.
I have a requirement to generate these images without an external file
or servlet embedded in xsl-fo but with a string of Base64 data passed
as a parameter. I have not been able to get to this work. I have an
application that a former co-worker wrote that was able to accomplish
this and I have tried cloning their code but still cannot succeed in
this.
I see in the other application there is a line of code (which I added
to my application):
System.setProperty("java.protocol.handler.pkgs","org.apache.fop.util.protocols");
which I assume is used to tell FOP where to look for its protocols.
The other application also has added in two classes in a similar
package that looks like it was acquired from Apache (I added these
classes as well, in the same package):
org.apache.fop.util.protocols.data/Handler.java
org.apache.fop.util.protocols.data/RFC2397URLConnection.java
Within Handler is a variable that I assume defines the data protocol:
public static final String PROTOCOL = "data";
and within RFC2397URLConnection is a class:
public void connect() {
if (data != null) {
return;
}
ParsedURLDataProtocolHandler handler = new
ParsedURLDataProtocolHandler();
data = handler.parseURL(getURL().toString());
headerFields.put("content-type", data.contentType);
}
All well and good. But here is the rub, in my application this code
never gets called, while in the application that I am trying to copy it
does (verified by putting simple System.out.println's in the methods to
see when they are called).
Thinking that perhaps the other application had different libraries, I
deleted all of the common libraries from my application and added them
into mine, using the same classpath as the other (and triple checked to
make sure that fop.jar and batik.jar were the same). Also note that
for testing purposes the image is a simple hard-coded Base64 string
that I put in both applications to make sure that my problem was not
related to the way that the data was generated.
Note also that the working code runs as a standalone Java program while
my code is a servlet based web app running in WSAD and I have been
doing this testing in WSAD 5.0.0.
In both the working and non-working apps the external-graphics are
identical:
<fo:external-graphic
src="url('data:image/gif;base64,R0lGODdhMAAwAPAAAAAAAP///ywAAAAAMAAwAAAC8IyPqcvt3wCcDkiLc7C0qwyGHhSWpjQu5yqmCYsapyuvUUlvONmOZtfzgFzByTB10QgxOR0TqBQejhRNzOfkVJ+5YiUqrXF5Y5lKh/DeuNcP5yLWGsEbtLiOSpa/TPg7JpJHxyendzWTBfX0cxOnKPjgBzi4diinWGdkF8kjdfnycQZXZeYGejmJlZeGl9i2icVqaNVailT6F5iJ90m6mvuTS4OK05M0vDk0Q4XUtwvKOzrcd3iq9uisF81M1OIcR7lEewwcLp7tuNNkM3uNna3F2JQFo97Vriy/Xl4/f1cf5VWzXyym7PHhhx4dbgYKAAA7')"
height="3cm" width="3cm" />
Anybody have any idea what I am missing? Or can anyone point me to any
good FOP resources/forums? I have been searching and have not been
able to find any yet. I also cannot even find from where within
http://xmlgraphics.apache.org/fop/ that my ex-colleague even got the
org.apache.fop.util.protocols.data package or the
java.protocol.handler.pkgs code. Please help!
Thanks.
Edward