use of javax.print.attribute.standard.PrinterName in project jdk8u_jdk by JetBrains.
the class UnixPrintServiceLookup method getPrintServices.
private PrintService[] getPrintServices(PrintServiceAttributeSet serviceSet) {
if (serviceSet == null || serviceSet.isEmpty()) {
return getPrintServices();
}
/* Typically expect that if a service attribute is specified that
* its a printer name and there ought to be only one match.
* Directly retrieve that service and confirm
* that it meets the other requirements.
* If printer name isn't mentioned then go a slow path checking
* all printers if they meet the reqiremements.
*/
PrintService[] services;
PrinterName name = (PrinterName) serviceSet.get(PrinterName.class);
PrintService defService;
if (name != null && (defService = getDefaultPrintService()) != null) {
/* To avoid execing a unix command see if the client is asking
* for the default printer by name, since we already have that
* initialised.
*/
PrinterName defName = (PrinterName) defService.getAttribute(PrinterName.class);
if (defName != null && name.equals(defName)) {
if (matchesAttributes(defService, serviceSet)) {
services = new PrintService[1];
services[0] = defService;
return services;
} else {
return new PrintService[0];
}
} else {
/* Its not the default service */
PrintService service = getServiceByName(name);
if (service != null && matchesAttributes(service, serviceSet)) {
services = new PrintService[1];
services[0] = service;
return services;
} else {
return new PrintService[0];
}
}
} else {
/* specified service attributes don't include a name.*/
Vector matchedServices = new Vector();
services = getPrintServices();
for (int i = 0; i < services.length; i++) {
if (matchesAttributes(services[i], serviceSet)) {
matchedServices.add(services[i]);
}
}
services = new PrintService[matchedServices.size()];
for (int i = 0; i < services.length; i++) {
services[i] = (PrintService) matchedServices.elementAt(i);
}
return services;
}
}
use of javax.print.attribute.standard.PrinterName in project jdk8u_jdk by JetBrains.
the class Win32PrintServiceLookup method getPrintServices.
public PrintService[] getPrintServices(DocFlavor flavor, AttributeSet attributes) {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkPrintJobAccess();
}
PrintRequestAttributeSet requestSet = null;
PrintServiceAttributeSet serviceSet = null;
if (attributes != null && !attributes.isEmpty()) {
requestSet = new HashPrintRequestAttributeSet();
serviceSet = new HashPrintServiceAttributeSet();
Attribute[] attrs = attributes.toArray();
for (int i = 0; i < attrs.length; i++) {
if (attrs[i] instanceof PrintRequestAttribute) {
requestSet.add(attrs[i]);
} else if (attrs[i] instanceof PrintServiceAttribute) {
serviceSet.add(attrs[i]);
}
}
}
/*
* Special case: If client is asking for a particular printer
* (by name) then we can save time by getting just that service
* to check against the rest of the specified attributes.
*/
PrintService[] services = null;
if (serviceSet != null && serviceSet.get(PrinterName.class) != null) {
PrinterName name = (PrinterName) serviceSet.get(PrinterName.class);
PrintService service = getPrintServiceByName(name.getValue());
if (service == null || !matchingService(service, serviceSet)) {
services = new PrintService[0];
} else {
services = new PrintService[1];
services[0] = service;
}
} else {
services = getPrintServices();
}
if (services.length == 0) {
return services;
} else {
ArrayList matchingServices = new ArrayList();
for (int i = 0; i < services.length; i++) {
try {
if (services[i].getUnsupportedAttributes(flavor, requestSet) == null) {
matchingServices.add(services[i]);
}
} catch (IllegalArgumentException e) {
}
}
services = new PrintService[matchingServices.size()];
return (PrintService[]) matchingServices.toArray(services);
}
}
use of javax.print.attribute.standard.PrinterName in project jdk8u_jdk by JetBrains.
the class UnixPrintServiceLookup method getServiceByName.
/* On a network with many (hundreds) of network printers, it
* can save several seconds if you know all you want is a particular
* printer, to ask for that printer rather than retrieving all printers.
*/
private PrintService getServiceByName(PrinterName nameAttr) {
String name = nameAttr.getValue();
if (name == null || name.equals("") || !checkPrinterName(name)) {
return null;
}
/* check if all printers are already available */
if (printServices != null) {
for (PrintService printService : printServices) {
PrinterName printerName = (PrinterName) printService.getAttribute(PrinterName.class);
if (printerName.getValue().equals(name)) {
return printService;
}
}
}
/* take CUPS into account first */
if (CUPSPrinter.isCupsRunning()) {
try {
return new IPPPrintService(name, new URL("http://" + CUPSPrinter.getServer() + ":" + CUPSPrinter.getPort() + "/" + name));
} catch (Exception e) {
IPPPrintService.debug_println(debugPrefix + " getServiceByName Exception " + e);
}
}
/* fallback if nothing not having a printer at this point */
PrintService printer = null;
if (isMac() || isSysV()) {
printer = getNamedPrinterNameSysV(name);
} else if (isAIX()) {
printer = getNamedPrinterNameAIX(name);
} else {
printer = getNamedPrinterNameBSD(name);
}
return printer;
}
use of javax.print.attribute.standard.PrinterName in project jdk8u_jdk by JetBrains.
the class GetPrintServices method lookupByName.
private static PrintService lookupByName(String name) {
AttributeSet attributes = new HashAttributeSet();
attributes.add(new PrinterName(name, null));
for (PrintService service : PrintServiceLookup.lookupPrintServices(null, attributes)) {
return service;
}
return null;
}
Aggregations