public String[] createPDF(String pedigreeID) { String[] filePath = new String[2]; try { String query = "tlsp:getRepackagedInfo_MD('" + pedigreeID + "')"; System.out.println("query in sendPDF method : " + query); String str = queryRunner.returnExecuteQueryStringsAsString(query); System.out.println("REsult in sendPDF method : " + str); if (str != null) { Node n1 = XMLUtil.parse(str); System.out.println("-------ni is-----" + n1); Node n2 = XMLUtil.getNode(n1, "/shippedPedigree"); Node n3 = XMLUtil.getNode(n2, "descendant::repackagedPedigree"); if (n3 != null) { String f = createRepackagePDF(pedigreeID, str); if (f == null) throw new Exception(); filePath[0] = f; } else { filePath[0] = createInitialPDF(str, pedigreeID); } } } catch (Exception e) { // TODO Auto-generated catch block try { System.out.println("IN CATCH BLOCK 343"); /*SendDHFormEmail.sendMailToSupport("*****@*****.**","*****@*****.**","smarthost.coxmail.com", "Error in Create PDF",e.getMessage(),"*****@*****.**","60empire"); e.printStackTrace();*/ } catch (Exception ex) { } e.printStackTrace(); } return filePath; }
private String createInitialPDF(String str, String pedigreeID) { String filePath1 = ""; System.out.println(" here in createInitialPDF....."); try { String xmlString = getInitialXSLString(str, pedigreeID, getBaseDirectory().getAbsolutePath()); File baseDir = getBaseDirectory(); // File baseDir = new File("C:/Documents and Settings/Jagadish // Pampatwar/workspace//Scheduler_MD"); File outDir = new File(baseDir, "out"); outDir.mkdirs(); // Setup input and output files File xmlfile = File.createTempFile("User", ".xml"); // Delete temp file when program exits. xmlfile.deleteOnExit(); // Write to temp file BufferedWriter bw = new BufferedWriter(new FileWriter(xmlfile)); bw.write(xmlString); bw.close(); File xsltfile = new File(baseDir, "/xsl/initial.fo"); // File pdffile = File.createTempFile("initial", ".pdf"); String newpedigreeID = pedigreeID.replaceAll("urn:uuid:", ""); File pdffile = new File(outDir, newpedigreeID + "1.pdf"); // Construct fop with desired output format Fop fop = new Fop(MimeConstants.MIME_PDF); // Setup output OutputStream out = new java.io.FileOutputStream(pdffile); out = new java.io.BufferedOutputStream(out); try { fop.setOutputStream(out); // Setup XSLT TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(new StreamSource(xsltfile)); // Set the value of a <param> in the stylesheet transformer.setParameter("versionParam", "2.0"); // Setup input for XSLT transformation Source src = new StreamSource(xmlfile); // Resulting SAX events (the generated FO) must be piped through to FOP Result res = new SAXResult(fop.getDefaultHandler()); // Start XSLT transformation and FOP processing transformer.transform(src, res); out.close(); // MessageResources messageResources = getResources(request); String[] filePath = new String[2]; filePath[0] = pdffile.getAbsolutePath(); /* String query = "for $i in collection('tig:///ePharma/ShippedPedigree')/*:pedigreeEnvelope/*:pedigree/*:shippedPedigree[*:documentInfo/*:serialNumber = '"+pedigreeID+"']//*:initialPedigree "; query = query + "return tlsp:GetBinaryImageForServlet(binary{$i/*:altPedigree/*:data},'data')";*/ String query = "for $i in collection('tig:///ePharma_MD/ShippedPedigree')/*:pedigreeEnvelope/*:pedigree/*:shippedPedigree "; query = query + "where $i/*:documentInfo/*:serialNumber = '" + pedigreeID + "' "; query = query + "return if(exists($i//*:initialPedigree/*:altPedigree)) then tlsp:GetBinaryImageForServlet(binary{$i//*:initialPedigree/*:altPedigree/*:data},'data') else ()"; System.out.println("Query : " + query); List initialStatus = queryRunner.executeQuery(query); // String initialStatus = queryRunner.returnExecuteQueryStringsAsString(query); String[] mergeFilePath = new String[1]; if (initialStatus != null && initialStatus.size() > 0) { filePath[1] = getInitialPedigreePDF(initialStatus, str); // filePath[1] = getInitialPedigreePDF1(initialStatus,str); System.out.println("file path : " + filePath[1]); filePath1 = mergePDF(filePath[1], filePath[0]); } else { mergeFilePath[0] = pdffile.getAbsolutePath(); System.out.println(" file path : " + mergeFilePath[0]); filePath1 = mergeFilePath[0]; } System.out.println(" here in sendInitialPDF....." + filePath1); } finally { } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); try { /*SendDHFormEmail.sendMailToSupport("*****@*****.**","*****@*****.**","smarthost.coxmail.com", "Error in Create PDF",e.getMessage(),"*****@*****.**","60empire"); e.printStackTrace();*/ } catch (Exception ex) { } } return filePath1; }
private String createRepackagePDF(String pedigreeID, String str) { // TODO Auto-generated method stub String[] filePath = new String[2]; String mergeFilePath = ""; try { System.out.println(" here in sendRepackagePDF....." + str); String xmlString = getRepackageXSLString(str, pedigreeID, getBaseDirectory().getAbsolutePath()); boolean checkMan = checkManufacturer(str); File baseDir = getBaseDirectory(); File outDir = new File(baseDir, "out"); outDir.mkdirs(); // Setup input and output files File xmlfile = File.createTempFile("User", ".xml"); // xmlfile.createNewFile(); // Delete temp file when program exits. xmlfile.deleteOnExit(); // Write to temp file BufferedWriter bw = new BufferedWriter(new FileWriter(xmlfile)); bw.write(xmlString); bw.close(); File xsltfile = null; if (checkMan) { xsltfile = new File(baseDir, "/xsl/repackFromManufaturer.fo"); } else { xsltfile = new File(baseDir, "/xsl/repackFromWholesaler.fo"); } File pdffile = new File(outDir, "repack.pdf"); // Construct fop with desired output format Fop fop = new Fop(MimeConstants.MIME_PDF); // Setup output OutputStream out = new java.io.FileOutputStream(pdffile); out = new java.io.BufferedOutputStream(out); fop.setOutputStream(out); // Setup XSLT TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(new StreamSource(xsltfile)); // Set the value of a <param> in the stylesheet transformer.setParameter("versionParam", "2.0"); // Setup input for XSLT transformation Source src = new StreamSource(xmlfile); // Resulting SAX events (the generated FO) must be piped through to FOP Result res = new SAXResult(fop.getDefaultHandler()); // Start XSLT transformation and FOP processing transformer.transform(src, res); out.close(); filePath[0] = pdffile.getAbsolutePath(); if (!checkMan) { /* String query = "for $i in collection('tig:///ePharma/ShippedPedigree')/*:pedigreeEnvelope/*:pedigree/*:shippedPedigree[*:documentInfo/*:serialNumber = '"+pedigreeID+"']/*:repackagedPedigree/*:previousPedigrees/*:initialPedigree "; query = query + "return tlsp:GetBinaryImageForServlet(binary{$i/*:altPedigree/*:data},'data')";*/ String query = "for $i in collection('tig:///ePharma_MD/ShippedPedigree')/*:pedigreeEnvelope/*:pedigree/*:shippedPedigree "; query = query + "where $i/*:documentInfo/*:serialNumber = '" + pedigreeID + "' "; query = query + "return if(exists($i//*:initialPedigree/*:altPedigree)) then tlsp:GetBinaryImageForServlet(binary{$i//*:initialPedigree/*:altPedigree/*:data},'data') else ()"; System.out.println("Query : " + query); List initialStatus = queryRunner.executeQuery(query); if (initialStatus != null && initialStatus.size() > 0) { // String initialStatus = queryRunner.returnExecuteQueryStringsAsString(query); filePath[1] = getInitialPedigreePDF(initialStatus, str); // filePath[1] = getInitialPedigreePDF1(initialStatus,str); System.out.println("file path : " + filePath[1]); mergeFilePath = mergePDF(filePath[1], filePath[0]); } } else mergeFilePath = pdffile.getAbsolutePath(); System.out.println(" file path : " + mergeFilePath); } catch (Exception e) { try { SendDHFormEmail.sendMailToSupport( "*****@*****.**", "*****@*****.**", "smarthost.coxmail.com", "Error in Create PDF", e.getMessage(), "*****@*****.**", "60empire"); e.printStackTrace(); } catch (Exception ex) { } // TODO Auto-generated catch block e.printStackTrace(); } return mergeFilePath; }