jdk/src/solaris/classes/sun/print/IPPPrintService.java
changeset 1737 90d4fe987b09
parent 1727 5e5e0235b14f
child 2386 7e59f81fd05b
equal deleted inserted replaced
1736:f617a19a81a7 1737:90d4fe987b09
    60 import java.util.HashSet;
    60 import java.util.HashSet;
    61 
    61 
    62 
    62 
    63 public class IPPPrintService implements PrintService, SunPrinterJobService {
    63 public class IPPPrintService implements PrintService, SunPrinterJobService {
    64 
    64 
    65     public static boolean debugPrint = false;
    65     public static final boolean debugPrint;
    66     private static String debugPrefix = "IPPPrintService>> ";
    66     private static final String debugPrefix = "IPPPrintService>> ";
    67     protected static void debug_println(String str) {
    67     protected static void debug_println(String str) {
    68         if (debugPrint) {
    68         if (debugPrint) {
    69             System.out.println(str);
    69             System.out.println(str);
    70         }
    70         }
    71     }
    71     }
    72 
    72 
       
    73     private static final String FORCE_PIPE_PROP = "sun.print.ippdebug";
       
    74 
       
    75     static {
       
    76         String debugStr =
       
    77                 (String)java.security.AccessController.doPrivileged(
       
    78                   new sun.security.action.GetPropertyAction(FORCE_PIPE_PROP));
       
    79 
       
    80         debugPrint = "true".equalsIgnoreCase(debugStr);
       
    81     }
    73 
    82 
    74     private String printer;
    83     private String printer;
    75     private URI    myURI;
    84     private URI    myURI;
    76     private URL    myURL;
    85     private URL    myURL;
    77     transient private ServiceNotifier notifier = null;
    86     transient private ServiceNotifier notifier = null;
   381             customMediaSizeNames = new CustomMediaSizeName[0];
   390             customMediaSizeNames = new CustomMediaSizeName[0];
   382 
   391 
   383             if ((urlConnection = getIPPConnection(myURL)) == null) {
   392             if ((urlConnection = getIPPConnection(myURL)) == null) {
   384                 mediaSizeNames = new MediaSizeName[0];
   393                 mediaSizeNames = new MediaSizeName[0];
   385                 mediaTrays = new MediaTray[0];
   394                 mediaTrays = new MediaTray[0];
   386                 debug_println("NULL urlConnection ");
   395                 debug_println(debugPrefix+"initAttributes, NULL urlConnection ");
   387                 init = true;
   396                 init = true;
   388                 return;
   397                 return;
   389             }
   398             }
   390 
   399 
   391             // get all supported attributes through IPP
   400             // get all supported attributes through IPP
   406                     urlConnection.disconnect();
   415                     urlConnection.disconnect();
   407                     init = true;
   416                     init = true;
   408                     return;
   417                     return;
   409                 } catch (Exception e) {
   418                 } catch (Exception e) {
   410                     IPPPrintService.debug_println(debugPrefix+
   419                     IPPPrintService.debug_println(debugPrefix+
   411                                        " error creating CUPSPrinter e="+e);
   420                                        "initAttributes, error creating CUPSPrinter e="+e);
   412                 }
   421                 }
   413             }
   422             }
   414 
   423 
   415             // use IPP to get all media,
   424             // use IPP to get all media,
   416             Media[] allMedia = (Media[])getSupportedMedia();
   425             Media[] allMedia = (Media[])getSupportedMedia();
   910 
   919 
   911     /**
   920     /**
   912      * Finds matching CustomMediaSizeName of given media.
   921      * Finds matching CustomMediaSizeName of given media.
   913      */
   922      */
   914     public CustomMediaSizeName findCustomMedia(MediaSizeName media) {
   923     public CustomMediaSizeName findCustomMedia(MediaSizeName media) {
       
   924         if (customMediaSizeNames == null) {
       
   925             return null;
       
   926         }
   915         for (int i=0; i< customMediaSizeNames.length; i++) {
   927         for (int i=0; i< customMediaSizeNames.length; i++) {
   916             CustomMediaSizeName custom =
   928             CustomMediaSizeName custom =
   917                 (CustomMediaSizeName)customMediaSizeNames[i];
   929                 (CustomMediaSizeName)customMediaSizeNames[i];
   918             MediaSizeName msn = custom.getStandardMedia();
   930             MediaSizeName msn = custom.getStandardMedia();
   919             if (media.equals(msn)) {
   931             if (media.equals(msn)) {
  1191 
  1203 
  1192         if (msn.equals((Media)getDefaultAttributeValue(Media.class))) {
  1204         if (msn.equals((Media)getDefaultAttributeValue(Media.class))) {
  1193             return true;
  1205             return true;
  1194         }
  1206         }
  1195         for (int i=0; i<mediaSizeNames.length; i++) {
  1207         for (int i=0; i<mediaSizeNames.length; i++) {
  1196             debug_println("mediaSizeNames[i] "+mediaSizeNames[i]);
  1208             debug_println(debugPrefix+"isSupportedMedia, mediaSizeNames[i] "+mediaSizeNames[i]);
  1197             if (msn.equals(mediaSizeNames[i])) {
  1209             if (msn.equals(mediaSizeNames[i])) {
  1198                 return true;
  1210                 return true;
  1199             }
  1211             }
  1200         }
  1212         }
  1201         return false;
  1213         return false;
  1652                                            AttributeClass[] attCl) {
  1664                                            AttributeClass[] attCl) {
  1653         OutputStreamWriter osw;
  1665         OutputStreamWriter osw;
  1654         try {
  1666         try {
  1655             osw = new OutputStreamWriter(os, "UTF-8");
  1667             osw = new OutputStreamWriter(os, "UTF-8");
  1656         } catch (java.io.UnsupportedEncodingException exc) {
  1668         } catch (java.io.UnsupportedEncodingException exc) {
  1657             debug_println("UTF-8 not supported? Exception: "+exc);
  1669             debug_println(debugPrefix+"writeIPPRequest, UTF-8 not supported? Exception: "+exc);
  1658             return false;
  1670             return false;
  1659         }
  1671         }
       
  1672         debug_println(debugPrefix+"writeIPPRequest, op code= "+operCode);
  1660         char[] opCode =  new char[2];
  1673         char[] opCode =  new char[2];
  1661         opCode[0] =  (char)Byte.parseByte(operCode.substring(0,2), 16);
  1674         opCode[0] =  (char)Byte.parseByte(operCode.substring(0,2), 16);
  1662         opCode[1] =  (char)Byte.parseByte(operCode.substring(2,4), 16);
  1675         opCode[1] =  (char)Byte.parseByte(operCode.substring(2,4), 16);
  1663         char[] bytes = {0x01, 0x01, 0x00, 0x01};
  1676         char[] bytes = {0x01, 0x01, 0x00, 0x01};
  1664         try {
  1677         try {
  1695 
  1708 
  1696             osw.write(GRPTAG_END_ATTRIBUTES);
  1709             osw.write(GRPTAG_END_ATTRIBUTES);
  1697             osw.flush();
  1710             osw.flush();
  1698             osw.close();
  1711             osw.close();
  1699         } catch (java.io.IOException ioe) {
  1712         } catch (java.io.IOException ioe) {
  1700             debug_println(debugPrefix+"IPPPrintService Exception in writeIPPRequest: "+ioe);
  1713             debug_println(debugPrefix+"writeIPPRequest, IPPPrintService Exception in writeIPPRequest: "+ioe);
  1701             return false;
  1714             return false;
  1702         }
  1715         }
  1703         return true;
  1716         return true;
  1704     }
  1717     }
  1705 
  1718 
  1732 
  1745 
  1733                 // check for group tags
  1746                 // check for group tags
  1734                 while ((response[0] >= GRPTAG_OP_ATTRIBUTES) &&
  1747                 while ((response[0] >= GRPTAG_OP_ATTRIBUTES) &&
  1735                        (response[0] <= GRPTAG_PRINTER_ATTRIBUTES)
  1748                        (response[0] <= GRPTAG_PRINTER_ATTRIBUTES)
  1736                           && (response[0] != GRPTAG_END_ATTRIBUTES)) {
  1749                           && (response[0] != GRPTAG_END_ATTRIBUTES)) {
  1737                     debug_println(debugPrefix+"checking group tag,  response[0]= "+
  1750                     debug_println(debugPrefix+"readIPPResponse, checking group tag,  response[0]= "+
  1738                                   response[0]);
  1751                                   response[0]);
  1739 
  1752 
  1740                     outObj = new ByteArrayOutputStream();
  1753                     outObj = new ByteArrayOutputStream();
  1741                     //make sure counter and attribStr are re-initialized
  1754                     //make sure counter and attribStr are re-initialized
  1742                     counter = 0;
  1755                     counter = 0;
  1771                                     new AttributeClass(attribStr,
  1784                                     new AttributeClass(attribStr,
  1772                                                        valTagByte,
  1785                                                        valTagByte,
  1773                                                        outArray);
  1786                                                        outArray);
  1774 
  1787 
  1775                                 responseMap.put(ac.getName(), ac);
  1788                                 responseMap.put(ac.getName(), ac);
       
  1789                                 debug_println(debugPrefix+ "readIPPResponse "+ac);
  1776                             }
  1790                             }
  1777 
  1791 
  1778                             outObj = new ByteArrayOutputStream();
  1792                             outObj = new ByteArrayOutputStream();
  1779                             counter = 0; //reset counter
  1793                             counter = 0; //reset counter
  1780                         }
  1794                         }
  1843                 return null;
  1857                 return null;
  1844             }
  1858             }
  1845 
  1859 
  1846         } catch (java.io.IOException e) {
  1860         } catch (java.io.IOException e) {
  1847             debug_println(debugPrefix+"readIPPResponse: "+e);
  1861             debug_println(debugPrefix+"readIPPResponse: "+e);
       
  1862             if (debugPrint) {
       
  1863                 e.printStackTrace();
       
  1864             }
  1848             return null;
  1865             return null;
  1849         }
  1866         }
  1850     }
  1867     }
  1851 
  1868 
  1852 
  1869