Mercurial > hg > shenandoah-preopenjdk-archive > openjdk8 > jdk
changeset 293:99f3a382f574
6678161: Printing to remote non-Postscript printer does not work in Linux
Reviewed-by: prr, tdv
author | jgodinez |
---|---|
date | Thu, 10 Apr 2008 13:57:15 -0700 |
parents | 929bf1062f64 |
children | 90e1f09ce553 |
files | src/solaris/classes/sun/print/CUPSPrinter.java src/solaris/classes/sun/print/IPPPrintService.java src/solaris/classes/sun/print/UnixPrintServiceLookup.java |
diffstat | 3 files changed, 72 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/src/solaris/classes/sun/print/CUPSPrinter.java Thu Apr 10 10:23:47 2008 -0700 +++ b/src/solaris/classes/sun/print/CUPSPrinter.java Thu Apr 10 13:57:15 2008 -0700 @@ -333,7 +333,7 @@ AttributeClass.ATTRIBUTES_NATURAL_LANGUAGE, new AttributeClass("requested-attributes", AttributeClass.TAG_KEYWORD, - "printer-name") + "printer-uri-supported") }; if (IPPPrintService.writeIPPRequest(os, @@ -354,7 +354,7 @@ ArrayList printerNames = new ArrayList(); for (int i=0; i< responseMap.length; i++) { AttributeClass attribClass = (AttributeClass) - responseMap[i].get("printer-name"); + responseMap[i].get("printer-uri-supported"); if (attribClass != null) { String nameStr = attribClass.getStringValue();
--- a/src/solaris/classes/sun/print/IPPPrintService.java Thu Apr 10 10:23:47 2008 -0700 +++ b/src/solaris/classes/sun/print/IPPPrintService.java Thu Apr 10 13:57:15 2008 -0700 @@ -335,6 +335,38 @@ } + IPPPrintService(String name, String uriStr, boolean isCups) { + if ((name == null) || (uriStr == null)){ + throw new IllegalArgumentException("null uri or printer name"); + } + printer = name; + supportedDocFlavors = null; + supportedCats = null; + mediaSizeNames = null; + customMediaSizeNames = null; + mediaTrays = null; + cps = null; + init = false; + defaultMediaIndex = -1; + try { + myURL = + new URL(uriStr.replaceFirst("ipp", "http")); + } catch (Exception e) { + IPPPrintService.debug_println(debugPrefix+ + " IPPPrintService, myURL="+ + myURL+" Exception= "+ + e); + } + + isCupsPrinter = isCups; + try { + myURI = new URI(uriStr); + debug_println(debugPrefix+"IPPPrintService myURI : "+myURI); + } catch (java.net.URISyntaxException e) { + throw new IllegalArgumentException("invalid uri"); + } + } + /* * Initialize mediaSizeNames, mediaTrays and other attributes. @@ -375,7 +407,7 @@ return; } catch (Exception e) { IPPPrintService.debug_println(debugPrefix+ - " error creating CUPSPrinter"); + " error creating CUPSPrinter e="+e); } } @@ -807,6 +839,18 @@ docList.addAll(Arrays.asList(flavors)); + if (isCupsPrinter) { + /* + Always add Pageable and Printable for CUPS + since it uses Filters to convert from Postscript + to device printer language. + */ + docList.add( + DocFlavor.SERVICE_FORMATTED.PAGEABLE); + docList.add( + DocFlavor.SERVICE_FORMATTED.PRINTABLE); + } + if (mimeType.equals("text/plain") && addHostEncoding) { docList.add(Arrays.asList(textPlainHost)); @@ -820,11 +864,6 @@ } else if (mimeType.equals("image/jpeg")) { jpgImagesAdded = true; } else if (mimeType.indexOf("postscript") != -1) { - docList.add( - DocFlavor.SERVICE_FORMATTED.PAGEABLE); - docList.add( - DocFlavor.SERVICE_FORMATTED.PRINTABLE); - psSupported = true; } break; @@ -841,7 +880,7 @@ } // check if we need to add image DocFlavors - if (psSupported) { + if (psSupported || isCupsPrinter) { if (!jpgImagesAdded) { docList.addAll(Arrays.asList(imageJPG)); } @@ -1540,10 +1579,7 @@ if (isCupsPrinter) { try { urlConnection = getIPPConnection( - new URL("http://"+ - CUPSPrinter.getServer()+":"+ - CUPSPrinter.getPort()+ - "/printers/"+printer+".ppd")); + new URL(myURL+".ppd")); InputStream is = urlConnection.getInputStream(); if (is != null) { @@ -1559,6 +1595,11 @@ } } } catch (java.io.IOException e) { + debug_println(" isPostscript, e= "+e); + /* if PPD is not found, this may be a raw printer + and in this case it is assumed that it is a + Postscript printer */ + // do nothing } } }
--- a/src/solaris/classes/sun/print/UnixPrintServiceLookup.java Thu Apr 10 10:23:47 2008 -0700 +++ b/src/solaris/classes/sun/print/UnixPrintServiceLookup.java Thu Apr 10 13:57:15 2008 -0700 @@ -196,11 +196,20 @@ // refreshes "printServices" public synchronized void refreshServices() { - String[] printers; /* excludes the default printer */ + /* excludes the default printer */ + String[] printers = null; // array of printer names + String[] printerURIs = null; //array of printer URIs getDefaultPrintService(); if (CUPSPrinter.isCupsRunning()) { - printers = CUPSPrinter.getAllPrinters(); + printerURIs = CUPSPrinter.getAllPrinters(); + if ((printerURIs != null) && (printerURIs.length > 0)) { + printers = new String[printerURIs.length]; + for (int i=0; i<printerURIs.length; i++) { + int lastIndex = printerURIs[i].lastIndexOf("/"); + printers[i] = printerURIs[i].substring(lastIndex+1); + } + } } else { if (isSysV()) { printers = getAllPrinterNamesSysV(); @@ -236,12 +245,9 @@ if (CUPSPrinter.isCupsRunning()) { try { - URL serviceURL = - new URL("http://"+ - CUPSPrinter.getServer()+":"+ - CUPSPrinter.getPort()+"/"+printers[p]); - printerList.add(new IPPPrintService( printers[p], - serviceURL)); + printerList.add(new IPPPrintService(printers[p], + printerURIs[p], + true)); } catch (Exception e) { IPPPrintService.debug_println(debugPrefix+ " getAllPrinters Exception "+ @@ -265,12 +271,10 @@ if (j == printServices.length) { // not found? if (CUPSPrinter.isCupsRunning()) { try { - URL serviceURL = - new URL("http://"+ - CUPSPrinter.getServer()+":"+ - CUPSPrinter.getPort()+"/"+printers[p]); - printerList.add(new IPPPrintService( printers[p], - serviceURL)); + printerList.add(new IPPPrintService( + printers[p], + printerURIs[p], + true)); } catch (Exception e) { IPPPrintService.debug_println(debugPrefix+ " getAllPrinters Exception "+