From 7b3df76e16c91f3147761564fb4fe0af77ead807 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 21 Apr 2014 11:53:24 -0400 Subject: [PATCH] hatch: more printing attrs Signed-off-by: Bill Erickson --- src/org/evergreen_ils/hatch/FileIO.java | 14 ++++++++++--- .../evergreen_ils/hatch/HatchWebSocketHandler.java | 24 ++++++++-------------- src/org/evergreen_ils/hatch/PrintManager.java | 23 +++++++++++++++++++++ 3 files changed, 42 insertions(+), 19 deletions(-) diff --git a/src/org/evergreen_ils/hatch/FileIO.java b/src/org/evergreen_ils/hatch/FileIO.java index 3d23c7f8c1..54517237c4 100644 --- a/src/org/evergreen_ils/hatch/FileIO.java +++ b/src/org/evergreen_ils/hatch/FileIO.java @@ -97,20 +97,28 @@ public class FileIO { return true; } - public BufferedReader get(String key) { + public String get(String key) { logger.info("get => " + key); File file = getFile(key); if (!file.exists()) return null; - StringBuffer sbuf = new StringBuffer(); + String line; + StringBuffer buf = new StringBuffer(); + try { - return new BufferedReader( + BufferedReader reader = new BufferedReader( new FileReader(file.getAbsoluteFile())); + + while ( (line = reader.readLine()) != null) { + buf.append(line); + } } catch (IOException e) { logger.warn("Error reading key: " + key); logger.warn(e); return null; } + + return buf.toString(); } public boolean delete(String key) { diff --git a/src/org/evergreen_ils/hatch/HatchWebSocketHandler.java b/src/org/evergreen_ils/hatch/HatchWebSocketHandler.java index 5a1e8eac39..274411d63c 100644 --- a/src/org/evergreen_ils/hatch/HatchWebSocketHandler.java +++ b/src/org/evergreen_ils/hatch/HatchWebSocketHandler.java @@ -131,7 +131,7 @@ public class HatchWebSocketHandler { Map response = new HashMap(); response.put("msgid", msgid); if (success) { - response.put("success", json); + response.put("content", json); } else { response.put("error", json); } @@ -218,22 +218,14 @@ public class HatchWebSocketHandler { } if (action.equals("get")) { - io = new FileIO(profileDirectory); - BufferedReader reader = io.get(key); - if (reader != null) { - String line; - try { - while ( (line = reader.readLine()) != null) { - // relay lines of text to the caller as we read them - // assume the text content is JSON and return it - // un-JSON-ified. - reply(line, msgid); - } - } catch (IOException e) { - logger.warn(e); - } + String val = new FileIO(profileDirectory).get(key); + // set() calls store bare JSON. We must pass an + // Object to reply so that it may be embedded into + // a larger JSON response object, hence the JSON.parse(). + if (val == null) { + reply(null, msgid); } else { - reply("Error accessing property " + key, msgid, false); + reply(JSON.parse(val), msgid); } return; } diff --git a/src/org/evergreen_ils/hatch/PrintManager.java b/src/org/evergreen_ils/hatch/PrintManager.java index c0624ab51b..ae52aeee79 100644 --- a/src/org/evergreen_ils/hatch/PrintManager.java +++ b/src/org/evergreen_ils/hatch/PrintManager.java @@ -26,10 +26,13 @@ import javax.print.PrintService; import javax.print.PrintServiceLookup; import javax.print.attribute.Attribute; import javax.print.attribute.AttributeSet; +import javax.print.attribute.standard.Media; +import javax.print.attribute.standard.OrientationRequested; // data structures import java.util.Map; import java.util.List; +import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedList; @@ -92,6 +95,26 @@ public class PrintManager { if (service.getName().equals(defaultPrinter)) printer.put("is-default", new Boolean(true)); + // collect information about the printer attributes we care about + Class[] attrClasses = { + Media.class, + //OrientationRequested.class + }; + + for (Class c : attrClasses) { + Attribute[] attrs = (Attribute[]) + service.getSupportedAttributeValues(c, null, null); + + if (attrs.length > 0) { + ArrayList values = new ArrayList(attrs.length); + for (Attribute a : attrs) { + String s = a.toString(); + if (!values.contains(s)) values.add(s); + } + printer.put(attrs[0].getName(), values); + } + } + AttributeSet attributes = service.getAttributes(); for (Attribute a : attributes.toArray()) { String name = a.getName(); -- 2.11.0