< prev index next >

src/java.desktop/unix/classes/sun/print/CUPSPrinter.java

Print this page

        

@@ -50,10 +50,11 @@
     private static final String debugPrefix = "CUPSPrinter>> ";
     private static final double PRINTER_DPI = 72.0;
     private boolean initialized;
     private static native String getCupsServer();
     private static native int getCupsPort();
+    private static native String getCupsDefaultPrinter();
     private static native boolean canConnect(String server, int port);
     private static native boolean initIDs();
     // These functions need to be synchronized as
     // CUPS does not support multi-threading.
     private static synchronized native String[] getMedia(String printer);

@@ -264,10 +265,19 @@
     /**
      * Get CUPS default printer using IPP.
      * Returns 2 values - index 0 is printer name, index 1 is the uri.
      */
     static String[] getDefaultPrinter() {
+        // Try to get user/lpoptions-defined printer name from CUPS
+        // if not user-set, then go for server default destination
+        String printerInfo[] = new String[2];
+        printerInfo[0] = getCupsDefaultPrinter();
+                             
+        if (printerInfo[0] != null) {
+            printerInfo[1] = null;
+            return printerInfo.clone();
+        }
         try {
             URL url = new URL("http", getServer(), getPort(), "");
             final HttpURLConnection urlConnection =
                 IPPPrintService.getIPPConnection(url);
 

@@ -299,11 +309,11 @@
                 if (IPPPrintService.writeIPPRequest(os,
                                         IPPPrintService.OP_CUPS_GET_DEFAULT,
                                         attCl)) {
 
                     HashMap<String, AttributeClass> defaultMap = null;
-                    String[] printerInfo = new String[2];
+                    
                     InputStream is = urlConnection.getInputStream();
                     HashMap<String, AttributeClass>[] responseMap = IPPPrintService.readIPPResponse(
                                          is);
                     is.close();
 
< prev index next >