Example usage for javax.print.attribute.standard PrinterName toString

List of usage examples for javax.print.attribute.standard PrinterName toString

Introduction

In this page you can find the example usage for javax.print.attribute.standard PrinterName toString.

Prototype

public String toString() 

Source Link

Document

Returns a String identifying this text attribute.

Usage

From source file:us.mn.state.health.lims.common.provider.reports.SampleLabelPrintProvider.java

private String validateInput(String accessionCount, String accessionStart, String accessionEnd,
        String printerName, String masterLabels, String itemLabels) {
    if ((StringUtil.isNullorNill(accessionCount) && StringUtil.isNullorNill(accessionStart)
            && StringUtil.isNullorNill(accessionEnd)) || StringUtil.isNullorNill(printerName)
            || StringUtil.isNullorNill(masterLabels) || "0".equals(masterLabels))
        return FWD_FAIL;

    masterCount = Integer.parseInt(masterLabels);
    itemCount = StringUtil.isNullorNill(itemLabels) ? 0 : Integer.parseInt(itemLabels);

    //bugzilla 2374 limit number of labels
    int maxNumberOfLabels = Integer.parseInt(SystemConfiguration.getInstance().getMaxNumberOfLabels());
    if (masterCount > maxNumberOfLabels || itemCount > maxNumberOfLabels) {
        LogEvent.logError("SampleLabelPrintProvider", "printLabels()",
                StringUtil.getMessageForKey("errors.labelprint.exceeded.maxnumber",
                        SystemConfiguration.getInstance().getMaxNumberOfLabels()));
        return FWD_FAIL_MAX_LABELS_EXCEED;
    }/*from ww  w.  j a va2s  .c  o m*/

    //validate printer
    PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
    String printer = null;
    PrinterName printerToUse = new PrinterName(printerName, null);

    for (int i = 0; i < services.length; i++) {
        printer = services[i].getName();
        if (printer.equalsIgnoreCase(printerToUse.toString())) {
            //System.out.println("This is the printer I will use "
            //+ printerName);
            ps = services[i];
            //bugzilla 2380: load all valid printer names for error message
            //break;
        }
    }

    if (ps == null) {
        LogEvent.logError("SampleLabelPrintProvider", "printLabels()",
                StringUtil.getMessageForKey("errors.labelprint.no.printer"));
        return FWD_FAIL_BAD_PRINTER;
    }

    return FWD_SUCCESS;
}