Search in sources :

Example 1 with PrintServiceAttribute

use of javax.print.attribute.PrintServiceAttribute in project jdk8u_jdk by JetBrains.

the class Win32PrintServiceLookup method matchingService.

boolean matchingService(PrintService service, PrintServiceAttributeSet serviceSet) {
    if (serviceSet != null) {
        Attribute[] attrs = serviceSet.toArray();
        Attribute serviceAttr;
        for (int i = 0; i < attrs.length; i++) {
            serviceAttr = service.getAttribute((Class<PrintServiceAttribute>) attrs[i].getCategory());
            if (serviceAttr == null || !serviceAttr.equals(attrs[i])) {
                return false;
            }
        }
    }
    return true;
}
Also used : PrintServiceAttribute(javax.print.attribute.PrintServiceAttribute) Attribute(javax.print.attribute.Attribute) PrintRequestAttribute(javax.print.attribute.PrintRequestAttribute)

Example 2 with PrintServiceAttribute

use of javax.print.attribute.PrintServiceAttribute 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);
    }
}
Also used : PrintServiceAttribute(javax.print.attribute.PrintServiceAttribute) Attribute(javax.print.attribute.Attribute) PrintRequestAttribute(javax.print.attribute.PrintRequestAttribute) ArrayList(java.util.ArrayList) HashPrintServiceAttributeSet(javax.print.attribute.HashPrintServiceAttributeSet) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintService(javax.print.PrintService) MultiDocPrintService(javax.print.MultiDocPrintService) PrinterName(javax.print.attribute.standard.PrinterName) PrintRequestAttribute(javax.print.attribute.PrintRequestAttribute) PrintServiceAttribute(javax.print.attribute.PrintServiceAttribute) PrintServiceAttributeSet(javax.print.attribute.PrintServiceAttributeSet) HashPrintServiceAttributeSet(javax.print.attribute.HashPrintServiceAttributeSet) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet)

Example 3 with PrintServiceAttribute

use of javax.print.attribute.PrintServiceAttribute in project jdk8u_jdk by JetBrains.

the class UnixPrintServiceLookup method getPrintServices.

/*
     * If service attributes are specified then there must be additional
     * filtering.
     */
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]);
            }
        }
    }
    PrintService[] services = getPrintServices(serviceSet);
    if (services.length == 0) {
        return services;
    }
    if (CUPSPrinter.isCupsRunning()) {
        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);
    } else {
        // We only need to compare 1 PrintService because all
        // UnixPrintServices are the same anyway.  We will not use
        // default PrintService because it might be null.
        PrintService service = services[0];
        if ((flavor == null || service.isDocFlavorSupported(flavor)) && service.getUnsupportedAttributes(flavor, requestSet) == null) {
            return services;
        } else {
            return new PrintService[0];
        }
    }
}
Also used : PrintServiceAttribute(javax.print.attribute.PrintServiceAttribute) PrintRequestAttribute(javax.print.attribute.PrintRequestAttribute) Attribute(javax.print.attribute.Attribute) ArrayList(java.util.ArrayList) HashPrintServiceAttributeSet(javax.print.attribute.HashPrintServiceAttributeSet) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) MultiDocPrintService(javax.print.MultiDocPrintService) PrintService(javax.print.PrintService) PrintRequestAttribute(javax.print.attribute.PrintRequestAttribute) PrintServiceAttribute(javax.print.attribute.PrintServiceAttribute) PrintServiceAttributeSet(javax.print.attribute.PrintServiceAttributeSet) HashPrintServiceAttributeSet(javax.print.attribute.HashPrintServiceAttributeSet) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet)

Example 4 with PrintServiceAttribute

use of javax.print.attribute.PrintServiceAttribute in project jdk8u_jdk by JetBrains.

the class UnixPrintServiceLookup method matchesAttributes.

private boolean matchesAttributes(PrintService service, PrintServiceAttributeSet attributes) {
    Attribute[] attrs = attributes.toArray();
    Attribute serviceAttr;
    for (int i = 0; i < attrs.length; i++) {
        serviceAttr = service.getAttribute((Class<PrintServiceAttribute>) attrs[i].getCategory());
        if (serviceAttr == null || !serviceAttr.equals(attrs[i])) {
            return false;
        }
    }
    return true;
}
Also used : PrintServiceAttribute(javax.print.attribute.PrintServiceAttribute) PrintRequestAttribute(javax.print.attribute.PrintRequestAttribute) Attribute(javax.print.attribute.Attribute)

Aggregations

Attribute (javax.print.attribute.Attribute)4 PrintRequestAttribute (javax.print.attribute.PrintRequestAttribute)4 PrintServiceAttribute (javax.print.attribute.PrintServiceAttribute)4 ArrayList (java.util.ArrayList)2 MultiDocPrintService (javax.print.MultiDocPrintService)2 PrintService (javax.print.PrintService)2 HashPrintRequestAttributeSet (javax.print.attribute.HashPrintRequestAttributeSet)2 HashPrintServiceAttributeSet (javax.print.attribute.HashPrintServiceAttributeSet)2 PrintRequestAttributeSet (javax.print.attribute.PrintRequestAttributeSet)2 PrintServiceAttributeSet (javax.print.attribute.PrintServiceAttributeSet)2 PrinterName (javax.print.attribute.standard.PrinterName)1