Example usage for javax.print PrintServiceLookup lookupDefaultPrintService

List of usage examples for javax.print PrintServiceLookup lookupDefaultPrintService

Introduction

In this page you can find the example usage for javax.print PrintServiceLookup lookupDefaultPrintService.

Prototype

public static final PrintService lookupDefaultPrintService() 

Source Link

Document

Locates the default print service for this environment.

Usage

From source file:org.springframework.integration.print.core.PrintServiceExecutor.java

public PrintServiceExecutor(String printerName) {

    if (!StringUtils.hasText(printerName)) {
        this.printService = PrintServiceLookup.lookupDefaultPrintService();
        Assert.notNull(this.printService, "Did not find a the default print service.");
    } else {//from   w  w w .j  a va  2s .c  o m
        PrintService matchingPrintService = null;

        for (PrintService printService : PrintServiceExecutor.getAvailablePrinterServices()) {
            if (printerName.equalsIgnoreCase(printService.getName())) {
                matchingPrintService = printService;
                break;
            }
        }

        this.printService = matchingPrintService;

        Assert.notNull(this.printService,
                String.format("Did not find the" + "print service for printer '%s'.", printerName));
    }

    if (logger.isInfoEnabled()) {
        logger.info("Setting up print service for printer '" + this.printService.getName() + "'.");
    } else if (logger.isDebugEnabled()) {
        logger.debug(this.getPrinterInfo());
    }

}