Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6921664

The number of copies and the job name are not passed to a 3rd party PrintService

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 6u12
    • Fix Version/s: 9
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
      2d
    • Resolved In Build:
      b117
    • CPU:
      x86
    • OS:
      linux

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0_12"
      Java(TM) SE Runtime Environment (build 1.6.0_12-b04)
      Java HotSpot(TM) Client VM (build 11.2-b01, mixed mode, sharing)


      ADDITIONAL OS VERSION INFORMATION :
      Linux bisonws0043.bissoldom.local 2.6.29.6-217.2.8.fc11.i586 #1 SMP Sat Aug 15 00:44:39 EDT 2009 i686 i686 i386 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      When calling the test code you will get the following output if no other printer are configured on the system:

      [rep@bisonws0043 PrintserviceTest]$ java -jar test.jar
      check printer name of service Dummy Printer : myDummyPrintService
      correct printer service do print...
      job name: null
      copies: null

      I would expect that the PrintRequestAttributeSet passed to the DummyDocPrintJob would contain the attributes
      javax.print.attribute.standard.Copies and javax.print.attribute.standard.JobName with the correct values (2/"myJobName").

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Execute Test.main()


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.Graphics;
      import java.awt.print.PageFormat;
      import java.awt.print.Printable;
      import java.awt.print.PrinterException;
      import java.awt.print.PrinterJob;
      import java.util.HashSet;
      import java.util.Set;

      import javax.print.Doc;
      import javax.print.DocFlavor;
      import javax.print.DocPrintJob;
      import javax.print.PrintException;
      import javax.print.PrintService;
      import javax.print.PrintServiceLookup;
      import javax.print.ServiceUIFactory;
      import javax.print.attribute.Attribute;
      import javax.print.attribute.AttributeSet;
      import javax.print.attribute.HashPrintJobAttributeSet;
      import javax.print.attribute.HashPrintServiceAttributeSet;
      import javax.print.attribute.PrintJobAttributeSet;
      import javax.print.attribute.PrintRequestAttributeSet;
      import javax.print.attribute.PrintServiceAttribute;
      import javax.print.attribute.PrintServiceAttributeSet;
      import javax.print.attribute.standard.Copies;
      import javax.print.attribute.standard.JobName;
      import javax.print.attribute.standard.PrinterName;
      import javax.print.attribute.standard.PrinterState;
      import javax.print.event.PrintJobAttributeListener;
      import javax.print.event.PrintJobListener;
      import javax.print.event.PrintServiceAttributeListener;

      public class Test {

        public static void main(String[] args) throws Exception {
          // register custom print service implementation
          String printerName = "myDummyPrintService";
          PrintServiceLookup.registerService(new DummyPrintService(printerName));
          // calling third party (BusinessObjects BOE 2008) print logic
          thirdPartyPrintLogic(printerName);
        }

        /**
         * This method reflects the third party print implementation as reverse engineered. This code can not be changed form our side.
         *
         * @param printerName
         * @throws Exception
         */
        static void thirdPartyPrintLogic(String printerName) throws Exception {
          PrinterJob printerjob = PrinterJob.getPrinterJob();
          printerjob.setCopies(2);
          printerjob.setJobName("myJobName");
          printerjob.setPrintable(new DummyPrintable());
          for (PrintService printService : PrinterJob.lookupPrintServices()) {
            System.out.println("check printer name of service " + printService);
            if (printerName.equals(printService.getName())) {
              System.out.println("correct printer service do print...");
              printerjob.setPrintService(printService);
              printerjob.print();
              break;
            }
          }
        }
      }

      class DummyPrintService implements PrintService {
        private final String _name;
        private final Set<DocFlavor> _supportedFlavors;
        private final PrintServiceAttributeSet _printServiceAttributeSet;

        public DummyPrintService(String name) {
          _name = name;
          _supportedFlavors = new HashSet<DocFlavor>();
          _supportedFlavors.add(DocFlavor.SERVICE_FORMATTED.PAGEABLE);
          _supportedFlavors.add(DocFlavor.SERVICE_FORMATTED.PRINTABLE);
          _printServiceAttributeSet = new HashPrintServiceAttributeSet();
          _printServiceAttributeSet.add(new PrinterName(name, null));
          _printServiceAttributeSet.add(PrinterState.IDLE);
        }

        @Override
        public String toString() {
          return "Dummy Printer : " + getName();
        }

        public String getName() {
          return _name;
        }

        public DocPrintJob createPrintJob() {
          return new DummyDocPrintJob(this);
        }

        public boolean isDocFlavorSupported(DocFlavor flavor) {
          return _supportedFlavors.contains(flavor);
        }

        public <T extends PrintServiceAttribute> T getAttribute(Class<T> category) {
          return category.cast(_printServiceAttributeSet.get(category));
        }

        public PrintServiceAttributeSet getAttributes() {
          return _printServiceAttributeSet;
        }

        public DocFlavor[] getSupportedDocFlavors() {
          return _supportedFlavors.toArray(new DocFlavor[_supportedFlavors.size()]);
        }

        public Object getDefaultAttributeValue(Class<? extends Attribute> category) {
          return null;
        }

        public ServiceUIFactory getServiceUIFactory() {
          return null;
        }

        public Class<?>[] getSupportedAttributeCategories() {
          return null;
        }

        public Object getSupportedAttributeValues(Class<? extends Attribute> category, DocFlavor flavor, AttributeSet attributes) {
          return null;
        }

        public AttributeSet getUnsupportedAttributes(DocFlavor flavor, AttributeSet attributes) {
          return null;
        }

        public boolean isAttributeCategorySupported(Class<? extends Attribute> category) {
          return false;
        }

        public boolean isAttributeValueSupported(Attribute attrval, DocFlavor flavor, AttributeSet attributes) {
          return false;
        }

        public void addPrintServiceAttributeListener(PrintServiceAttributeListener listener) {
        }

        public void removePrintServiceAttributeListener(PrintServiceAttributeListener listener) {
        }
      }

      class DummyDocPrintJob implements DocPrintJob {
        private static int _counter;
        private final PrintService _printService;
        private final PrintJobAttributeSet _printJobAttributeSet;

        public DummyDocPrintJob(PrintService printService) {
          _counter++;
          _printService = printService;
          _printJobAttributeSet = new HashPrintJobAttributeSet();
        }

        public PrintService getPrintService() {
          return _printService;
        }

        public PrintJobAttributeSet getAttributes() {
          return _printJobAttributeSet;
        }

        public void addPrintJobAttributeListener(PrintJobAttributeListener listener, PrintJobAttributeSet printJobAttributeSet) {
        }

        public void removePrintJobAttributeListener(PrintJobAttributeListener listener) {
        }

        public void addPrintJobListener(PrintJobListener listener) {
        }

        public void removePrintJobListener(PrintJobListener listener) {
        }

        public void print(Doc doc, PrintRequestAttributeSet printRequestAttributeSet) throws PrintException {
          System.out.println("job name: " + printRequestAttributeSet.get(JobName.class));
          System.out.println("copies: " + printRequestAttributeSet.get(Copies.class));
        }
      }

      class DummyPrintable implements Printable {
        public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
          if (pageIndex == 0) {
            return Printable.PAGE_EXISTS;
          } else {
            return Printable.NO_SUCH_PAGE;
          }
        }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      There is no workaround

      SUPPORT :
      YES

        Attachments

          Activity

            People

            Assignee:
            psadhukhan Prasanta Sadhukhan
            Reporter:
            igor Igor Nekrestyanov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: