You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Gregory <de...@yahoo.com> on 2005/07/05 03:27:00 UTC

Transcoding with DOM => NullPointerException

Hi,

I have an svg document with the following element:
<image x="0" y="0" width="612" height="792"
xlink:href="http://xml.apache.org/batik/images/splash.png"/>

I works fine with the rasterizer and with squiggle. 

But if I try the Transcoder API with something like
this:
...
TranscoderOutput out = new
TranscoderOutput(outputStream);
transcoder.transcode(in, out);
...

I get:

java.lang.NullPointerException
at
org.apache.batik.bridge.DocumentLoader.getLineNumber(Unknown
Source)
at org.apache.batik.bridge.GVTBuilder.build(Unknown
Source)
at
org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(Unknown
Source)
at
org.apache.batik.transcoder.image.ImageTranscoder.transcode(Unknown
Source)
at
org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(Unknown
Source)
...

Any idea?

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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


Re: Transcoding with DOM => NullPointerException

Posted by Tonny Kohar <to...@kiyut.com>.
Hi,

On Mon, 2005-07-04 at 18:32 -0700, Gregory wrote:
> Sorry, there was a missing line before the java code
> snippet. It should have been:
> 
> ...
> TranscoderOutput out = new
> TranscoderOutput(outputStream);
> // doc is SVGDocument
> TranscoderInput in = new TranscoderInput(doc);
> transcoder.transcode(in, out);

Did the transcoder work fine with other svg doc, or it is only error
with the particular svg doc ? try to use simple doc without image
element eg: only rect element?

I could be wrong, if you create the doc on the fly did you also put doc
base attribute ?

Regards
Tonny Kohar
-- 
Sketsa 
SVG Graphics Editor
http://www.kiyut.com


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


Re: Transcoding with DOM => NullPointerException

Posted by Gregory <de...@yahoo.com>.
I solved the problem.

Actually it had nothing to do with the base uri. It
happens that the Document was provided by an object
that read the svg file with the SAXSVGDocumentFactory.

When I use the SAXSVGDocumentFactory directly in my
test case to parse the svg input all works fine. 

The weird thing is that the providing object doesn't
change much of the Document. It just uses it with
JXPath to check some attributes but it doesn't change
them.

I will check more carefully that class and will post
the results if they are of interest.

> > For the base uri I set in the svg source or with
> > setURI(), I have tried also
> "/http://xml.apache.org/"
> >  or "/http://xml.apache.org/my-doc" but with the
> same
> > results.
> 
>     Neither of these is a valid url, I suspect the
> second is
> coming close to what you want
> 'http://xml.apache.org/myDoc.svg'

Correct the leading slash was not supposed to be
there. 

Just this annoying thing of using copy and paste
inside the small text area of a web email form.

Thanks for your help.




		
__________________________________ 
Discover Yahoo! 
Use Yahoo! to plan a weekend, have fun online and more. Check it out! 
http://discover.yahoo.com/

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


Re: Transcoding with DOM => NullPointerException

Posted by Thomas DeWeese <Th...@Kodak.com>.
Gregory wrote:

> I have other problems though:
> 
> 1- If I trancode the same document, I get an output
> file with a broken href/image picture not the real
> image. The display of the file used to build the
> document is fine in a browser (Firefox).
> 
> 2- If I add xml:base="http://xml.apache.org" to the
> svg  root element the transcoder generates an empty
> file. The svg source file displays correctly in
> Firefox.

    xml:base should be the absolute URL of the
Document you are setting it on (assuming the document
has proper relative references to it's resources
normally).  The url's you give as examples do not
look like such URL's.  Also when you set the xml:base
attribute you need to take care to use the
setAttributeNS call with the proper xml Namespace
(http://www.w3.org/XML/1998/namespace).

> For the base uri I set in the svg source or with
> setURI(), I have tried also "/http://xml.apache.org/"
>  or "/http://xml.apache.org/my-doc" but with the same
> results.

    Neither of these is a valid url, I suspect the second is
coming close to what you want 'http://xml.apache.org/myDoc.svg'

> 1- I have noticed that if the initial heap size is too
> low, I can get "broken images" with the transcoder and
> the rasteriser. Here I have used a heap size that is
> usually fine with this type of documents. I have also
> used the rasterizer with the same heap size and the
> result is always fine.
> 
>  I would prefer an Exception to be thrown rather than
> a "broken image" pic when the transcoder cannot render
> a document (whether because the link is broken or
> because of memory problems).
> Is it possible?

    Yes, but you would need to write some code.  Basically
you want to replace the SVGImageElementBridge with a
custom subclass (done by registering it with the BridgeContext)
and replace the 'createBrokenImageNode' call with one that
throws an error).  It might be nice if this were exposed to the
UserAgent class.

> 2- The rastizer seems to works always fine whether I
> use absolute url link, xml:base + relative url link or
> xml:base + absolute url link.

    This is a pretty clear indication that your use of
xml:base and or setURI is wrong as the rasterizer is
just a wrapper around the Transcoder classes.

> 
> I badly need to solve this problem so your help is
> really appreciated.



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


Re: Transcoding with DOM => NullPointerException

Posted by Gregory <de...@yahoo.com>.
[...]
>     So I'm fairly sure that the problem is that
> Batik doesn't know the URL base to use to resolve
> xlink:href's in 'doc'.  There are two ways to solve
> this.
> First you can use the xml:base attribute to provide
> a
> base URL for resolution.  Second you can use
> TranscoderInput.setURI
> to provide a uri to go with your doc.
[...]
>     This looks like a bug from 1.5.1 where it would
> get an NPE
> when looking up the line number so it could generate
> a useful
> error message.  What version of Batik are you using?


I was using 1.5. I switched to 1.6 and there is no
more a NPE. 

I have other problems though:

1- If I trancode the same document, I get an output
file with a broken href/image picture not the real
image. The display of the file used to build the
document is fine in a browser (Firefox).

2- If I add xml:base="http://xml.apache.org" to the
svg  root element the transcoder generates an empty
file. The svg source file displays correctly in
Firefox.

3- If I add xml:base="http://xml.apache.org" to the
svg  image element I get the same results as in 1.

4- If I do transcoder.setURI("/http://xml.apache.org")
same as 1 and 3;

For the base uri I set in the svg source or with
setURI(), I have tried also "/http://xml.apache.org/"
 or "/http://xml.apache.org/my-doc" but with the same
results.

Some remarks:

1- I have noticed that if the initial heap size is too
low, I can get "broken images" with the transcoder and
the rasteriser. Here I have used a heap size that is
usually fine with this type of documents. I have also
used the rasterizer with the same heap size and the
result is always fine.

 I would prefer an Exception to be thrown rather than
a "broken image" pic when the transcoder cannot render
a document (whether because the link is broken or
because of memory problems).
Is it possible?

2- The rastizer seems to works always fine whether I
use absolute url link, xml:base + relative url link or
xml:base + absolute url link.

I badly need to solve this problem so your help is
really appreciated.




		
____________________________________________________ 
Yahoo! Sports 
Rekindle the Rivalries. Sign up for Fantasy Football 
http://football.fantasysports.yahoo.com

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


Re: Transcoding with DOM => NullPointerException

Posted by Thomas DeWeese <Th...@Kodak.com>.
Hi Gregory,

Gregory wrote:

>>I have an svg document with the following element:
>><image x="0" y="0" width="612" height="792"
>>  xlink:href="http://xml.apache.org/batik/images/splash.png"/>

>> It works fine with the rasterizer and with squiggle. 
>> 
>> But if I try the Transcoder API with something like
>> this:

>> TranscoderOutput out = new
>> TranscoderOutput(outputStream);
>> // doc is SVGDocument
>> TranscoderInput in = new TranscoderInput(doc);
>> transcoder.transcode(in, out);

    So I'm fairly sure that the problem is that
Batik doesn't know the URL base to use to resolve
xlink:href's in 'doc'.  There are two ways to solve this.
First you can use the xml:base attribute to provide a
base URL for resolution.  Second you can use TranscoderInput.setURI
to provide a uri to go with your doc.

