You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by Juergen Lippold <jl...@unilog.de> on 2002/05/14 15:45:12 UTC

close the Stream in the CommandLineStarter

Hello, 

I am trying to include the FOP-Framework into a Java-Environment and to start the conversion inline. But the System.exit exits the whole application. Is there a way to have a java Program starting FOP-Konversion not from the CommandLine?


in the class org.apache.fop.apps.CommandLineStarter there is a 
System.exit(0) 
in the run-method, why ?
Is it a problem to add a FileOutputStream and to close the stream in the finally method instead of using the exit?

Thanks for help 
Juergen Lippold


public void run() throws FOPException {
        String version = Version.getVersion();

        log.info(version);

        XMLReader parser = inputHandler.getParser();
        setParserFeatures(parser);

        Driver driver = new Driver();
        driver.setLogger(log);
        driver.setBufferFile(commandLineOptions.getBufferFile());

        if (errorDump) {
            driver.setErrorDump(true);
        }

        FileOutputStream fos = null;
        
        try {
            driver.setRenderer(commandLineOptions.getRenderer());
            //driver.setOutputStream( new FileOutputStream(
            //                          commandLineOptions.getOutputFile()));
            fos = new FileOutputStream(commandLineOptions.getOutputFile());
            driver.setOutputStream(fos);
            driver.getRenderer().setOptions(
              commandLineOptions.getRendererOptions());
            driver.render(parser, inputHandler.getInputSource());
            //
            //System.exit(0);   Do not stop here in the finally part the file will be closed
           //
        } catch (Exception e) {
            if (e instanceof FOPException) {
                throw (FOPException) e;
            }
            throw new FOPException(e);
        }
        finally {
          try {
            if (fos != null) fos.close();     // closing the stream
          }
          catch (IOException e) {
            throw new FOPException(e);
          }  
        }
    }


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
For additional commands, email: fop-dev-help@xml.apache.org


Re: close the Stream in the CommandLineStarter

Posted by "J.Pietschmann" <j3...@yahoo.de>.
Juergen Lippold wrote:
> I am trying to include the FOP-Framework into a Java-Environment
 > and to start the conversion inline. But the System.exit exits the
 > whole application. Is there a way to have a java Program starting
 > FOP-Konversion not from the CommandLine?

Yes. Check docs/html-docs/embedding.html and the example code
in docs/examples/embedding/. Search the list archive for
"servlet" or "Driver".

> in the class org.apache.fop.apps.CommandLineStarter there is a 
> System.exit(0) 
> in the run-method, why ?
There were problems with certain JRE and using SVG.

J.Pietschmann


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
For additional commands, email: fop-dev-help@xml.apache.org