1 package com.easysw.cups;
4 * @version 1.00 06-NOV-2002
5 * @author Easy Software Products
7 * Internet Printing Protocol definitions for the Common UNIX Printing
10 * Copyright 1997-2002 by Easy Software Products.
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
19 * Attn: CUPS Licensing Information
20 * Easy Software Products
21 * 44141 Airport View Drive, Suite 204
22 * Hollywood, Maryland 20636-3111 USA
24 * Voice: (301) 373-9603
25 * EMail: cups-info@cups.org
26 * WWW: http://www.cups.org
30 * An <code>IPPValue</code> object is used to hold the
31 * different kinds of values in a generic object.
42 int value_type; // Type of value for this object.
44 int integer_value; // Integer value
45 boolean boolean_value; // Boolean value
48 char date_value[]; // Date/time value
49 long unix_time; // Unix time ....
80 * @param <code>p_byte</code> Byte value.
82 public IPPValue( byte p_byte )
84 value_type = IPPDefs.TAG_INTEGER;
85 integer_value = (int)p_byte;
91 * @param <code>p_short</code> Short value.
93 public IPPValue( short p_short )
95 value_type = IPPDefs.TAG_INTEGER;
96 integer_value = (int)p_short;
100 * Integer constructor.
102 * @param <code>p_int</code> Integer value.
104 public IPPValue( int p_int )
106 value_type = IPPDefs.TAG_INTEGER;
107 integer_value = p_int;
113 * @param <code>p_int</code> Integer value - force to IPP enum.
115 public IPPValue( int p_int, boolean anything )
117 value_type = IPPDefs.TAG_ENUM;
118 integer_value = p_int;
122 * Boolean constructor.
124 * @param <code>p_boolean</code> Boolean value.
126 public IPPValue( boolean p_boolean )
128 value_type = IPPDefs.TAG_BOOLEAN;
129 boolean_value = p_boolean;
134 * Date constructor. Also set the <code>unix_time</code> member.
136 * @param <code>p_date[]</code> Character array with date value.
138 public IPPValue( char p_date[] )
140 value_type = IPPDefs.TAG_DATE;
142 unix_time = IPPDateToTime();
148 * String constructor. Set the <code>string</code> and
149 * <code>charset</code> values.
151 * @param <code>p_charset</code> Charset for string.
152 * @param <code>p_text</code> Text for string.
154 public IPPValue( String p_charset, String p_text )
156 value_type = IPPDefs.TAG_STRING;
163 * Range constructor. Automatically swap as needed.
165 * @param <code>p_lower</code> Integer lower value.
166 * @param <code>p_upper</code> Integer upper value.
168 public IPPValue( int p_lower, int p_upper )
170 value_type = IPPDefs.TAG_RANGE;
171 if (p_lower < p_upper)
185 * Resolution constructor.
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.
191 public IPPValue( byte p_units, int p_xres, int p_yres )
193 value_type = IPPDefs.TAG_RESOLUTION;
201 * Raw data constructor.
203 * @param <code>p_length</code> Size of array.
204 * @param <code>p_data[]</code> Data.
206 public IPPValue( int p_length, char p_data[] )
208 value_type = IPPDefs.TAG_UNKNOWN;
216 * Convert an IPP Date value to Unix Time.
218 * @return <code>long</code> Unix time in seconds.
219 * @see <code>IPPCalender</code>
221 public long IPPDateToTime()
225 // Compute the offset from GMT in milliseconds.
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;
232 // Get the timezone for that offset.
234 TimeZone tz = new SimpleTimeZone(raw_offset,"GMT");
237 // Create a subclassed gregorian calendar (sub classed so we have
238 // access to the getTimeInMillis() method).
240 IPPCalendar cl = new IPPCalendar();
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];
250 // Now set the calendar to the matching time.
252 cl.setTimeZone( tz );
253 cl.set( year, month, day, hour, minute, second );
256 // And finally get the unix time.
258 long the_time = cl.getTimeInMillis();