/* * FichaAptidaoCreator.java * * Created on May 14, 2007, 4:50 PM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package siprp.ficha; import com.evolute.utils.UnicodeChecker; import com.evolute.utils.fop.FOPCreator; import com.evolute.utils.fop.FOPPrinter; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.util.HashMap; /** * * @author lflores */ public class FichaAptidaoCreator implements FichaAptidaoConstants { private final FOPCreator fopCreator; private final FOPPrinter fopPrinter; private static FichaAptidaoCreator creator = null; /** Creates a new instance of FichaAptidaoCreator */ private FichaAptidaoCreator() { fopCreator = FOPCreator.getFOPCreator(); fopPrinter = FOPPrinter.getFOPPrinter(); } public static FichaAptidaoCreator getCreator() { if( creator == null ) { creator = new FichaAptidaoCreator(); } return creator; } public void print( byte fo[] ) throws Exception { ByteArrayInputStream in = new ByteArrayInputStream( fo ); fopPrinter.printFO( in, true, true, null ); // System.out.println( "DONE" ); } public void printSilent( byte fo[], String printerName ) throws Exception { ByteArrayInputStream in = new ByteArrayInputStream( fo ); fopPrinter.printFO( in, true, false, null ); } public byte[] createFO( HashMap values ) { StringBuilder buff = new StringBuilder( "\n\n" ); values.put( PORTARIA, "Portaria n. 299/2007, de 16 de Março" ); // ☐ square // ☑ checked square for( String key: values.keySet() ) { buff.append( "\t<" + key + ">" ); String val = values.get( key ); buff.append( UnicodeChecker.parseToUnicode( "&#x", ";", val, true ) ); buff.append( "\n" ); } buff.append( "" ); String xml = buff.toString(); System.out.println( "XML: " + xml ); ByteArrayOutputStream out = new ByteArrayOutputStream(); InputStream xmlIn = new ByteArrayInputStream( xml.getBytes() ); try { InputStream xslStream = getClass().getClassLoader().getResourceAsStream( "siprp/ficha/ficha_aptidao.xsl" ); fopCreator.createFOfromXML( xmlIn, xslStream, out ); // System.out.println( "FO created" ); } catch( Exception ex ) { ex.printStackTrace(); } System.out.println( "FO str sz: " + out.size() ); return out.toByteArray(); } public byte[] createPDF( byte[] fo ) { return null; } }