001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Igor A. Pyankov
019: * @version $Revision: 1.2 $
020: */package org.apache.harmony.x.print.ipp.util;
021:
022: import javax.print.attribute.Attribute;
023: import javax.print.attribute.DateTimeSyntax;
024: import javax.print.attribute.EnumSyntax;
025: import javax.print.attribute.IntegerSyntax;
026: import javax.print.attribute.ResolutionSyntax;
027: import javax.print.attribute.SetOfIntegerSyntax;
028: import javax.print.attribute.Size2DSyntax;
029: import javax.print.attribute.TextSyntax;
030: import javax.print.attribute.URISyntax;
031: import javax.print.attribute.standard.Chromaticity;
032: import javax.print.attribute.standard.ColorSupported;
033: import javax.print.attribute.standard.Compression;
034: import javax.print.attribute.standard.Fidelity;
035: import javax.print.attribute.standard.Finishings;
036: import javax.print.attribute.standard.JobSheets;
037: import javax.print.attribute.standard.JobState;
038: import javax.print.attribute.standard.JobStateReason;
039: import javax.print.attribute.standard.MediaName;
040: import javax.print.attribute.standard.MediaSizeName;
041: import javax.print.attribute.standard.MediaTray;
042: import javax.print.attribute.standard.MultipleDocumentHandling;
043: import javax.print.attribute.standard.OrientationRequested;
044: import javax.print.attribute.standard.PDLOverrideSupported;
045: import javax.print.attribute.standard.PresentationDirection;
046: import javax.print.attribute.standard.PrintQuality;
047: import javax.print.attribute.standard.PrinterIsAcceptingJobs;
048: import javax.print.attribute.standard.PrinterState;
049: import javax.print.attribute.standard.PrinterStateReason;
050: import javax.print.attribute.standard.ReferenceUriSchemesSupported;
051: import javax.print.attribute.standard.Severity;
052: import javax.print.attribute.standard.SheetCollate;
053: import javax.print.attribute.standard.Sides;
054:
055: import org.apache.harmony.x.print.attributes.PPDMediaSizeName;
056: import org.apache.harmony.x.print.ipp.IppAttribute;
057:
058: /**
059: * Supporing class for Ipp2Java
060: */
061:
062: public class IppAttributeUtils {
063: public static Object getIppValue(Attribute attr, byte ippvtag) {
064: Object o = null;
065:
066: switch (ippvtag) {
067: // integer values for the "value-tag" field.
068: case IppAttribute.TAG_BOOLEAN:
069: case IppAttribute.TAG_INTEGER:
070: case IppAttribute.TAG_ENUM:
071: if (attr instanceof IntegerSyntax) {
072: o = new Integer(((IntegerSyntax) attr).getValue());
073: } else if (attr instanceof EnumSyntax) {
074: o = new Integer(((EnumSyntax) attr).getValue());
075: } else if (attr instanceof DateTimeSyntax
076: || attr instanceof ResolutionSyntax
077: || attr instanceof SetOfIntegerSyntax
078: || attr instanceof Size2DSyntax
079: || attr instanceof TextSyntax
080: || attr instanceof URISyntax) {
081: // TODO - process other attr's types
082: }
083: break;
084: // octetString values for the "value-tag" field.
085: case IppAttribute.TAG_DATETIME:
086: case IppAttribute.TAG_RESOLUTION:
087: case IppAttribute.TAG_RANGEOFINTEGER:
088: case IppAttribute.TAG_OCTETSTRINGUNSPECIFIEDFORMAT:
089: case IppAttribute.TAG_TEXTWITHLANGUAGE:
090: case IppAttribute.TAG_NAMEWITHLANGUAGE:
091: if (attr instanceof IntegerSyntax) {
092: // TODO - it seems that this needs to be fixed
093: o = new Integer(((IntegerSyntax) attr).toString());
094: } else if (attr instanceof EnumSyntax) {
095: // TODO - it seems that this needs to be fixed
096: o = new Integer(((EnumSyntax) attr).toString());
097: } else if (attr instanceof DateTimeSyntax
098: || attr instanceof ResolutionSyntax
099: || attr instanceof SetOfIntegerSyntax
100: || attr instanceof Size2DSyntax) {
101: // TODO - process other attr's types
102: } else if (attr instanceof TextSyntax) {
103: // TODO - it seems that this needs to be fixed
104: o = new Integer(((TextSyntax) attr).toString());
105: } else if (attr instanceof URISyntax) {
106: // TODO - it seems that this needs to be fixed
107: o = new Integer(((URISyntax) attr).toString());
108: }
109: break;
110: // character-string values for the "value-tag" field
111: case IppAttribute.TAG_TEXTWITHOUTLANGUAGE:
112: case IppAttribute.TAG_NAMEWITHOUTLANGUAGE:
113: case IppAttribute.TAG_KEYWORD:
114: case IppAttribute.TAG_URI:
115: case IppAttribute.TAG_URISCHEME:
116: case IppAttribute.TAG_CHARSET:
117: case IppAttribute.TAG_NATURAL_LANGUAGE:
118: case IppAttribute.TAG_MIMEMEDIATYPE:
119: if (attr instanceof IntegerSyntax) {
120: o = ((IntegerSyntax) attr).toString();
121: } else if (attr instanceof EnumSyntax) {
122: o = ((EnumSyntax) attr).toString();
123: } else if (attr instanceof DateTimeSyntax
124: || attr instanceof ResolutionSyntax
125: || attr instanceof SetOfIntegerSyntax
126: || attr instanceof Size2DSyntax) {
127: // TODO - process other attr's types
128: } else if (attr instanceof TextSyntax) {
129: o = ((TextSyntax) attr).toString();
130: } else if (attr instanceof URISyntax) {
131: o = ((URISyntax) attr).toString();
132: }
133: break;
134: default:
135: break;
136: }
137:
138: return o;
139: }
140:
141: public static Object getObject(Class e, int eval) {
142: Object o = null;
143: EnumSyntax[] et = getEnumValueTable(e);
144:
145: if (et != null) {
146: for (int i = 0, ii = et.length; i < ii; i++) {
147: if (et[i] != null && et[i].getValue() == eval) {
148: o = et[i];
149: break;
150: }
151: }
152: }
153:
154: return o;
155: }
156:
157: public static Object getObject(Class e, String eval) {
158: Object o = null;
159: EnumSyntax[] et = getEnumValueTable(e);
160:
161: if (et != null) {
162: for (int i = 0, ii = et.length; i < ii; i++) {
163: if (et[i] != null && et[i].toString().equals(eval)) {
164: o = et[i];
165: break;
166: }
167: }
168: }
169:
170: return o;
171: }
172:
173: public static EnumSyntax[] getEnumValueTable(Class e) {
174: for (int i = 0, ii = enumTables.length; i < ii; i++) {
175: if (enumTables[i][0] == e) {
176: return (EnumSyntax[]) enumTables[i][1];
177: }
178: }
179: return null;
180: }
181:
182: static Chromaticity[] enumChromaticityTable = {
183: Chromaticity.MONOCHROME, Chromaticity.COLOR };
184:
185: static ColorSupported[] enumColorSupportedTable = {
186: ColorSupported.NOT_SUPPORTED, ColorSupported.SUPPORTED };
187:
188: static Compression[] enumCompressionTable = { Compression.NONE,
189: Compression.DEFLATE, Compression.GZIP, Compression.COMPRESS };
190:
191: static Fidelity[] enumFidelityTable = { Fidelity.FIDELITY_TRUE,
192: Fidelity.FIDELITY_FALSE };
193:
194: static Finishings[] enumFinishingsTable = { Finishings.NONE,
195: Finishings.STAPLE, null, Finishings.COVER, Finishings.BIND,
196: Finishings.SADDLE_STITCH, Finishings.EDGE_STITCH, null,
197: null, null, null, null, null, null, null, null, null,
198: Finishings.STAPLE_TOP_LEFT, Finishings.STAPLE_BOTTOM_LEFT,
199: Finishings.STAPLE_TOP_RIGHT,
200: Finishings.STAPLE_BOTTOM_RIGHT,
201: Finishings.EDGE_STITCH_LEFT, Finishings.EDGE_STITCH_TOP,
202: Finishings.EDGE_STITCH_RIGHT,
203: Finishings.EDGE_STITCH_BOTTOM, Finishings.STAPLE_DUAL_LEFT,
204: Finishings.STAPLE_DUAL_TOP, Finishings.STAPLE_DUAL_RIGHT,
205: Finishings.STAPLE_DUAL_BOTTOM };
206:
207: static JobSheets[] enumJobSheetsTable = { JobSheets.NONE,
208: JobSheets.STANDARD };
209:
210: static JobState[] enumJobStateTable = { JobState.UNKNOWN, null,
211: null, JobState.PENDING, JobState.PENDING_HELD,
212: JobState.PROCESSING, JobState.PROCESSING_STOPPED,
213: JobState.CANCELED, JobState.ABORTED, JobState.COMPLETED };
214:
215: static JobStateReason[] enumJobStateReasonTable = {
216: JobStateReason.JOB_INCOMING,
217: JobStateReason.JOB_DATA_INSUFFICIENT,
218: JobStateReason.DOCUMENT_ACCESS_ERROR,
219: JobStateReason.SUBMISSION_INTERRUPTED,
220: JobStateReason.JOB_OUTGOING,
221: JobStateReason.JOB_HOLD_UNTIL_SPECIFIED,
222: JobStateReason.RESOURCES_ARE_NOT_READY,
223: JobStateReason.PRINTER_STOPPED_PARTLY,
224: JobStateReason.PRINTER_STOPPED,
225: JobStateReason.JOB_INTERPRETING, JobStateReason.JOB_QUEUED,
226: JobStateReason.JOB_TRANSFORMING,
227: JobStateReason.JOB_QUEUED_FOR_MARKER,
228: JobStateReason.JOB_PRINTING,
229: JobStateReason.JOB_CANCELED_BY_USER,
230: JobStateReason.JOB_CANCELED_BY_OPERATOR,
231: JobStateReason.JOB_CANCELED_AT_DEVICE,
232: JobStateReason.ABORTED_BY_SYSTEM,
233: JobStateReason.UNSUPPORTED_COMPRESSION,
234: JobStateReason.COMPRESSION_ERROR,
235: JobStateReason.UNSUPPORTED_DOCUMENT_FORMAT,
236: JobStateReason.DOCUMENT_FORMAT_ERROR,
237: JobStateReason.PROCESSING_TO_STOP_POINT,
238: JobStateReason.SERVICE_OFF_LINE,
239: JobStateReason.JOB_COMPLETED_SUCCESSFULLY,
240: JobStateReason.JOB_COMPLETED_WITH_WARNINGS,
241: JobStateReason.JOB_COMPLETED_WITH_ERRORS,
242: JobStateReason.JOB_RESTARTABLE,
243: JobStateReason.QUEUED_IN_DEVICE };
244:
245: static MediaName[] enumMediaNameTable = {
246: MediaName.NA_LETTER_WHITE, MediaName.NA_LETTER_TRANSPARENT,
247: MediaName.ISO_A4_WHITE, MediaName.ISO_A4_TRANSPARENT };
248:
249: static MediaSizeName[] enumMediaSizeNameTable = {
250: MediaSizeName.ISO_A0, MediaSizeName.ISO_A1,
251: MediaSizeName.ISO_A2, MediaSizeName.ISO_A3,
252: MediaSizeName.ISO_A4, MediaSizeName.ISO_A5,
253: MediaSizeName.ISO_A6, MediaSizeName.ISO_A7,
254: MediaSizeName.ISO_A8, MediaSizeName.ISO_A9,
255: MediaSizeName.ISO_A10, MediaSizeName.ISO_B0,
256: MediaSizeName.ISO_B1, MediaSizeName.ISO_B2,
257: MediaSizeName.ISO_B3, MediaSizeName.ISO_B4,
258: MediaSizeName.ISO_B5, MediaSizeName.ISO_B6,
259: MediaSizeName.ISO_B7, MediaSizeName.ISO_B8,
260: MediaSizeName.ISO_B9, MediaSizeName.ISO_B10,
261: MediaSizeName.JIS_B0, MediaSizeName.JIS_B1,
262: MediaSizeName.JIS_B2, MediaSizeName.JIS_B3,
263: MediaSizeName.JIS_B4, MediaSizeName.JIS_B5,
264: MediaSizeName.JIS_B6, MediaSizeName.JIS_B7,
265: MediaSizeName.JIS_B8, MediaSizeName.JIS_B9,
266: MediaSizeName.JIS_B10, MediaSizeName.ISO_C0,
267: MediaSizeName.ISO_C1, MediaSizeName.ISO_C2,
268: MediaSizeName.ISO_C3, MediaSizeName.ISO_C4,
269: MediaSizeName.ISO_C5, MediaSizeName.ISO_C6,
270: MediaSizeName.NA_LETTER, MediaSizeName.NA_LEGAL,
271: MediaSizeName.EXECUTIVE, MediaSizeName.LEDGER,
272: MediaSizeName.TABLOID, MediaSizeName.INVOICE,
273: MediaSizeName.FOLIO, MediaSizeName.QUARTO,
274: MediaSizeName.JAPANESE_POSTCARD,
275: MediaSizeName.JAPANESE_DOUBLE_POSTCARD, MediaSizeName.A,
276: MediaSizeName.B, MediaSizeName.C, MediaSizeName.D,
277: MediaSizeName.E, MediaSizeName.ISO_DESIGNATED_LONG,
278: MediaSizeName.ITALY_ENVELOPE,
279: MediaSizeName.MONARCH_ENVELOPE,
280: MediaSizeName.PERSONAL_ENVELOPE,
281: MediaSizeName.NA_NUMBER_9_ENVELOPE,
282: MediaSizeName.NA_NUMBER_10_ENVELOPE,
283: MediaSizeName.NA_NUMBER_11_ENVELOPE,
284: MediaSizeName.NA_NUMBER_12_ENVELOPE,
285: MediaSizeName.NA_NUMBER_14_ENVELOPE,
286: MediaSizeName.NA_6X9_ENVELOPE,
287: MediaSizeName.NA_7X9_ENVELOPE,
288: MediaSizeName.NA_9X11_ENVELOPE,
289: MediaSizeName.NA_9X12_ENVELOPE,
290: MediaSizeName.NA_10X13_ENVELOPE,
291: MediaSizeName.NA_10X14_ENVELOPE,
292: MediaSizeName.NA_10X15_ENVELOPE, MediaSizeName.NA_5X7,
293: MediaSizeName.NA_8X10 };
294:
295: static MediaTray[] enumMediaTrayTable = { MediaTray.TOP,
296: MediaTray.MIDDLE, MediaTray.BOTTOM, MediaTray.ENVELOPE,
297: MediaTray.MANUAL, MediaTray.LARGE_CAPACITY, MediaTray.MAIN,
298: MediaTray.SIDE };
299:
300: static MultipleDocumentHandling[] enumMultipleDocumentHandlingTable = {
301: MultipleDocumentHandling.SINGLE_DOCUMENT,
302: MultipleDocumentHandling.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES,
303: MultipleDocumentHandling.SEPARATE_DOCUMENTS_COLLATED_COPIES,
304: MultipleDocumentHandling.SINGLE_DOCUMENT_NEW_SHEET };
305:
306: static OrientationRequested[] enumOrientationRequestedTable = {
307: OrientationRequested.PORTRAIT,
308: OrientationRequested.LANDSCAPE,
309: OrientationRequested.REVERSE_LANDSCAPE,
310: OrientationRequested.REVERSE_PORTRAIT };
311:
312: static PDLOverrideSupported[] enumPDLOverrideSupportedTable = {
313: PDLOverrideSupported.NOT_ATTEMPTED,
314: PDLOverrideSupported.ATTEMPTED };
315:
316: static PresentationDirection[] enumPresentationDirectionTable = {
317: PresentationDirection.TOBOTTOM_TORIGHT,
318: PresentationDirection.TOBOTTOM_TOLEFT,
319: PresentationDirection.TOTOP_TORIGHT,
320: PresentationDirection.TOTOP_TOLEFT,
321: PresentationDirection.TORIGHT_TOBOTTOM,
322: PresentationDirection.TORIGHT_TOTOP,
323: PresentationDirection.TOLEFT_TOBOTTOM,
324: PresentationDirection.TOLEFT_TOTOP };
325:
326: static PrinterIsAcceptingJobs[] enumPrinterIsAcceptingJobsTable = {
327: PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS,
328: PrinterIsAcceptingJobs.ACCEPTING_JOBS };
329:
330: static PrinterState[] enumPrinterStateTable = {
331: PrinterState.UNKNOWN, null, null, PrinterState.IDLE,
332: PrinterState.PROCESSING, PrinterState.STOPPED };
333:
334: static PrinterStateReason[] enumPrinterStateReasonTable = {
335: PrinterStateReason.OTHER, PrinterStateReason.MEDIA_NEEDED,
336: PrinterStateReason.MEDIA_JAM,
337: PrinterStateReason.MOVING_TO_PAUSED,
338: PrinterStateReason.PAUSED, PrinterStateReason.SHUTDOWN,
339: PrinterStateReason.CONNECTING_TO_DEVICE,
340: PrinterStateReason.TIMED_OUT, PrinterStateReason.STOPPING,
341: PrinterStateReason.STOPPED_PARTLY,
342: PrinterStateReason.TONER_LOW,
343: PrinterStateReason.TONER_EMPTY,
344: PrinterStateReason.SPOOL_AREA_FULL,
345: PrinterStateReason.COVER_OPEN,
346: PrinterStateReason.INTERLOCK_OPEN,
347: PrinterStateReason.DOOR_OPEN,
348: PrinterStateReason.INPUT_TRAY_MISSING,
349: PrinterStateReason.MEDIA_LOW,
350: PrinterStateReason.MEDIA_EMPTY,
351: PrinterStateReason.OUTPUT_TRAY_MISSING,
352: PrinterStateReason.OUTPUT_AREA_ALMOST_FULL,
353: PrinterStateReason.OUTPUT_AREA_FULL,
354: PrinterStateReason.MARKER_SUPPLY_LOW,
355: PrinterStateReason.MARKER_SUPPLY_EMPTY,
356: PrinterStateReason.MARKER_WASTE_ALMOST_FULL,
357: PrinterStateReason.MARKER_WASTE_FULL,
358: PrinterStateReason.FUSER_OVER_TEMP,
359: PrinterStateReason.FUSER_UNDER_TEMP,
360: PrinterStateReason.OPC_NEAR_EOL,
361: PrinterStateReason.OPC_LIFE_OVER,
362: PrinterStateReason.DEVELOPER_LOW,
363: PrinterStateReason.DEVELOPER_EMPTY,
364: PrinterStateReason.INTERPRETER_RESOURCE_UNAVAILABLE };
365:
366: static PrintQuality[] enumPrintQualityTable = { PrintQuality.DRAFT,
367: PrintQuality.NORMAL, PrintQuality.HIGH };
368:
369: static ReferenceUriSchemesSupported[] enumReferenceUriSchemesSupportedTable = {
370: ReferenceUriSchemesSupported.FTP,
371: ReferenceUriSchemesSupported.HTTP,
372: ReferenceUriSchemesSupported.HTTPS,
373: ReferenceUriSchemesSupported.GOPHER,
374: ReferenceUriSchemesSupported.NEWS,
375: ReferenceUriSchemesSupported.NNTP,
376: ReferenceUriSchemesSupported.WAIS,
377: ReferenceUriSchemesSupported.FILE };
378:
379: static Severity[] enumSeverityTable = { Severity.REPORT,
380: Severity.WARNING, Severity.ERROR };
381:
382: static SheetCollate[] enumSheetCollateTable = {
383: SheetCollate.UNCOLLATED, SheetCollate.COLLATED };
384:
385: static Sides[] enumSidesTable = { Sides.ONE_SIDED,
386: Sides.TWO_SIDED_LONG_EDGE, Sides.TWO_SIDED_SHORT_EDGE };
387:
388: static PPDMediaSizeName[] enumPPDMediaSizeNameTable = (PPDMediaSizeName[]) PPDMediaSizeName.A4
389: .getEnumValueTable();
390:
391: static Object[][] enumTables = {
392: { Chromaticity.class, enumChromaticityTable },
393: { ColorSupported.class, enumColorSupportedTable },
394: { Compression.class, enumCompressionTable },
395: { Fidelity.class, enumFidelityTable },
396: { Finishings.class, enumFinishingsTable },
397: { JobSheets.class, enumJobSheetsTable },
398: { JobState.class, enumJobStateTable },
399: { JobStateReason.class, enumJobStateReasonTable },
400: { MediaName.class, enumMediaNameTable },
401: { MediaSizeName.class, enumMediaSizeNameTable },
402: { MediaTray.class, enumMediaTrayTable },
403: { MultipleDocumentHandling.class,
404: enumMultipleDocumentHandlingTable },
405: { OrientationRequested.class, enumOrientationRequestedTable },
406: { PDLOverrideSupported.class, enumPDLOverrideSupportedTable },
407: { PresentationDirection.class,
408: enumPresentationDirectionTable },
409: { PrinterIsAcceptingJobs.class,
410: enumPrinterIsAcceptingJobsTable },
411: { PrinterState.class, enumPrinterStateTable },
412: { PrinterStateReason.class, enumPrinterStateReasonTable },
413: { PrintQuality.class, enumPrintQualityTable },
414: { ReferenceUriSchemesSupported.class,
415: enumReferenceUriSchemesSupportedTable },
416: { Severity.class, enumSeverityTable },
417: { SheetCollate.class, enumSheetCollateTable },
418: { Sides.class, enumSidesTable },
419: { PPDMediaSizeName.class, enumPPDMediaSizeNameTable } };
420:
421: }
|