hatch: more printing attrs
authorBill Erickson <berick@esilibrary.com>
Mon, 21 Apr 2014 15:53:24 +0000 (11:53 -0400)
committerJeff Godin <jgodin@tadl.org>
Fri, 3 Jun 2016 20:38:47 +0000 (16:38 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
src/org/evergreen_ils/hatch/FileIO.java
src/org/evergreen_ils/hatch/HatchWebSocketHandler.java
src/org/evergreen_ils/hatch/PrintManager.java

index 3d23c7f..5451723 100644 (file)
@@ -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) {
index 5a1e8ea..274411d 100644 (file)
@@ -131,7 +131,7 @@ public class HatchWebSocketHandler {
         Map<String, Object> response = new HashMap<String, Object>();
         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;
         }
index c0624ab..ae52aee 100644 (file)
@@ -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<String> values = new ArrayList<String>(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();