javax.print.attribute.standard.PrinterIsAcceptingJobs Java Examples

The following examples show how to use javax.print.attribute.standard.PrinterIsAcceptingJobs. 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: UnixPrintService.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private PrinterIsAcceptingJobs getPrinterIsAcceptingJobsAIX() {
    // On AIX there should not be a blank after '-a'.
    String command = "/usr/bin/lpstat -a" + printer;
    String results[]= PrintServiceLookupProvider.execCmd(command);

    // Remove headers and bogus entries added by remote printers.
    results = filterPrinterNamesAIX(results);

    if (results != null && results.length > 0) {
        for (int i = 0; i < results.length; i++) {
            if (results[i].contains("READY") ||
                results[i].contains("RUNNING")) {
                return PrinterIsAcceptingJobs.ACCEPTING_JOBS;
            }
        }
    }

    return PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS;

}
 
Example #2
Source File: UnixPrintService.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private PrinterIsAcceptingJobs getPrinterIsAcceptingJobsAIX() {
    // On AIX there should not be a blank after '-a'.
    String command = "/usr/bin/lpstat -a" + printer;
    String results[]= UnixPrintServiceLookup.execCmd(command);

    // Remove headers and bogus entries added by remote printers.
    results = filterPrinterNamesAIX(results);

    if (results != null && results.length > 0) {
        for (int i = 0; i < results.length; i++) {
            if (results[i].contains("READY") ||
                results[i].contains("RUNNING")) {
                return PrinterIsAcceptingJobs.ACCEPTING_JOBS;
            }
        }
    }

    return PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS;

}
 
Example #3
Source File: PrintServiceStub.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public PrintServiceStub(String name) {
    _name = name;
    _flavors = new HashSet<DocFlavor>();
    _flavors.add(DocFlavor.SERVICE_FORMATTED.PAGEABLE);
    _flavors.add(DocFlavor.SERVICE_FORMATTED.PRINTABLE);
    _attributes = new HashMap<>();
    _attributes.put(PrinterName.class, new PrinterName(name, null));
    _attributes.put(PrinterState.class, PrinterState.IDLE);
    _attributes.put(PrinterInfo.class, new PrinterInfo("Custom location",
            null));
    _attributes.put(PrinterIsAcceptingJobs.class,
            PrinterIsAcceptingJobs.ACCEPTING_JOBS);
    _attributes.put(PrinterMakeAndModel.class, new PrinterMakeAndModel(
            "Custom printer", null));
    _attributes.put(Media.class, new Media[] { MediaSizeName.ISO_A4 });
}
 
Example #4
Source File: UnixPrintService.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private PrinterIsAcceptingJobs getPrinterIsAcceptingJobsSysV() {
    String command = "/usr/bin/lpstat -a " + printer;
    String results[]= PrintServiceLookupProvider.execCmd(command);

    if (results != null && results.length > 0) {
        if (results[0].startsWith(printer + " accepting requests")) {
            return PrinterIsAcceptingJobs.ACCEPTING_JOBS;
        }
        else if (results[0].startsWith(printer)) {
            /* As well as "myprinter accepting requests", look for
             * "myprinter@somehost accepting requests".
             */
            int index = printer.length();
            String str = results[0];
            if (str.length() > index &&
                str.charAt(index) == '@' &&
                str.indexOf(" accepting requests", index) > 0 &&
                str.indexOf(" not accepting requests", index) == -1) {
               return PrinterIsAcceptingJobs.ACCEPTING_JOBS;
            }
        }
    }
    return PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS ;
}
 
Example #5
Source File: UnixPrintService.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private PrinterIsAcceptingJobs getPrinterIsAcceptingJobsAIX() {
    // On AIX there should not be a blank after '-a'.
    String command = "/usr/bin/lpstat -a" + printer;
    String results[]= PrintServiceLookupProvider.execCmd(command);

    // Remove headers and bogus entries added by remote printers.
    results = filterPrinterNamesAIX(results);

    if (results != null && results.length > 0) {
        for (int i = 0; i < results.length; i++) {
            if (results[i].contains("READY") ||
                results[i].contains("RUNNING")) {
                return PrinterIsAcceptingJobs.ACCEPTING_JOBS;
            }
        }
    }

    return PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS;

}
 
