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 |
19 | package de.lohndirekt.print;\r |
20 | \r |
21 | import java.io.ByteArrayInputStream;\r |
22 | import java.io.ByteArrayOutputStream;\r |
23 | import java.io.IOException;\r |
24 | import java.io.InputStream;\r |
25 | import java.io.SequenceInputStream;\r |
26 | import java.io.UnsupportedEncodingException;\r |
27 | import java.net.HttpURLConnection;\r |
28 | import java.net.URI;\r |
29 | import java.util.HashMap;\r |
30 | import java.util.Map;\r |
31 | import java.util.Vector;\r |
32 | import java.util.logging.Level;\r |
33 | import java.util.logging.Logger;\r |
34 | \r |
35 | import javax.print.attribute.Attribute;\r |
36 | import javax.print.attribute.AttributeSet;\r |
37 | import javax.print.attribute.HashAttributeSet;\r |
38 | import javax.print.attribute.HashPrintJobAttributeSet;\r |
39 | import javax.print.attribute.PrintJobAttributeSet;\r |
40 | import javax.print.attribute.TextSyntax;\r |
41 | \r |
42 | import de.lohndirekt.print.attribute.AttributeHelper;\r |
43 | import de.lohndirekt.print.attribute.AttributeParser;\r |
44 | import de.lohndirekt.print.attribute.AttributeWriter;\r |
45 | import de.lohndirekt.print.attribute.IppAttributeName;\r |
46 | import de.lohndirekt.print.attribute.IppDelimiterTag;\r |
47 | import de.lohndirekt.print.attribute.IppStatus;\r |
48 | import de.lohndirekt.print.attribute.ipp.Charset;\r |
49 | import de.lohndirekt.print.attribute.ipp.NaturalLanguage;\r |
50 | import de.lohndirekt.print.attribute.ipp.printerdesc.supported.OperationsSupported;\r |
51 | \r |
52 | /**\r |
53 | * @author bpusch, speters, sefftinge\r |
54 | * \r |
55 | */\r |
56 | class 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 |