src/solaris/classes/sun/print/CUPSPrinter.java

Print this page




 256                 }
 257 
 258                 AttributeClass attCl[] = {
 259                     AttributeClass.ATTRIBUTES_CHARSET,
 260                     AttributeClass.ATTRIBUTES_NATURAL_LANGUAGE,
 261                     new AttributeClass("requested-attributes",
 262                                        AttributeClass.TAG_KEYWORD,
 263                                        "printer-name")
 264                 };
 265 
 266                 if (IPPPrintService.writeIPPRequest(os,
 267                                         IPPPrintService.OP_CUPS_GET_DEFAULT,
 268                                         attCl)) {
 269 
 270                     HashMap defaultMap = null;
 271                     InputStream is = urlConnection.getInputStream();
 272                     HashMap[] responseMap = IPPPrintService.readIPPResponse(
 273                                          is);
 274                     is.close();
 275 
 276                     if (responseMap.length > 0) {
 277                         defaultMap = responseMap[0];
 278                     }
 279 
 280                     if (defaultMap == null) {
 281                         os.close();
 282                         urlConnection.disconnect();











 283                         return null;
 284                     }

 285 
 286                     AttributeClass attribClass = (AttributeClass)
 287                         defaultMap.get("printer-name");
 288 
 289                     if (attribClass != null) {
 290                         String nameStr = attribClass.getStringValue();
 291                         os.close();
 292                         urlConnection.disconnect();
 293                         return nameStr;
 294                     }
 295                 }
 296                 os.close();
 297                 urlConnection.disconnect();
 298             }
 299         } catch (Exception e) {
 300         }
 301         return null;
 302     }
 303 
 304 




 256                 }
 257 
 258                 AttributeClass attCl[] = {
 259                     AttributeClass.ATTRIBUTES_CHARSET,
 260                     AttributeClass.ATTRIBUTES_NATURAL_LANGUAGE,
 261                     new AttributeClass("requested-attributes",
 262                                        AttributeClass.TAG_KEYWORD,
 263                                        "printer-name")
 264                 };
 265 
 266                 if (IPPPrintService.writeIPPRequest(os,
 267                                         IPPPrintService.OP_CUPS_GET_DEFAULT,
 268                                         attCl)) {
 269 
 270                     HashMap defaultMap = null;
 271                     InputStream is = urlConnection.getInputStream();
 272                     HashMap[] responseMap = IPPPrintService.readIPPResponse(
 273                                          is);
 274                     is.close();
 275 
 276                     if (responseMap != null && responseMap.length > 0) {
 277                         defaultMap = responseMap[0];
 278                     }
 279 
 280                     if (defaultMap == null) {
 281                         os.close();
 282                         urlConnection.disconnect();
 283 
 284                         /* CUPS on OS X, as initially configured, considers the
 285                          * default printer to be the last one used that's
 286                          * presently available. So if no default was
 287                          * reported, exec lpstat -d which has all the Apple
 288                          * special behaviour for this built in.
 289                          */
 290                          if (UnixPrintServiceLookup.isMac()) {
 291                              return UnixPrintServiceLookup.
 292                                                    getDefaultPrinterNameSysV();
 293                          } else {
 294                              return null;
 295                          }
 296                     }
 297 
 298                     AttributeClass attribClass = (AttributeClass)
 299                         defaultMap.get("printer-name");
 300 
 301                     if (attribClass != null) {
 302                         String nameStr = attribClass.getStringValue();
 303                         os.close();
 304                         urlConnection.disconnect();
 305                         return nameStr;
 306                     }
 307                 }
 308                 os.close();
 309                 urlConnection.disconnect();
 310             }
 311         } catch (Exception e) {
 312         }
 313         return null;
 314     }
 315 
 316