Example #6
Source File: PrintServiceStub.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public PrintServiceStub(String name) {
    _name = name;
    _flavors = new HashSet<DocFlavor>();
    _flavors.add(DocFlavor.SERVICE_FORMATTED.PAGEABLE);
    _flavors.add(DocFlavor.SERVICE_FORMATTED.PRINTABLE);
    _attributes = new HashMap<>();
    _attributes.put(PrinterName.class, new PrinterName(name, null));
    _attributes.put(PrinterState.class, PrinterState.IDLE);
    _attributes.put(PrinterInfo.class, new PrinterInfo("Custom location",
            null));
    _attributes.put(PrinterIsAcceptingJobs.class,
            PrinterIsAcceptingJobs.ACCEPTING_JOBS);
    _attributes.put(PrinterMakeAndModel.class, new PrinterMakeAndModel(
            "Custom printer", null));
    _attributes.put(Media.class, new Media[] { MediaSizeName.ISO_A4 });
}
 
Example #7
Source File: PrintServiceStub.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public PrintServiceStub(String name) {
    _name = name;
    _flavors = new HashSet<DocFlavor>();
    _flavors.add(DocFlavor.SERVICE_FORMATTED.PAGEABLE);
    _flavors.add(DocFlavor.SERVICE_FORMATTED.PRINTABLE);
    _attributes = new HashMap<>();
    _attributes.put(PrinterName.class, new PrinterName(name, null));
    _attributes.put(PrinterState.class, PrinterState.IDLE);
    _attributes.put(PrinterInfo.class, new PrinterInfo("Custom location",
            null));
    _attributes.put(PrinterIsAcceptingJobs.class,
            PrinterIsAcceptingJobs.ACCEPTING_JOBS);
    _attributes.put(PrinterMakeAndModel.class, new PrinterMakeAndModel(
            "Custom printer", null));
    _attributes.put(Media.class, new Media[] { MediaSizeName.ISO_A4 });
}
 
Example #8
Source File: UnixPrintService.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private PrinterIsAcceptingJobs getPrinterIsAcceptingJobsSysV() {
    String command = "/usr/bin/lpstat -a " + printer;
    String results[]= PrintServiceLookupProvider.execCmd(command);

    if (results != null && results.length > 0) {
        if (results[0].startsWith(printer + " accepting requests")) {
            return PrinterIsAcceptingJobs.ACCEPTING_JOBS;
        }
        else if (results[0].startsWith(printer)) {
            /* As well as "myprinter accepting requests", look for
             * "myprinter@somehost accepting requests".
             */
            int index = printer.length();
            String str = results[0];
            if (str.length() > index &&
                str.charAt(index) == '@' &&
                str.indexOf(" accepting requests", index) > 0 &&
                str.indexOf(" not accepting requests", index) == -1) {
               return PrinterIsAcceptingJobs.ACCEPTING_JOBS;
            }
        }
    }
    return PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS ;
}
 
Example #9
Source File: UnixPrintService.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private PrinterIsAcceptingJobs getPrinterIsAcceptingJobsSysV() {
    String command = "/usr/bin/lpstat -a " + printer;
    String results[]= UnixPrintServiceLookup.execCmd(command);

    if (results != null && results.length > 0) {
        if (results[0].startsWith(printer + " accepting requests")) {
            return PrinterIsAcceptingJobs.ACCEPTING_JOBS;
        }
        else if (results[0].startsWith(printer)) {
            /* As well as "myprinter accepting requests", look for
             * "myprinter@somehost accepting requests".
             */
            int index = printer.length();
            String str = results[0];
            if (str.length() > index &&
                str.charAt(index) == '@' &&
                str.indexOf(" accepting requests", index) > 0 &&
                str.indexOf(" not accepting requests", index) == -1) {
               return PrinterIsAcceptingJobs.ACCEPTING_JOBS;
            }
        }
    }
    return PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS ;
}
 
Example #10
Source File: UnixPrintService.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public <T extends PrintServiceAttribute>
    T getAttribute(Class<T> category)
{
    if (category == null) {
        throw new NullPointerException("category");
    }
    if (!(PrintServiceAttribute.class.isAssignableFrom(category))) {
        throw new IllegalArgumentException("Not a PrintServiceAttribute");
    }

    if (category == PrinterName.class) {
        return (T)getPrinterName();
    } else if (category == PrinterState.class) {
        return (T)getPrinterState();
    } else if (category == PrinterStateReasons.class) {
        return (T)getPrinterStateReasons();
    } else if (category == QueuedJobCount.class) {
        return (T)getQueuedJobCount();
    } else if (category == PrinterIsAcceptingJobs.class) {
        return (T)getPrinterIsAcceptingJobs();
    } else {
        return null;
    }
}
 
Example #11
Source File: UnixPrintService.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public <T extends PrintServiceAttribute>
    T getAttribute(Class<T> category)
{
    if (category == null) {
        throw new NullPointerException("category");
    }
    if (!(PrintServiceAttribute.class.isAssignableFrom(category))) {
        throw new IllegalArgumentException("Not a PrintServiceAttribute");
    }

    if (category == PrinterName.class) {
        return (T)getPrinterName();
    } else if (category == PrinterState.class) {
        return (T)getPrinterState();
    } else if (category == PrinterStateReasons.class) {
        return (T)getPrinterStateReasons();
    } else if (category == QueuedJobCount.class) {
        return (T)getQueuedJobCount();
    } else if (category == PrinterIsAcceptingJobs.class) {
        return (T)getPrinterIsAcceptingJobs();
    } else {
        return null;
    }
}
 
Example #12
Source File: PrintServiceStub.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public PrintServiceStub(String name) {
    _name = name;
    _flavors = new HashSet<DocFlavor>();
    _flavors.add(DocFlavor.SERVICE_FORMATTED.PAGEABLE);
    _flavors.add(DocFlavor.SERVICE_FORMATTED.PRINTABLE);
    _attributes = new HashMap<>();
    _attributes.put(PrinterName.class, new PrinterName(name, null));
    _attributes.put(PrinterState.class, PrinterState.IDLE);
    _attributes.put(PrinterInfo.class, new PrinterInfo("Custom location",
            null));
    _attributes.put(PrinterIsAcceptingJobs.class,
            PrinterIsAcceptingJobs.ACCEPTING_JOBS);
    _attributes.put(PrinterMakeAndModel.class, new PrinterMakeAndModel(
            "Custom printer", null));
    _attributes.put(Media.class, new Media[] { MediaSizeName.ISO_A4 });
}
 
Example #13
Source File: UnixPrintService.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public <T extends PrintServiceAttribute>
    T getAttribute(Class<T> category)
{
    if (category == null) {
        throw new NullPointerException("category");
    }
    if (!(PrintServiceAttribute.class.isAssignableFrom(category))) {
        throw new IllegalArgumentException("Not a PrintServiceAttribute");
    }

    if (category == PrinterName.class) {
        return (T)getPrinterName();
    } else if (category == PrinterState.class) {
        return (T)getPrinterState();
    } else if (category == PrinterStateReasons.class) {
        return (T)getPrinterStateReasons();
    } else if (category == QueuedJobCount.class) {
        return (T)getQueuedJobCount();
    } else if (category == PrinterIsAcceptingJobs.class) {
        return (T)getPrinterIsAcceptingJobs();
    } else {
        return null;
    }
}
 
Example #14
Source File: PrintServiceStub.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public PrintServiceStub(String name) {
    _name = name;
    _flavors = new HashSet<DocFlavor>();
    _flavors.add(DocFlavor.SERVICE_FORMATTED.PAGEABLE);
    _flavors.add(DocFlavor.SERVICE_FORMATTED.PRINTABLE);
    _attributes = new HashMap<>();
    _attributes.put(PrinterName.class, new PrinterName(name, null));
    _attributes.put(PrinterState.class, PrinterState.IDLE);
    _attributes.put(PrinterInfo.class, new PrinterInfo("Custom location",
            null));
    _attributes.put(PrinterIsAcceptingJobs.class,
            PrinterIsAcceptingJobs.ACCEPTING_JOBS);
    _attributes.put(PrinterMakeAndModel.class, new PrinterMakeAndModel(
            "Custom printer", null));
    _attributes.put(Media.class, new Media[] { MediaSizeName.ISO_A4 });
}
 
Example #15
Source File: UnixPrintService.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private PrinterIsAcceptingJobs getPrinterIsAcceptingJobsSysV() {
    String command = "/usr/bin/lpstat -a " + printer;
    String results[]= PrintServiceLookupProvider.execCmd(command);

    if (results != null && results.length > 0) {
        if (results[0].startsWith(printer + " accepting requests")) {
            return PrinterIsAcceptingJobs.ACCEPTING_JOBS;
        }
        else if (results[0].startsWith(printer)) {
            /* As well as "myprinter accepting requests", look for
             * "myprinter@somehost accepting requests".
             */
            int index = printer.length();
            String str = results[0];
            if (str.length() > index &&
                str.charAt(index) == '@' &&
                str.indexOf(" accepting requests", index) > 0 &&
                str.indexOf(" not accepting requests", index) == -1) {
               return PrinterIsAcceptingJobs.ACCEPTING_JOBS;
            }
        }
    }
    return PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS ;
}
 
