package org.cups; /** * @version 1.00 06-NOV-2003 * @author Easy Software Products * * Internet Printing Protocol definitions for the Common UNIX Printing * System (CUPS). * * Copyright 1997-2003 by Easy Software Products. * * These coded instructions, statements, and computer programs are the * property of Easy Software Products and are protected by Federal * copyright law. Distribution and use rights are outlined in the file * "LICENSE.txt" which should have been included with this file. If this * file is missing or damaged please contact Easy Software Products * at: * * Attn: CUPS Licensing Information * Easy Software Products * 44141 Airport View Drive, Suite 204 * Hollywood, Maryland 20636-3111 USA * * Voice: (301) 373-9603 * EMail: cups-info@cups.org * WWW: http://www.cups.org */ /** * An IPPValue object is used to hold the * different kinds of values in a generic object. * * @author TDB * @version 1.0 * @since JDK1.3 */ import java.util.*; public class IPPValue { int value_type; // Type of value for this object. int integer_value; // Integer value boolean boolean_value; // Boolean value char date_value[]; // Date/time value long unix_time; // Unix time .... // // Resolution Type // int xres; int yres; byte units; // // Range Type // int lower; int upper; // // String Type // String charset; String text; // // Unknown Type // int length; char data[]; /** * Byte constructor. * * @param p_byte Byte value. */ public IPPValue( byte p_byte ) { value_type = IPPDefs.TAG_INTEGER; integer_value = (int)p_byte; } /** * Short constructor. * * @param p_short Short value. */ public IPPValue( short p_short ) { value_type = IPPDefs.TAG_INTEGER; integer_value = (int)p_short; } /** * Integer constructor. * * @param p_int Integer value. */ public IPPValue( int p_int ) { value_type = IPPDefs.TAG_INTEGER; integer_value = p_int; } /** * Enum constructor. * * @param p_int Integer value - force to IPP enum. */ public IPPValue( int p_int, boolean anything ) { value_type = IPPDefs.TAG_ENUM; integer_value = p_int; } /** * Boolean constructor. * * @param p_boolean Boolean value. */ public IPPValue( boolean p_boolean ) { value_type = IPPDefs.TAG_BOOLEAN; boolean_value = p_boolean; } /** * Date constructor. Also set the unix_time member. * * @param p_date[] Character array with date value. */ public IPPValue( char p_date[] ) { value_type = IPPDefs.TAG_DATE; date_value = p_date; unix_time = IPPDateToTime(); } /** * String constructor. Set the string and * charset values. * * @param p_charset Charset for string. * @param p_text Text for string. */ public IPPValue( String p_charset, String p_text ) { value_type = IPPDefs.TAG_STRING; charset = p_charset; text = p_text; } /** * Range constructor. Automatically swap as needed. * * @param p_lower Integer lower value. * @param p_upper Integer upper value. */ public IPPValue( int p_lower, int p_upper ) { value_type = IPPDefs.TAG_RANGE; if (p_lower < p_upper) { lower = p_lower; upper = p_upper; } else { lower = p_upper; upper = p_lower; } } /** * Resolution constructor. * * @param p_units Unit of measure. * @param p_xres X resolution. * @param p_yres Y resolution. */ public IPPValue( byte p_units, int p_xres, int p_yres ) { value_type = IPPDefs.TAG_RESOLUTION; units = p_units; xres = p_xres; yres = p_yres; } /** * Raw data constructor. * * @param p_length Size of array. * @param p_data[] Data. */ public IPPValue( int p_length, char p_data[] ) { value_type = IPPDefs.TAG_UNKNOWN; length = p_length; data = p_data; } /** * Convert an IPP Date value to Unix Time. * * @return long Unix time in seconds. * @see IPPCalender */ public long IPPDateToTime() { // // Compute the offset from GMT in milliseconds. // int raw_offset = (((int)date_value[9] * 3600) + ((int)date_value[10] * 60)) * 1000; if (date_value[8] == '-') raw_offset = 0 - raw_offset; // // Get the timezone for that offset. // TimeZone tz = new SimpleTimeZone(raw_offset,"GMT"); // // Create a subclassed gregorian calendar (sub classed so we have // access to the getTimeInMillis() method). // IPPCalendar cl = new IPPCalendar(); int year = ((((int)date_value[0]) << 8) | (((int)date_value[1]) - 1900)); int month = ((int)date_value[2]) - 1; int day = (int)date_value[3]; int hour = (int)date_value[4]; int minute = (int)date_value[5]; int second = (int)date_value[6]; // // Now set the calendar to the matching time. // cl.setTimeZone( tz ); cl.set( year, month, day, hour, minute, second ); // // And finally get the unix time. // long the_time = cl.getTimeInMillis(); the_time /= 1000; return(the_time); } } // End of class