harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r454289 [17/22] - in /incubator/harmony/enhanced/classlib/trunk/modules/H-1609: ./ modules/ modules/applet/ modules/applet/src/ modules/applet/src/main/ modules/applet/src/main/java/ modules/applet/src/main/java/java/ modules/applet/src/mai...
Date Mon, 09 Oct 2006 05:33:21 GMT
Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/util/IppAttributeUtils.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/util/IppAttributeUtils.java?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/util/IppAttributeUtils.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/util/IppAttributeUtils.java Sun Oct  8 22:33:09 2006
@@ -0,0 +1,479 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/** 
+ * @author Igor A. Pyankov 
+ * @version $Revision: 1.2 $ 
+ */ 
+
+package org.apache.harmony.x.print.ipp.util;
+
+import javax.print.attribute.Attribute;
+import javax.print.attribute.DateTimeSyntax;
+import javax.print.attribute.EnumSyntax;
+import javax.print.attribute.IntegerSyntax;
+import javax.print.attribute.ResolutionSyntax;
+import javax.print.attribute.SetOfIntegerSyntax;
+import javax.print.attribute.Size2DSyntax;
+import javax.print.attribute.TextSyntax;
+import javax.print.attribute.URISyntax;
+import javax.print.attribute.standard.Chromaticity;
+import javax.print.attribute.standard.ColorSupported;
+import javax.print.attribute.standard.Compression;
+import javax.print.attribute.standard.Fidelity;
+import javax.print.attribute.standard.Finishings;
+import javax.print.attribute.standard.JobSheets;
+import javax.print.attribute.standard.JobState;
+import javax.print.attribute.standard.JobStateReason;
+import javax.print.attribute.standard.MediaName;
+import javax.print.attribute.standard.MediaSizeName;
+import javax.print.attribute.standard.MediaTray;
+import javax.print.attribute.standard.MultipleDocumentHandling;
+import javax.print.attribute.standard.OrientationRequested;
+import javax.print.attribute.standard.PDLOverrideSupported;
+import javax.print.attribute.standard.PresentationDirection;
+import javax.print.attribute.standard.PrintQuality;
+import javax.print.attribute.standard.PrinterIsAcceptingJobs;
+import javax.print.attribute.standard.PrinterState;
+import javax.print.attribute.standard.PrinterStateReason;
+import javax.print.attribute.standard.ReferenceUriSchemesSupported;
+import javax.print.attribute.standard.Severity;
+import javax.print.attribute.standard.SheetCollate;
+import javax.print.attribute.standard.Sides;
+
+import org.apache.harmony.x.print.attributes.PPDMediaSizeName;
+import org.apache.harmony.x.print.ipp.IppAttribute;
+
+/** 
+ * Supporing class for Ipp2Java 
+ */
+
+public class IppAttributeUtils {
+    public static Object getIppValue(Attribute attr, byte ippvtag) {
+        Object o = null;
+
+        switch (ippvtag) {
+        // integer values for the "value-tag" field.
+        case IppAttribute.TAG_BOOLEAN:
+        case IppAttribute.TAG_INTEGER:
+        case IppAttribute.TAG_ENUM:
+            if (attr instanceof IntegerSyntax) {
+                o = new Integer(((IntegerSyntax) attr).getValue());
+            } else if (attr instanceof EnumSyntax) {
+                o = new Integer(((EnumSyntax) attr).getValue());
+            } else if (attr instanceof DateTimeSyntax
+                    || attr instanceof ResolutionSyntax
+                    || attr instanceof SetOfIntegerSyntax
+                    || attr instanceof Size2DSyntax
+                    || attr instanceof TextSyntax || attr instanceof URISyntax) {
+                // TODO - process other attr's types
+            }
+            break;
+        // octetString values for the "value-tag" field.
+        case IppAttribute.TAG_DATETIME:
+        case IppAttribute.TAG_RESOLUTION:
+        case IppAttribute.TAG_RANGEOFINTEGER:
+        case IppAttribute.TAG_OCTETSTRINGUNSPECIFIEDFORMAT:
+        case IppAttribute.TAG_TEXTWITHLANGUAGE:
+        case IppAttribute.TAG_NAMEWITHLANGUAGE:
+            if (attr instanceof IntegerSyntax) {
+                // TODO - it seems that this needs to be fixed
+                o = new Integer(((IntegerSyntax) attr).toString());
+            } else if (attr instanceof EnumSyntax) {
+                // TODO - it seems that this needs to be fixed
+                o = new Integer(((EnumSyntax) attr).toString());
+            } else if (attr instanceof DateTimeSyntax
+                    || attr instanceof ResolutionSyntax
+                    || attr instanceof SetOfIntegerSyntax
+                    || attr instanceof Size2DSyntax) {
+                // TODO - process other attr's types
+            } else if (attr instanceof TextSyntax) {
+                // TODO - it seems that this needs to be fixed
+                o = new Integer(((TextSyntax) attr).toString());
+            } else if (attr instanceof URISyntax) {
+                // TODO - it seems that this needs to be fixed
+                o = new Integer(((URISyntax) attr).toString());
+            }
+            break;
+        // character-string values for the "value-tag" field
+        case IppAttribute.TAG_TEXTWITHOUTLANGUAGE:
+        case IppAttribute.TAG_NAMEWITHOUTLANGUAGE:
+        case IppAttribute.TAG_KEYWORD:
+        case IppAttribute.TAG_URI:
+        case IppAttribute.TAG_URISCHEME:
+        case IppAttribute.TAG_CHARSET:
+        case IppAttribute.TAG_NATURAL_LANGUAGE:
+        case IppAttribute.TAG_MIMEMEDIATYPE:
+            if (attr instanceof IntegerSyntax) {
+                o = ((IntegerSyntax) attr).toString();
+            } else if (attr instanceof EnumSyntax) {
+                o = ((EnumSyntax) attr).toString();
+            } else if (attr instanceof DateTimeSyntax
+                    || attr instanceof ResolutionSyntax
+                    || attr instanceof SetOfIntegerSyntax
+                    || attr instanceof Size2DSyntax) {
+                // TODO - process other attr's types
+            } else if (attr instanceof TextSyntax) {
+                o = ((TextSyntax) attr).toString();
+            } else if (attr instanceof URISyntax) {
+                o = ((URISyntax) attr).toString();
+            }
+            break;
+        default:
+            break;
+        }
+
+        return o;
+    }
+
+    public static Object getObject(Class e, int eval) {
+        Object o = null;
+        EnumSyntax[] et = getEnumValueTable(e);
+
+        if (et != null) {
+            for (int i = 0, ii = et.length; i < ii; i++) {
+                if (et[i] != null && et[i].getValue() == eval) {
+                    o = et[i];
+                    break;
+                }
+            }
+        }
+
+        return o;
+    }
+
+    public static Object getObject(Class e, String eval) {
+        Object o = null;
+        EnumSyntax[] et = getEnumValueTable(e);
+
+        if (et != null) {
+            for (int i = 0, ii = et.length; i < ii; i++) {
+                if (et[i] != null && et[i].toString().equals(eval)) {
+                    o = et[i];
+                    break;
+                }
+            }
+        }
+
+        return o;
+    }
+
+    public static EnumSyntax[] getEnumValueTable(Class e) {
+        for (int i = 0, ii = enumTables.length; i < ii; i++) {
+            if (enumTables[i][0] == e) {
+                return (EnumSyntax[]) enumTables[i][1];
+            }
+        }
+        return null;
+    }
+
+    static Chromaticity[] enumChromaticityTable = { Chromaticity.MONOCHROME,
+            Chromaticity.COLOR };
+
+    static ColorSupported[] enumColorSupportedTable = { ColorSupported.NOT_SUPPORTED,
+            ColorSupported.SUPPORTED };
+
+    static Compression[] enumCompressionTable = { Compression.NONE,
+            Compression.DEFLATE,
+            Compression.GZIP,
+            Compression.COMPRESS };
+
+    static Fidelity[] enumFidelityTable = { Fidelity.FIDELITY_TRUE,
+            Fidelity.FIDELITY_FALSE };
+
+    static Finishings[] enumFinishingsTable = { Finishings.NONE,
+            Finishings.STAPLE,
+            null,
+            Finishings.COVER,
+            Finishings.BIND,
+            Finishings.SADDLE_STITCH,
+            Finishings.EDGE_STITCH,
+            null,
+            null,
+            null,
+            null,
+            null,
+            null,
+            null,
+            null,
+            null,
+            null,
+            Finishings.STAPLE_TOP_LEFT,
+            Finishings.STAPLE_BOTTOM_LEFT,
+            Finishings.STAPLE_TOP_RIGHT,
+            Finishings.STAPLE_BOTTOM_RIGHT,
+            Finishings.EDGE_STITCH_LEFT,
+            Finishings.EDGE_STITCH_TOP,
+            Finishings.EDGE_STITCH_RIGHT,
+            Finishings.EDGE_STITCH_BOTTOM,
+            Finishings.STAPLE_DUAL_LEFT,
+            Finishings.STAPLE_DUAL_TOP,
+            Finishings.STAPLE_DUAL_RIGHT,
+            Finishings.STAPLE_DUAL_BOTTOM };
+
+    static JobSheets[] enumJobSheetsTable = { JobSheets.NONE,
+            JobSheets.STANDARD };
+
+    static JobState[] enumJobStateTable = { JobState.UNKNOWN,
+            null,
+            null,
+            JobState.PENDING,
+            JobState.PENDING_HELD,
+            JobState.PROCESSING,
+            JobState.PROCESSING_STOPPED,
+            JobState.CANCELED,
+            JobState.ABORTED,
+            JobState.COMPLETED };
+
+    static JobStateReason[] enumJobStateReasonTable = { JobStateReason.JOB_INCOMING,
+            JobStateReason.JOB_DATA_INSUFFICIENT,
+            JobStateReason.DOCUMENT_ACCESS_ERROR,
+            JobStateReason.SUBMISSION_INTERRUPTED,
+            JobStateReason.JOB_OUTGOING,
+            JobStateReason.JOB_HOLD_UNTIL_SPECIFIED,
+            JobStateReason.RESOURCES_ARE_NOT_READY,
+            JobStateReason.PRINTER_STOPPED_PARTLY,
+            JobStateReason.PRINTER_STOPPED,
+            JobStateReason.JOB_INTERPRETING,
+            JobStateReason.JOB_QUEUED,
+            JobStateReason.JOB_TRANSFORMING,
+            JobStateReason.JOB_QUEUED_FOR_MARKER,
+            JobStateReason.JOB_PRINTING,
+            JobStateReason.JOB_CANCELED_BY_USER,
+            JobStateReason.JOB_CANCELED_BY_OPERATOR,
+            JobStateReason.JOB_CANCELED_AT_DEVICE,
+            JobStateReason.ABORTED_BY_SYSTEM,
+            JobStateReason.UNSUPPORTED_COMPRESSION,
+            JobStateReason.COMPRESSION_ERROR,
+            JobStateReason.UNSUPPORTED_DOCUMENT_FORMAT,
+            JobStateReason.DOCUMENT_FORMAT_ERROR,
+            JobStateReason.PROCESSING_TO_STOP_POINT,
+            JobStateReason.SERVICE_OFF_LINE,
+            JobStateReason.JOB_COMPLETED_SUCCESSFULLY,
+            JobStateReason.JOB_COMPLETED_WITH_WARNINGS,
+            JobStateReason.JOB_COMPLETED_WITH_ERRORS,
+            JobStateReason.JOB_RESTARTABLE,
+            JobStateReason.QUEUED_IN_DEVICE };
+
+    static MediaName[] enumMediaNameTable = { MediaName.NA_LETTER_WHITE,
+            MediaName.NA_LETTER_TRANSPARENT,
+            MediaName.ISO_A4_WHITE,
+            MediaName.ISO_A4_TRANSPARENT };
+
+    static MediaSizeName[] enumMediaSizeNameTable = { MediaSizeName.ISO_A0,
+            MediaSizeName.ISO_A1,
+            MediaSizeName.ISO_A2,
+            MediaSizeName.ISO_A3,
+            MediaSizeName.ISO_A4,
+            MediaSizeName.ISO_A5,
+            MediaSizeName.ISO_A6,
+            MediaSizeName.ISO_A7,
+            MediaSizeName.ISO_A8,
+            MediaSizeName.ISO_A9,
+            MediaSizeName.ISO_A10,
+            MediaSizeName.ISO_B0,
+            MediaSizeName.ISO_B1,
+            MediaSizeName.ISO_B2,
+            MediaSizeName.ISO_B3,
+            MediaSizeName.ISO_B4,
+            MediaSizeName.ISO_B5,
+            MediaSizeName.ISO_B6,
+            MediaSizeName.ISO_B7,
+            MediaSizeName.ISO_B8,
+            MediaSizeName.ISO_B9,
+            MediaSizeName.ISO_B10,
+            MediaSizeName.JIS_B0,
+            MediaSizeName.JIS_B1,
+            MediaSizeName.JIS_B2,
+            MediaSizeName.JIS_B3,
+            MediaSizeName.JIS_B4,
+            MediaSizeName.JIS_B5,
+            MediaSizeName.JIS_B6,
+            MediaSizeName.JIS_B7,
+            MediaSizeName.JIS_B8,
+            MediaSizeName.JIS_B9,
+            MediaSizeName.JIS_B10,
+            MediaSizeName.ISO_C0,
+            MediaSizeName.ISO_C1,
+            MediaSizeName.ISO_C2,
+            MediaSizeName.ISO_C3,
+            MediaSizeName.ISO_C4,
+            MediaSizeName.ISO_C5,
+            MediaSizeName.ISO_C6,
+            MediaSizeName.NA_LETTER,
+            MediaSizeName.NA_LEGAL,
+            MediaSizeName.EXECUTIVE,
+            MediaSizeName.LEDGER,
+            MediaSizeName.TABLOID,
+            MediaSizeName.INVOICE,
+            MediaSizeName.FOLIO,
+            MediaSizeName.QUARTO,
+            MediaSizeName.JAPANESE_POSTCARD,
+            MediaSizeName.JAPANESE_DOUBLE_POSTCARD,
+            MediaSizeName.A,
+            MediaSizeName.B,
+            MediaSizeName.C,
+            MediaSizeName.D,
+            MediaSizeName.E,
+            MediaSizeName.ISO_DESIGNATED_LONG,
+            MediaSizeName.ITALY_ENVELOPE,
+            MediaSizeName.MONARCH_ENVELOPE,
+            MediaSizeName.PERSONAL_ENVELOPE,
+            MediaSizeName.NA_NUMBER_9_ENVELOPE,
+            MediaSizeName.NA_NUMBER_10_ENVELOPE,
+            MediaSizeName.NA_NUMBER_11_ENVELOPE,
+            MediaSizeName.NA_NUMBER_12_ENVELOPE,
+            MediaSizeName.NA_NUMBER_14_ENVELOPE,
+            MediaSizeName.NA_6X9_ENVELOPE,
+            MediaSizeName.NA_7X9_ENVELOPE,
+            MediaSizeName.NA_9X11_ENVELOPE,
+            MediaSizeName.NA_9X12_ENVELOPE,
+            MediaSizeName.NA_10X13_ENVELOPE,
+            MediaSizeName.NA_10X14_ENVELOPE,
+            MediaSizeName.NA_10X15_ENVELOPE,
+            MediaSizeName.NA_5X7,
+            MediaSizeName.NA_8X10 };
+
+    static MediaTray[] enumMediaTrayTable = { MediaTray.TOP,
+            MediaTray.MIDDLE,
+            MediaTray.BOTTOM,
+            MediaTray.ENVELOPE,
+            MediaTray.MANUAL,
+            MediaTray.LARGE_CAPACITY,
+            MediaTray.MAIN,
+            MediaTray.SIDE };
+
+    static MultipleDocumentHandling[] enumMultipleDocumentHandlingTable = { MultipleDocumentHandling.SINGLE_DOCUMENT,
+            MultipleDocumentHandling.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES,
+            MultipleDocumentHandling.SEPARATE_DOCUMENTS_COLLATED_COPIES,
+            MultipleDocumentHandling.SINGLE_DOCUMENT_NEW_SHEET };
+
+    static OrientationRequested[] enumOrientationRequestedTable = { OrientationRequested.PORTRAIT,
+            OrientationRequested.LANDSCAPE,
+            OrientationRequested.REVERSE_LANDSCAPE,
+            OrientationRequested.REVERSE_PORTRAIT };
+
+    static PDLOverrideSupported[] enumPDLOverrideSupportedTable = { PDLOverrideSupported.NOT_ATTEMPTED,
+            PDLOverrideSupported.ATTEMPTED };
+
+    static PresentationDirection[] enumPresentationDirectionTable = { PresentationDirection.TOBOTTOM_TORIGHT,
+            PresentationDirection.TOBOTTOM_TOLEFT,
+            PresentationDirection.TOTOP_TORIGHT,
+            PresentationDirection.TOTOP_TOLEFT,
+            PresentationDirection.TORIGHT_TOBOTTOM,
+            PresentationDirection.TORIGHT_TOTOP,
+            PresentationDirection.TOLEFT_TOBOTTOM,
+            PresentationDirection.TOLEFT_TOTOP };
+
+    static PrinterIsAcceptingJobs[] enumPrinterIsAcceptingJobsTable = { PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS,
+            PrinterIsAcceptingJobs.ACCEPTING_JOBS };
+
+    static PrinterState[] enumPrinterStateTable = { PrinterState.UNKNOWN,
+            null,
+            null,
+            PrinterState.IDLE,
+            PrinterState.PROCESSING,
+            PrinterState.STOPPED };
+
+    static PrinterStateReason[] enumPrinterStateReasonTable = { PrinterStateReason.OTHER,
+            PrinterStateReason.MEDIA_NEEDED,
+            PrinterStateReason.MEDIA_JAM,
+            PrinterStateReason.MOVING_TO_PAUSED,
+            PrinterStateReason.PAUSED,
+            PrinterStateReason.SHUTDOWN,
+            PrinterStateReason.CONNECTING_TO_DEVICE,
+            PrinterStateReason.TIMED_OUT,
+            PrinterStateReason.STOPPING,
+            PrinterStateReason.STOPPED_PARTLY,
+            PrinterStateReason.TONER_LOW,
+            PrinterStateReason.TONER_EMPTY,
+            PrinterStateReason.SPOOL_AREA_FULL,
+            PrinterStateReason.COVER_OPEN,
+            PrinterStateReason.INTERLOCK_OPEN,
+            PrinterStateReason.DOOR_OPEN,
+            PrinterStateReason.INPUT_TRAY_MISSING,
+            PrinterStateReason.MEDIA_LOW,
+            PrinterStateReason.MEDIA_EMPTY,
+            PrinterStateReason.OUTPUT_TRAY_MISSING,
+            PrinterStateReason.OUTPUT_AREA_ALMOST_FULL,
+            PrinterStateReason.OUTPUT_AREA_FULL,
+            PrinterStateReason.MARKER_SUPPLY_LOW,
+            PrinterStateReason.MARKER_SUPPLY_EMPTY,
+            PrinterStateReason.MARKER_WASTE_ALMOST_FULL,
+            PrinterStateReason.MARKER_WASTE_FULL,
+            PrinterStateReason.FUSER_OVER_TEMP,
+            PrinterStateReason.FUSER_UNDER_TEMP,
+            PrinterStateReason.OPC_NEAR_EOL,
+            PrinterStateReason.OPC_LIFE_OVER,
+            PrinterStateReason.DEVELOPER_LOW,
+            PrinterStateReason.DEVELOPER_EMPTY,
+            PrinterStateReason.INTERPRETER_RESOURCE_UNAVAILABLE };
+
+    static PrintQuality[] enumPrintQualityTable = { PrintQuality.DRAFT,
+            PrintQuality.NORMAL,
+            PrintQuality.HIGH };
+
+    static ReferenceUriSchemesSupported[] enumReferenceUriSchemesSupportedTable = { ReferenceUriSchemesSupported.FTP,
+            ReferenceUriSchemesSupported.HTTP,
+            ReferenceUriSchemesSupported.HTTPS,
+            ReferenceUriSchemesSupported.GOPHER,
+            ReferenceUriSchemesSupported.NEWS,
+            ReferenceUriSchemesSupported.NNTP,
+            ReferenceUriSchemesSupported.WAIS,
+            ReferenceUriSchemesSupported.FILE };
+
+    static Severity[] enumSeverityTable = { Severity.REPORT,
+            Severity.WARNING,
+            Severity.ERROR };
+
+    static SheetCollate[] enumSheetCollateTable = { SheetCollate.UNCOLLATED,
+            SheetCollate.COLLATED };
+
+    static Sides[] enumSidesTable = { Sides.ONE_SIDED,
+            Sides.TWO_SIDED_LONG_EDGE,
+            Sides.TWO_SIDED_SHORT_EDGE };
+
+    static PPDMediaSizeName[] enumPPDMediaSizeNameTable = (PPDMediaSizeName[]) PPDMediaSizeName.A4
+            .getEnumValueTable();
+
+    static Object[][] enumTables = { { Chromaticity.class,
+            enumChromaticityTable },
+            { ColorSupported.class, enumColorSupportedTable },
+            { Compression.class, enumCompressionTable },
+            { Fidelity.class, enumFidelityTable },
+            { Finishings.class, enumFinishingsTable },
+            { JobSheets.class, enumJobSheetsTable },
+            { JobState.class, enumJobStateTable },
+            { JobStateReason.class, enumJobStateReasonTable },
+            { MediaName.class, enumMediaNameTable },
+            { MediaSizeName.class, enumMediaSizeNameTable },
+            { MediaTray.class, enumMediaTrayTable },
+            { MultipleDocumentHandling.class, enumMultipleDocumentHandlingTable },
+            { OrientationRequested.class, enumOrientationRequestedTable },
+            { PDLOverrideSupported.class, enumPDLOverrideSupportedTable },
+            { PresentationDirection.class, enumPresentationDirectionTable },
+            { PrinterIsAcceptingJobs.class, enumPrinterIsAcceptingJobsTable },
+            { PrinterState.class, enumPrinterStateTable },
+            { PrinterStateReason.class, enumPrinterStateReasonTable },
+            { PrintQuality.class, enumPrintQualityTable },
+            { ReferenceUriSchemesSupported.class,
+                    enumReferenceUriSchemesSupportedTable },
+            { Severity.class, enumSeverityTable },
+            { SheetCollate.class, enumSheetCollateTable },
+            { Sides.class, enumSidesTable },
+            { PPDMediaSizeName.class, enumPPDMediaSizeNameTable } };
+
+}
+

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/util/IppAttributeUtils.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/util/IppHttpAuthenticator.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/util/IppHttpAuthenticator.java?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/util/IppHttpAuthenticator.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/util/IppHttpAuthenticator.java Sun Oct  8 22:33:09 2006
@@ -0,0 +1,61 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/** 
+ * @author Igor A. Pyankov 
+ * @version $Revision: 1.2 $ 
+ */ 
+
+package org.apache.harmony.x.print.ipp.util;
+
+import java.awt.GridLayout;
+import java.net.Authenticator;
+import java.net.PasswordAuthentication;
+
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JPasswordField;
+import javax.swing.JTextField;
+
+public class IppHttpAuthenticator extends Authenticator {
+    protected PasswordAuthentication getPasswordAuthentication() {
+        JTextField username = new JTextField();
+        JTextField password = new JPasswordField();
+        JPanel panel = new JPanel(new GridLayout(2, 2));
+        
+        panel.add(new JLabel("username"));
+        panel.add(username);
+        panel.add(new JLabel("password"));
+        panel.add(password);
+        
+        int option = JOptionPane.showConfirmDialog(null,
+            new Object[] { "Site: " + getRequestingHost(),
+                    "Realm: " + getRequestingPrompt(),
+                    panel },
+            "Enter Username and Password",
+            JOptionPane.OK_CANCEL_OPTION,
+            JOptionPane.PLAIN_MESSAGE);
+        
+        if (option == JOptionPane.OK_OPTION) {
+            String user = username.getText();
+            char   pass[] = password.getText().toCharArray();
+            
+            return new PasswordAuthentication(user, pass);
+        }
+        return null;
+    }
+
+}
\ No newline at end of file

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/util/IppHttpAuthenticator.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/util/IppMimeType.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/util/IppMimeType.java?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/util/IppMimeType.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/util/IppMimeType.java Sun Oct  8 22:33:09 2006
@@ -0,0 +1,57 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/** 
+ * @author Igor A. Pyankov 
+ * @version $Revision: 1.2 $ 
+ */ 
+
+package org.apache.harmony.x.print.ipp.util;
+
+import org.apache.harmony.x.print.MimeType;
+
+public class IppMimeType extends MimeType {
+
+    /*
+     * @param mimeType
+     */
+    public IppMimeType(String mimeType) {
+        super(mimeType);
+    }
+
+    /*
+     * returns IPP/CUPS specific for MimeType object.
+     */
+    public String getIppSpecificForm() {
+        StringBuffer s = new StringBuffer();
+        s.append(getType());
+        s.append("/");
+        s.append(getSubtype());
+        for (int i = 0; i < getParams().length; i++) {
+            s.append("; ");
+            s.append(getParams()[i][0]);
+            if (getParams()[i][0].equalsIgnoreCase("charset")) {
+                s.append("=");
+                s.append(getParams()[i][1]);
+            } else {
+                s.append("=\"");
+                s.append(getParams()[i][1]);
+                s.append("\"");
+            }
+        }
+        return s.toString();
+    }
+
+}
\ No newline at end of file

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/ipp/util/IppMimeType.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/javax.print.StreamPrintServiceFactory
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/javax.print.StreamPrintServiceFactory?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/javax.print.StreamPrintServiceFactory (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/javax.print.StreamPrintServiceFactory Sun Oct  8 22:33:09 2006
@@ -0,0 +1,2 @@
+#Factory 
+org.apache.harmony.x.print.PSStreamPrintServiceFactory

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/javax.print.StreamPrintServiceFactory
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/util/FactoryLocator.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/util/FactoryLocator.java?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/util/FactoryLocator.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/util/FactoryLocator.java Sun Oct  8 22:33:09 2006
@@ -0,0 +1,142 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/** 
+ * @author Igor A. Pyankov 
+ * @version $Revision: 1.3 $ 
+ */ 
+
+package org.apache.harmony.x.print.util;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.Enumeration;
+
+/*
+ *  auxilary class FactoryLocator 
+ *  for abstract class javax.print.StreamPrintServiceFactory
+ */
+public class FactoryLocator {    
+    ArrayList factoryClasses; /* List of accessible Factories */  
+             
+    /*
+     * Constructor for FactoryLocator
+     */
+    public FactoryLocator() {
+        super();
+        factoryClasses = new ArrayList();
+    }
+    
+    public ArrayList getFactoryClasses(){
+        return  factoryClasses;
+    }
+    
+    public void lookupAllFactories() throws IOException{        
+        Enumeration setOfFactories = null;                         
+        ClassLoader classLoader = null;     // current class loader
+        InputStream inputStream = null;     // stream for reader
+
+
+        classLoader = (ClassLoader) AccessController
+                                        .doPrivileged(new PrivilegedAction() {
+                public Object run(){
+                    ClassLoader cl = Thread.currentThread()
+                                        .getContextClassLoader();
+                    if (cl == null) {
+                        cl = ClassLoader.getSystemClassLoader();
+                    }
+                    return cl;
+                }
+            }
+        );
+
+        if (classLoader == null) {
+            return; //something is wrong with classloader    
+        }      
+        
+        // get all needed resources
+        try {
+            setOfFactories = classLoader.getResources(
+                   "META-INF/services/javax.print.StreamPrintServiceFactory");
+        } catch (IOException e) {
+            e.printStackTrace();
+            throw new IOException("IOException during resource finding");
+        }
+        
+        try {
+            while (setOfFactories.hasMoreElements()) {
+                URL url = (URL) setOfFactories.nextElement();               
+                inputStream = url.openStream();
+                getFactoryClasses(inputStream);            
+            }
+        } catch (IOException e1) {
+            e1.printStackTrace();
+            throw new IOException("IOException during resource reading");
+        }
+       
+    }
+
+    /*
+     * factory class extraction method 
+     */  
+    private void getFactoryClasses(InputStream is) throws IOException {
+        BufferedReader factoryNameReader;
+        Class factoryClass;
+        String name = null;        
+        
+        // creation reader
+        try {
+            factoryNameReader = new BufferedReader(new InputStreamReader(is,
+                    "UTF-8"));
+        } catch (UnsupportedEncodingException uee) {
+            // Let's try 7-bit encoding :(
+            factoryNameReader = new BufferedReader(new InputStreamReader(is));
+        }
+
+        if (factoryNameReader == null) {            
+            return; //no reader for classes
+        }
+        //reading class names and filling factoryClasses array         
+        try {
+            while(true){
+                name = factoryNameReader.readLine();                
+                if (name == null){
+                    return;
+                }
+                if (name.length() > 0 && name.charAt(0) != '#'){
+                    //it is not comment nor empty string
+                    factoryClass = Class.forName(name);                   
+                    factoryClasses.add(factoryClass.newInstance());  
+                }
+            }
+        } catch (IOException e) {             
+            throw new IOException("IOException during reading file");
+        } catch (ClassNotFoundException e) {
+            throw new IOException("Class" + name + " is not found");
+        } catch (InstantiationException e) {
+            throw new IOException("Bad instantiation of class" + name);
+        } catch (IllegalAccessException e) {
+            throw new IOException("Illegal access for class" + name);
+        } 
+    }
+
+}
\ No newline at end of file

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/common/org/apache/harmony/x/print/util/FactoryLocator.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/linux/org/apache/harmony/x/print/javax.print.PrintServiceLookup
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/linux/org/apache/harmony/x/print/javax.print.PrintServiceLookup?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/linux/org/apache/harmony/x/print/javax.print.PrintServiceLookup (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/linux/org/apache/harmony/x/print/javax.print.PrintServiceLookup Sun Oct  8 22:33:09 2006
@@ -0,0 +1 @@
+org.apache.harmony.x.print.cups.CUPSPrintServiceProvider

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/linux/org/apache/harmony/x/print/javax.print.PrintServiceLookup
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/windows/org/apache/harmony/x/print/GDIClient.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/windows/org/apache/harmony/x/print/GDIClient.java?view=auto&rev=454289
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/windows/org/apache/harmony/x/print/GDIClient.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/windows/org/apache/harmony/x/print/GDIClient.java Sun Oct  8 22:33:09 2006
@@ -0,0 +1,697 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/** 
+ * @author Aleksei V. Ivaschenko 
+ * @version $Revision: 1.4 $ 
+ */ 
+
+package org.apache.harmony.x.print;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Locale;
+import javax.print.Doc;
+import javax.print.DocFlavor;
+import javax.print.PrintException;
+import javax.print.attribute.Attribute;
+import javax.print.attribute.AttributeSet;
+import javax.print.attribute.HashPrintServiceAttributeSet;
+import javax.print.attribute.PrintRequestAttributeSet;
+import javax.print.attribute.PrintServiceAttributeSet;
+import javax.print.attribute.standard.Chromaticity;
+import javax.print.attribute.standard.ColorSupported;
+import javax.print.attribute.standard.Copies;
+import javax.print.attribute.standard.CopiesSupported;
+import javax.print.attribute.standard.Destination;
+import javax.print.attribute.standard.JobName;
+import javax.print.attribute.standard.Media;
+import javax.print.attribute.standard.MediaSize;
+import javax.print.attribute.standard.MediaSizeName;
+import javax.print.attribute.standard.OrientationRequested;
+import javax.print.attribute.standard.PagesPerMinute;
+import javax.print.attribute.standard.PagesPerMinuteColor;
+import javax.print.attribute.standard.PrinterIsAcceptingJobs;
+import javax.print.attribute.standard.PrinterLocation;
+import javax.print.attribute.standard.PrinterName;
+import javax.print.attribute.standard.PrinterResolution;
+import javax.print.attribute.standard.QueuedJobCount;
+import javax.print.attribute.standard.RequestingUserName;
+import javax.print.attribute.standard.SheetCollate;
+import javax.print.attribute.standard.Sides;
+
+import org.apache.harmony.x.print.PrintClient;
+
+/*
+ * GDIClient is a print client based on windows GDI inteface.
+ * See description of PrintClient interface for more information.
+ */
+class GDIClient implements PrintClient {
+
+    private String serviceName = null;
+    private boolean isPrinting = false;
+
+    private static final int MAX_BUFFER_SIZE = 10240;
+
+    private static final int ATTRIBUTES_ARRAY_SIZE = 8;
+    private static final int COPIES_INDEX = 0;
+    private static final int SIDES_INDEX = 1;
+    private static final int PAPER_ID_INDEX = 2;
+    private static final int COLLATE_INDEX = 3;
+    private static final int CHROMATICITY_INDEX = 4;
+    private static final int ORIENTATION_INDEX = 5;
+    private static final int XRESOLUTION_INDEX = 6;
+    private static final int YRESOLUTION_INDEX = 7;
+
+    private static final int NOT_STANDARD_MEDIA = 1000;
+    private HashMap medias = new HashMap();
+    
+    GDIClient(String serviceName) {
+        this.serviceName = serviceName;
+    }
+    
+    /*
+     * @see org.apache.harmony.x.print.PrintClient#getSupportedDocFlavors()
+     */
+    public DocFlavor[] getSupportedDocFlavors() {
+        if (checkPostScript(serviceName)) {
+            return new DocFlavor[] {
+                new DocFlavor.INPUT_STREAM("INTERNAL/postscript"),
+                DocFlavor.INPUT_STREAM.POSTSCRIPT,
+                DocFlavor.BYTE_ARRAY.POSTSCRIPT,
+                DocFlavor.URL.POSTSCRIPT,
+                DocFlavor.INPUT_STREAM.AUTOSENSE,
+                DocFlavor.BYTE_ARRAY.AUTOSENSE,
+                DocFlavor.URL.AUTOSENSE
+            };
+        } else {
+            return new DocFlavor[] {
+                new DocFlavor.INPUT_STREAM("INTERNAL/postscript"),
+                DocFlavor.INPUT_STREAM.AUTOSENSE,
+                DocFlavor.BYTE_ARRAY.AUTOSENSE,
+                DocFlavor.URL.AUTOSENSE
+            };
+        }
+    }
+
+    /*
+     * @see org.apache.harmony.x.print.PrintClient#getAttributes()
+     */
+    public PrintServiceAttributeSet getAttributes() {
+        PrintServiceAttributeSet attributes =
+            new HashPrintServiceAttributeSet();
+        attributes.add(new PrinterName(serviceName, Locale.getDefault()));
+        if (getColorSupported(serviceName)) {
+            attributes.add(ColorSupported.SUPPORTED);
+            int colorPPM = getPagesPerMinuteColor(serviceName);
+            if (colorPPM > 0) {
+                attributes.add(new PagesPerMinuteColor(colorPPM));
+            }
+        } else {
+            attributes.add(ColorSupported.NOT_SUPPORTED);
+        }
+        
+        int pagesPerMinute = getPagesPerMinute(serviceName);
+        if (pagesPerMinute > 0) {
+            attributes.add(new PagesPerMinute(pagesPerMinute));
+        }
+        
+        String printerLocation = getPrinterLocation(serviceName);
+        if (printerLocation != null) {
+            attributes.add(new PrinterLocation(printerLocation,
+                    Locale.getDefault()));
+        }
+        
+        int acceptingJobs = getPrinterIsAcceptingJobs(serviceName);
+        if (acceptingJobs == 0) {
+            attributes.add(PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS);
+        } else if (acceptingJobs == 1) {
+            attributes.add(PrinterIsAcceptingJobs.ACCEPTING_JOBS);
+        }
+        
+        int jobCount = getQueuedJobCount(serviceName);
+        if (jobCount >= 0) {
+            attributes.add(new QueuedJobCount(jobCount));
+        }
+        return attributes;
+    }
+
+    /*
+     * @see org.apache.harmony.x.print.PrintClient#getSupportedAttributeCategories()
+     */
+    public Class[] getSupportedAttributeCategories() {
+        ArrayList supportedCategories = new ArrayList();
+        if (getCopiesSupported(serviceName) >= 1) {
+            supportedCategories.add(Copies.class);
+        }
+        if (getSidesSupported(serviceName)) {
+            supportedCategories.add(Sides.class);
+        }
+        if (getSupportedMediaSizeNames() != null) {
+            supportedCategories.add(Media.class);
+        }
+        if (getResolutionsSupported(serviceName) != null) {
+            supportedCategories.add(PrinterResolution.class);
+        }
+        if (getOrientationSupported(serviceName)) {
+            supportedCategories.add(OrientationRequested.class);
+        }
+        if (getCollateSupported(serviceName)) {
+            supportedCategories.add(SheetCollate.class);
+        }
+        supportedCategories.add(Chromaticity.class);
+        supportedCategories.add(JobName.class);
+        supportedCategories.add(RequestingUserName.class);
+        supportedCategories.add(Destination.class);
+        
+        Class[] categories = new Class[supportedCategories.size()];
+        supportedCategories.toArray(categories);
+        return categories;
+    }
+
+    /*
+     * @see org.apache.harmony.x.print.PrintClient#getDefaultAttributeValue(
+     * java.lang.Class)
+     */
+    public Object getDefaultAttributeValue(Class category) {
+        if (category.equals(JobName.class)) {
+            return new JobName("Java GDI client print job", Locale.US);
+        } else if (category.equals(RequestingUserName.class)) {
+            return new RequestingUserName(System.getProperty("user.name"),
+                    Locale.US);
+        } else if (category.equals(Destination.class)) {
+            File file = new File(System.getProperty("user.dir") +
+                    File.separator + "output.prn");
+            return new Destination(file.toURI());
+        } else if (category.equals(SheetCollate.class)) {
+            return SheetCollate.COLLATED;
+        } else if (category.equals(Copies.class)) {
+            return new Copies(1);
+        }
+        return null;
+    }
+
+    /*
+     * @see org.apache.harmony.x.print.PrintClient#isAttributeValueSupported(
+     * javax.print.attribute.Attribute, javax.print.DocFlavor,
+     * javax.print.attribute.AttributeSet)
+     */
+    public boolean isAttributeValueSupported(Attribute attribute,
+            DocFlavor flavor, AttributeSet attributes) {
+        Class category = attribute.getCategory();
+        if (category.equals(JobName.class) ||
+            category.equals(RequestingUserName.class)) {
+            return true;
+        } else  if (category.equals(Destination.class)) {
+            Destination destination = (Destination)attribute;
+            if (destination.getURI().getScheme().equals("file")) {
+                return true;
+            }
+        }
+        if (flavor != null) {
+            if (flavor.equals(DocFlavor.INPUT_STREAM.AUTOSENSE) ||
+                flavor.equals(DocFlavor.BYTE_ARRAY.AUTOSENSE) ||
+                flavor.equals(DocFlavor.URL.AUTOSENSE) ||
+                flavor.equals(DocFlavor.INPUT_STREAM.POSTSCRIPT) ||
+                flavor.equals(DocFlavor.BYTE_ARRAY.POSTSCRIPT) ||
+                flavor.equals(DocFlavor.URL.POSTSCRIPT)) {
+                return false;
+            }
+        }
+        if (category.equals(Copies.class)) {
+            CopiesSupported copies =
+                (CopiesSupported)getSupportedAttributeValues(category, flavor,
+                                                             attributes);
+            int value = ((Copies)attribute).getValue();
+            if (copies != null && copies.contains(value)) {
+                return true;
+            }
+        } else if (category.equals(Sides.class)) {
+            Sides[] sides = (Sides[])getSupportedAttributeValues(category,
+                    flavor, attributes);
+            if (sides != null) {
+                for (int i = 0; i < sides.length; i++) {
+                    if (sides[i].equals(attribute)) {
+                        return true;
+                    }
+                }
+            }
+        } else if (category.equals(Media.class)) {
+            Media[] medias = (Media[])getSupportedAttributeValues(category,
+                    flavor, attributes);
+            if (medias != null) {
+                for (int i = 0; i < medias.length; i++) {
+                    if (medias[i].equals(attribute)) {
+                        return true;
+                    }
+                }
+            }
+        } else if (category.equals(Chromaticity.class)) {
+            if (attribute.equals(Chromaticity.COLOR)) {
+                if (!getColorSupported(serviceName)) {
+                    return false;
+                }
+            }
+            return true;
+        } else if (category.equals(OrientationRequested.class)) {
+            if (getOrientationSupported(serviceName)) {
+                if (attribute.equals(OrientationRequested.PORTRAIT) ||
+                    attribute.equals(OrientationRequested.LANDSCAPE))
+                return true;
+            }
+        } else if (category.equals(PrinterResolution.class)) {
+            int[] resolutions = getResolutionsSupported(serviceName);
+            if (resolutions != null && resolutions.length > 1) {
+                PrinterResolution resolution = (PrinterResolution)attribute;
+                int xres = resolution.getCrossFeedResolution(
+                        PrinterResolution.DPI);
+                int yres = resolution.getFeedResolution(PrinterResolution.DPI);
+                for (int i = 0; i < resolutions.length / 2; i++) {
+                    if (xres == resolutions[i * 2] &&
+                        yres == resolutions[i * 2 + 1]) {
+                        return true;
+                    }
+                }
+            }
+        } else if (category.equals(SheetCollate.class)) {
+            if (getCollateSupported(serviceName)) {
+                if (attribute == SheetCollate.COLLATED ||
+                    attribute == SheetCollate.UNCOLLATED) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    /*
+     * @see org.apache.harmony.x.print.PrintClient#getSupportedAttributeValues(
+     * java.lang.Class, javax.print.DocFlavor,
+     * javax.print.attribute.AttributeSet)
+     */
+    public Object getSupportedAttributeValues(Class category, DocFlavor flavor,
+            AttributeSet attributes) {
+        if (flavor != null &&
+            (flavor.equals(DocFlavor.INPUT_STREAM.AUTOSENSE) ||
+             flavor.equals(DocFlavor.BYTE_ARRAY.AUTOSENSE) ||
+             flavor.equals(DocFlavor.URL.AUTOSENSE) ||
+             flavor.equals(DocFlavor.INPUT_STREAM.POSTSCRIPT) ||
+             flavor.equals(DocFlavor.BYTE_ARRAY.POSTSCRIPT) ||
+             flavor.equals(DocFlavor.URL.POSTSCRIPT))) {
+            return null;
+        }
+        if (category.equals(Copies.class)) {
+            int copies = getCopiesSupported(serviceName);
+            if (copies == 1) {
+                return new CopiesSupported(1);
+            } else if (copies > 1) {
+                return new CopiesSupported(1, copies);
+            }
+        } else if (category.equals(Sides.class)) {
+            if (getSidesSupported(serviceName)) {
+                return new Sides[] {Sides.ONE_SIDED,
+                                    Sides.TWO_SIDED_SHORT_EDGE,
+                                    Sides.TWO_SIDED_LONG_EDGE,
+                                    Sides.DUPLEX,
+                                    Sides.TUMBLE};
+            }
+        } else if (category.equals(Media.class)) {
+            return getSupportedMediaSizeNames();
+        } else if (category.equals(MediaSizeName.class)) {
+            return getSupportedMediaSizeNames();
+        } else if (category.equals(Chromaticity.class)) {
+            if (getColorSupported(serviceName)) {
+                return new Chromaticity[] { Chromaticity.MONOCHROME,
+                                            Chromaticity.COLOR };
+            } else {
+                return new Chromaticity[] { Chromaticity.MONOCHROME };
+            }
+        } else if (category.equals(OrientationRequested.class)) {
+            if (getOrientationSupported(serviceName)) {
+                return new OrientationRequested[]
+                    { OrientationRequested.PORTRAIT,
+                      OrientationRequested.LANDSCAPE };
+            }
+        } else if (category.equals(PrinterResolution.class)) {
+            int[] resolutions = getResolutionsSupported(serviceName);
+            if (resolutions != null && resolutions.length > 1) {
+                PrinterResolution[] res =
+                    new PrinterResolution[resolutions.length / 2];
+                for (int i = 0; i < resolutions.length / 2; i++) {
+                    res[i] = new PrinterResolution(resolutions[i * 2],
+                            resolutions[i * 2 + 1], PrinterResolution.DPI);
+                }
+                return res;
+            }
+        } else if (category.equals(SheetCollate.class)) {
+            if (getCollateSupported(serviceName)) {
+                return new SheetCollate[] { SheetCollate.COLLATED,
+                                            SheetCollate.UNCOLLATED };
+            }
+        }
+        return null;
+    }
+
+    private MediaSizeName[] getSupportedMediaSizeNames() {
+        int[][] mediaSizes = getMediaSizesSupported(serviceName);
+        if (mediaSizes == null || mediaSizes.length == 0) {
+            return null;
+        }
+        int[] ids = getMediaIDs(serviceName);
+        String[] names = getMediaNames(serviceName);
+        if (ids == null || names == null || ids.length != mediaSizes.length ||
+                names.length != mediaSizes.length) {
+            /*
+             * Something wrong. Don't know exactly what happend,
+             * but printer driver returned different ammount of
+             * sizes, IDs and names of media.
+             */
+            return null;
+        }
+        MediaSizeName[] mediaNames =  GDIMediaName.getStandardMediaSizeNames();
+        if (mediaNames == null || mediaNames.length == 0) {
+            return null;
+        }
+        ArrayList result = new ArrayList();
+        medias.clear();
+        for (int i = 0; i < mediaSizes.length; i++) {
+            float sizeX = mediaSizes[i][0] / 10.0f;
+            float sizeY = mediaSizes[i][1] / 10.0f;
+            if (sizeX > 0 && sizeY > 0) {
+                boolean standardFound = false;
+                for (int j = 0; j < mediaNames.length; j++) {
+                    MediaSize mediaSize =
+                        MediaSize.getMediaSizeForName(mediaNames[j]);
+                    if (mediaSize != null &&
+                        Math.abs(sizeX - mediaSize.getX(MediaSize.MM)) < 1 &&
+                        Math.abs(sizeY - mediaSize.getY(MediaSize.MM)) < 1) {
+                        standardFound = true;
+                        if (!result.contains(mediaNames[j])) {
+                            result.add(mediaNames[j]);
+                            medias.put(mediaNames[j], new Integer(ids[i]));
+                            /* TODO:
+                             * Do we have to do this break? If not,
+                             * all names of one size returned.
+                             */
+                            break;
+                        }
+                    }
+                }
+                if (!standardFound) {
+                    GDIMediaName name = new GDIMediaName(names[i],
+                            NOT_STANDARD_MEDIA + i);
+                    MediaSizeName sname = MediaSize.findMedia(sizeX, sizeY,
+                            MediaSize.MM);
+                    if (sname == null) {
+                        MediaSize size = new MediaSize(sizeX, sizeY,
+                                MediaSize.MM, name);
+                    } else {
+                        MediaSize size = MediaSize.getMediaSizeForName(sname);
+                        if (size.getX(MediaSize.MM) != sizeX ||
+                            size.getY(MediaSize.MM) != sizeY) {
+                            MediaSize newSize = new MediaSize(sizeX, sizeY,
+                                    MediaSize.MM, name);
+                        }
+                    }
+                    if (!result.contains(name)) {
+                        result.add(name);
+                        medias.put(name, new Integer(ids[i]));
+                    }
+                }
+            }
+        }
+        if (result.size() > 0) {
+            return (MediaSizeName[])result.toArray(new MediaSizeName[0]);
+        }
+        return null;
+    }
+
+    private MediaSize[] getSupportedMediaSizes() {
+        MediaSizeName[] mediaSizeNames = getSupportedMediaSizeNames();
+        if (mediaSizeNames != null) {
+            MediaSize[] mediaSizes = new MediaSize[mediaSizeNames.length];
+            for (int i = 0; i < mediaSizeNames.length; i++) {
+                mediaSizes[i] =
+                    MediaSize.getMediaSizeForName(mediaSizeNames[i]);
+            }
+            return mediaSizes;
+        }
+        return null;
+    }
+
+//----------------------- Printing ---------------------------------------------    
+    
+    /*
+     * @see org.apache.harmony.x.print.PrintClient#print(javax.print.Doc,
+     * javax.print.attribute.PrintRequestAttributeSet)
+     */
+    public void print(Doc doc, PrintRequestAttributeSet attributes)
+            throws PrintException {
+        synchronized (this) {
+            DocFlavor flavor = doc.getDocFlavor();
+            if (flavor.equals(DocFlavor.INPUT_STREAM.POSTSCRIPT) ||
+                flavor.equals(DocFlavor.BYTE_ARRAY.POSTSCRIPT) ||
+                flavor.equals(DocFlavor.URL.POSTSCRIPT) ||
+                flavor.equals(DocFlavor.INPUT_STREAM.AUTOSENSE) ||
+                flavor.equals(DocFlavor.BYTE_ARRAY.AUTOSENSE) ||
+                flavor.equals(DocFlavor.URL.AUTOSENSE)) {
+                InputStream data = null;
+                try {
+                    if (flavor.equals(DocFlavor.URL.POSTSCRIPT)) {
+                        data = ((URL)doc.getPrintData()).openStream();
+                    } else {
+                        data = doc.getStreamForBytes();
+                    }
+                } catch (IOException ioe) {
+                    throw new PrintException(
+                            "Can't read data from document souce");
+                }
+                int printerID = startDocPrinter(serviceName,
+                        convertAttributes(attributes, flavor),
+                        getJobName(attributes), getDestination(attributes));
+                if (printerID != 0) {
+                    byte[] buffer = new byte[10240];
+                    try {
+                        int bytesRead = data.read(buffer);
+                        while (bytesRead >= 0) {
+                            if (!writePrinter(buffer, bytesRead, printerID)) {
+                                endDocPrinter(printerID);
+                                throw new PrintException(
+                                        "Can't send data to printer");
+                            }
+                            bytesRead = data.read(buffer);
+                        }
+                    } catch (IOException ioe) {
+                        throw new PrintException(
+                                "Can't read print data from Doc");
+                    }
+                    if (!endDocPrinter(printerID)) {
+                        throw new PrintException("Can't finish job normally");
+                    }
+                } else {
+                    throw new PrintException("Can't start printing");
+                }
+            } else if (flavor.getMimeType().toLowerCase().equals(
+                           "internal/postscript") &&
+                       flavor.getRepresentationClassName().equals(
+                           "java.io.InputStream")) {
+                InputStream data = null;
+                try {
+                    data = (InputStream)doc.getPrintData();
+                } catch (IOException ioe) {
+                    throw new PrintException(
+                            "Can't read data from document souce");
+                }
+                PSInterpreter interpreter = new PSInterpreter(data, serviceName,
+                        this, attributes);
+                interpreter.interpret();
+            } else {
+                throw new PrintException("DocFlavor is not supported");
+            }
+        }
+    }
+
+    int[] convertAttributes(PrintRequestAttributeSet attrs, DocFlavor flavor)
+            throws PrintException {
+        PrintRequestAttributeSet attributes = null;
+        if (attrs == null ||
+            flavor.equals(DocFlavor.INPUT_STREAM.AUTOSENSE) ||
+            flavor.equals(DocFlavor.BYTE_ARRAY.AUTOSENSE) ||
+            flavor.equals(DocFlavor.URL.AUTOSENSE)) {
+            int[] defaultValues = {-1, -1, -1, -1, -1, -1, -1, -1}; 
+            return defaultValues;
+        } else {
+            attributes = attrs;
+        }
+        Attribute[] requestAttrs = attributes.toArray();
+        int[] printAttributes = new int[ATTRIBUTES_ARRAY_SIZE];
+        Arrays.fill(printAttributes, -1);
+        for (int i = 0; i < requestAttrs.length; i++) {
+            Class category = requestAttrs[i].getCategory();
+            if (!isAttributeValueSupported(requestAttrs[i], flavor, attrs)) {
+                // Do nothing or throw PrintException if Fidelity supported.
+            } else if (category.equals(Copies.class)) {
+                Copies copies = (Copies)requestAttrs[i];
+                printAttributes[COPIES_INDEX] = copies.getValue();
+            } else if (category.equals(Sides.class)) {
+                Sides sides = (Sides)requestAttrs[i];
+                printAttributes[SIDES_INDEX] = 1;
+                if (sides.equals(Sides.DUPLEX) ||
+                    sides.equals(Sides.TWO_SIDED_LONG_EDGE)) {
+                    printAttributes[SIDES_INDEX] = 2;
+                } else if (sides.equals(Sides.TUMBLE) ||
+                           sides.equals(Sides.TWO_SIDED_SHORT_EDGE)) {
+                    printAttributes[SIDES_INDEX] = 3;
+                }
+            } else if (category.equals(Media.class)) {
+                if (medias.containsKey(requestAttrs[i])) {
+                    Integer id = (Integer)medias.get(requestAttrs[i]);
+                    printAttributes[PAPER_ID_INDEX] = id.intValue();
+                }
+            } else if (category.equals(Chromaticity.class)) {
+                if (requestAttrs[i].equals(Chromaticity.MONOCHROME)) {
+                    printAttributes[CHROMATICITY_INDEX] = 1;
+                } else if (requestAttrs[i].equals(Chromaticity.COLOR)) {
+                    printAttributes[CHROMATICITY_INDEX] = 2;
+                }
+            } else if (category.equals(OrientationRequested.class)) {
+                if (requestAttrs[i].equals(OrientationRequested.PORTRAIT)) {
+                    printAttributes[ORIENTATION_INDEX] = 1;
+                } else
+                  if (requestAttrs[i].equals(OrientationRequested.LANDSCAPE)) {
+                    printAttributes[ORIENTATION_INDEX] = 2;
+                }
+            } else if (category.equals(PrinterResolution.class)) {
+                PrinterResolution res = (PrinterResolution)requestAttrs[i];
+                int xres = res.getCrossFeedResolution(PrinterResolution.DPI);
+                int yres = res.getFeedResolution(PrinterResolution.DPI);
+                printAttributes[XRESOLUTION_INDEX] = xres;
+                printAttributes[YRESOLUTION_INDEX] = yres;
+            } else if (category.equals(SheetCollate.class)) {
+                SheetCollate collate = (SheetCollate)requestAttrs[i];
+                if (collate == SheetCollate.COLLATED) {
+                    printAttributes[COLLATE_INDEX] = 1;
+                } else if (collate == SheetCollate.UNCOLLATED) {
+                    printAttributes[COLLATE_INDEX] = 0;
+                }
+            }
+        }
+        return printAttributes;
+    }
+    
+    String getDestination(PrintRequestAttributeSet attrs)
+            throws PrintException {
+        if (attrs != null) {
+            if (attrs.containsKey(Destination.class)) {
+                Destination destination =
+                    (Destination)attrs.get(Destination.class);
+                if (!destination.getURI().getScheme().equals("file")) {
+                    throw new PrintException(
+                            "Only files supported as destinations.");
+                }
+                String file = destination.getURI().getPath();
+                if (file.startsWith("/")) {
+                    file = file.substring(1);
+                }
+                return file;
+            }
+        }
+        return null;
+    }
+
+    String getJobName(PrintRequestAttributeSet attrs) {
+        if (attrs != null) {
+            if (attrs.containsKey(JobName.class)) {
+                JobName name = (JobName)attrs.get(JobName.class);
+                return name.getValue();
+            }
+        }
+        return "Java GDI client print job";
+    }
+    
+//----------------------- DocFlavors -------------------------------------------
+
+    private static native boolean checkPostScript(String serviceName);
+    
+//----------------------- PrintService attributes ------------------------------    
+    
+    private static native boolean getColorSupported(String printerName);
+    private static native int getPagesPerMinute(String printerNmae);
+    private static native int getPagesPerMinuteColor(String printerNmae);
+    private static native int getPrinterIsAcceptingJobs(String printerNmae);
+    private static native String getPrinterLocation(String printerNmae);
+    private static native int getQueuedJobCount(String printerName);
+
+//  --------------------- Print request attributes -----------------------------    
+
+    private static native int getCopiesSupported(String printerName);
+    private static native boolean getSidesSupported(String printerName);
+    private static native int[][] getMediaSizesSupported(String printerName);
+    private static native int[] getMediaIDs(String printerName);
+    private static native String[] getMediaNames(String printerName);
+    private static native int[] getMediaTraysSupported(String printerName);
+    private static native int[] getResolutionsSupported(String printerName);
+    private static native boolean getOrientationSupported(String printerName);
+    private static native boolean getCollateSupported(String printerName);
+
+//----------------------- Printing methods -------------------------------------
+
+    private static native int startDocPrinter(String serviceName,
+            int[] attributes, String jobName, String destination);
+    private static native boolean writePrinter(byte[] data, int bytes,
+            int printerID);
+    private static native boolean endDocPrinter(int printerID);
+
+//----------------------- Internal classes -------------------------------------
+    
+    private static class GDIMediaName extends MediaSizeName {
+
+        private static GDIMediaName staticMediaName = new GDIMediaName(-1);
+        private String mediaName = null;
+        
+        private GDIMediaName(int value) {
+            super(value);
+        }
+
+        private GDIMediaName(String mediaName, int value) {
+            super(value);
+            this.mediaName = mediaName;
+        }
+        
+        private static MediaSizeName[] getStandardMediaSizeNames() {
+            return (MediaSizeName[])staticMediaName.getEnumValueTable();
+        }
+        
+        public String toString() {
+            return mediaName;
+        }
+
+        public boolean equals(MediaSizeName name) {
+            if (name.hashCode() == hashCode()) {
+                return true;
+            }
+            return false;
+        }
+        
+        public int hashCode() {
+            return mediaName.hashCode();
+        }
+    }
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/H-1609/modules/print/src/main/java/windows/org/apache/harmony/x/print/GDIClient.java
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message