6633656: Cross platform print dialog doesn't check for orientation being unsupported.
authorjgodinez
Wed, 09 Apr 2008 15:16:57 -0700
changeset 535 e6b909c9e627
parent 532 6eb7f9aa0b05
child 536 a29f1f8c0983
6633656: Cross platform print dialog doesn't check for orientation being unsupported. Reviewed-by: prr, tdv
jdk/src/share/classes/sun/print/ServiceDialog.java
jdk/src/solaris/classes/sun/print/AttributeClass.java
jdk/src/solaris/classes/sun/print/IPPPrintService.java
--- a/jdk/src/share/classes/sun/print/ServiceDialog.java	Fri Mar 07 12:13:17 2008 -0800
+++ b/jdk/src/share/classes/sun/print/ServiceDialog.java	Wed Apr 09 15:16:57 2008 -0700
@@ -2149,48 +2149,55 @@
                         }
                     }
                 }
-            }
-            rbPortrait.setEnabled(pSupported);
-            rbLandscape.setEnabled(lSupported);
-            rbRevPortrait.setEnabled(rpSupported);
-            rbRevLandscape.setEnabled(rlSupported);
-
-            OrientationRequested or = (OrientationRequested)asCurrent.get(orCategory);
-            if (or == null ||
-                !psCurrent.isAttributeValueSupported(or, docFlavor, asCurrent)) {
-
-                or = (OrientationRequested)psCurrent.getDefaultAttributeValue(orCategory);
-                // need to validate if default is not supported
-                if (!psCurrent.isAttributeValueSupported(or, docFlavor, asCurrent)) {
-                    or = null;
-                    Object values =
-                        psCurrent.getSupportedAttributeValues(orCategory,
-                                                              docFlavor,
-                                                              asCurrent);
-                    if (values instanceof OrientationRequested[]) {
-                        OrientationRequested[] orValues =
+
+                rbPortrait.setEnabled(pSupported);
+                rbLandscape.setEnabled(lSupported);
+                rbRevPortrait.setEnabled(rpSupported);
+                rbRevLandscape.setEnabled(rlSupported);
+
+                OrientationRequested or = (OrientationRequested)asCurrent.get(orCategory);
+                if (or == null ||
+                    !psCurrent.isAttributeValueSupported(or, docFlavor, asCurrent)) {
+
+                    or = (OrientationRequested)psCurrent.getDefaultAttributeValue(orCategory);
+                    // need to validate if default is not supported
+                    if (!psCurrent.isAttributeValueSupported(or, docFlavor, asCurrent)) {
+                        or = null;
+                        values =
+                            psCurrent.getSupportedAttributeValues(orCategory,
+                                                                  docFlavor,
+                                                                  asCurrent);
+                        if (values instanceof OrientationRequested[]) {
+                            OrientationRequested[] orValues =
                                                 (OrientationRequested[])values;
-                        if (orValues.length > 1) {
-                            // get the first in the list
-                            or = orValues[0];
+                            if (orValues.length > 1) {
+                                // get the first in the list
+                                or = orValues[0];
+                            }
                         }
                     }
-                }
-
-                if (or == null) {
-                    or = OrientationRequested.PORTRAIT;
+
+                    if (or == null) {
+                        or = OrientationRequested.PORTRAIT;
+                    }
+                    asCurrent.add(or);
                 }
-                asCurrent.add(or);
-            }
-
-            if (or == OrientationRequested.PORTRAIT) {
-                rbPortrait.setSelected(true);
-            } else if (or == OrientationRequested.LANDSCAPE) {
-                rbLandscape.setSelected(true);
-            } else if (or == OrientationRequested.REVERSE_PORTRAIT) {
-                rbRevPortrait.setSelected(true);
-            } else { // if (or == OrientationRequested.REVERSE_LANDSCAPE)
-                rbRevLandscape.setSelected(true);
+
+                if (or == OrientationRequested.PORTRAIT) {
+                    rbPortrait.setSelected(true);
+                } else if (or == OrientationRequested.LANDSCAPE) {
+                    rbLandscape.setSelected(true);
+                } else if (or == OrientationRequested.REVERSE_PORTRAIT) {
+                    rbRevPortrait.setSelected(true);
+                } else { // if (or == OrientationRequested.REVERSE_LANDSCAPE)
+                    rbRevLandscape.setSelected(true);
+                }
+                } else {
+                rbPortrait.setEnabled(pSupported);
+                rbLandscape.setEnabled(lSupported);
+                rbRevPortrait.setEnabled(rpSupported);
+                rbRevLandscape.setEnabled(rlSupported);
+
             }
         }
     }
--- a/jdk/src/solaris/classes/sun/print/AttributeClass.java	Fri Mar 07 12:13:17 2008 -0800
+++ b/jdk/src/solaris/classes/sun/print/AttributeClass.java	Wed Apr 09 15:16:57 2008 -0700
@@ -32,6 +32,7 @@
     private int nameLen;
     private Object myValue;
 
+    public static final int TAG_UNSUPPORTED_VALUE = 0x10;
     public static final int TAG_INT = 0x21;
     public static final int TAG_BOOL = 0x22;
     public static final int TAG_ENUM = 0x23;
--- a/jdk/src/solaris/classes/sun/print/IPPPrintService.java	Fri Mar 07 12:13:17 2008 -0800
+++ b/jdk/src/solaris/classes/sun/print/IPPPrintService.java	Wed Apr 09 15:16:57 2008 -0700
@@ -621,17 +621,8 @@
                 }
             }
         } else if (category == OrientationRequested.class) {
-            if (flavor == null ||
-                flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
-                flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
-                // Orientation is emulated in Pageable/Printable flavors
-                // so we report the 3 orientations as supported.
-                OrientationRequested []orientSup = new OrientationRequested[3];
-                orientSup[0] = OrientationRequested.PORTRAIT;
-                orientSup[1] = OrientationRequested.LANDSCAPE;
-                orientSup[2] = OrientationRequested.REVERSE_LANDSCAPE;
-                return orientSup;
-            }
+            boolean revPort = false;
+            OrientationRequested[] orientSup = null;
 
             AttributeClass attribClass = (getAttMap != null) ?
               (AttributeClass)getAttMap.get("orientation-requested-supported")
@@ -639,7 +630,7 @@
             if (attribClass != null) {
                 int[] orientArray = attribClass.getArrayOfIntValues();
                 if ((orientArray != null) && (orientArray.length > 0)) {
-                    OrientationRequested[] orientSup =
+                    orientSup =
                         new OrientationRequested[orientArray.length];
                     for (int i=0; i<orientArray.length; i++) {
                         switch (orientArray[i]) {
@@ -657,12 +648,33 @@
                         case 6:
                             orientSup[i] =
                                 OrientationRequested.REVERSE_PORTRAIT;
+                            revPort = true;
                             break;
                         }
                     }
-                    return orientSup;
                 }
             }
+            if (flavor == null ||
+                flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
+                flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
+
+                if (revPort && flavor == null) {
+                    OrientationRequested []orSup = new OrientationRequested[4];
+                    orSup[0] = OrientationRequested.PORTRAIT;
+                    orSup[1] = OrientationRequested.LANDSCAPE;
+                    orSup[2] = OrientationRequested.REVERSE_LANDSCAPE;
+                    orSup[3] = OrientationRequested.REVERSE_PORTRAIT;
+                    return orSup;
+                } else {
+                    OrientationRequested []orSup = new OrientationRequested[3];
+                    orSup[0] = OrientationRequested.PORTRAIT;
+                    orSup[1] = OrientationRequested.LANDSCAPE;
+                    orSup[2] = OrientationRequested.REVERSE_LANDSCAPE;
+                    return orSup;
+                }
+            } else {
+                return orientSup;
+            }
         } else if (category == PageRanges.class) {
            if (flavor == null ||
                 flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
@@ -991,6 +1003,14 @@
             getSupportedAttributeCategories();
         }
 
+        // It is safe to assume that Orientation is always supported
+        // and even if CUPS or an IPP device reports it as not,
+        // our renderer can do portrait, landscape and
+        // reverse landscape.
+        if (category == OrientationRequested.class) {
+            return true;
+        }
+
         for (int i=0;i<supportedCats.length;i++) {
             if (category == supportedCats[i]) {
                 return true;
@@ -1602,7 +1622,13 @@
     public static boolean writeIPPRequest(OutputStream os,
                                            String operCode,
                                            AttributeClass[] attCl) {
-        OutputStreamWriter osw = new OutputStreamWriter(os);
+        OutputStreamWriter osw;
+        try {
+            osw = new OutputStreamWriter(os, "UTF-8");
+        } catch (java.io.UnsupportedEncodingException exc) {
+            debug_println("UTF-8 not supported? Exception: "+exc);
+            return false;
+        }
         char[] opCode =  new char[2];
         opCode[0] =  (char)Byte.parseByte(operCode.substring(0,2), 16);
         opCode[1] =  (char)Byte.parseByte(operCode.substring(2,4), 16);
@@ -1690,7 +1716,7 @@
 
                     // read value tag
                     response[0] = ois.readByte();
-                    while (response[0] >= AttributeClass.TAG_INT &&
+                    while (response[0] >= AttributeClass.TAG_UNSUPPORTED_VALUE &&
                            response[0] <= AttributeClass.TAG_MEMBER_ATTRNAME) {
                         // read name length
                         len  = ois.readShort();
@@ -1710,12 +1736,16 @@
                                 respList.add(responseMap);
                                 responseMap = new HashMap();
                             }
-                            AttributeClass ac =
-                                new AttributeClass(attribStr,
-                                                   valTagByte,
-                                                   outArray);
 
-                            responseMap.put(ac.getName(), ac);
+                            // exclude those that are unknown
+                            if (valTagByte >= AttributeClass.TAG_INT) {
+                                AttributeClass ac =
+                                    new AttributeClass(attribStr,
+                                                       valTagByte,
+                                                       outArray);
+
+                                responseMap.put(ac.getName(), ac);
+                            }
 
                             outObj = new ByteArrayOutputStream();
                             counter = 0; //reset counter