List of usage examples for javax.print.attribute Attribute getCategory
public Class<? extends Attribute> getCategory();
From source file:Main.java
public static void main(String[] argv) throws Exception { OutputStream fos = new BufferedOutputStream(new FileOutputStream("filename.ps")); DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF; StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType()); StreamPrintService service = factories[0].getPrintService(fos); Class[] cats = service.getSupportedAttributeCategories(); for (int j = 0; j < cats.length; j++) { Attribute attr = (Attribute) service.getDefaultAttributeValue(cats[j]); if (attr != null) { String attrName = attr.getName(); String attrValue = attr.toString(); Object o = service.getSupportedAttributeValues(attr.getCategory(), null, null); if (o.getClass().isArray()) { for (int k = 0; k < Array.getLength(o); k++) { Object o2 = Array.get(o, k); System.out.println(o2); }/*from w w w . j a v a 2s . c o m*/ } } } }
From source file:org.springframework.integration.print.core.PrintServiceExecutor.java
public String getPrinterInfo() { StringBuilder sb = new StringBuilder(); final SortedSet<DocFlavor> docFlavors = this.getDocFlavors(); final AttributeSet attributes = this.printService.getAttributes(); sb.append("\nPrinter Information\n"); sb.append("==========================================================\n"); sb.append("Name: " + this.printService.getName() + "\n"); sb.append("Supported DocFlavors:\n"); for (DocFlavor docFlavor : docFlavors) { sb.append(" " + docFlavor + "\n"); }/*w w w . j a v a 2s.c o m*/ @SuppressWarnings("unchecked") Class<? extends Attribute>[] categories = (Class<? extends Attribute>[]) this.printService .getSupportedAttributeCategories(); sb.append("Supported Categories:\n"); for (Class<?> clazz : categories) { sb.append(" " + clazz.getName() + "\n"); } final SortedSet<Attribute> supportedAttributes = new TreeSet<Attribute>(new AttributeComparator()); for (Class<? extends Attribute> clazz : categories) { for (DocFlavor docFlavor : docFlavors) { Object value = this.printService.getSupportedAttributeValues(clazz, docFlavor, attributes); if (value != null) { if (value instanceof Attribute) { supportedAttributes.add((Attribute) value); } else if (value instanceof Attribute[]) { supportedAttributes.addAll(Arrays.asList((Attribute[]) value)); } } } } sb.append("Supported Attributes:\n"); for (Attribute attribute : supportedAttributes) { sb.append(" " + attribute + "(" + attribute.getCategory().getSimpleName() + ")\n"); } return sb.toString(); }
From source file:org.springframework.integration.print.core.PrintServiceExecutor.java
public SortedSet<DocFlavor> getDocFlavorsSupportingAttribute(Attribute attribute) { final SortedSet<DocFlavor> docFlavors = this.getDocFlavors(); final AttributeSet attributes = this.printService.getAttributes(); final SortedSet<DocFlavor> matchedDocFlavors = new TreeSet<DocFlavor>(new DocFlavorComparator()); for (DocFlavor docFlavor : docFlavors) { final Object value = this.printService.getSupportedAttributeValues(attribute.getCategory(), docFlavor, attributes);// w w w . ja v a2 s. co m if (value != null) { matchedDocFlavors.add(docFlavor); } } return matchedDocFlavors; }