Java Code Examples for javax.print.attribute.standard.PrinterName#getValue()

The following examples show how to use javax.print.attribute.standard.PrinterName#getValue() . 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: GetPrintServices.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    for (PrintService service : PrintServiceLookup.lookupPrintServices(null, null)) {
        String serviceName = service.getName();
        PrinterName name = service.getAttribute(PrinterName.class);
        String printerName = name.getValue();

        PrintService serviceByName = lookupByName(printerName);
        System.out.println("service " + service);
        System.out.println("serviceByName " + serviceByName);
        if (!service.equals(serviceByName)) {
            throw new RuntimeException("NOK " + serviceName
                               + " expected: " + service.getClass().getName()
                               + " got: " + serviceByName.getClass().getName());
        }
    }
    System.out.println("Test PASSED");
}
 
Example 2
Source File: PrintServiceLookupProvider.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 3
Source File: PrintServiceLookupProvider.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 4
Source File: UnixPrintServiceLookup.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 5
Source File: PrintServiceLookupProvider.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 6
Source File: UnixPrintServiceLookup.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 7
Source File: PrintServiceLookupProvider.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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 = 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;
}
 
Example 8
Source File: UnixPrintServiceLookup.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 9
Source File: UnixPrintServiceLookup.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 10
Source File: UnixPrintServiceLookup.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
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 {
        printer = getNamedPrinterNameBSD(name);
    }
    return printer;
}
 
Example 11
Source File: UnixPrintServiceLookup.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
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 {
        printer = getNamedPrinterNameBSD(name);
    }
    return printer;
}
 
Example 12
Source File: PrintServiceLookupProvider.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 13
Source File: UnixPrintServiceLookup.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 14
Source File: UnixPrintServiceLookup.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
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;
}