Hi Sam,

I've changed the script as following:
---------
protected void configureFopFactory() {
        try {
                fopFactory.setUserConfig(new 
File("/opt/coolstack/fop/conf/fop.xconf"));
        } catch (SAXException e) {
                System.out.println(e);
        }
    }
--------Compile: javac FopServlet.java
FopServlet.java:116: unreported exception java.io.IOException; must be caught 
or declared to be thrown
                fopFactory.setUserConfig(new 
File("/opt/coolstack/fop/conf/fop.xconf"));
                                        ^
1 error

Then I added IOException:
--------
 protected void configureFopFactory() throws IOException {
        try {
                fopFactory.setUserConfig(new 
File("/opt/coolstack/fop/conf/fop.xconf"));
        } catch (SAXException e) {
                System.out.println(e);
        }
    }

------- Compile:  javac FopServlet.java
FopServlet.java:106: unreported exception java.io.IOException; must be caught 
or declared to be thrown
        configureFopFactory();
                           ^
1 error

Then I added IOException in the void init()

 public void init() throws IOException, ServletException {
        this.log = new SimpleLog("FOP/Servlet");
        log.setLevel(SimpleLog.LOG_LEVEL_WARN);
        this.uriResolver = new ServletContextURIResolver(getServletContext());
        this.transFactory = TransformerFactory.newInstance();
        this.transFactory.setURIResolver(this.uriResolver);
        //Configure FopFactory as desired
        this.fopFactory = FopFactory.newInstance();
        this.fopFactory.setURIResolver(this.uriResolver);
        configureFopFactory();
    }

------- Compile:  javac FopServlet.java
FopServlet.java:97: init() in org.apache.fop.servlet.FopServlet cannot override 
init() in javax.servlet.GenericServlet; overridden method does not throw 
java.io.IOException
    public void init() throws IOException, ServletException {
                ^
1 error

I'm not familiar with the Java Programming :(
and don't know much about the Exception.

Al

--- On Tue, 4/21/09, Sam Fuqua <[email protected]> wrote:

From: Sam Fuqua <[email protected]>
Subject: Re: FOP in servlet and configuration
To: [email protected]
Date: Tuesday, April 21, 2009, 3:04 PM

Hi Al,

It looks like we're getting to the home stretch of your application.

As Andreas said earlier, setUserConfig() can throw an exception which, 
regardless of whether or not it actually happens, must be handled.  You can fix 
this by placing the call inside of a try/catch as follows:


try {
//your call goes here -- fopFactory.setUse...
} catch (SAXException e) {
System.out.println(e);
}

Hope that helps!



On Tue, Apr 21, 2009 at 5:15 PM, Al Dancer <[email protected]> wrote:



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 <[email protected]> wrote:


From: Sam Fuqua <[email protected]>
Subject: Re: FOP in servlet and configuration
To: [email protected]

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 <[email protected]>

Hi Al,

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




On Tue, Apr 21, 2009 at 4:37 PM, Al Dancer <[email protected]> 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 <[email protected]> wrote:




From: Andreas Delmelle <[email protected]>
Subject: Re: FOP in servlet and configuration
To: [email protected]



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: [email protected]



For additional commands, e-mail: [email protected]







      


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

To unsubscribe, e-mail: [email protected]

For additional commands, e-mail: [email protected]





-- 
Sam Fuqua
ΣΝ ΘΗ 454




-- 
Sam Fuqua
ΣΝ ΘΗ 454






      


-- 
Sam Fuqua
ΣΝ ΘΗ 454




      

Reply via email to