You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by Keiron Liddle <ke...@aftexsw.com> on 2001/09/21 14:39:10 UTC

error when image not found

Using the current cvs I get this class cast exception. This happens if an
image cannot be found.
Also how can I set the base directory for resolving external images.

java.lang.ClassCastException: java.lang.Object
	at org.apache.batik.bridge.SVGImageElementBridge.createRasterImageNode(SVGImageElementBridge.java:167)
	at org.apache.batik.bridge.SVGImageElementBridge.createGraphicsNode(SVGImageElementBridge.java:109)
	at org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(GVTBuilder.java:167)
	at org.apache.batik.bridge.GVTBuilder.buildComposite(GVTBuilder.java:133)
	at org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(GVTBuilder.java:173)
	at org.apache.batik.bridge.GVTBuilder.buildComposite(GVTBuilder.java:133)
	at org.apache.batik.bridge.GVTBuilder.build(GVTBuilder.java:66)
	at org.apache.fop.svg.SVGElement.layout(SVGElement.java:146)
	at org.apache.fop.fo.flow.InstreamForeignObject.layout(InstreamForeignObject.java:198)

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org


Re: error when image not found

Posted by Thomas E Deweese <th...@kodak.com>.
>>>>> "KL" == Keiron Liddle <ke...@aftexsw.com> writes:

KL> On Tue, 25 Sep 2001 22:40:32 Thomas E Deweese wrote:

>> [...] for some reason you are hitting the default broken-link
>> handler instead of the SVG broken link handler.  [...]

KL> I've found out where the problem is. The BrokenLink.svg is
KL> available and it tries to load the document but the problem is
KL> that it is using the wrong xml parser and cannot load the
KL> document. [...]  The error is: java.io.IOException: SAX2 driver
KL> class org.apache.crimson.parser.XMLReaderImpl not found

KL> I am using a different xml parser which has always worked
KL> previously, so it looks like for this case it is using the default
KL> parser name.

    How are you getting it to use your alternate parser? My
understanding is if you want Batik to use the alternate parser you
should be calling:

batik.util.XMLResourceDesciptor.setXMLParserClassName(String classname);

    With the name of your XMLParser. Are you doing this?

    You might currently be subclassing batik.bridge.UserAgentAdapter
and reimplementing the getXMLParserClassName, this won't get
communicated to the SVGBrokenLinkProvider (since it unfortunately has
no way to get back to your UserAgent).

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org


Re: error when image not found

Posted by Keiron Liddle <ke...@aftexsw.com>.
On Tue, 25 Sep 2001 22:40:32 Thomas E Deweese wrote:
>     Thanks for working with me on this...
> 
>     I think I have tracked it down to a bug in the way BufferedImage
> handles properties (see attached Java file for demonstration).
> 
>     So I guess I'll bend an put in the 'instanceof' check before the
> cast, expect the commit shortly.

Thanks.

>     FYI: you are hitting this probably because for some reason you are
> hitting the default broken-link handler instead of the SVG broken link
> handler.  Which is probably something worth checking into at some
> point.  I'm guessing the SVG provider is failing somewhere, most
> likely being unable to find the broken-link image resource (normally
> org/apache/batik/bridge/BrokenLink.svg) is it possible this isn't
> available on your classpath for some reason?

I've found out where the problem is. The BrokenLink.svg is available and it
tries to load the document but the problem is that it is using the wrong
xml parser and cannot load the document. Then of course it tries the
default broken link provider which caused the other problem (which is fixed
now thanks).
The error is:
java.io.IOException: SAX2 driver class
org.apache.crimson.parser.XMLReaderImpl not found

I am using a different xml parser which has always worked previously, so it
looks like for this case it is using the default parser name.

Keiron.

ps. Thanks for the hints on replacements for getWidth and getHeight, that
seems to be working better now.

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org


Re: error when image not found

Posted by Thomas E Deweese <th...@kodak.com>.
>>>>> "KL" == Keiron Liddle <ke...@aftexsw.com> writes:

KL> On Tue, 25 Sep 2001 15:22:36 Thomas E Deweese wrote:
>> What about printing the 'img'?  Is it a GraphicsNodeRable8Bit?

KL> it is org.apache.batik.ext.awt.image.renderable.RedRable@aeb74

KL> The object returned is this

KL> java.lang.Object@3b494b:class java.lang.Object

KL> and this statement System.out.println("test:" +
KL> img.getProperty("blah")); prints this test:java.lang.Object@3b494b

