From: Bill Erickson Date: Wed, 26 Feb 2014 14:16:44 +0000 (-0500) Subject: added 'printers' action to list all printers w/ properties X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=fa14bf0f4c3881057a6a52d586bea6fcb2bfb1eb;p=working%2Frandom.git added 'printers' action to list all printers w/ properties Signed-off-by: Bill Erickson --- diff --git a/src/org/evergreen_ils/hatch/HatchServlet.java b/src/org/evergreen_ils/hatch/HatchServlet.java index c6db31086..2fa4f4039 100644 --- a/src/org/evergreen_ils/hatch/HatchServlet.java +++ b/src/org/evergreen_ils/hatch/HatchServlet.java @@ -11,6 +11,7 @@ import org.eclipse.jetty.util.ajax.JSON; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import java.util.Arrays; +import java.util.List; public class HatchServlet extends HttpServlet { @@ -127,6 +128,14 @@ public class HatchServlet extends HttpServlet { return; } + if (action.equals("printers")) { + List printers = new PrintDriver().getPrinters(); + response.setStatus(HttpServletResponse.SC_OK); + response.getWriter().println(JSON.toString(printers)); + return; + } + + // all remaining requests require a key if (key == null || key.equals("")) { String err = JSON.toString("No key specified in request"); diff --git a/src/org/evergreen_ils/hatch/PrintDriver.java b/src/org/evergreen_ils/hatch/PrintDriver.java index 316814b18..5247e3818 100644 --- a/src/org/evergreen_ils/hatch/PrintDriver.java +++ b/src/org/evergreen_ils/hatch/PrintDriver.java @@ -21,6 +21,11 @@ import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.text.AttributedString; +import java.util.Map; +import java.util.List; +import java.util.HashMap; +import java.util.LinkedList; + public class PrintDriver implements Printable { private String printText; @@ -148,6 +153,33 @@ public class PrintDriver implements Printable { } } + public List getPrinters() { + + List printers = new LinkedList(); + PrintService[] printServices = + PrintServiceLookup.lookupPrintServices(null, null); + + String defaultPrinter = ""; + PrintService def = PrintServiceLookup.lookupDefaultPrintService(); + if (def != null) defaultPrinter = def.getName(); + + for (PrintService service : printServices) { + HashMap printer = new HashMap(); + printers.add(printer); + + if (service.getName().equals(defaultPrinter)) + printer.put("is-default", new Boolean(true)); + + AttributeSet attributes = service.getAttributes(); + for (Attribute a : attributes.toArray()) { + String name = a.getName(); + String value = attributes.get(a.getClass()).toString(); + printer.put(name, value); + } + } + + return printers; + } // experiment // show our own print dialog before the real print action takes over