//------------------FOR DEMO USE ONLY---------------------------------- //-------- Copyright by Artem Saveliev artem@savelev.com ------------ //--------------------------------------------------------------------- package com.broadstr.xslfoserver; import java.io.*; import javax.xml.transform.TransformerException; import org.apache.xpath.XPathAPI; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.Text; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; import java.net.URI; import java.net.URISyntaxException; import java.nio.channels.FileChannel; import java.util.TimerTask; import javax.print.PrintService; import javax.print.PrintServiceLookup; import javax.print.DocPrintJob; import javax.print.Doc; import javax.print.SimpleDoc; import javax.print.PrintException; import javax.print.DocFlavor; import javax.print.DocFlavor.INPUT_STREAM; import javax.print.attribute.DocAttributeSet; import javax.print.attribute.HashDocAttributeSet; import javax.print.attribute.HashPrintRequestAttributeSet; import javax.print.attribute.PrintRequestAttributeSet; import javax.print.attribute.standard.Destination; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.FactoryConfigurationError; import javax.xml.parsers.ParserConfigurationException; import org.tanukisoftware.wrapper.WrapperManager; public class Monitor extends TimerTask { public String in; public String out; public fo2pdf app; public FilenameFilter fo; public Document document; private Element printNameSpace; public Monitor(){ app = new fo2pdf(); fo = new FOFilter(); } public void run() { File pdffile; File psfile; String outfile; String outputType; File inDir = new File(in); File outDir = new File(out); Node n; File[] fofiles = inDir.listFiles(fo); if (fofiles == null) return; for (int fileIndex = 0;fileIndex < fofiles.length; fileIndex++){ WrapperManager.log(WrapperManager.WRAPPER_LOG_LEVEL_DEBUG,"Found file " + fofiles[fileIndex].getPath()); outfile = fofiles[fileIndex].getName().replaceAll("\\.fo",""); try{ if (LoadFODOM(fofiles[fileIndex].getPath())){ WrapperManager.log(WrapperManager.WRAPPER_LOG_LEVEL_DEBUG,"Loaded FO file"); //-- Convert to PDF if required NodeList nl; try{ nl = XPathAPI.selectNodeList(document,"//print:printManifest/out[format='pdf']",printNameSpace); } catch (Exception e) { WrapperManager.log(WrapperManager.WRAPPER_LOG_LEVEL_ERROR,"Unable to find PDF format of text, query failed\n\t"+e.getMessage()); throw new Exception("Reading print manifest failed"); } WrapperManager.log(WrapperManager.WRAPPER_LOG_LEVEL_DEBUG,"\nTotal PDF requests found: " + nl.getLength()); if (nl.getLength()> 0){ WrapperManager.log(WrapperManager.WRAPPER_LOG_LEVEL_DEBUG,"Found PDF generation request in " + fofiles[fileIndex].getName()); WrapperManager.log(WrapperManager.WRAPPER_LOG_LEVEL_DEBUG,"Generating empty file object"); pdffile = new File(out,outfile+".pdf.temp"); WrapperManager.log(WrapperManager.WRAPPER_LOG_LEVEL_DEBUG,"Converting to PDF"); app.convertFO2PDF(fofiles[fileIndex], pdffile); WrapperManager.log(WrapperManager.WRAPPER_LOG_LEVEL_DEBUG,"Distributing to location"); for(int i=0;i 0){ WrapperManager.log(WrapperManager.WRAPPER_LOG_LEVEL_DEBUG,"Found PS generation request in " + fofiles[fileIndex].getName()); WrapperManager.log(WrapperManager.WRAPPER_LOG_LEVEL_DEBUG,"Generating empty file object"); psfile = new File(out,outfile+".ps.temp"); WrapperManager.log(WrapperManager.WRAPPER_LOG_LEVEL_DEBUG,"Converting to PDF"); app.convertFO2PS(fofiles[fileIndex], psfile); for(int i=0;i> setpagedevice"); out.newLine(); } if (tray > 1){ WrapperManager.log(WrapperManager.WRAPPER_LOG_LEVEL_DEBUG,"Setting tray to "+tray); out.write("<< /ManualFeed false /MediaPosition null >> setpagedevice"); out.newLine(); out.write("userdict /lms"); out.newLine(); out.write("currentpagedevice /InputAttributes get "+(tray-1)+" known { "+(tray-1)+" }{ 0 }ifelse put"); out.newLine(); out.write("currentpagedevice /InputAttributes get lms get setpagedevice"); out.newLine(); out.write("<< /InputAttributes << /Priority [lms] >> >> setpagedevice"); out.newLine(); out.write("<< /Policies << /PageSize 7 >> >> setpagedevice"); out.newLine(); } } out.write(str); out.newLine(); previousline = str; } in.close(); out.close(); return output; } }