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 {
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");
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;
}
}
+ public List<HashMap> getPrinters() {
+
+ List<HashMap> printers = new LinkedList<HashMap>();
+ PrintService[] printServices =
+ PrintServiceLookup.lookupPrintServices(null, null);
+
+ String defaultPrinter = "";
+ PrintService def = PrintServiceLookup.lookupDefaultPrintService();
+ if (def != null) defaultPrinter = def.getName();
+
+ for (PrintService service : printServices) {
+ HashMap<String, Object> printer = new HashMap<String, Object>();
+ 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