>>I get:
>>
>>java.lang.NullPointerException
>>at org.apache.batik.bridge.DocumentLoader.getLineNumber(Unknown

    This looks like a bug from 1.5.1 where it would get an NPE
when looking up the line number so it could generate a useful
error message.  What version of Batik are you using?

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


Re: Transcoding with DOM => NullPointerException

Posted by Gregory <de...@yahoo.com>.
I switched from batik 1.5 to batik 1.6 the
NullPointerException disappeared but I had other
problems.

Mainly that the referenced image appears as "broken"
in the resulting file while using the transcoder.

I have used many combinaison of xml:base +
absolute|relative url link and the result is fine with
the rasterizer and "broken" with the transcoder.

I had more details in a previous reply to Thomas
DeWeese.

--- Tonny Kohar <to...@kiyut.com> wrote:

> Hi,
> 
> On Mon, 2005-07-04 at 18:32 -0700, Gregory wrote:
> > Sorry, there was a missing line before the java
> code
> > snippet. It should have been:
> > 
> > ...
> > TranscoderOutput out = new
> > TranscoderOutput(outputStream);
> > // doc is SVGDocument
> > TranscoderInput in = new TranscoderInput(doc);
> > transcoder.transcode(in, out);
> 
> Did the transcoder work fine with other svg doc, or
> it is only error
> with the particular svg doc ? try to use simple doc
> without image
> element eg: only rect element?
> 
> I could be wrong, if you create the doc on the fly
> did you also put doc
> base attribute ?
> 
> Regards
> Tonny Kohar
> -- 
> Sketsa 
> SVG Graphics Editor
> http://www.kiyut.com
> -- 
> Sketsa 
> SVG Graphics Editor
> http://www.kiyut.com
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail:
> batik-users-help@xmlgraphics.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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


Re: Transcoding with DOM => NullPointerException

Posted by Tonny Kohar <to...@kiyut.com>.
Hi,

On Mon, 2005-07-04 at 18:32 -0700, Gregory wrote:
> Sorry, there was a missing line before the java code
> snippet. It should have been:
> 
> ...
> TranscoderOutput out = new
> TranscoderOutput(outputStream);
> // doc is SVGDocument
> TranscoderInput in = new TranscoderInput(doc);
> transcoder.transcode(in, out);

Did the transcoder work fine with other svg doc, or it is only error
with the particular svg doc ? try to use simple doc without image
element eg: only rect element?

I could be wrong, if you create the doc on the fly did you also put doc
base attribute ?

Regards
Tonny Kohar
-- 
Sketsa 
SVG Graphics Editor
http://www.kiyut.com
-- 
Sketsa 
SVG Graphics Editor
http://www.kiyut.com


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


Re: Transcoding with DOM => NullPointerException

Posted by Gregory <de...@yahoo.com>.
Sorry, there was a missing line before the java code
snippet. It should have been:

...
TranscoderOutput out = new
TranscoderOutput(outputStream);
// doc is SVGDocument
TranscoderInput in = new TranscoderInput(doc);
transcoder.transcode(in, out);
...

--- Gregory <de...@yahoo.com> wrote:

> Hi,
> 
> I have an svg document with the following element:
> <image x="0" y="0" width="612" height="792"
>
xlink:href="http://xml.apache.org/batik/images/splash.png"/>
> 
> I works fine with the rasterizer and with squiggle. 
> 
> But if I try the Transcoder API with something like
> this:
> ...
> TranscoderOutput out = new
> TranscoderOutput(outputStream);
> transcoder.transcode(in, out);
> ...
> 
> I get:
> 
> java.lang.NullPointerException
> at
>
org.apache.batik.bridge.DocumentLoader.getLineNumber(Unknown
> Source)
> at org.apache.batik.bridge.GVTBuilder.build(Unknown
> Source)
> at
>
org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(Unknown
> Source)
> at
>
org.apache.batik.transcoder.image.ImageTranscoder.transcode(Unknown
> Source)
> at
>
org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(Unknown
> Source)
> ...
> 
> Any idea?
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam
> protection around 
> http://mail.yahoo.com 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail:
> batik-users-help@xmlgraphics.apache.org
> 
> 



		
__________________________________ 
Yahoo! Mail Mobile 
Take Yahoo! Mail with you! Check email on your mobile phone. 
http://mobile.yahoo.com/learn/mail 

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