diff --git a/trunk/SIPRPSoft/src/siprp/fop/PDFCreator.java b/trunk/SIPRPSoft/src/siprp/fop/PDFCreator.java deleted file mode 100644 index 2cf0e0cb..00000000 --- a/trunk/SIPRPSoft/src/siprp/fop/PDFCreator.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * PDFCreator.java - * - * Created on 19 de Abril de 2006, 18:20 - * - * To change this template, choose Tools | Template Manager - * and open the template in the editor. - */ - -package siprp.fop; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import javax.swing.JFileChooser; -import javax.xml.transform.Result; -import javax.xml.transform.Source; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.sax.SAXResult; -import javax.xml.transform.stream.StreamSource; - -import org.apache.avalon.framework.logger.ConsoleLogger; -import org.apache.fop.apps.Driver; -import org.apache.fop.apps.Options; -import org.apache.fop.viewer.SecureResourceBundle; -import org.apache.fop.viewer.Translator; - -import com.evolute.utils.fop.FOPCreator; - -/** - * PDFCreator creates PDF's using FO. - * - * @author Frederico Palma - * @version %I%, %G% - */ -public class PDFCreator -{ - private final Translator translator = new SecureResourceBundle( null ); - - private static final Object LOCK = new Object(); - - private static PDFCreator pdfCreator; - - private static String userConfig; - - public static PDFCreator getPDFCreator() - { - synchronized( LOCK ) - { - if( pdfCreator == null ) - { - pdfCreator = new PDFCreator(); - } - } - return pdfCreator; - } - - public static void setUserConfig(String string) - { - PDFCreator.userConfig = string; - } - - public static void main( String arg[] ) - throws Exception - { - final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - final FOPCreator creator = FOPCreator.getFOPCreator(); - System.out.println( "Creating FO" ); - - JFileChooser chooser = new JFileChooser(); - chooser.setDialogTitle( "Select XML data file:" ); - int returnVal = chooser.showOpenDialog( null ); - String dataFile = null; - if( returnVal == JFileChooser.APPROVE_OPTION ) - { - dataFile = chooser.getSelectedFile().getAbsolutePath(); - } - chooser.setDialogTitle( "Select XSL-FO template file:" ); - returnVal = chooser.showOpenDialog( null ); - String templateFile = null; - if( returnVal == JFileChooser.APPROVE_OPTION ) - { - templateFile = chooser.getSelectedFile().getAbsolutePath(); -System.out.println( chooser.getSelectedFile().getAbsolutePath() ); - } - - final String DATA = dataFile; - final String TEMPLATE = templateFile; - creator.createFOfromXML( new FileInputStream( DATA ), - new FileInputStream( TEMPLATE ), baos ); -// Thread t = new Thread() { -// public void run() -// { -// try -// { -// creator.createFOfromXML( new FileInputStream( DATA ), -// new FileInputStream( TEMPLATE ), baos ); -// System.out.println( "FO created" ); -// } -// catch( Exception ex ) -// { -// ex.printStackTrace(); -// } -// } }; -// t.start(); -// Thread.currentThread().sleep( 2 ); - System.out.println( "Starting to print" ); -// options.put( FOP_DUPLEX_TYPE, javax.print.attribute.standard.Sides.TUMBLE ); - byte pdf[] = PDFCreator.getPDFCreator().createPdfFromFo( baos.toByteArray() ); -// new FOPPrinter().printFO( new FileInputStream( "c:\\simplecol.fo" ), true, false ); - File pdfFile = new File( "/home/fpalma/acss/teste.pdf" ); - File foFile = new File( "/home/fpalma/Desktop/teste.fo" ); - pdfFile.createNewFile(); - foFile.createNewFile(); - FileOutputStream fos = new FileOutputStream( pdfFile ); - FileOutputStream fofos = new FileOutputStream( foFile ); - fos.write( pdf ); - fofos.write( baos.toByteArray() ); - fos.close(); - fofos.close(); - System.out.println( "DONE" ); - } - - /** Creates a new instance of PDFCreator */ - private PDFCreator() - { - } - - /** - * Creates PDF content as an array of bytes, given FO content as an array of bytes. - * - * @param fo the byte[] with the FO content to convert - * @return the PDF content - * @throws Exception if the conversion fails - * - */ - public byte[]createPdfFromFo( byte []fo ) - throws Exception - { - - InputStream inputStreamConf = ClassLoader.getSystemClassLoader().getResourceAsStream("siprp/fop/fop.xml"); - InputStream inputStreamDTD = ClassLoader.getSystemClassLoader().getResourceAsStream("siprp/fop/config.dtd"); - - /*************************/ - - File f = File.createTempFile("fop", "conf"); - f.deleteOnExit(); - writeFile(inputStreamConf, f); - - System.out.println(f.getParentFile()); - - /*************************/ - File dtd = new File(f.getParentFile(), "config.dtd"); - writeFile(inputStreamDTD, dtd); - - new Options(f); - - ByteArrayOutputStream pdf = new ByteArrayOutputStream(); - TransformerFactory factory = TransformerFactory.newInstance(); - Transformer transformer = factory.newTransformer(); - Source src = new StreamSource( new ByteArrayInputStream( fo ) ); - Driver driver = new Driver(); - driver.setLogger( new ConsoleLogger( ConsoleLogger.LEVEL_INFO ) ); - driver.setRenderer( Driver.RENDER_PDF ); - driver.setOutputStream( pdf ); - Result res = new SAXResult( driver.getContentHandler() ); - transformer.transform( src, res ); - return pdf.toByteArray(); - - } - - private void writeFile(InputStream inputStreamConf, File f) - throws FileNotFoundException, IOException { - OutputStream out = new FileOutputStream(f); - byte buf[] = new byte[1024]; - int len; - while ((len = inputStreamConf.read(buf)) > 0) - out.write(buf, 0, len); - out.close(); - inputStreamConf.close(); - } -} diff --git a/trunk/SIPRPSoft/src/siprp/fop/config.dtd b/trunk/SIPRPSoft/src/siprp/fop/config.dtd deleted file mode 100644 index 6b05bebe..00000000 --- a/trunk/SIPRPSoft/src/siprp/fop/config.dtd +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - diff --git a/trunk/SIPRPSoft/src/siprp/fop/fop.xml b/trunk/SIPRPSoft/src/siprp/fop/fop.xml deleted file mode 100644 index ca87f437..00000000 --- a/trunk/SIPRPSoft/src/siprp/fop/fop.xml +++ /dev/null @@ -1,89 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - -