protected void performAction(Node[] node) { try { List<ClearingItem> clearingList = getClearingItems(); log.info("found " + clearingList.size() + " clearing items."); for (ClearingItem item : clearingList) { ClearingPrintTO to = new ClearingPrintTO(); to.setMessage(ClearingPrintTO.resolveMessage(item)); to.setCreated(to.getCreated()); } List<PropertyDescriptor> props = new ArrayList<PropertyDescriptor>(); PropertyDescriptor pd = new PropertyDescriptor("created", ClearingItem.class, "getCreated", null); pd.setDisplayName("Datum"); props.add(pd); pd = new PropertyDescriptor("message", ClearingItem.class); pd.setDisplayName("Klärfall"); props.add(pd); byte[] bytes = export("Klärfallliste", clearingList, props); log.info("received " + bytes.length + " bytes"); log.info("going to print"); ReportServiceBean reportService = new ReportServiceBean(); reportService.print("default", bytes, DocumentTypes.APPLICATION_PDF.toString()); // print("default", bytes, DocumentTypes.APPLICATION_PDF.toString()); log.info("printing on default"); } catch (Throwable ex) { ExceptionAnnotator.annotate(ex); } }
public static void openDocument(String url) { try { // ------------------------------------------- // posted by David G. Simmons, see // http://www.nabble.com/open-pdf-viewer-from-code-to7584869.html#a7584869 String osName = System.getProperty("os.name"); if (osName.startsWith("Mac OS")) { Class fileMgr = Class.forName("com.apple.eio.FileManager"); Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[] {String.class}); openURL.invoke(null, new Object[] {url}); } else if (osName.startsWith("Windows")) { Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url); } else if (osName.equalsIgnoreCase("Linux")) { // Linux if (url.endsWith("pdf") || url.endsWith("PDF")) { String[] pdfViewers = {"evince", "kpdf", "xpdf", "Xpdf", "gv", "acroread", "acrobat"}; String viewer = null; // pick the PDF Viewer for (int count = 0; count < pdfViewers.length && viewer == null; count++) { if (Runtime.getRuntime().exec(new String[] {"which", pdfViewers[count]}).waitFor() == 0) { viewer = pdfViewers[count]; } } if (viewer == null) // got no pdf viewer { throw new NoViewerException("pdf"); } else { // got a pdf viewer, so launch it int ind = url.indexOf(":"); if (ind >= 0) { url.substring(ind); } Runtime.getRuntime().exec(new String[] {viewer, url}); } // launch html urls in a browser } else if (url.startsWith("http") || url.endsWith("html") || url.endsWith("htm") || url.endsWith("HTML") || url.endsWith("HTM")) { String[] browsers = { // list of html browsers "firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape" }; String browser = null; for (int count = 0; count < browsers.length && browser == null; count++) { if (Runtime.getRuntime().exec(new String[] {"which", browsers[count]}).waitFor() == 0) { browser = browsers[count]; } } if (browser == null) // got no browser, bummer { throw new NoViewerException("html"); } else { Runtime.getRuntime().exec(new String[] {browser, url}); } } } } catch (Exception ex) { // bollux! ExceptionAnnotator.annotate(ex); } }