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) {
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);
}
}
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;
}
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;
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();