]>
git.ipfire.org Git - thirdparty/cups.git/blob - scripting/java/src/com/easysw/cups/IPPValue.java
1 package com
.easysw
.cups
;
4 * @version 1.00 06-NOV-2002
7 * Internet Printing Protocol definitions for the Common UNIX Printing
10 * Copyright 2007 by Apple Inc.
11 * Copyright 1997-2002 by Easy Software Products.
13 * These coded instructions, statements, and computer programs are the
14 * property of Apple Inc. and are protected by Federal copyright
15 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
16 * which should have been included with this file. If this file is
17 * file is missing or damaged, see the license at "http://www.cups.org/".
21 * An <code>IPPValue</code> object is used to hold the
22 * different kinds of values in a generic object.
33 int value_type
; // Type of value for this object.
35 int integer_value
; // Integer value
36 boolean boolean_value
; // Boolean value
39 char date_value
[]; // Date/time value
40 long unix_time
; // Unix time ....
71 * @param <code>p_byte</code> Byte value.
73 public IPPValue( byte p_byte
)
75 value_type
= IPPDefs
.TAG_INTEGER
;
76 integer_value
= (int)p_byte
;
82 * @param <code>p_short</code> Short value.
84 public IPPValue( short p_short
)
86 value_type
= IPPDefs
.TAG_INTEGER
;
87 integer_value
= (int)p_short
;
91 * Integer constructor.
93 * @param <code>p_int</code> Integer value.
95 public IPPValue( int p_int
)
97 value_type
= IPPDefs
.TAG_INTEGER
;
98 integer_value
= p_int
;
104 * @param <code>p_int</code> Integer value - force to IPP enum.
106 public IPPValue( int p_int
, boolean anything
)
108 value_type
= IPPDefs
.TAG_ENUM
;
109 integer_value
= p_int
;
113 * Boolean constructor.
115 * @param <code>p_boolean</code> Boolean value.
117 public IPPValue( boolean p_boolean
)
119 value_type
= IPPDefs
.TAG_BOOLEAN
;
120 boolean_value
= p_boolean
;
125 * Date constructor. Also set the <code>unix_time</code> member.
127 * @param <code>p_date[]</code> Character array with date value.
129 public IPPValue( char p_date
[] )
131 value_type
= IPPDefs
.TAG_DATE
;
133 unix_time
= IPPDateToTime();
139 * String constructor. Set the <code>string</code> and
140 * <code>charset</code> values.
142 * @param <code>p_charset</code> Charset for string.
143 * @param <code>p_text</code> Text for string.
145 public IPPValue( String p_charset
, String p_text
)
147 value_type
= IPPDefs
.TAG_STRING
;
154 * Range constructor. Automatically swap as needed.
156 * @param <code>p_lower</code> Integer lower value.
157 * @param <code>p_upper</code> Integer upper value.
159 public IPPValue( int p_lower
, int p_upper
)
161 value_type
= IPPDefs
.TAG_RANGE
;
162 if (p_lower
< p_upper
)
176 * Resolution constructor.
178 * @param <code>p_units</code> Unit of measure.
179 * @param <code>p_xres</code> X resolution.
180 * @param <code>p_yres</code> Y resolution.
182 public IPPValue( byte p_units
, int p_xres
, int p_yres
)
184 value_type
= IPPDefs
.TAG_RESOLUTION
;
192 * Raw data constructor.
194 * @param <code>p_length</code> Size of array.
195 * @param <code>p_data[]</code> Data.
197 public IPPValue( int p_length
, char p_data
[] )
199 value_type
= IPPDefs
.TAG_UNKNOWN
;
207 * Convert an IPP Date value to Unix Time.
209 * @return <code>long</code> Unix time in seconds.
210 * @see <code>IPPCalender</code>
212 public long IPPDateToTime()
216 // Compute the offset from GMT in milliseconds.
218 int raw_offset
= (((int)date_value
[9] * 3600) + ((int)date_value
[10] * 60)) * 1000;
219 if (date_value
[8] == '-')
220 raw_offset
= 0 - raw_offset
;
223 // Get the timezone for that offset.
225 TimeZone tz
= new SimpleTimeZone(raw_offset
,"GMT");
228 // Create a subclassed gregorian calendar (sub classed so we have
229 // access to the getTimeInMillis() method).
231 IPPCalendar cl
= new IPPCalendar();
233 int year
= ((((int)date_value
[0]) << 8) | (((int)date_value
[1]) - 1900));
234 int month
= ((int)date_value
[2]) - 1;
235 int day
= (int)date_value
[3];
236 int hour
= (int)date_value
[4];
237 int minute
= (int)date_value
[5];
238 int second
= (int)date_value
[6];
241 // Now set the calendar to the matching time.
243 cl
.setTimeZone( tz
);
244 cl
.set( year
, month
, day
, hour
, minute
, second
);
247 // And finally get the unix time.
249 long the_time
= cl
.getTimeInMillis();