Initial import.
[clinton/mirror/jspi/.git] / jspi / src / main / java / de / lohndirekt / print / test / IppRequestTestImpl.java
diff --git a/jspi/src/main/java/de/lohndirekt/print/test/IppRequestTestImpl.java b/jspi/src/main/java/de/lohndirekt/print/test/IppRequestTestImpl.java
new file mode 100644 (file)
index 0000000..bdf17b9
--- /dev/null
@@ -0,0 +1,307 @@
+/**\r
+ * Copyright (C) 2003 <a href="http://www.lohndirekt.de/">lohndirekt.de</a>\r
+ *\r
+ * This library is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU Lesser General Public\r
+ * License as published by the Free Software Foundation; either\r
+ * version 2.1 of the License, or (at your option) any later version.\r
+ * \r
+ * This library is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
+ * Lesser General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU Lesser General Public\r
+ * License along with this library; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+ *  \r
+ */\r
+package de.lohndirekt.print.test;\r
+\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.net.URI;\r
+import java.net.URISyntaxException;\r
+import java.util.HashMap;\r
+import java.util.HashSet;\r
+import java.util.Locale;\r
+import java.util.Map;\r
+import java.util.Set;\r
+import java.util.logging.Logger;\r
+\r
+import javax.print.attribute.AttributeSet;\r
+import javax.print.attribute.HashAttributeSet;\r
+import javax.print.attribute.HashPrintJobAttributeSet;\r
+import javax.print.attribute.PrintJobAttributeSet;\r
+import javax.print.attribute.standard.ColorSupported;\r
+import javax.print.attribute.standard.Compression;\r
+import javax.print.attribute.standard.CopiesSupported;\r
+import javax.print.attribute.standard.JobImpressionsSupported;\r
+import javax.print.attribute.standard.JobKOctetsSupported;\r
+import javax.print.attribute.standard.JobMediaSheetsSupported;\r
+import javax.print.attribute.standard.JobPrioritySupported;\r
+import javax.print.attribute.standard.JobSheets;\r
+import javax.print.attribute.standard.MultipleDocumentHandling;\r
+import javax.print.attribute.standard.NumberUpSupported;\r
+import javax.print.attribute.standard.OrientationRequested;\r
+import javax.print.attribute.standard.PDLOverrideSupported;\r
+import javax.print.attribute.standard.ReferenceUriSchemesSupported;\r
+import javax.print.attribute.standard.Sides;\r
+\r
+import de.lohndirekt.print.IppRequest;\r
+import de.lohndirekt.print.IppResponse;\r
+import de.lohndirekt.print.attribute.IppAttributeName;\r
+import de.lohndirekt.print.attribute.IppStatus;\r
+import de.lohndirekt.print.attribute.ipp.Charset;\r
+import de.lohndirekt.print.attribute.ipp.NaturalLanguage;\r
+import de.lohndirekt.print.attribute.ipp.jobtempl.LdJobHoldUntil;\r
+import de.lohndirekt.print.attribute.ipp.printerdesc.PrinterDriverInstaller;\r
+import de.lohndirekt.print.attribute.ipp.printerdesc.supported.CompressionSupported;\r
+import de.lohndirekt.print.attribute.ipp.printerdesc.supported.FinishingsSupported;\r
+import de.lohndirekt.print.attribute.ipp.printerdesc.supported.JobHoldUntilSupported;\r
+import de.lohndirekt.print.attribute.ipp.printerdesc.supported.JobSheetsSupported;\r
+import de.lohndirekt.print.attribute.ipp.printerdesc.supported.MediaSupported;\r
+import de.lohndirekt.print.attribute.ipp.printerdesc.supported.MultipleDocumentHandlingSupported;\r
+import de.lohndirekt.print.attribute.ipp.printerdesc.supported.OperationsSupported;\r
+import de.lohndirekt.print.attribute.ipp.printerdesc.supported.OrientationRequestedSupported;\r
+import de.lohndirekt.print.attribute.ipp.printerdesc.supported.PageRangesSupported;\r
+import de.lohndirekt.print.attribute.ipp.printerdesc.supported.PrinterUriSupported;\r
+import de.lohndirekt.print.attribute.ipp.printerdesc.supported.SidesSupported;\r
+\r
+public class IppRequestTestImpl implements IppRequest {\r
+       private Logger log = Logger.getLogger(this.getClass().getName());\r
+       \r
+    class IppResponseTestImpl implements IppResponse {\r
+        \r
+        IppStatus status;\r
+        Map attributes;\r
+\r
+        IppResponseTestImpl() {\r
+\r
+        }\r
+\r
+        /**\r
+         * @return\r
+         */\r
+        public Map getAttributes() {\r
+            return attributes;\r
+        }\r
+\r
+        /**\r
+         * @return\r
+         */\r
+        public IppStatus getStatus() {\r
+            return status;\r
+        }\r
+\r
+    }\r
+\r
+    private IppResponseTestImpl response;\r
+    private Object data;\r
+    private OperationsSupported operation;\r
+    //Id wird in der Cups-API zwar übergeben, ist aber auch immer 1.\r
+    private PrintJobAttributeSet jobAttributes = new HashPrintJobAttributeSet();\r
+    private AttributeSet operationAttributes = new HashAttributeSet();\r
+    private AttributeSet printerAttributes = new HashAttributeSet();\r
+\r
+    /**\r
+     * @param printerAttributes\r
+     */\r
+    public void setPrinterAttributes(AttributeSet attrs) {\r
+        this.printerAttributes = attrs;\r
+    }\r
+\r
+    /**\r
+     * @param operation\r
+     */\r
+    public IppRequestTestImpl(URI path, OperationsSupported operation) {\r
+        this.operation = operation;\r
+        init();\r
+    }\r
+\r
+    /**\r
+     * \r
+     */\r
+    private void init() {\r
+        setStandardAttributes();\r
+    }\r
+\r
+    /**\r
+     * \r
+     */\r
+    private void setStandardAttributes() {\r
+        operationAttributes.add(Charset.ISO_8859_1);\r
+        operationAttributes.add(NaturalLanguage.EN);\r
+    }\r
+\r
+    /**\r
+     * @param attributes\r
+     */\r
+    public void addOperationAttributes(AttributeSet attributes) {\r
+        this.operationAttributes.addAll(attributes);\r
+    }\r
+\r
+    /**\r
+     * @param data the data as input stream\r
+     * @param the size of the data\r
+     */\r
+    public void setData(InputStream data) {\r
+        this.data = data;\r
+    }\r
+    /**\r
+     * @param data\r
+     */\r
+    public void setData(byte[] data) {\r
+        this.data = data;\r
+    }\r
+\r
+    /**\r
+     * @param attributes\r
+     */\r
+    public void setJobAttributes(PrintJobAttributeSet attributes) {\r
+        this.jobAttributes = attributes;\r
+    }\r
+\r
+    public IppResponse send() throws IOException {\r
+       try {\r
+       this.response = new IppResponseTestImpl();\r
+        this.send(this.operation);\r
+       } catch (Exception e){\r
+               throw new RuntimeException(e);\r
+       }\r
+       return response;\r
+    }\r
+\r
+    /**\r
+     * @param supported\r
+     */\r
+    private void send(OperationsSupported operation) throws URISyntaxException {\r
+       if (operation.equals(OperationsSupported.GET_PRINTER_ATTRIBUTES)) {\r
+           sendGetPrinterAttributes();\r
+        } else if (operation.equals(OperationsSupported.CUPS_GET_PRINTERS)) {\r
+                       sendCupsGetPrinter();\r
+        } else{\r
+               log.warning("Call to request " + operation.toString() + " not implemented");\r
+               this.response.attributes = new HashMap();\r
+        }\r
+               response.status = IppStatus.SUCCESSFUL_OK;\r
+    }\r
+\r
+    /**\r
+     * \r
+     */\r
+    private void sendCupsGetPrinter() throws URISyntaxException {\r
+       Map attributes = new HashMap();\r
+       Set printerUris = new HashSet();\r
+       printerUris.add(new PrinterUriSupported(new URI("http://127.0.0.1")));\r
+       attributes.put(IppAttributeName.PRINTER_URI_SUPPORTED.getCategory(),printerUris);\r
+       this.response.attributes = attributes;\r
+    }\r
+\r
+    /**\r
+     * \r
+     */\r
+    private void sendGetPrinterAttributes() throws URISyntaxException {\r
+        //     \r
+        //             - Printer attributes that are Job Template attributes ("xxx-\r
+        //                             default" "xxx-supported", and "xxx-ready" in the Table in\r
+        //                             Section 4.2),\r
+        //                       - "pdl-override-supported",\r
+        //                       - "compression-supported",\r
+        //                       - "job-k-octets-supported",\r
+        //                       - "job-impressions-supported",\r
+        //                       - "job-media-sheets-supported",\r
+        //                       - "printer-driver-installer",\r
+        //                       - "color-supported", and\r
+        //                       - "reference-uri-schemes-supported"\r
+\r
+        Map attributes = new HashMap();\r
+        Set pdlOverride = new HashSet();\r
+        pdlOverride.add(PDLOverrideSupported.ATTEMPTED);\r
+        pdlOverride.add(PDLOverrideSupported.NOT_ATTEMPTED);\r
+        attributes.put(IppAttributeName.PDL_OVERRIDE_SUPPORTED.getCategory(), pdlOverride);\r
+        Set compression = new HashSet();\r
+        compression.add(new CompressionSupported(Compression.GZIP.toString(), Locale.getDefault()));\r
+        compression.add(new CompressionSupported(Compression.NONE.toString(), Locale.getDefault()));\r
+        attributes.put(IppAttributeName.COMPRESSION_SUPORTED.getCategory(), compression);\r
+        Set jobKOctets = new HashSet();\r
+        jobKOctets.add(new JobKOctetsSupported(1, 10));\r
+        attributes.put(IppAttributeName.JOB_K_OCTETS_SUPPORTED.getCategory(), jobKOctets);\r
+        Set jobImpressions = new HashSet();\r
+        jobImpressions.add(new JobImpressionsSupported(1, 10));\r
+        attributes.put(IppAttributeName.JOB_IMPRESSIONS_SUPPORTED.getCategory(), jobImpressions);\r
+        Set jobMediaSheets = new HashSet();\r
+        jobMediaSheets.add(new JobMediaSheetsSupported(1, 10));\r
+        attributes.put(IppAttributeName.JOB_MEDIA_SHEETS_SUPPORTED.getCategory(), jobMediaSheets);\r
+        Set printerDriverInst = new HashSet();\r
+        printerDriverInst.add(new PrinterDriverInstaller(new URI("http://127.0.0.1")));\r
+        attributes.put(IppAttributeName.PRINTER_DRIVER_INSTALLER.getCategory(), printerDriverInst);\r
+        Set color = new HashSet();\r
+        color.add(ColorSupported.SUPPORTED);\r
+        attributes.put(IppAttributeName.COLOR_SUPPORTED.getCategory(), color);\r
+        Set refUriScheme = new HashSet();\r
+        refUriScheme.add(ReferenceUriSchemesSupported.HTTP);\r
+        refUriScheme.add(ReferenceUriSchemesSupported.FTP);\r
+        attributes.put(IppAttributeName.REFERENCE_URI_SCHEMES_SUPPORTED.getCategory(), refUriScheme);\r
+\r
+        //Attributes named in 4.2 of rfc2911\r
+        Set jobPrio = new HashSet();\r
+        jobPrio.add(new JobPrioritySupported(99));\r
+        attributes.put(IppAttributeName.JOB_PRIORIY_SUPPORTED.getCategory(), jobPrio);\r
+        Set jobHoldUntil = new HashSet();\r
+        jobHoldUntil.add(new JobHoldUntilSupported(new LdJobHoldUntil("12:00:00",Locale.getDefault()).toString(),Locale.getDefault()));\r
+        jobHoldUntil.add(new JobHoldUntilSupported(LdJobHoldUntil.THIRD_SHIFT.toString(),Locale.getDefault()));\r
+        attributes.put(IppAttributeName.JOB_HOLD_UNTIL_SUPPORTED.getCategory(), jobHoldUntil);\r
+        Set jobSheets = new HashSet();\r
+        jobSheets.add(new JobSheetsSupported(JobSheets.NONE.toString(), Locale.getDefault()));\r
+        jobSheets.add(new JobSheetsSupported(JobSheets.STANDARD.toString(), Locale.getDefault()));\r
+        attributes.put(IppAttributeName.JOB_SHEETS_SUPORTED.getCategory(), jobSheets);\r
+        Set multipleDocumentHandling = new HashSet();\r
+        multipleDocumentHandling.add(\r
+            new MultipleDocumentHandlingSupported(\r
+                MultipleDocumentHandling.SEPARATE_DOCUMENTS_COLLATED_COPIES.toString(),\r
+                Locale.getDefault()));\r
+        multipleDocumentHandling.add(\r
+            new MultipleDocumentHandlingSupported(\r
+                MultipleDocumentHandling.SINGLE_DOCUMENT.toString(),\r
+                Locale.getDefault()));\r
+        attributes.put(\r
+            IppAttributeName.MULTIPLE_DOCUMENT_HANDLING_SUPPORTED.getCategory(),\r
+            multipleDocumentHandling);\r
+        Set copies = new HashSet();\r
+        copies.add(new CopiesSupported(1, 100));\r
+        attributes.put(IppAttributeName.COPIES_SUPPORTED.getCategory(), copies);\r
+        Set finishings = new HashSet();\r
+        finishings.add(new FinishingsSupported(1));\r
+        finishings.add(new FinishingsSupported(2));\r
+        attributes.put(IppAttributeName.FINISHINGS_SUPPORTED.getCategory(), finishings);\r
+        Set pageRanges = new HashSet();\r
+        pageRanges.add(PageRangesSupported.SUPPORTED);\r
+        attributes.put(IppAttributeName.PAGE_RANGES_SUPPORTED.getCategory(), pageRanges);\r
+        Set sides = new HashSet();\r
+        sides.add(new SidesSupported(Sides.DUPLEX.toString(), Locale.getDefault()));\r
+        sides.add(new SidesSupported(Sides.TWO_SIDED_SHORT_EDGE.toString(), Locale.getDefault()));\r
+        attributes.put(IppAttributeName.SIDES_SUPPORTED.getCategory(), sides);\r
+        Set numberUp = new HashSet();\r
+        numberUp.add(new NumberUpSupported(1, 10));\r
+        numberUp.add(new NumberUpSupported(100));\r
+        attributes.put(IppAttributeName.NUMBER_UP_SUPPORTED.getCategory(), numberUp);\r
+        Set orientationReq = new HashSet();\r
+        orientationReq.add(new OrientationRequestedSupported(OrientationRequested.LANDSCAPE.getValue()));\r
+        orientationReq.add(new OrientationRequestedSupported(OrientationRequested.PORTRAIT.getValue()));\r
+        attributes.put(IppAttributeName.ORIENTATION_REQUESTED_SUPPORTED.getCategory(), orientationReq);\r
+        Set media = new HashSet();\r
+        media.add(new MediaSupported("test", Locale.getDefault()));\r
+        media.add(new MediaSupported("test2", Locale.getDefault()));\r
+        attributes.put(IppAttributeName.MEDIA_SUPPORTED.getCategory(), media);\r
+        //media-ready not implemented\r
+        //printer-resolution-supported not implemented\r
+               //print-quality-supported not implemented\r
+               response.attributes = attributes;\r
+               \r
+    }\r
+\r
+    private IppResponse getResponse() throws IOException {\r
+        return this.response;\r
+    }\r
+}\r