Example #16
Source File: PrintServiceStub.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public PrintServiceStub(String name) {
    _name = name;
    _flavors = new HashSet<DocFlavor>();
    _flavors.add(DocFlavor.SERVICE_FORMATTED.PAGEABLE);
    _flavors.add(DocFlavor.SERVICE_FORMATTED.PRINTABLE);
    _attributes = new HashMap<>();
    _attributes.put(PrinterName.class, new PrinterName(name, null));
    _attributes.put(PrinterState.class, PrinterState.IDLE);
    _attributes.put(PrinterInfo.class, new PrinterInfo("Custom location",
            null));
    _attributes.put(PrinterIsAcceptingJobs.class,
            PrinterIsAcceptingJobs.ACCEPTING_JOBS);
    _attributes.put(PrinterMakeAndModel.class, new PrinterMakeAndModel(
            "Custom printer", null));
    _attributes.put(Media.class, new Media[] { MediaSizeName.ISO_A4 });
}
 
Example #17
Source File: UnixPrintService.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private PrinterIsAcceptingJobs getPrinterIsAcceptingJobsSysV() {
    String command = "/usr/bin/lpstat -a " + printer;
    String results[]= UnixPrintServiceLookup.execCmd(command);

    if (results != null && results.length > 0) {
        if (results[0].startsWith(printer + " accepting requests")) {
            return PrinterIsAcceptingJobs.ACCEPTING_JOBS;
        }
        else if (results[0].startsWith(printer)) {
            /* As well as "myprinter accepting requests", look for
             * "myprinter@somehost accepting requests".
             */
            int index = printer.length();
            String str = results[0];
            if (str.length() > index &&
                str.charAt(index) == '@' &&
                str.indexOf(" accepting requests", index) > 0 &&
                str.indexOf(" not accepting requests", index) == -1) {
               return PrinterIsAcceptingJobs.ACCEPTING_JOBS;
            }
        }
    }
    return PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS ;
}
 
Example #18
Source File: UnixPrintService.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public <T extends PrintServiceAttribute>
    T getAttribute(Class<T> category)
{
    if (category == null) {
        throw new NullPointerException("category");
    }
    if (!(PrintServiceAttribute.class.isAssignableFrom(category))) {
        throw new IllegalArgumentException("Not a PrintServiceAttribute");
    }

    if (category == PrinterName.class) {
        return (T)getPrinterName();
    } else if (category == PrinterState.class) {
        return (T)getPrinterState();
    } else if (category == PrinterStateReasons.class) {
        return (T)getPrinterStateReasons();
    } else if (category == QueuedJobCount.class) {
        return (T)getQueuedJobCount();
    } else if (category == PrinterIsAcceptingJobs.class) {
        return (T)getPrinterIsAcceptingJobs();
    } else {
        return null;
    }
}
 
Example #19
Source File: PrintServiceStub.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public PrintServiceStub(String name) {
    _name = name;
    _flavors = new HashSet<DocFlavor>();
    _flavors.add(DocFlavor.SERVICE_FORMATTED.PAGEABLE);
    _flavors.add(DocFlavor.SERVICE_FORMATTED.PRINTABLE);
    _attributes = new HashMap<>();
    _attributes.put(PrinterName.class, new PrinterName(name, null));
    _attributes.put(PrinterState.class, PrinterState.IDLE);
    _attributes.put(PrinterInfo.class, new PrinterInfo("Custom location",
            null));
    _attributes.put(PrinterIsAcceptingJobs.class,
            PrinterIsAcceptingJobs.ACCEPTING_JOBS);
    _attributes.put(PrinterMakeAndModel.class, new PrinterMakeAndModel(
            "Custom printer", null));
    _attributes.put(Media.class, new Media[] { MediaSizeName.ISO_A4 });
}
 
Example #20
Source File: UnixPrintService.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private PrinterIsAcceptingJobs getPrinterIsAcceptingJobsAIX() {
    // On AIX there should not be a blank after '-a'.
    String command = "/usr/bin/lpstat -a" + printer;
    String results[]= UnixPrintServiceLookup.execCmd(command);

    // Remove headers and bogus entries added by remote printers.
    results = filterPrinterNamesAIX(results);

    if (results != null && results.length > 0) {
        for (int i = 0; i < results.length; i++) {
            if (results[i].contains("READY") ||
                results[i].contains("RUNNING")) {
                return PrinterIsAcceptingJobs.ACCEPTING_JOBS;
            }
        }
    }

    return PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS;

}
 
