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 Wed, 22 Apr 2009 07:27:48 GMT
Hello Georg, Sam and Andreas,

that's great, it's working now !
Thanks a lot for your help that I really appreciate.

Al

--- On Wed, 4/22/09, Georg Datterl <georg.datterl@geneon.de> wrote:

From: Georg Datterl <georg.datterl@geneon.de>
Subject: AW: FOP in servlet and configuration
To: fop-users@xmlgraphics.apache.org
Date: Wednesday, April 22, 2009, 12:19 AM

Hi Al,

try:

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


Mit freundlichen Grüßen
 
Georg Datterl
 
------ Kontakt ------
 
Georg Datterl
 
Geneon media solutions gmbh
Gutenstetter Straße 8a
90449 Nürnberg
 
HRB Nürnberg: 17193
Geschäftsführer: Yong-Harry Steiert 

Tel.: 0911/36 78 88 - 26
Fax: 0911/36 78 88 - 20
 
www.geneon.de
 
Weitere Mitglieder der Willmy MediaGroup:
 
IRS Integrated Realization Services GmbH:    www.irs-nbg.de 
Willmy PrintMedia GmbH:                            www.willmy.de
Willmy Consult & Content GmbH:                 www.willmycc.de 
-----Ursprüngliche Nachricht-----
Von: Al Dancer [mailto:reggaepercus@yahoo.com] 
Gesendet: Mittwoch, 22. April 2009 09:14
An: fop-users@xmlgraphics.apache.org
Betreff: Re: FOP in servlet and configuration

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 <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, 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 <reggaepercus@yahoo.com> 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 <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 <http://mc/compose?to=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 <http://mc/compose?to=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 <http://mc/compose?to=andreas.delmelle@telenet.be>
> wrote:



    From: Andreas Delmelle <andreas.delmelle@telenet.be <http://mc/compose?to=andreas.delmelle@telenet.be>
>

    Subject: Re: FOP in servlet and configuration
    To: fop-users@xmlgraphics.apache.org <http://mc/compose?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 <http://mc/compose?to=fop-users-unsubscribe@xmlgraphics.apache.org>

    For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org <http://mc/compose?to=fop-users-help@xmlgraphics.apache.org>

    
    




            ---------------------------------------------------------------------
            To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
<http://mc/compose?to=fop-users-unsubscribe@xmlgraphics.apache.org> 
            For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
<http://mc/compose?to=fop-users-help@xmlgraphics.apache.org> 
            




        -- 
        Sam Fuqua
        ΣΝ ΘΗ 454
        




    -- 
    Sam Fuqua
    ΣΝ ΘΗ 454
    





    -- 
    Sam Fuqua
    ΣΝ ΘΗ 454
    





      
Mime
View raw message