2 * Copyright (C) 2003 <a href="http://www.lohndirekt.de/">lohndirekt.de</a>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 package de
.lohndirekt
.print
.test
;
21 import java
.io
.IOException
;
22 import java
.io
.InputStream
;
24 import java
.net
.URISyntaxException
;
25 import java
.util
.HashMap
;
26 import java
.util
.HashSet
;
27 import java
.util
.Locale
;
30 import java
.util
.logging
.Logger
;
32 import javax
.print
.attribute
.AttributeSet
;
33 import javax
.print
.attribute
.HashAttributeSet
;
34 import javax
.print
.attribute
.HashPrintJobAttributeSet
;
35 import javax
.print
.attribute
.PrintJobAttributeSet
;
36 import javax
.print
.attribute
.standard
.ColorSupported
;
37 import javax
.print
.attribute
.standard
.Compression
;
38 import javax
.print
.attribute
.standard
.CopiesSupported
;
39 import javax
.print
.attribute
.standard
.JobImpressionsSupported
;
40 import javax
.print
.attribute
.standard
.JobKOctetsSupported
;
41 import javax
.print
.attribute
.standard
.JobMediaSheetsSupported
;
42 import javax
.print
.attribute
.standard
.JobPrioritySupported
;
43 import javax
.print
.attribute
.standard
.JobSheets
;
44 import javax
.print
.attribute
.standard
.MultipleDocumentHandling
;
45 import javax
.print
.attribute
.standard
.NumberUpSupported
;
46 import javax
.print
.attribute
.standard
.OrientationRequested
;
47 import javax
.print
.attribute
.standard
.PDLOverrideSupported
;
48 import javax
.print
.attribute
.standard
.ReferenceUriSchemesSupported
;
49 import javax
.print
.attribute
.standard
.Sides
;
51 import de
.lohndirekt
.print
.IppRequest
;
52 import de
.lohndirekt
.print
.IppResponse
;
53 import de
.lohndirekt
.print
.attribute
.IppAttributeName
;
54 import de
.lohndirekt
.print
.attribute
.IppStatus
;
55 import de
.lohndirekt
.print
.attribute
.ipp
.Charset
;
56 import de
.lohndirekt
.print
.attribute
.ipp
.NaturalLanguage
;
57 import de
.lohndirekt
.print
.attribute
.ipp
.jobtempl
.LdJobHoldUntil
;
58 import de
.lohndirekt
.print
.attribute
.ipp
.printerdesc
.PrinterDriverInstaller
;
59 import de
.lohndirekt
.print
.attribute
.ipp
.printerdesc
.supported
.CompressionSupported
;
60 import de
.lohndirekt
.print
.attribute
.ipp
.printerdesc
.supported
.FinishingsSupported
;
61 import de
.lohndirekt
.print
.attribute
.ipp
.printerdesc
.supported
.JobHoldUntilSupported
;
62 import de
.lohndirekt
.print
.attribute
.ipp
.printerdesc
.supported
.JobSheetsSupported
;
63 import de
.lohndirekt
.print
.attribute
.ipp
.printerdesc
.supported
.MediaSupported
;
64 import de
.lohndirekt
.print
.attribute
.ipp
.printerdesc
.supported
.MultipleDocumentHandlingSupported
;
65 import de
.lohndirekt
.print
.attribute
.ipp
.printerdesc
.supported
.OperationsSupported
;
66 import de
.lohndirekt
.print
.attribute
.ipp
.printerdesc
.supported
.OrientationRequestedSupported
;
67 import de
.lohndirekt
.print
.attribute
.ipp
.printerdesc
.supported
.PageRangesSupported
;
68 import de
.lohndirekt
.print
.attribute
.ipp
.printerdesc
.supported
.PrinterUriSupported
;
69 import de
.lohndirekt
.print
.attribute
.ipp
.printerdesc
.supported
.SidesSupported
;
71 public class IppRequestTestImpl
implements IppRequest
{
72 private Logger log
= Logger
.getLogger(this.getClass().getName());
74 class IppResponseTestImpl
implements IppResponse
{
79 IppResponseTestImpl() {
86 public Map
getAttributes() {
93 public IppStatus
getStatus() {
99 private IppResponseTestImpl response
;
101 private OperationsSupported operation
;
102 //Id wird in der Cups-API zwar übergeben, ist aber auch immer 1.
103 private PrintJobAttributeSet jobAttributes
= new HashPrintJobAttributeSet();
104 private AttributeSet operationAttributes
= new HashAttributeSet();
105 private AttributeSet printerAttributes
= new HashAttributeSet();
108 * @param printerAttributes
110 public void setPrinterAttributes(AttributeSet attrs
) {
111 this.printerAttributes
= attrs
;
117 public IppRequestTestImpl(URI path
, OperationsSupported operation
) {
118 this.operation
= operation
;
125 private void init() {
126 setStandardAttributes();
132 private void setStandardAttributes() {
133 operationAttributes
.add(Charset
.ISO_8859_1
);
134 operationAttributes
.add(NaturalLanguage
.EN
);
140 public void addOperationAttributes(AttributeSet attributes
) {
141 this.operationAttributes
.addAll(attributes
);
145 * @param data the data as input stream
146 * @param the size of the data
148 public void setData(InputStream data
) {
154 public void setData(byte[] data
) {
161 public void setJobAttributes(PrintJobAttributeSet attributes
) {
162 this.jobAttributes
= attributes
;
165 public IppResponse
send() throws IOException
{
167 this.response
= new IppResponseTestImpl();
168 this.send(this.operation
);
169 } catch (Exception e
){
170 throw new RuntimeException(e
);
178 private void send(OperationsSupported operation
) throws URISyntaxException
{
179 if (operation
.equals(OperationsSupported
.GET_PRINTER_ATTRIBUTES
)) {
180 sendGetPrinterAttributes();
181 } else if (operation
.equals(OperationsSupported
.CUPS_GET_PRINTERS
)) {
182 sendCupsGetPrinter();
184 log
.warning("Call to request " + operation
.toString() + " not implemented");
185 this.response
.attributes
= new HashMap();
187 response
.status
= IppStatus
.SUCCESSFUL_OK
;
193 private void sendCupsGetPrinter() throws URISyntaxException
{
194 Map attributes
= new HashMap();
195 Set printerUris
= new HashSet();
196 printerUris
.add(new PrinterUriSupported(new URI("http://127.0.0.1")));
197 attributes
.put(IppAttributeName
.PRINTER_URI_SUPPORTED
.getCategory(),printerUris
);
198 this.response
.attributes
= attributes
;
204 private void sendGetPrinterAttributes() throws URISyntaxException
{
206 // - Printer attributes that are Job Template attributes ("xxx-
207 // default" "xxx-supported", and "xxx-ready" in the Table in
209 // - "pdl-override-supported",
210 // - "compression-supported",
211 // - "job-k-octets-supported",
212 // - "job-impressions-supported",
213 // - "job-media-sheets-supported",
214 // - "printer-driver-installer",
215 // - "color-supported", and
216 // - "reference-uri-schemes-supported"
218 Map attributes
= new HashMap();
219 Set pdlOverride
= new HashSet();
220 pdlOverride
.add(PDLOverrideSupported
.ATTEMPTED
);
221 pdlOverride
.add(PDLOverrideSupported
.NOT_ATTEMPTED
);
222 attributes
.put(IppAttributeName
.PDL_OVERRIDE_SUPPORTED
.getCategory(), pdlOverride
);
223 Set compression
= new HashSet();
224 compression
.add(new CompressionSupported(Compression
.GZIP
.toString(), Locale
.getDefault()));
225 compression
.add(new CompressionSupported(Compression
.NONE
.toString(), Locale
.getDefault()));
226 attributes
.put(IppAttributeName
.COMPRESSION_SUPORTED
.getCategory(), compression
);
227 Set jobKOctets
= new HashSet();
228 jobKOctets
.add(new JobKOctetsSupported(1, 10));
229 attributes
.put(IppAttributeName
.JOB_K_OCTETS_SUPPORTED
.getCategory(), jobKOctets
);
230 Set jobImpressions
= new HashSet();
231 jobImpressions
.add(new JobImpressionsSupported(1, 10));
232 attributes
.put(IppAttributeName
.JOB_IMPRESSIONS_SUPPORTED
.getCategory(), jobImpressions
);
233 Set jobMediaSheets
= new HashSet();
234 jobMediaSheets
.add(new JobMediaSheetsSupported(1, 10));
235 attributes
.put(IppAttributeName
.JOB_MEDIA_SHEETS_SUPPORTED
.getCategory(), jobMediaSheets
);
236 Set printerDriverInst
= new HashSet();
237 printerDriverInst
.add(new PrinterDriverInstaller(new URI("http://127.0.0.1")));
238 attributes
.put(IppAttributeName
.PRINTER_DRIVER_INSTALLER
.getCategory(), printerDriverInst
);
239 Set color
= new HashSet();
240 color
.add(ColorSupported
.SUPPORTED
);
241 attributes
.put(IppAttributeName
.COLOR_SUPPORTED
.getCategory(), color
);
242 Set refUriScheme
= new HashSet();
243 refUriScheme
.add(ReferenceUriSchemesSupported
.HTTP
);
244 refUriScheme
.add(ReferenceUriSchemesSupported
.FTP
);
245 attributes
.put(IppAttributeName
.REFERENCE_URI_SCHEMES_SUPPORTED
.getCategory(), refUriScheme
);
247 //Attributes named in 4.2 of rfc2911
248 Set jobPrio
= new HashSet();
249 jobPrio
.add(new JobPrioritySupported(99));
250 attributes
.put(IppAttributeName
.JOB_PRIORIY_SUPPORTED
.getCategory(), jobPrio
);
251 Set jobHoldUntil
= new HashSet();
252 jobHoldUntil
.add(new JobHoldUntilSupported(new LdJobHoldUntil("12:00:00",Locale
.getDefault()).toString(),Locale
.getDefault()));
253 jobHoldUntil
.add(new JobHoldUntilSupported(LdJobHoldUntil
.THIRD_SHIFT
.toString(),Locale
.getDefault()));
254 attributes
.put(IppAttributeName
.JOB_HOLD_UNTIL_SUPPORTED
.getCategory(), jobHoldUntil
);
255 Set jobSheets
= new HashSet();
256 jobSheets
.add(new JobSheetsSupported(JobSheets
.NONE
.toString(), Locale
.getDefault()));
257 jobSheets
.add(new JobSheetsSupported(JobSheets
.STANDARD
.toString(), Locale
.getDefault()));
258 attributes
.put(IppAttributeName
.JOB_SHEETS_SUPORTED
.getCategory(), jobSheets
);
259 Set multipleDocumentHandling
= new HashSet();
260 multipleDocumentHandling
.add(
261 new MultipleDocumentHandlingSupported(
262 MultipleDocumentHandling
.SEPARATE_DOCUMENTS_COLLATED_COPIES
.toString(),
263 Locale
.getDefault()));
264 multipleDocumentHandling
.add(
265 new MultipleDocumentHandlingSupported(
266 MultipleDocumentHandling
.SINGLE_DOCUMENT
.toString(),
267 Locale
.getDefault()));
269 IppAttributeName
.MULTIPLE_DOCUMENT_HANDLING_SUPPORTED
.getCategory(),
270 multipleDocumentHandling
);
271 Set copies
= new HashSet();
272 copies
.add(new CopiesSupported(1, 100));
273 attributes
.put(IppAttributeName
.COPIES_SUPPORTED
.getCategory(), copies
);
274 Set finishings
= new HashSet();
275 finishings
.add(new FinishingsSupported(1));
276 finishings
.add(new FinishingsSupported(2));
277 attributes
.put(IppAttributeName
.FINISHINGS_SUPPORTED
.getCategory(), finishings
);
278 Set pageRanges
= new HashSet();
279 pageRanges
.add(PageRangesSupported
.SUPPORTED
);
280 attributes
.put(IppAttributeName
.PAGE_RANGES_SUPPORTED
.getCategory(), pageRanges
);
281 Set sides
= new HashSet();
282 sides
.add(new SidesSupported(Sides
.DUPLEX
.toString(), Locale
.getDefault()));
283 sides
.add(new SidesSupported(Sides
.TWO_SIDED_SHORT_EDGE
.toString(), Locale
.getDefault()));
284 attributes
.put(IppAttributeName
.SIDES_SUPPORTED
.getCategory(), sides
);
285 Set numberUp
= new HashSet();
286 numberUp
.add(new NumberUpSupported(1, 10));
287 numberUp
.add(new NumberUpSupported(100));
288 attributes
.put(IppAttributeName
.NUMBER_UP_SUPPORTED
.getCategory(), numberUp
);
289 Set orientationReq
= new HashSet();
290 orientationReq
.add(new OrientationRequestedSupported(OrientationRequested
.LANDSCAPE
.getValue()));
291 orientationReq
.add(new OrientationRequestedSupported(OrientationRequested
.PORTRAIT
.getValue()));
292 attributes
.put(IppAttributeName
.ORIENTATION_REQUESTED_SUPPORTED
.getCategory(), orientationReq
);
293 Set media
= new HashSet();
294 media
.add(new MediaSupported("test", Locale
.getDefault()));
295 media
.add(new MediaSupported("test2", Locale
.getDefault()));
296 attributes
.put(IppAttributeName
.MEDIA_SUPPORTED
.getCategory(), media
);
297 //media-ready not implemented
298 //printer-resolution-supported not implemented
299 //print-quality-supported not implemented
300 response
.attributes
= attributes
;
304 private IppResponse
getResponse() throws IOException
{
305 return this.response
;