KL> So it is the same object and I presume you never set the property
KL> "blah".  So maybe this is a jvm issue.  I am running jdk1.3.0_02
KL> on linux.

    Thanks for working with me on this...

    I think I have tracked it down to a bug in the way BufferedImage
handles properties (see attached Java file for demonstration).

    So I guess I'll bend an put in the 'instanceof' check before the
cast, expect the commit shortly.

    FYI: you are hitting this probably because for some reason you are
hitting the default broken-link handler instead of the SVG broken link
handler.  Which is probably something worth checking into at some
point.  I'm guessing the SVG provider is failing somewhere, most
likely being unable to find the broken-link image resource (normally
org/apache/batik/bridge/BrokenLink.svg) is it possible this isn't
available on your classpath for some reason?


Re: error when image not found

Posted by Keiron Liddle <ke...@aftexsw.com>.
On Tue, 25 Sep 2001 15:22:36 Thomas E Deweese wrote:
>     What about printing the 'img'?  Is it a GraphicsNodeRable8Bit?

it is
org.apache.batik.ext.awt.image.renderable.RedRable@aeb74

>     Since I still can't reproduce the problem (is it possible there is
> some sort of build issue?).  Can you try adding the following method
> into SVGImageElementBridge, and calling it from createRasterImageNode
> immediately after the call to readURL: Filter img = reg.readURL(purl,
> extractColorSpace(e, ctx)); printFilterTree(img, "");
> 
> ---
> 
>     protected static void printFilterTree(Filter filt, String pref) {
>         System.out.println(pref + filt);
>         java.util.Vector   v = filt.getSources();
>         java.util.Iterator i = v.iterator();
>         while (i.hasNext()) 
>             printFilterTree((Filter)i.next(), pref+"   ");
>     }

this is the result
- print filter
org.apache.batik.ext.awt.image.renderable.RedRable@aeb74
- end print filter


> KL> The SVGImageElementBridge then gets the 
> KL> SVG_BROKEN_LINK_DOCUMENT_PROPERTY which is not set by the Default
> KL> one (I can't see where the value is coming from, maybe it is a
> KL> default).
> 
>     what do you mean by 'a default'?  The only place this is set in my
> code base is in SVGBrokenLinkProvider and it is always given a value
> of the SVGDocument to use.

The object returned is this

java.lang.Object@3b494b:class java.lang.Object

and this statement
System.out.println("test:" + img.getProperty("blah"));
prints this
test:java.lang.Object@3b494b

So it is the same object and I presume you never set the property "blah".
So maybe this is a jvm issue.
I am running jdk1.3.0_02 on linux.

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org


Re: error when image not found

Posted by Thomas E Deweese <th...@kodak.com>.
>>>>> "KL" == Keiron Liddle <ke...@aftexsw.com> writes:

KL> On Mon, 24 Sep 2001 13:20:42 Thomas E Deweese wrote:
>> >>>>> "KL" == Keiron Liddle <ke...@aftexsw.com> writes:
>> 
KL> Using the current cvs I get this class cast exception. This
KL> happens if an image cannot be found.

>> This seems like a bigger issue than just the class cast problem.
>> Can you provide more information on the image returned from
>> reg.readURL(..) in createRasterImageNode? It's type for example,
>> also printing the object that is returned from the
>> img.getProperty(...)  call might be useful...

KL> The object that is return from the getProperty is just and
KL> "Object" it doesn't have any more info than that.

    What about printing the 'img'?  Is it a GraphicsNodeRable8Bit?

    Since I still can't reproduce the problem (is it possible there is
some sort of build issue?).  Can you try adding the following method
into SVGImageElementBridge, and calling it from createRasterImageNode
immediately after the call to readURL: Filter img = reg.readURL(purl,
extractColorSpace(e, ctx)); printFilterTree(img, "");

---

    protected static void printFilterTree(Filter filt, String pref) {
        System.out.println(pref + filt);
        java.util.Vector   v = filt.getSources();
        java.util.Iterator i = v.iterator();
        while (i.hasNext()) 
            printFilterTree((Filter)i.next(), pref+"   ");
    }


KL> After a quick look it seems there is a difference between the
KL> SVGBrokenLinkProvider and the DefaultBrokenLinkProvider.  

    Yup.

KL> The Default one sets the BROKEN_LINK_PROPERTY with a message and
KL> the SVG one sets the BROKEN_LINK_PROPERTY and the
KL> SVG_BROKEN_LINK_DOCUMENT_PROPERTY. 

    Yup.

KL> So presumably the BROKEN_LINK_PROPERTY is the one used to indicate
KL> a broken link. 

    Yup, more specifically if the Filter (or chain of Filters) has
this property set then the source image is a stand-in for an
unavailable image.

KL> The SVGImageElementBridge then gets the 
KL> SVG_BROKEN_LINK_DOCUMENT_PROPERTY which is not set by the Default
KL> one (I can't see where the value is coming from, maybe it is a
KL> default).

    what do you mean by 'a default'?  The only place this is set in my
code base is in SVGBrokenLinkProvider and it is always given a value
of the SVGDocument to use.
    

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org


Re: error when image not found

Posted by Keiron Liddle <ke...@aftexsw.com>.
On Mon, 24 Sep 2001 13:20:42 Thomas E Deweese wrote:
> >>>>> "KL" == Keiron Liddle <ke...@aftexsw.com> writes:
> 
> KL> Using the current cvs I get this class cast exception. This
> KL> happens if an image cannot be found.  
> 
>     Hmm, I (or you for testing purposes) can easily wrap the cast in a
> try catch block which would probably make the problem go away for now
> for you (I can't reproduce the problem in my copy of Batik). I also
> really have to wonder who is setting the
> SVG_BROKEN_LINK_DOCUMENT_PROPERTY, on an image returned from the
> ImageTagRegistry, if it isn't the SVGBrokenLinkProvider which always
> sets it to an SVGDocument.
> 
>     This seems like a bigger issue than just the class cast problem.
> Can you provide more information on the image returned from
> reg.readURL(..) in createRasterImageNode? It's type for example, also
> printing the object that is returned from the img.getProperty(...)
> call might be useful...

The object that is return from the getProperty is just and "Object" it
doesn't have any more info than that.

After a quick look it seems there is a difference between the
SVGBrokenLinkProvider and the DefaultBrokenLinkProvider.
The Default one sets the BROKEN_LINK_PROPERTY with a message and the SVG
one sets the BROKEN_LINK_PROPERTY and the
SVG_BROKEN_LINK_DOCUMENT_PROPERTY. So presumably the BROKEN_LINK_PROPERTY
is the one used to indicate a broken link. The SVGImageElementBridge then
gets the SVG_BROKEN_LINK_DOCUMENT_PROPERTY which is not set by the Default
one (I can't see where the value is coming from, maybe it is a default).

The image is coming from line 145 in the ImageTagRegistry.

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org


error when image not found

Posted by Thomas E Deweese <th...@kodak.com>.
>>>>> "KL" == Keiron Liddle <ke...@aftexsw.com> writes:

KL> Using the current cvs I get this class cast exception. This
KL> happens if an image cannot be found.  

    Hmm, I (or you for testing purposes) can easily wrap the cast in a
try catch block which would probably make the problem go away for now
for you (I can't reproduce the problem in my copy of Batik). I also
really have to wonder who is setting the
SVG_BROKEN_LINK_DOCUMENT_PROPERTY, on an image returned from the
ImageTagRegistry, if it isn't the SVGBrokenLinkProvider which always
sets it to an SVGDocument.

    This seems like a bigger issue than just the class cast problem.
Can you provide more information on the image returned from
reg.readURL(..) in createRasterImageNode? It's type for example, also
printing the object that is returned from the img.getProperty(...)
call might be useful...

KL> Also how can I set the base directory for resolving external
KL> images.

KL> java.lang.ClassCastException: java.lang.Object at
KL> org.apache.batik.bridge.SVGImageElementBridge.createRasterImageNode(SVGImageElementBridge.java:167)
KL> at
KL> org.apache.batik.bridge.SVGImageElementBridge.createGraphicsNode(SVGImageElementBridge.java:109)
KL> at
KL> org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(GVTBuilder.java:167)
KL> at
KL> org.apache.batik.bridge.GVTBuilder.buildComposite(GVTBuilder.java:133)
KL> at
KL> org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(GVTBuilder.java:173)
KL> at
KL> org.apache.batik.bridge.GVTBuilder.buildComposite(GVTBuilder.java:133)
KL> at org.apache.batik.bridge.GVTBuilder.build(GVTBuilder.java:66) at
KL> org.apache.fop.svg.SVGElement.layout(SVGElement.java:146) at
KL> org.apache.fop.fo.flow.InstreamForeignObject.layout(InstreamForeignObject.java:198)

KL> ---------------------------------------------------------------------
KL> To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org For
KL> additional commands, e-mail: batik-dev-help@xml.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org