Example #21
Source File: UnixPrintService.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public <T extends PrintServiceAttribute>
    T getAttribute(Class<T> category)
{
    if (category == null) {
        throw new NullPointerException("category");
    }
    if (!(PrintServiceAttribute.class.isAssignableFrom(category))) {
        throw new IllegalArgumentException("Not a PrintServiceAttribute");
    }

    if (category == PrinterName.class) {
        return (T)getPrinterName();
    } else if (category == PrinterState.class) {
        return (T)getPrinterState();
    } else if (category == PrinterStateReasons.class) {
        return (T)getPrinterStateReasons();
    } else if (category == QueuedJobCount.class) {
        return (T)getQueuedJobCount();
    } else if (category == PrinterIsAcceptingJobs.class) {
        return (T)getPrinterIsAcceptingJobs();
    } else {
        return null;
    }
}
 
Example #22
Source File: UnixPrintService.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private PrinterIsAcceptingJobs getPrinterIsAcceptingJobsSysV() {
    String command = "/usr/bin/lpstat -a " + printer;
    String results[]= UnixPrintServiceLookup.execCmd(command);

    if (results != null && results.length > 0) {
        if (results[0].startsWith(printer + " accepting requests")) {
            return PrinterIsAcceptingJobs.ACCEPTING_JOBS;
        }
        else if (results[0].startsWith(printer)) {
            /* As well as "myprinter accepting requests", look for
             * "myprinter@somehost accepting requests".
             */
            int index = printer.length();
            String str = results[0];
            if (str.length() > index &&
                str.charAt(index) == '@' &&
                str.indexOf(" accepting requests", index) > 0 &&
                str.indexOf(" not accepting requests", index) == -1) {
               return PrinterIsAcceptingJobs.ACCEPTING_JOBS;
            }
        }
    }
    return PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS ;
}
 
Example #23
Source File: UnixPrintService.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public <T extends PrintServiceAttribute>
    T getAttribute(Class<T> category)
{
    if (category == null) {
        throw new NullPointerException("category");
    }
    if (!(PrintServiceAttribute.class.isAssignableFrom(category))) {
        throw new IllegalArgumentException("Not a PrintServiceAttribute");
    }

    if (category == PrinterName.class) {
        return (T)getPrinterName();
    } else if (category == PrinterState.class) {
        return (T)getPrinterState();
    } else if (category == PrinterStateReasons.class) {
        return (T)getPrinterStateReasons();
    } else if (category == QueuedJobCount.class) {
        return (T)getQueuedJobCount();
    } else if (category == PrinterIsAcceptingJobs.class) {
        return (T)getPrinterIsAcceptingJobs();
    } else {
        return null;
    }
}
 
Example #24
Source File: UnixPrintService.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private PrinterIsAcceptingJobs getPrinterIsAcceptingJobsAIX() {
    // On AIX there should not be a blank after '-a'.
    String command = "/usr/bin/lpstat -a" + printer;
    String results[]= UnixPrintServiceLookup.execCmd(command);

    // Remove headers and bogus entries added by remote printers.
    results = filterPrinterNamesAIX(results);

    if (results != null && results.length > 0) {
        for (int i = 0; i < results.length; i++) {
            if (results[i].contains("READY") ||
                results[i].contains("RUNNING")) {
                return PrinterIsAcceptingJobs.ACCEPTING_JOBS;
            }
        }
    }

    return PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS;

}
 
Example #25
Source File: PrintServiceStub.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public PrintServiceStub(String name) {
    _name = name;
    _flavors = new HashSet<DocFlavor>();
    _flavors.add(DocFlavor.SERVICE_FORMATTED.PAGEABLE);
    _flavors.add(DocFlavor.SERVICE_FORMATTED.PRINTABLE);
    _attributes = new HashMap<>();
    _attributes.put(PrinterName.class, new PrinterName(name, null));
    _attributes.put(PrinterState.class, PrinterState.IDLE);
    _attributes.put(PrinterInfo.class, new PrinterInfo("Custom location",
            null));
    _attributes.put(PrinterIsAcceptingJobs.class,
            PrinterIsAcceptingJobs.ACCEPTING_JOBS);
    _attributes.put(PrinterMakeAndModel.class, new PrinterMakeAndModel(
            "Custom printer", null));
    _attributes.put(Media.class, new Media[] { MediaSizeName.ISO_A4 });
}
 
