}
}
+ public JSONObject getPrintersOptions(String printerName) {
+ Printer printer;
+
+ if (printerName == null) { // no name provided, use default.
+ printer = Printer.getDefaultPrinter();
+ } else {
+ printer = getPrinterByName(printerName);
+ }
+
+ if (printer == null) return null;
+
+ JSONObject options = new JSONObject();
+
+ PrinterAttributes printerAttrs = printer.getPrinterAttributes();
+
+ Set<Paper> papers = printerAttrs.getSupportedPapers();
+ JSONArray papersArray = new JSONArray();
+ for (Paper source : papers) {
+ papersArray.put(source.getName());
+ }
+ options.put("paper", papersArray);
+
+ Set<PaperSource> paperSources =
+ printerAttrs.getSupportedPaperSources();
+ JSONArray paperSourcesArray = new JSONArray();
+ for (PaperSource source : paperSources) {
+ paperSourcesArray.put(source.getName());
+ }
+ options.put("paperSource", papersArray);
+
+
+ Set<Collation> collations = printerAttrs.getSupportedCollations();
+ JSONArray collationsArray = new JSONArray();
+ for (Collation collation : collations) {
+ collationsArray.put(collation.toString());
+ }
+ options.put("collation", collationsArray);
+
+ Set<PrintColor> colors = printerAttrs.getSupportedPrintColors();
+ JSONArray colorsArray = new JSONArray();
+ for (PrintColor color : colors) {
+ colorsArray.put(color.toString());
+ }
+ options.put("printColor", colorsArray);
+
+ Set<PrintQuality> qualities = printerAttrs.getSupportedPrintQuality();
+ JSONArray qualityArray = new JSONArray();
+ for (PrintQuality quality : qualities) {
+ qualityArray.put(quality.toString());
+ }
+ options.put("printQuality", qualityArray);
+
+ Set<PrintSides> sides = printerAttrs.getSupportedPrintSides();
+ JSONArray sidesArray = new JSONArray();
+ for (PrintSides side : sides) {
+ sidesArray.put(side.toString());
+ }
+ options.put("printSides", qualityArray);
+
+ Set<PageOrientation> orients =
+ printerAttrs.getSupportedPageOrientations();
+ JSONArray orientsArray = new JSONArray();
+ for (PageOrientation orient : orients) {
+ orientsArray.put(orient.toString());
+ }
+ options.put("pageOrientation", orientsArray);
+
+ return options;
+ }
+
}
new PrintManager().getPrintersAsMaps());
break;
+ case "printer-options":
+
+ String printer = request.optString("printer", null);
+ JSONObject options =
+ new PrintManager().getPrintersOptions(printer);
+
+ if (options == null) {
+ response.put("status", 400);
+ if (printer == null) {
+ response.put("message", "No default printer found");
+ } else {
+ response.put("message", "No such printer: " + printer);
+ }
+ } else {
+ response.put("content", options);
+ }
+
+ break;
+
case "print":
// Confirm a minimal data set to enqueue print requests.
content = request.getString("content");
}
case "keys": // Return stored keys
- String pfxKey = request.optString("key");
- response.put("content", fileIO.keys(pfxKey));
+ key = request.optString("key");
+ response.put("content", fileIO.keys(key));
break;
case "get":