javax.print.attribute.standard.RequestingUserName Java Examples

The following examples show how to use javax.print.attribute.standard.RequestingUserName. 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: PDFPrinterJob.java    From jpexs-decompiler with GNU General Public License v3.0 4 votes vote down vote up
@Override
public String getUserName() {
	return ((TextSyntax) attributes.get(RequestingUserName.class))
			.getValue();
}
 
Example #2
Source File: PrintServiceImpl.java    From jqm with Apache License 2.0 4 votes vote down vote up
@Override
public void print(String printQueueName, String jobName, Object data, DocFlavor flavor, String endUserName) throws PrintException
{
    // Arguments tests
    if (printQueueName == null || printQueueName.isEmpty())
    {
        throw new IllegalArgumentException("printQueueName must be non null and non empty");
    }
    if (data == null)
    {
        throw new IllegalArgumentException("data must be non null");
    }
    if (flavor == null)
    {
        throw new IllegalArgumentException("flavor must be non null");
    }
    if (jobName == null || jobName.isEmpty())
    {
        throw new IllegalArgumentException("job name must be non null and non empty");
    }
    if (endUserName != null && endUserName.isEmpty())
    {
        throw new IllegalArgumentException("endUserName can be null but cannot be empty is specified");
    }

    // Find the queue
    AttributeSet set = new HashPrintServiceAttributeSet();
    set.add(new PrinterName(printQueueName, null));
    javax.print.PrintService[] services = PrintServiceLookup.lookupPrintServices(null, set);

    if (services.length == 0 || services[0] == null)
    {
        throw new IllegalArgumentException("There is no printer queue defined with name " + printQueueName
                + " supporting document flavour " + flavor.toString());
    }
    javax.print.PrintService queue = services[0];

    // Create job
    DocPrintJob job = queue.createPrintJob();
    PrintRequestAttributeSet jobAttrs = new HashPrintRequestAttributeSet();
    jobAttrs.add(new JobName(jobName, null));
    if (endUserName != null && queue.isAttributeCategorySupported(RequestingUserName.class))
    {
        jobAttrs.add(new RequestingUserName(endUserName, null));
    }

    // Create payload
    Doc doc = new SimpleDoc(data, flavor, null);

    // Do it
    job.print(doc, jobAttrs);
}