Example #26
Source File: UnixPrintService.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public <T extends PrintServiceAttribute>
    T getAttribute(Class<T> category)
{
    if (category == null) {
        throw new NullPointerException("category");
    }
    if (!(PrintServiceAttribute.class.isAssignableFrom(category))) {
        throw new IllegalArgumentException("Not a PrintServiceAttribute");
    }

    if (category == PrinterName.class) {
        return (T)getPrinterName();
    } else if (category == PrinterState.class) {
        return (T)getPrinterState();
    } else if (category == PrinterStateReasons.class) {
        return (T)getPrinterStateReasons();
    } else if (category == QueuedJobCount.class) {
        return (T)getQueuedJobCount();
    } else if (category == PrinterIsAcceptingJobs.class) {
        return (T)getPrinterIsAcceptingJobs();
    } else {
        return null;
    }
}
 
Example #27
Source File: PrintServiceStub.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public PrintServiceStub(String name) {
    _name = name;
    _flavors = new HashSet<DocFlavor>();
    _flavors.add(DocFlavor.SERVICE_FORMATTED.PAGEABLE);
    _flavors.add(DocFlavor.SERVICE_FORMATTED.PRINTABLE);
    _attributes = new HashMap<>();
    _attributes.put(PrinterName.class, new PrinterName(name, null));
    _attributes.put(PrinterState.class, PrinterState.IDLE);
    _attributes.put(PrinterInfo.class, new PrinterInfo("Custom location",
            null));
    _attributes.put(PrinterIsAcceptingJobs.class,
            PrinterIsAcceptingJobs.ACCEPTING_JOBS);
    _attributes.put(PrinterMakeAndModel.class, new PrinterMakeAndModel(
            "Custom printer", null));
    _attributes.put(Media.class, new Media[] { MediaSizeName.ISO_A4 });
}
 
Example #28
Source File: UnixPrintService.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private PrinterIsAcceptingJobs getPrinterIsAcceptingJobsSysV() {
    String command = "/usr/bin/lpstat -a " + printer;
    String results[]= PrintServiceLookupProvider.execCmd(command);

    if (results != null && results.length > 0) {
        if (results[0].startsWith(printer + " accepting requests")) {
            return PrinterIsAcceptingJobs.ACCEPTING_JOBS;
        }
        else if (results[0].startsWith(printer)) {
            /* As well as "myprinter accepting requests", look for
             * "myprinter@somehost accepting requests".
             */
            int index = printer.length();
            String str = results[0];
            if (str.length() > index &&
                str.charAt(index) == '@' &&
                str.indexOf(" accepting requests", index) > 0 &&
                str.indexOf(" not accepting requests", index) == -1) {
               return PrinterIsAcceptingJobs.ACCEPTING_JOBS;
            }
        }
    }
    return PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS ;
}
 
Example #29
Source File: UnixPrintService.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public <T extends PrintServiceAttribute>
    T getAttribute(Class<T> category)
{
    if (category == null) {
        throw new NullPointerException("category");
    }
    if (!(PrintServiceAttribute.class.isAssignableFrom(category))) {
        throw new IllegalArgumentException("Not a PrintServiceAttribute");
    }

    if (category == PrinterName.class) {
        return (T)getPrinterName();
    } else if (category == PrinterState.class) {
        return (T)getPrinterState();
    } else if (category == PrinterStateReasons.class) {
        return (T)getPrinterStateReasons();
    } else if (category == QueuedJobCount.class) {
        return (T)getQueuedJobCount();
    } else if (category == PrinterIsAcceptingJobs.class) {
        return (T)getPrinterIsAcceptingJobs();
    } else {
        return null;
    }
}
 
Example #30
Source File: UnixPrintService.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private PrinterIsAcceptingJobs getPrinterIsAcceptingJobsAIX() {
    // On AIX there should not be a blank after '-a'.
    String command = "/usr/bin/lpstat -a" + printer;
    String results[]= PrintServiceLookupProvider.execCmd(command);

    // Remove headers and bogus entries added by remote printers.
    results = filterPrinterNamesAIX(results);

    if (results != null && results.length > 0) {
        for (int i = 0; i < results.length; i++) {
            if (results[i].contains("READY") ||
                results[i].contains("RUNNING")) {
                return PrinterIsAcceptingJobs.ACCEPTING_JOBS;
            }
        }
    }

    return PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS;

}