diff --git a/make/mapfiles/libawt/mapfile-mawt-vers b/make/mapfiles/libawt/mapfile-mawt-vers index 28ad3538d2342fa2e13a9c1c09545f82773f088a..94e66a78719f29d42de7be9f54ebe26a7b5bb3ce 100644 --- a/make/mapfiles/libawt/mapfile-mawt-vers +++ b/make/mapfiles/libawt/mapfile-mawt-vers @@ -201,6 +201,7 @@ SUNWprivate_1.1 { Java_sun_print_CUPSPrinter_initIDs; Java_sun_print_CUPSPrinter_getCupsServer; Java_sun_print_CUPSPrinter_getCupsPort; + Java_sun_print_CUPSPrinter_getCupsDefaultPrinter; Java_sun_print_CUPSPrinter_canConnect; Java_sun_print_CUPSPrinter_getMedia; Java_sun_print_CUPSPrinter_getPageSizes; diff --git a/make/mapfiles/libawt_headless/mapfile-vers b/make/mapfiles/libawt_headless/mapfile-vers index 44efc298b916bb674171c52c83f4c4675ae1851e..0ce2867bd27f8188e55bbf1450dc44f2cc2063da 100644 --- a/make/mapfiles/libawt_headless/mapfile-vers +++ b/make/mapfiles/libawt_headless/mapfile-vers @@ -73,6 +73,7 @@ SUNWprivate_1.1 { Java_sun_print_CUPSPrinter_initIDs; Java_sun_print_CUPSPrinter_getCupsServer; Java_sun_print_CUPSPrinter_getCupsPort; + Java_sun_print_CUPSPrinter_getCupsDefaultPrinter; Java_sun_print_CUPSPrinter_canConnect; Java_sun_print_CUPSPrinter_getMedia; Java_sun_print_CUPSPrinter_getPageSizes; diff --git a/make/mapfiles/libawt_xawt/mapfile-vers b/make/mapfiles/libawt_xawt/mapfile-vers index d24a527b03f3057b41073fc773f18f74b19e9843..101c288e0f3d40c179946cd63c981b2ef9a083d6 100644 --- a/make/mapfiles/libawt_xawt/mapfile-vers +++ b/make/mapfiles/libawt_xawt/mapfile-vers @@ -439,6 +439,7 @@ SUNWprivate_1.1 { Java_sun_print_CUPSPrinter_initIDs; Java_sun_print_CUPSPrinter_getCupsServer; Java_sun_print_CUPSPrinter_getCupsPort; + Java_sun_print_CUPSPrinter_getCupsDefaultPrinter; Java_sun_print_CUPSPrinter_canConnect; Java_sun_print_CUPSPrinter_getMedia; Java_sun_print_CUPSPrinter_getPageSizes; diff --git a/src/solaris/classes/sun/print/CUPSPrinter.java b/src/solaris/classes/sun/print/CUPSPrinter.java index 1a941d01449a6047c0ca6a4dcfc9178c56745a96..ef33dde42056be8d30c3a1111ed75cddbca024a8 100644 --- a/src/solaris/classes/sun/print/CUPSPrinter.java +++ b/src/solaris/classes/sun/print/CUPSPrinter.java @@ -51,6 +51,7 @@ public class CUPSPrinter { 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 @@ -250,6 +251,15 @@ public class CUPSPrinter { * 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 = @@ -285,7 +295,7 @@ public class CUPSPrinter { attCl)) { HashMap defaultMap = null; - String[] printerInfo = new String[2]; + InputStream is = urlConnection.getInputStream(); HashMap[] responseMap = IPPPrintService.readIPPResponse( is); diff --git a/src/solaris/native/sun/awt/CUPSfuncs.c b/src/solaris/native/sun/awt/CUPSfuncs.c index d7d989629bb5535a3743816891e44b125f07df3e..ce8350dec3b6467864443910379203c1589a7b25 100644 --- a/src/solaris/native/sun/awt/CUPSfuncs.c +++ b/src/solaris/native/sun/awt/CUPSfuncs.c @@ -43,6 +43,10 @@ typedef int (*fn_ippPort)(void); typedef http_t* (*fn_httpConnect)(const char *, int); typedef void (*fn_httpClose)(http_t *); typedef char* (*fn_cupsGetPPD)(const char *); +typedef cups_dest_t* (*fn_cupsGetDest)(const char *name, + const char *instance, int num_dests, cups_dest_t *dests); +typedef int (*fn_cupsGetDests)(cups_dest_t **dests); +typedef void (*fn_cupsFreeDests)(int num_dests, cups_dest_t *dests); typedef ppd_file_t* (*fn_ppdOpenFile)(const char *); typedef void (*fn_ppdClose)(ppd_file_t *); typedef ppd_option_t* (*fn_ppdFindOption)(ppd_file_t *, const char *); @@ -53,6 +57,9 @@ fn_ippPort j2d_ippPort; fn_httpConnect j2d_httpConnect; fn_httpClose j2d_httpClose; fn_cupsGetPPD j2d_cupsGetPPD; +fn_cupsGetDest j2d_cupsGetDest; +fn_cupsGetDests j2d_cupsGetDests; +fn_cupsFreeDests j2d_cupsFreeDests; fn_ppdOpenFile j2d_ppdOpenFile; fn_ppdClose j2d_ppdClose; fn_ppdFindOption j2d_ppdFindOption; @@ -106,6 +113,24 @@ Java_sun_print_CUPSPrinter_initIDs(JNIEnv *env, return JNI_FALSE; } + j2d_cupsGetDest = (fn_cupsGetDest)dlsym(handle, "cupsGetDest"); + if (j2d_cupsGetDest == NULL) { + dlclose(handle); + return JNI_FALSE; + } + + j2d_cupsGetDests = (fn_cupsGetDests)dlsym(handle, "cupsGetDests"); + if (j2d_cupsGetDests == NULL) { + dlclose(handle); + return JNI_FALSE; + } + + j2d_cupsFreeDests = (fn_cupsFreeDests)dlsym(handle, "cupsFreeDests"); + if (j2d_cupsFreeDests == NULL) { + dlclose(handle); + return JNI_FALSE; + } + j2d_ppdOpenFile = (fn_ppdOpenFile)dlsym(handle, "ppdOpenFile"); if (j2d_ppdOpenFile == NULL) { dlclose(handle); @@ -169,6 +194,30 @@ Java_sun_print_CUPSPrinter_getCupsPort(JNIEnv *env, } +/* + * Gets CUPS default printer name. + * + */ +JNIEXPORT jstring JNICALL +Java_sun_print_CUPSPrinter_getCupsDefaultPrinter(JNIEnv *env, + jobject printObj) +{ + jstring cDefPrinter = NULL; + cups_dest_t *dests; + char *defaultPrinter = NULL; + int num_dests = j2d_cupsGetDests(&dests); + int i = 0; + cups_dest_t *dest = j2d_cupsGetDest(NULL, NULL, num_dests, dests); + if (dest != NULL) { + defaultPrinter = dest->name; + if (defaultPrinter != NULL) { + cDefPrinter = JNU_NewStringPlatform(env, defaultPrinter); + } + } + j2d_cupsFreeDests(num_dests, dests); + return cDefPrinter; +} + /* * Checks if connection can be made to the server. *