javax.print.attribute.standard.PrinterURI Java Examples

The following examples show how to use javax.print.attribute.standard.PrinterURI. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PrintServiceLookupProvider.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private int addPrintServiceToList(ArrayList<PrintService> printerList, PrintService ps) {
    int index = printerList.indexOf(ps);
    // Check if PrintService with same name is already in the list.
    if (CUPSPrinter.isCupsRunning() && index != -1) {
        // Bug in Linux: Duplicate entry of a remote printer
        // and treats it as local printer but it is returning wrong
        // information when queried using IPP. Workaround is to remove it.
        // Even CUPS ignores these entries as shown in lpstat or using
        // their web configuration.
        PrinterURI uri = ps.getAttribute(PrinterURI.class);
        if (uri.getURI().getHost().equals("localhost")) {
            IPPPrintService.debug_println(debugPrefix+"duplicate PrintService, ignoring the new local printer: "+ps);
            return index;  // Do not add this.
        }
        PrintService oldPS = printerList.get(index);
        uri = oldPS.getAttribute(PrinterURI.class);
        if (uri.getURI().getHost().equals("localhost")) {
            IPPPrintService.debug_println(debugPrefix+"duplicate PrintService, removing existing local printer: "+oldPS);
            printerList.remove(oldPS);
        } else {
            return index;
        }
    }
    printerList.add(ps);
    return (printerList.size() - 1);
}