3ea135bb |
1 | /**\r |
2 | * Copyright (C) 2003 <a href="http://www.lohndirekt.de/">lohndirekt.de</a>\r |
3 | *\r |
4 | * This library is free software; you can redistribute it and/or\r |
5 | * modify it under the terms of the GNU Lesser General Public\r |
6 | * License as published by the Free Software Foundation; either\r |
7 | * version 2.1 of the License, or (at your option) any later version.\r |
8 | * \r |
9 | * This library is distributed in the hope that it will be useful,\r |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of\r |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r |
12 | * Lesser General Public License for more details.\r |
13 | * \r |
14 | * You should have received a copy of the GNU Lesser General Public\r |
15 | * License along with this library; if not, write to the Free Software\r |
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r |
17 | * \r |
18 | */\r |
19 | package de.lohndirekt.print;\r |
20 | import java.io.IOException;\r |
21 | import java.net.URI;\r |
22 | import java.util.ArrayList;\r |
23 | import java.util.Arrays;\r |
24 | import java.util.HashSet;\r |
25 | import java.util.Iterator;\r |
26 | import java.util.List;\r |
27 | import java.util.Locale;\r |
28 | import java.util.Map;\r |
29 | import java.util.Set;\r |
30 | import java.util.logging.Level;\r |
31 | import java.util.logging.Logger;\r |
32 | \r |
33 | import javax.print.DocFlavor;\r |
34 | import javax.print.DocPrintJob;\r |
35 | import javax.print.PrintException;\r |
36 | import javax.print.PrintService;\r |
37 | import javax.print.ServiceUIFactory;\r |
38 | import javax.print.attribute.*;\r |
39 | import javax.print.attribute.standard.PrinterURI;\r |
40 | import javax.print.attribute.standard.RequestingUserName;\r |
41 | import javax.print.event.PrintServiceAttributeListener;\r |
42 | \r |
43 | import de.lohndirekt.print.attribute.IppAttributeName;\r |
44 | import de.lohndirekt.print.attribute.IppStatus;\r |
45 | import de.lohndirekt.print.attribute.auth.RequestingUserPassword;\r |
46 | import de.lohndirekt.print.attribute.ipp.DocumentFormat;\r |
47 | import de.lohndirekt.print.attribute.ipp.jobdesc.JobId;\r |
48 | import de.lohndirekt.print.attribute.ipp.printerdesc.supported.DocumentFormatSupported;\r |
49 | import de.lohndirekt.print.attribute.ipp.printerdesc.supported.OperationsSupported;\r |
50 | \r |
51 | /**\r |
52 | * @author bpusch\r |
53 | *\r |
54 | * \r |
55 | */\r |
56 | public class IppPrintService implements PrintService {\r |
57 | \r |
58 | private final Logger log = Logger.getLogger(this.getClass().getName());\r |
59 | private DocFlavor[] supportedFlavors = null;\r |
60 | private URI uri;\r |
61 | private RequestingUserName requestingUserName = null;\r |
62 | private RequestingUserPassword requestingUserPassword = null;\r |
63 | private Map attributes = null;\r |
64 | \r |
65 | /**\r |
66 | * @param uri\r |
67 | */\r |
68 | public IppPrintService(URI uri) {\r |
69 | this.uri = uri;\r |
70 | }\r |
71 | \r |
72 | \r |
73 | \r |
74 | /**\r |
75 | * @return\r |
76 | */\r |
77 | URI getUri() {\r |
78 | return this.uri;\r |
79 | }\r |
80 | \r |
81 | /* (non-Javadoc)\r |
82 | * @see javax.print.PrintService#getName()\r |
83 | */\r |
84 | public String getName() {\r |
85 | return uri.getPath().substring(uri.getPath().lastIndexOf("/") + 1);\r |
86 | }\r |
87 | \r |
88 | /**\r |
89 | * \r |
90 | */\r |
91 | public void reset() {\r |
92 | supportedFlavors = null;\r |
93 | attributes = null;\r |
94 | }\r |
95 | \r |
96 | /* (non-Javadoc)\r |
97 | * @see javax.print.PrintService#createPrintJob()\r |
98 | */\r |
99 | public DocPrintJob createPrintJob() {\r |
100 | return new CancelableJob(this);\r |
101 | }\r |
102 | \r |
103 | /* (non-Javadoc)\r |
104 | * @see javax.print.PrintService#getAttributes()\r |
105 | */\r |
106 | public PrintServiceAttributeSet getAttributes() {\r |
107 | PrintServiceAttributeSet set = new HashPrintServiceAttributeSet();\r |
108 | for (Iterator mapIter = getAllAttributes().values().iterator(); mapIter.hasNext();) {\r |
109 | Set values = (Set) mapIter.next();\r |
110 | for (Iterator listIter = values.iterator(); listIter.hasNext();) {\r |
111 | Attribute attribute = (Attribute) listIter.next();\r |
112 | if (attribute instanceof PrintServiceAttribute) {\r |
113 | set.add(attribute);\r |
114 | }\r |
115 | }\r |
116 | }\r |
117 | return set;\r |
118 | }\r |
119 | \r |
120 | /* (non-Javadoc)\r |
121 | * @see javax.print.PrintService#getAttribute(java.lang.Class)\r |
122 | */\r |
123 | public PrintServiceAttribute getAttribute(Class category) {\r |
124 | if (category == null) {\r |
125 | throw new NullPointerException("category must not be null");\r |
126 | }\r |
127 | //TODO As CUPS seems not to support this operation-tag (requested-attributes), we need to get all attributes\r |
128 | Set attributes = (Set) getAllAttributes().get(category);\r |
129 | if (attributes != null) {\r |
130 | try {\r |
131 | return (PrintServiceAttribute) attributes.iterator().next();\r |
132 | } catch (ClassCastException e) {\r |
133 | throw new IllegalArgumentException("category must be a Class that implements interface PrintServiceAttribute");\r |
134 | }\r |
135 | }\r |
136 | return null;\r |
137 | }\r |
138 | \r |
139 | /* (non-Javadoc)\r |
140 | * @see javax.print.PrintService#getSupportedDocFlavors()\r |
141 | */\r |
142 | public DocFlavor[] getSupportedDocFlavors() {\r |
143 | if (supportedFlavors == null) {\r |
144 | List flavors = new ArrayList();\r |
145 | Set flavorAttributes =\r |
146 | (Set) getAllAttributes().get(IppAttributeName.DOCUMENT_FORMAT_SUPORTED.getCategory());\r |
147 | if (flavorAttributes != null) {\r |
148 | for (Iterator iter = flavorAttributes.iterator(); iter.hasNext();) {\r |
149 | Attribute attribute = (Attribute) iter.next();\r |
150 | String mimeType = ((DocumentFormatSupported) attribute).getValue();\r |
151 | if (mimeType.equals(DocFlavor.BYTE_ARRAY.AUTOSENSE.getMimeType())) {\r |
152 | flavors.add(DocFlavor.INPUT_STREAM.AUTOSENSE);\r |
153 | } else if (mimeType.equals(DocFlavor.BYTE_ARRAY.GIF.getMimeType())) {\r |
154 | flavors.add(DocFlavor.INPUT_STREAM.GIF);\r |
155 | } else if (mimeType.equals(DocFlavor.BYTE_ARRAY.JPEG.getMimeType())) {\r |
156 | flavors.add(DocFlavor.INPUT_STREAM.JPEG);\r |
157 | } else if (mimeType.equals(DocFlavor.BYTE_ARRAY.PCL.getMimeType())) {\r |
158 | flavors.add(DocFlavor.INPUT_STREAM.PCL);\r |
159 | } else if (mimeType.equals(DocFlavor.BYTE_ARRAY.PDF.getMimeType())) {\r |
160 | flavors.add(DocFlavor.INPUT_STREAM.PDF);\r |
161 | } else if (mimeType.equals(DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType())) {\r |
162 | flavors.add(DocFlavor.INPUT_STREAM.POSTSCRIPT);\r |
163 | } else if (mimeType.equals(DocFlavor.BYTE_ARRAY.PNG.getMimeType())) {\r |
164 | flavors.add(DocFlavor.INPUT_STREAM.PNG);\r |
165 | } else if (mimeType.equals(DocFlavor.BYTE_ARRAY.TEXT_HTML_HOST.getMimeType().substring(0, 9))) {\r |
166 | flavors.add(DocFlavor.INPUT_STREAM.TEXT_HTML_HOST);\r |
167 | } else if (mimeType.equals(DocFlavor.BYTE_ARRAY.TEXT_PLAIN_HOST.getMimeType().substring(0, 10))) {\r |
168 | flavors.add(DocFlavor.INPUT_STREAM.TEXT_PLAIN_HOST);\r |
169 | }\r |
170 | }\r |
171 | }\r |
172 | DocFlavor[] flavorArray = new DocFlavor[flavors.size()];\r |
173 | flavorArray = (DocFlavor[]) flavors.toArray(flavorArray);\r |
174 | supportedFlavors = flavorArray;\r |
175 | }\r |
176 | return supportedFlavors;\r |
177 | }\r |
178 | \r |
179 | /* (non-Javadoc)\r |
180 | * @see javax.print.PrintService#isDocFlavorSupported(javax.print.DocFlavor)\r |
181 | */\r |
182 | public boolean isDocFlavorSupported(DocFlavor flavor) {\r |
183 | List supportedFlavors = Arrays.asList(getSupportedDocFlavors());\r |
184 | return supportedFlavors.contains(flavor);\r |
185 | }\r |
186 | \r |
187 | /* (non-Javadoc)\r |
188 | * @see javax.print.PrintService#getSupportedAttributeCategories()\r |
189 | */\r |
190 | public Class[] getSupportedAttributeCategories() {\r |
191 | Set supportedCategories = new HashSet();\r |
192 | //Attributes named in 4.2 of rfc2911 are optional\r |
193 | if (getAllAttributes().containsKey(IppAttributeName.JOB_PRIORIY_SUPPORTED.getCategory())) {\r |
194 | supportedCategories.add(IppAttributeName.JOB_PRIORIY.getCategory());\r |
195 | }\r |
196 | if (getAllAttributes().containsKey(IppAttributeName.JOB_HOLD_UNTIL_SUPPORTED.getCategory())) {\r |
197 | supportedCategories.add(IppAttributeName.JOB_HOLD_UNTIL.getCategory());\r |
198 | }\r |
199 | if (getAllAttributes().containsKey(IppAttributeName.JOB_SHEETS_SUPORTED.getCategory())) {\r |
200 | supportedCategories.add(IppAttributeName.JOB_SHEETS.getCategory());\r |
201 | }\r |
202 | if (getAllAttributes().containsKey(IppAttributeName.MULTIPLE_DOCUMENT_HANDLING_SUPPORTED.getCategory())) {\r |
203 | supportedCategories.add(IppAttributeName.MULTIPLE_DOCUMENT_HANDLING.getCategory());\r |
204 | }\r |
205 | if (getAllAttributes().containsKey(IppAttributeName.COPIES_SUPPORTED.getCategory())) {\r |
206 | supportedCategories.add(IppAttributeName.COPIES.getCategory());\r |
207 | }\r |
208 | if (getAllAttributes().containsKey(IppAttributeName.FINISHINGS_SUPPORTED.getCategory())) {\r |
209 | supportedCategories.add(IppAttributeName.FINISHINGS.getCategory());\r |
210 | }\r |
211 | if (getAllAttributes().containsKey(IppAttributeName.PAGE_RANGES_SUPPORTED.getCategory())) {\r |
212 | supportedCategories.add(IppAttributeName.PAGE_RANGES.getCategory());\r |
213 | }\r |
214 | if (getAllAttributes().containsKey(IppAttributeName.SIDES_SUPPORTED.getCategory())) {\r |
215 | supportedCategories.add(IppAttributeName.SIDES.getCategory());\r |
216 | }\r |
217 | if (getAllAttributes().containsKey(IppAttributeName.NUMBER_UP_SUPPORTED.getCategory())) {\r |
218 | supportedCategories.add(IppAttributeName.NUMBER_UP.getCategory());\r |
219 | }\r |
220 | if (getAllAttributes().containsKey(IppAttributeName.ORIENTATION_REQUESTED_SUPPORTED.getCategory())) {\r |
221 | supportedCategories.add(IppAttributeName.ORIENTATION_REQUESTED.getCategory());\r |
222 | }\r |
223 | if (getAllAttributes().containsKey(IppAttributeName.MEDIA_SUPPORTED.getCategory())) {\r |
224 | supportedCategories.add(IppAttributeName.MEDIA.getCategory());\r |
225 | }\r |
226 | if (getAllAttributes().containsKey(IppAttributeName.PRINTER_RESOLUTION.getCategory())) {\r |
227 | //printer-resolution-supported attribute currently not implemented\r |
228 | }\r |
229 | if (getAllAttributes().containsKey(IppAttributeName.PRINT_QUALITY.getCategory())) {\r |
230 | //print-quality-supported attribute currently not implemented\r |
231 | }\r |
232 | if (getAllAttributes().containsKey(IppAttributeName.JOB_K_OCTETS_SUPPORTED.getCategory())) {\r |
233 | supportedCategories.add(IppAttributeName.JOB_K_OCTETS.getCategory());\r |
234 | }\r |
235 | if (getAllAttributes().containsKey(IppAttributeName.JOB_IMPRESSIONS_SUPPORTED.getCategory())) {\r |
236 | supportedCategories.add(IppAttributeName.JOB_IMPRESSIONS.getCategory());\r |
237 | }\r |
238 | if (getAllAttributes().containsKey(IppAttributeName.JOB_MEDIA_SHEETS_SUPPORTED.getCategory())) {\r |
239 | supportedCategories.add(IppAttributeName.JOB_MEDIA_SHEETS.getCategory());\r |
240 | }\r |
241 | //Printer object MUST support compression attribute\r |
242 | supportedCategories.add(IppAttributeName.COMPRESSION.getCategory());\r |
243 | Class[] categories = new Class[supportedCategories.size()];\r |
244 | categories = (Class[]) supportedCategories.toArray(categories);\r |
245 | return categories;\r |
246 | }\r |
247 | \r |
248 | /* (non-Javadoc)\r |
249 | * @see javax.print.PrintService#isAttributeCategorySupported(java.lang.Class)\r |
250 | */\r |
251 | public boolean isAttributeCategorySupported(Class category) {\r |
252 | return Arrays.asList(this.getSupportedAttributeCategories()).contains(category);\r |
253 | }\r |
254 | \r |
255 | /* (non-Javadoc)\r |
256 | * @see javax.print.PrintService#getDefaultAttributeValue(java.lang.Class)\r |
257 | */\r |
258 | public Object getDefaultAttributeValue(Class category) {\r |
259 | //Only the attributes listed in rfc2911 4.2(Job Template Attributes) make sense here\r |
260 | Object value = null;\r |
261 | if (category.equals(IppAttributeName.JOB_PRIORIY.getCategory())) {\r |
262 | Attribute attr = getAttribute(IppAttributeName.JOB_PRIORITY_DEFAULT.getCategory());\r |
263 | if (attr != null) {\r |
264 | value = new Integer(((IntegerSyntax) attr).getValue());\r |
265 | }\r |
266 | } else if (category.equals(IppAttributeName.JOB_HOLD_UNTIL.getCategory())) {\r |
267 | Attribute attr = getAttribute(IppAttributeName.JOB_HOLD_UNTIL.getCategory());\r |
268 | if (attr != null) {\r |
269 | value = new Integer(((TextSyntax) attr).getValue());\r |
270 | }\r |
271 | } else if (category.equals(IppAttributeName.JOB_SHEETS_DEFAULT.getCategory())) {\r |
272 | Attribute attr = getAttribute(IppAttributeName.JOB_SHEETS_DEFAULT.getCategory());\r |
273 | if (attr != null) {\r |
274 | value = new Integer(((TextSyntax) attr).getValue());\r |
275 | }\r |
276 | } else if (category.equals(IppAttributeName.COPIES.getCategory())) {\r |
277 | Attribute attr = getAttribute(IppAttributeName.COPIES_DEFAULT.getCategory());\r |
278 | if (attr != null) {\r |
279 | value = new Integer(((IntegerSyntax) attr).getValue());\r |
280 | }\r |
281 | } else if (category.equals(IppAttributeName.FINISHINGS.getCategory())) {\r |
282 | Attribute attr = getAttribute(IppAttributeName.FINISHINGS_DEFAULT.getCategory());\r |
283 | if (attr != null) {\r |
284 | value = new Integer(((IntegerSyntax) attr).toString());\r |
285 | }\r |
286 | } else if (category.equals(IppAttributeName.SIDES.getCategory())) {\r |
287 | Attribute attr = getAttribute(IppAttributeName.SIDES_DEFAULT.getCategory());\r |
288 | if (attr != null) {\r |
289 | value = new Integer(((TextSyntax) attr).getValue());\r |
290 | }\r |
291 | } else if (category.equals(IppAttributeName.NUMBER_UP.getCategory())) {\r |
292 | Attribute attr = getAttribute(IppAttributeName.NUMBER_UP_DEFAULT.getCategory());\r |
293 | if (attr != null) {\r |
294 | value = new Integer(((IntegerSyntax) attr).getValue());\r |
295 | }\r |
296 | } else if (category.equals(IppAttributeName.ORIENTATION_REQUESTED.getCategory())) {\r |
297 | Attribute attr = getAttribute(IppAttributeName.ORIENTATION_REQUESTED_DEFAULT.getCategory());\r |
298 | if (attr != null) {\r |
299 | value = ((TextSyntax) attr).getValue();\r |
300 | }\r |
301 | } else if (category.equals(IppAttributeName.MEDIA.getCategory())) {\r |
302 | Attribute attr = getAttribute(IppAttributeName.MEDIA_DEFAULT.getCategory());\r |
303 | if (attr != null) {\r |
304 | value = ((TextSyntax) attr).getValue();\r |
305 | }\r |
306 | } else if (category.equals(IppAttributeName.PRINTER_RESOLUTION.getCategory())) {\r |
307 | //Cups does not support the printer-resolution-default attribute\r |
308 | } else if (category.equals(IppAttributeName.PRINT_QUALITY.getCategory())) {\r |
309 | //Cups does not support the print-quality-default attribute\r |
310 | } else if (category.equals(IppAttributeName.MULTIPLE_DOCUMENT_HANDLING.getCategory())) {\r |
311 | Attribute attr = getAttribute(IppAttributeName.MULTIPLE_DOCUMENT_HANDLING_DEFAULT.getCategory());\r |
312 | if (attr != null) {\r |
313 | value = ((TextSyntax) attr).getValue();\r |
314 | }\r |
315 | }\r |
316 | return value;\r |
317 | }\r |
318 | \r |
319 | /* (non-Javadoc)\r |
320 | * @see javax.print.PrintService#getSupportedAttributeValues(java.lang.Class, javax.print.DocFlavor, javax.print.attribute.AttributeSet)\r |
321 | */\r |
322 | public Object getSupportedAttributeValues(Class category, DocFlavor flavor, AttributeSet attributes) {\r |
323 | Set supportedAttributes = new HashSet();\r |
324 | // Only the attributes listed in rfc2911 4.2(Job Template Attributes) do make sense here\r |
325 | if (category.equals(IppAttributeName.JOB_PRIORIY.getCategory())) {\r |
326 | supportedAttributes = (Set) getAllAttributes().get(IppAttributeName.JOB_PRIORIY_SUPPORTED.getCategory());\r |
327 | } else if (category.equals(IppAttributeName.JOB_HOLD_UNTIL.getCategory())) {\r |
328 | supportedAttributes = (Set) getAllAttributes().get(IppAttributeName.JOB_HOLD_UNTIL_SUPPORTED.getCategory());\r |
329 | } else if (category.equals(IppAttributeName.JOB_SHEETS.getCategory())) {\r |
330 | supportedAttributes = (Set) getAllAttributes().get(IppAttributeName.JOB_SHEETS_SUPORTED.getCategory());\r |
331 | } else if (category.equals(IppAttributeName.MULTIPLE_DOCUMENT_HANDLING.getCategory())) {\r |
332 | supportedAttributes =\r |
333 | (Set) getAllAttributes().get(IppAttributeName.MULTIPLE_DOCUMENT_HANDLING_SUPPORTED.getCategory());\r |
334 | } else if (category.equals(IppAttributeName.COPIES.getCategory())) {\r |
335 | supportedAttributes = (Set) getAllAttributes().get(IppAttributeName.COPIES_SUPPORTED.getCategory());\r |
336 | } else if (category.equals(IppAttributeName.FINISHINGS.getCategory())) {\r |
337 | supportedAttributes = (Set) getAllAttributes().get(IppAttributeName.FINISHINGS_SUPPORTED.getCategory());\r |
338 | } else if (category.equals(IppAttributeName.SIDES.getCategory())) {\r |
339 | supportedAttributes = (Set) getAllAttributes().get(IppAttributeName.SIDES_SUPPORTED.getCategory());\r |
340 | }\r |
341 | //TODO page-ranges\r |
342 | else if (category.equals(IppAttributeName.NUMBER_UP.getCategory())) {\r |
343 | supportedAttributes = (Set) getAllAttributes().get(IppAttributeName.NUMBER_UP_SUPPORTED.getCategory());\r |
344 | } else if (category.equals(IppAttributeName.ORIENTATION_REQUESTED.getCategory())) {\r |
345 | supportedAttributes =\r |
346 | (Set) getAllAttributes().get(IppAttributeName.ORIENTATION_REQUESTED_SUPPORTED.getCategory());\r |
347 | } else if (category.equals(IppAttributeName.MEDIA.getCategory())) {\r |
348 | supportedAttributes = (Set) getAllAttributes().get(IppAttributeName.MEDIA_SUPPORTED.getCategory());\r |
349 | } else if (category.equals(IppAttributeName.PRINTER_RESOLUTION)) {\r |
350 | //printer-resolution-supported attribute currently not implemented\r |
351 | } else if (category.equals(IppAttributeName.PRINT_QUALITY.getCategory())) {\r |
352 | //printer-quality-supported attribute currently not implemented\r |
353 | } else if (category.equals(IppAttributeName.MULTIPLE_DOCUMENT_HANDLING.getCategory())) {\r |
354 | supportedAttributes =\r |
355 | (Set) getAllAttributes().get(IppAttributeName.MULTIPLE_DOCUMENT_HANDLING_SUPPORTED.getCategory());\r |
356 | } else if (category.equals(IppAttributeName.JOB_IMPRESSIONS.getCategory())) {\r |
357 | supportedAttributes =\r |
358 | (Set) getAllAttributes().get(IppAttributeName.JOB_IMPRESSIONS_SUPPORTED.getCategory());\r |
359 | } else if (category.equals(IppAttributeName.JOB_K_OCTETS.getCategory())) {\r |
360 | supportedAttributes = (Set) getAllAttributes().get(IppAttributeName.JOB_K_OCTETS_SUPPORTED.getCategory());\r |
361 | } else if (category.equals(IppAttributeName.JOB_MEDIA_SHEETS.getCategory())) {\r |
362 | supportedAttributes =\r |
363 | (Set) getAllAttributes().get(IppAttributeName.JOB_MEDIA_SHEETS_SUPPORTED.getCategory());\r |
364 | } else if (category.equals(IppAttributeName.COMPRESSION.getCategory())) {\r |
365 | supportedAttributes = (Set) getAllAttributes().get(IppAttributeName.COMPRESSION_SUPORTED.getCategory());\r |
366 | }\r |
367 | if (supportedAttributes == null) {\r |
368 | supportedAttributes = new HashSet();\r |
369 | }\r |
370 | return supportedAttributes.toArray(new Attribute[supportedAttributes.size()]);\r |
371 | }\r |
372 | \r |
373 | /* (non-Javadoc)\r |
374 | * @see javax.print.PrintService#isAttributeValueSupported(javax.print.attribute.Attribute, javax.print.DocFlavor, javax.print.attribute.AttributeSet)\r |
375 | */\r |
376 | public boolean isAttributeValueSupported(Attribute attrVal, DocFlavor flavor, AttributeSet attributes) {\r |
377 | AttributeSet operationAttributes = new HashAttributeSet();\r |
378 | if (flavor != null) {\r |
379 | operationAttributes.add(new DocumentFormat(flavor.getMimeType(), Locale.getDefault()));\r |
380 | }\r |
381 | IppRequest request = this.request(OperationsSupported.VALIDATE_JOB);\r |
382 | if (attributes == null) {\r |
383 | attributes = new HashAttributeSet();\r |
384 | }\r |
385 | attributes.add(attrVal);\r |
386 | Object[] attributeArray = attributes.toArray();\r |
387 | PrintJobAttributeSet jobAttributes = new HashPrintJobAttributeSet();\r |
388 | for (int i = 0; i < attributeArray.length; i++) {\r |
389 | Attribute attribute = (Attribute) attributeArray[i];\r |
390 | //attributes-charset, attributes-natural-language etc. are not set by the user\r |
391 | if (attribute instanceof PrintRequestAttribute && attribute instanceof PrintJobAttribute) {\r |
392 | if (attribute.getCategory().equals(IppAttributeName.JOB_NAME.getCategory())\r |
393 | || attribute.getCategory().equals(IppAttributeName.FIDELITY.getCategory())\r |
394 | || attribute.getCategory().equals(IppAttributeName.JOB_IMPRESSIONS.getCategory())\r |
395 | || attribute.getCategory().equals(IppAttributeName.JOB_K_OCTETS.getCategory())\r |
396 | || attribute.getCategory().equals(IppAttributeName.JOB_MEDIA_SHEETS.getCategory())) {\r |
397 | operationAttributes.add(attribute);\r |
398 | } else if (\r |
399 | attribute.getCategory().equals(IppAttributeName.JOB_NAME.getCategory())\r |
400 | || attribute.getCategory().equals(IppAttributeName.FIDELITY.getCategory())) {\r |
401 | //do nothing, Job Template Attributes can not be used in a Validate-Job operation\r |
402 | } else {\r |
403 | jobAttributes.add(attribute);\r |
404 | }\r |
405 | }\r |
406 | }\r |
407 | request.addOperationAttributes(operationAttributes);\r |
408 | request.setJobAttributes(jobAttributes);\r |
409 | IppResponse response = null;\r |
410 | try {\r |
411 | response = request.send();\r |
412 | } catch (IOException e) {\r |
413 | log.log(Level.SEVERE, e.getMessage(), e);\r |
414 | }\r |
415 | boolean supported = false;\r |
416 | if (response != null) {\r |
417 | if (response.getStatus().equals(IppStatus.SUCCESSFUL_OK)\r |
418 | || response.getStatus().equals(IppStatus.SUCCESSFUL_OK_CONFLICTING_ATTRIBUTES)\r |
419 | || response.getStatus().equals(IppStatus.SUCCESSFUL_OK_CONFLICTING_ATTRIBUTES)) {\r |
420 | supported = true;\r |
421 | }\r |
422 | }\r |
423 | return supported;\r |
424 | }\r |
425 | \r |
426 | /* (non-Javadoc)\r |
427 | * @see javax.print.PrintService#getUnsupportedAttributes(javax.print.DocFlavor, javax.print.attribute.AttributeSet)\r |
428 | */\r |
429 | public AttributeSet getUnsupportedAttributes(DocFlavor flavor, AttributeSet attributes) {\r |
430 | return null;\r |
431 | }\r |
432 | \r |
433 | /* (non-Javadoc)\r |
434 | * @see javax.print.PrintService#getServiceUIFactory()\r |
435 | */\r |
436 | public ServiceUIFactory getServiceUIFactory() {\r |
437 | return null;\r |
438 | }\r |
439 | \r |
440 | /* (non-Javadoc)\r |
441 | * @see javax.print.PrintService#addPrintServiceAttributeListener(javax.print.event.PrintServiceAttributeListener)\r |
442 | */\r |
443 | public void addPrintServiceAttributeListener(PrintServiceAttributeListener listener) {\r |
444 | }\r |
445 | \r |
446 | /* (non-Javadoc)\r |
447 | * @see javax.print.PrintService#removePrintServiceAttributeListener(javax.print.event.PrintServiceAttributeListener)\r |
448 | */\r |
449 | public void removePrintServiceAttributeListener(PrintServiceAttributeListener listener) {\r |
450 | }\r |
451 | \r |
452 | /**\r |
453 | * @return\r |
454 | */\r |
455 | private Map getAllAttributes() {\r |
456 | if (this.attributes == null) {\r |
457 | IppRequest request = this.request(OperationsSupported.GET_PRINTER_ATTRIBUTES);\r |
458 | IppResponse response = null;\r |
459 | try {\r |
460 | response = request.send();\r |
461 | } catch (IOException e) {\r |
462 | log.log(Level.SEVERE, e.getMessage(), e);\r |
463 | }\r |
464 | if (response != null) {\r |
465 | this.attributes = response.getAttributes();\r |
466 | }\r |
467 | }\r |
468 | return this.attributes;\r |
469 | }\r |
470 | \r |
471 | public String toString() {\r |
472 | return this.getName();\r |
473 | }\r |
474 | \r |
475 | /**\r |
476 | * @param operation\r |
477 | * @return\r |
478 | */\r |
479 | protected IppRequest request(OperationsSupported operation) {\r |
480 | IppRequest request = IppRequestFactory.createIppRequest(this.uri, operation, this.getRequestingUserName(), this.getRequestingUserPassword());\r |
481 | AttributeSet operationAttributes = new HashAttributeSet();\r |
482 | operationAttributes.add(new PrinterURI(this.uri));\r |
483 | request.addOperationAttributes(operationAttributes);\r |
484 | return request;\r |
485 | }\r |
486 | \r |
487 | /**\r |
488 | * Returns a job with the given JobId, or null if no such\r |
489 | * Job exists.\r |
490 | * <br>\r |
491 | * Use jobExists to check for a Job with this JobId.\r |
492 | * <br>\r |
493 | * This method might return a Job which is not hold by this PrintService\r |
494 | * but the same CUPS server \r |
495 | * \r |
496 | * @param jobId\r |
497 | * @return the corresponding Job wihth the given JobId, or null if no such Job exists \r |
498 | * @throws PrintException\r |
499 | */\r |
500 | //public Methods which are not part of the JPS API\r |
501 | public DocPrintJob getJob(JobId jobId) throws PrintException {\r |
502 | Job job = Job.getJob(this, jobId);\r |
503 | return job;\r |
504 | }\r |
505 | \r |
506 | /**\r |
507 | * \r |
508 | * Check for a Job with the given JobId.\r |
509 | * <br>\r |
510 | * This method might return true, even if the printservice does not hold any \r |
511 | * job with the given JobId, but another PrintService on the same \r |
512 | * Cups server does. \r |
513 | * \r |
514 | * @param jobId\r |
515 | * @return true if a Job with the given JobId exists, false otherwise\r |
516 | * @throws PrintException\r |
517 | */\r |
518 | public boolean jobExists(JobId jobId) throws PrintException {\r |
519 | return Job.getJob(this, jobId) != null;\r |
520 | }\r |
521 | \r |
522 | \r |
523 | public RequestingUserName getRequestingUserName() {\r |
524 | return requestingUserName;\r |
525 | }\r |
526 | public void setRequestingUserName(RequestingUserName requestingUserName) {\r |
527 | this.requestingUserName = requestingUserName;\r |
528 | }\r |
529 | public RequestingUserPassword getRequestingUserPassword() {\r |
530 | return requestingUserPassword;\r |
531 | }\r |
532 | public void setRequestingUserPassword(\r |
533 | RequestingUserPassword requestingUserPassword) {\r |
534 | this.requestingUserPassword = requestingUserPassword;\r |
535 | }\r |
536 | }\r |