xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fawzib Rojas <f_ro...@spectron-msim.com>
Subject Re: Batik problems in Cocoon 2.2
Date Wed, 27 Oct 2010 12:41:29 GMT
On 10/27/2010 5:50 AM, thomas.deweese@kodak.com wrote:
> Hi Fawzib,
> Fawzib Rojas <f_rojas@spectron-msim.com> wrote on 10/21/2010 12:46:13 PM:
> > Since it cant find the attribute, there is no namespace. I added
> > some code so that if there is no namespace it adds it.
> >
> > After those changes things moved along a little bit farther down the
> > line but now batik gives me a NullPointerException in
> > JPEGTranscoder.writeImage, I checked the output stream and it is
> > valid, so must be something else:
>         It probably isn't finding the JPEG writer. So this line:
>             ImageWriter writer = ImageWriterRegistry.getInstance()
>                 .getWriterFor("image/jpeg");
>         Is returning NULL.  This is typically caused by Batik not
> being able to find the file:
> resources/META-INF/services/org.apache.batik.ext.awt.image.spi.ImageWriter
>         Or potentially an inability to create the JPEGImageWriter
> (possibly due to a lack of the com.sun.image.codec.jpeg classes.
Or because when I add batik-1.7 as a dependency in the pom.xml, all the 
dependencies are added *except* batik-codec. I was testing with the JPEG 
transcoder, when I tested the PNG transcoder it actually gave a decent 
error message: "Could not write PNG file because no WriteAdapter is 
available". I found a bug report 
(https://issues.apache.org/bugzilla/show_bug.cgi?id=44682) from *2008* 
explaining the problem and the solution. Two years (almost 3) and the 
problem still there.

I removed all the extra stuff from the SVGBuilder class, I only override 
startElement now. All I do is set things up so it doesnt crash with the 
standard SAXSVGDocumentFactory class:

public void startElement(String uri, String localName, String 
rawName,Attributes attributes) throws SAXException {
         // if we dont set a parser, it will crash, so set one up.
             SAXParserFactory factory=SAXParserFactory.newInstance();
             SAXParser saxParser;
             try {
                 saxParser = factory.newSAXParser();
             } catch (ParserConfigurationException pce) {
                 throw new SAXException("Could not create SAXParser: " + 
             parser = saxParser.getXMLReader();
         // if svg has no namespace transcoding wont work, so add it if 
not found
         // (Even if svg has namespace in the document, something 
somewhere removes it)
             AttributesImpl attrs=new AttributesImpl(attributes);
             String[] element=rawName.split(":");
             String key="xmlns";
             if(element.length>1) key="xmlns:"+element[0];
             super.startElement(uri, localName, rawName,attrs);
             super.startElement(uri, localName, rawName,attributes);

It seems smaller (and cleaner) than what was there. After that change 
and adding the batik-codec dependency to the pom, all is working now. 
Thanks a lot for the help.

View raw message