Initial import.
[clinton/mirror/jspi/.git] / jspi / src / main / java / de / lohndirekt / print / IppRequestCupsImpl.java
CommitLineData
3ea135bb 1/**\r
2 * Copyright (C) 2004 <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
19package de.lohndirekt.print;\r
20\r
21import java.io.ByteArrayInputStream;\r
22import java.io.ByteArrayOutputStream;\r
23import java.io.IOException;\r
24import java.io.InputStream;\r
25import java.io.SequenceInputStream;\r
26import java.io.UnsupportedEncodingException;\r
27import java.net.HttpURLConnection;\r
28import java.net.URI;\r
29import java.util.HashMap;\r
30import java.util.Map;\r
31import java.util.Vector;\r
32import java.util.logging.Level;\r
33import java.util.logging.Logger;\r
34\r
35import javax.print.attribute.Attribute;\r
36import javax.print.attribute.AttributeSet;\r
37import javax.print.attribute.HashAttributeSet;\r
38import javax.print.attribute.HashPrintJobAttributeSet;\r
39import javax.print.attribute.PrintJobAttributeSet;\r
40import javax.print.attribute.TextSyntax;\r
41\r
42import de.lohndirekt.print.attribute.AttributeHelper;\r
43import de.lohndirekt.print.attribute.AttributeParser;\r
44import de.lohndirekt.print.attribute.AttributeWriter;\r
45import de.lohndirekt.print.attribute.IppAttributeName;\r
46import de.lohndirekt.print.attribute.IppDelimiterTag;\r
47import de.lohndirekt.print.attribute.IppStatus;\r
48import de.lohndirekt.print.attribute.ipp.Charset;\r
49import de.lohndirekt.print.attribute.ipp.NaturalLanguage;\r
50import de.lohndirekt.print.attribute.ipp.printerdesc.supported.OperationsSupported;\r
51\r
52/**\r
53 * @author bpusch, speters, sefftinge\r
54 * \r
55 */\r
56class IppRequestCupsImpl implements IppRequest {\r
57 class IppResponseIppImpl implements IppResponse {\r
58 private Logger log = Logger.getLogger(this.getClass().getName());\r
59\r
60 private IppStatus status;\r
61\r
62 private Map attributes;\r
63\r
64 IppResponseIppImpl(InputStream response) {\r
65 try{\r
66 parseResponse(response);\r
67 } catch (IOException e) {\r
68 log.log(Level.SEVERE, e.getMessage(), e);\r
69 throw new RuntimeException(e);\r
70 }\r
71 \r
72 }\r
73\r
74 private void parseResponse(InputStream response) throws IOException {\r
75 byte[] header = new byte[8];\r
76 response.read(header);\r
77 this.status = IppStatus.get((int) (header[2] << 8)\r
78 + (int) header[3]);\r
79 if (response.available() != 0) {\r
80 this.attributes = AttributeParser.parseResponse(response);\r
81 } else {\r
82 this.attributes = new HashMap();\r
83 }\r
84 if (log.isLoggable(Level.FINEST)) {\r
85 log.finest("Status: " + status.getText());\r
86 }\r
87 }\r
88\r
89 /**\r
90 * @return\r
91 */\r
92 public Map getAttributes() {\r
93 return attributes;\r
94 }\r
95\r
96 /**\r
97 * @return\r
98 */\r
99 public IppStatus getStatus() {\r
100 return status;\r
101 }\r
102\r
103 }\r
104\r
105 private IppConnection conn;\r
106\r
107 private boolean sent = false;\r
108\r
109 private Object data;\r
110\r
111 private URI path;\r
112\r
113 private OperationsSupported operation;\r
114\r
115