]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | package com.easysw.cups; |
2 | ||
3 | /** | |
4 | * @version 1.00 06-NOV-2002 | |
5 | * @author Easy Software Products | |
6 | * | |
7 | * Internet Printing Protocol definitions for the Common UNIX Printing | |
8 | * System (CUPS). | |
9 | * | |
10 | * Copyright 1997-2002 by Easy Software Products. | |
11 | * | |
12 | * These coded instructions, statements, and computer programs are the | |
13 | * property of Easy Software Products and are protected by Federal | |
14 | * copyright law. Distribution and use rights are outlined in the file | |
15 | * "LICENSE.txt" which should have been included with this file. If this | |
16 | * file is missing or damaged please contact Easy Software Products | |
17 | * at: | |
18 | * | |
19 | * Attn: CUPS Licensing Information | |
20 | * Easy Software Products | |
21 | * 44141 Airport View Drive, Suite 204 | |
22 | * Hollywood, Maryland 20636-3111 USA | |
23 | * | |
24 | * Voice: (301) 373-9603 | |
25 | * EMail: cups-info@cups.org | |
26 | * WWW: http://www.cups.org | |
27 | */ | |
28 | ||
29 | /** | |
30 | * An <code>IPPValue</code> object is used to hold the | |
31 | * different kinds of values in a generic object. | |
32 | * | |
33 | * @author TDB | |
34 | * @version 1.0 | |
35 | * @since JDK1.3 | |
36 | */ | |
37 | import java.util.*; | |
38 | ||
39 | public class IPPValue | |
40 | { | |
41 | ||
42 | int value_type; // Type of value for this object. | |
43 | ||
44 | int integer_value; // Integer value | |
45 | boolean boolean_value; // Boolean value | |
46 | ||
47 | ||
48 | char date_value[]; // Date/time value | |
49 | long unix_time; // Unix time .... | |
50 | ||
51 | // | |
52 | // Resolution Type | |
53 | // | |
54 | int xres; | |
55 | int yres; | |
56 | byte units; | |
57 | ||
58 | // | |
59 | // Range Type | |
60 | // | |
61 | int lower; | |
62 | int upper; | |
63 | ||
64 | // | |
65 | // String Type | |
66 | // | |
67 | String charset; | |
68 | String text; | |
69 | ||
70 | // | |
71 | // Unknown Type | |
72 | // | |
73 | int length; | |
74 | char data[]; | |
75 | ||
76 | ||
77 | /** | |
78 | * Byte constructor. | |
79 | * | |
80 | * @param <code>p_byte</code> Byte value. | |
81 | */ | |
82 | public IPPValue( byte p_byte ) | |
83 | { | |
84 | value_type = IPPDefs.TAG_INTEGER; | |
85 | integer_value = (int)p_byte; | |
86 | } | |
87 | ||
88 | /** | |
89 | * Short constructor. | |
90 | * | |
91 | * @param <code>p_short</code> Short value. | |
92 | */ | |
93 | public IPPValue( short p_short ) | |
94 | { | |
95 | value_type = IPPDefs.TAG_INTEGER; | |
96 | integer_value = (int)p_short; | |
97 | } | |
98 | ||
99 | /** | |
100 | * Integer constructor. | |
101 | * | |
102 | * @param <code>p_int</code> Integer value. | |
103 | */ | |
104 | public IPPValue( int p_int ) | |
105 | { | |
106 | value_type = IPPDefs.TAG_INTEGER; | |
107 | integer_value = p_int; | |
108 | } | |
109 | ||
110 | /** | |
111 | * Enum constructor. | |
112 | * | |
113 | * @param <code>p_int</code> Integer value - force to IPP enum. | |
114 | */ | |
115 | public IPPValue( int p_int, boolean anything ) | |
116 | { | |
117 | value_type = IPPDefs.TAG_ENUM; | |
118 | integer_value = p_int; | |
119 | } | |
120 | ||
121 | /** | |
122 | * Boolean constructor. | |
123 | * | |
124 | * @param <code>p_boolean</code> Boolean value. | |
125 | */ | |
126 | public IPPValue( boolean p_boolean ) | |
127 | { | |
128 | value_type = IPPDefs.TAG_BOOLEAN; | |
129 | boolean_value = p_boolean; | |
130 | } | |
131 | ||
132 | ||
133 | /** | |
134 | * Date constructor. Also set the <code>unix_time</code> member. | |
135 | * | |
136 | * @param <code>p_date[]</code> Character array with date value. | |
137 | */ | |
138 | public IPPValue( char p_date[] ) | |
139 | { | |
140 | value_type = IPPDefs.TAG_DATE; | |
141 | date_value = p_date; | |
142 | unix_time = IPPDateToTime(); | |
143 | } | |
144 | ||
145 | ||
146 | ||
147 | /** | |
148 | * String constructor. Set the <code>string</code> and | |
149 | * <code>charset</code> values. | |
150 | * | |
151 | * @param <code>p_charset</code> Charset for string. | |
152 | * @param <code>p_text</code> Text for string. | |
153 | */ | |
154 | public IPPValue( String p_charset, String p_text ) | |
155 | { | |
156 | value_type = IPPDefs.TAG_STRING; | |
157 | charset = p_charset; | |
158 | text = p_text; | |
159 | } | |
160 | ||
161 | ||
162 | /** | |
163 | * Range constructor. Automatically swap as needed. | |
164 | * | |
165 | * @param <code>p_lower</code> Integer lower value. | |
166 | * @param <code>p_upper</code> Integer upper value. | |
167 | */ | |
168 | public IPPValue( int p_lower, int p_upper ) | |
169 | { | |
170 | value_type = IPPDefs.TAG_RANGE; | |
171 | if (p_lower < p_upper) | |
172 | { | |
173 | lower = p_lower; | |
174 | upper = p_upper; | |
175 | } | |
176 | else | |
177 | { | |
178 | lower = p_upper; | |
179 | upper = p_lower; | |
180 | } | |
181 | } | |
182 | ||
183 | ||
184 | /** | |
185 | * Resolution constructor. | |
186 | * | |
187 | * @param <code>p_units</code> Unit of measure. | |
188 | * @param <code>p_xres</code> X resolution. | |
189 | * @param <code>p_yres</code> Y resolution. | |
190 | */ | |
191 | public IPPValue( byte p_units, int p_xres, int p_yres ) | |
192 | { | |
193 | value_type = IPPDefs.TAG_RESOLUTION; | |
194 | units = p_units; | |
195 | xres = p_xres; | |
196 | yres = p_yres; | |
197 | } | |
198 | ||
199 | ||
200 | /** | |
201 | * Raw data constructor. | |
202 | * | |
203 | * @param <code>p_length</code> Size of array. | |
204 | * @param <code>p_data[]</code> Data. | |
205 | */ | |
206 | public IPPValue( int p_length, char p_data[] ) | |
207 | { | |
208 | value_type = IPPDefs.TAG_UNKNOWN; | |
209 | length = p_length; | |
210 | data = p_data; | |
211 | } | |
212 | ||
213 | ||
214 | ||
215 | /** | |
216 | * Convert an IPP Date value to Unix Time. | |
217 | * | |
218 | * @return <code>long</code> Unix time in seconds. | |
219 | * @see <code>IPPCalender</code> | |
220 | */ | |
221 | public long IPPDateToTime() | |
222 | { | |
223 | ||
224 | // | |
225 | // Compute the offset from GMT in milliseconds. | |
226 | // | |
227 | int raw_offset = (((int)date_value[9] * 3600) + ((int)date_value[10] * 60)) * 1000; | |
228 | if (date_value[8] == '-') | |
229 | raw_offset = 0 - raw_offset; | |
230 | ||
231 | // | |
232 | // Get the timezone for that offset. | |
233 | // | |
234 | TimeZone tz = new SimpleTimeZone(raw_offset,"GMT"); | |
235 | ||
236 | // | |
237 | // Create a subclassed gregorian calendar (sub classed so we have | |
238 | // access to the getTimeInMillis() method). | |
239 | // | |
240 | IPPCalendar cl = new IPPCalendar(); | |
241 | ||
242 | int year = ((((int)date_value[0]) << 8) | (((int)date_value[1]) - 1900)); | |
243 | int month = ((int)date_value[2]) - 1; | |
244 | int day = (int)date_value[3]; | |
245 | int hour = (int)date_value[4]; | |
246 | int minute = (int)date_value[5]; | |
247 | int second = (int)date_value[6]; | |
248 | ||
249 | // | |
250 | // Now set the calendar to the matching time. | |
251 | // | |
252 | cl.setTimeZone( tz ); | |
253 | cl.set( year, month, day, hour, minute, second ); | |
254 | ||
255 | // | |
256 | // And finally get the unix time. | |
257 | // | |
258 | long the_time = cl.getTimeInMillis(); | |
259 | the_time /= 1000; | |
260 | ||
261 | return(the_time); | |
262 | } | |
263 | ||
264 | } // End of class |