xmlgraphics-fop-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Al Dancer <reggaeper...@yahoo.com>
Subject Re: FOP in servlet and configuration
Date Tue, 21 Apr 2009 21:15:51 GMT

Hello Sam,

thank you for your notice,after adding 
import org.xml.sax.SAXException;
the ExampleFO2PDF.java compilation was successfull,

but the FopServlet.java failed:

% javac FopServlet.java

FopServlet.java:114: unreported exception org.xml.sax.SAXException; must be caught or declared
to be thrown
        fopFactory.setUserConfig(new File("/opt/coolstack/fop/conf/fop.xconf"));
                                ^
1 error

Here below is the modofication in my FopServlet.java

import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
import org.xml.sax.SAXException;
[...]

 protected void configureFopFactory() {
        fopFactory.setUserConfig(new File("/opt/coolstack/fop/conf/fop.xconf"));
        //Subclass and override this method to perform additional configuration
    }

[...]

protected void renderFO(String fo, HttpServletResponse response)
                //throws FOPException, TransformerException, IOException {
                throws SAXException, TransformerException, IOException {
        //Setup source
        Source foSrc = convertString2Source(fo);
        //Setup the identity transformation
        Transformer transformer = this.transFactory.newTransformer();
        transformer.setURIResolver(this.uriResolver);
        //Start transformation and rendering process
        render(foSrc, transformer, response);
    }

[...]

 protected void renderXML(String xml, String xslt, HttpServletResponse response)
                //throws FOPException, TransformerException, IOException {
                throws SAXException, TransformerException, IOException {
        //Setup sources
        Source xmlSrc = convertString2Source(xml);
        Source xsltSrc = convertString2Source(xslt);
        //Setup the XSL transformation
        Transformer transformer = this.transFactory.newTransformer(xsltSrc);
        transformer.setURIResolver(this.uriResolver);
        //Start transformation and rendering process
        render(xmlSrc, transformer, response);
    }
[...]

Al.

--- On Tue, 4/21/09, Sam Fuqua <samfuqua@gmail.com> wrote:

From: Sam Fuqua <samfuqua@gmail.com>
Subject: Re: FOP in servlet and configuration
To: fop-users@xmlgraphics.apache.org
Date: Tuesday, April 21, 2009, 1:44 PM

I'm sorry, I didn't mean to split this into 2 emails.  If you don't have the SAXException
included, you need to import 
org.xml.sax.SAXException


in your program.

2009/4/21 Sam Fuqua <samfuqua@gmail.com>

Hi Al,

Have you made sure to include the SAXException in your imports?



On Tue, Apr 21, 2009 at 4:37 PM, Al Dancer <reggaepercus@yahoo.com> wrote:



Hello Andreas,

I've tried to replace the FOPException by SAXException as you said, 
but it didn't work:

 //public void convertFO2PDF(File fo, File pdf) throws IOException, FOPException {
    public void convertFO2PDF(File fo, File pdf) throws IOException, SAXException {


        fopFactory.setUserConfig(new File("/opt/coolstack/fop/conf/fop.xconf"));

        OutputStream out = null;

        try { ...}

Compilation: www-slave:root>javac ExampleFO2PDF.java


ExampleFO2PDF.java:67: cannot find symbol
symbol  : class SAXException
location: class org.apache.fop.servlet.ExampleFO2PDF
    public void convertFO2PDF(File fo, File pdf)
 throws IOException, SAXException {
                                                                    
^
1 error

The same for the FopServlet.java program from the FOP 0.95 distribution :


In the directory {fop-dir}/src/java/org/apache/fop/servlet

I replaced FOPException by SAXException, and put there the configuration as following:
------------------------------------------------------------

vi FopServlet.java


[...]
 protected void configureFopFactory() {
        fopFactory.setUserConfig(new File("/opt/coolstack/fop/conf/fop.xconf"));
        //Subclass and override this method to perform additional configuration


    }

[...]
 protected void renderFO(String fo, HttpServletResponse response)
                //throws FOPException, TransformerException, IOException {
                throws SAXException, TransformerException, IOException {





When I compiled this servlet: javac FopServlet.java
------------------------------------------
I've got error:

FopServlet.java:184: cannot find symbol
symbol  : class SAXException
location: class
 org.apache.fop.servlet.FopServlet
                throws SAXException, TransformerException, IOException {
                       ^
FopServlet.java:242: cannot find symbol
symbol  : class SAXException
location: class org.apache.fop.servlet.FopServlet


                throws SAXException, TransformerException, IOException {
                       ^
2 errors

Have you got any idea, how to compile the FopServlet.java using a configuration ?
btw, the FopServlet.java attached to the mail.



thank you,

Al


--- On Tue, 4/21/09, Andreas
 Delmelle <andreas.delmelle@telenet.be> wrote:



From: Andreas Delmelle <andreas.delmelle@telenet.be>
Subject: Re: FOP in servlet and configuration
To: fop-users@xmlgraphics.apache.org


Date: Tuesday, April 21, 2009, 9:10 AM

On 21 Apr 2009, at 15:50, Al Dancer wrote:

Hi Al

> www-slave:root>javac ExampleFO2PDF.java
> ExampleFO2PDF.java:68: unreported exception org.xml.sax.SAXException; must be caught
or declared to be thrown


>         fopFactory.setUserConfig(new File("/opt/coolstack/fop/conf/fop.xconf"));
>                                 ^
> <snip />
> That's weird, the compile was successfull if only I move this line
 into the
> try { } as following:
> 
> ----------------
>  public void convertFO2PDF(File fo, File pdf) throws IOException, FOPException {
>         //fopFactory.setUserConfig(new File("/opt/coolstack/fop/conf/fop.xconf"));


>         OutputStream out = null;
>         try {
>           fopFactory.setUserConfig(new File("/opt/coolstack/fop/conf/fop.xconf"));

That's normal, and basic Java. FopFactory.setUserConfig() can throw a checked SAXException,
which means you either have to add it to the 'throws' clause to the method signature, or you
need to try-catch it explicitly.



Make it:
convertFO2PDF(...) throws IOException, SAXException {

Replacing FOPException with SAXException is sufficient, since a FOPException is itself a
 SAXException.

HTH!

Andreas


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org


For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org






      


---------------------------------------------------------------------

To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org

For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org




-- 
Sam Fuqua
ΣΝ ΘΗ 454




-- 
Sam Fuqua
ΣΝ ΘΗ 454




      
Mime
View raw message