提交 cd93ab9e 编写于 作者: J jgodinez

6678161: Printing to remote non-Postscript printer does not work in Linux

Reviewed-by: prr, tdv
上级 e7d97dea
...@@ -333,7 +333,7 @@ public class CUPSPrinter { ...@@ -333,7 +333,7 @@ public class CUPSPrinter {
AttributeClass.ATTRIBUTES_NATURAL_LANGUAGE, AttributeClass.ATTRIBUTES_NATURAL_LANGUAGE,
new AttributeClass("requested-attributes", new AttributeClass("requested-attributes",
AttributeClass.TAG_KEYWORD, AttributeClass.TAG_KEYWORD,
"printer-name") "printer-uri-supported")
}; };
if (IPPPrintService.writeIPPRequest(os, if (IPPPrintService.writeIPPRequest(os,
...@@ -354,7 +354,7 @@ public class CUPSPrinter { ...@@ -354,7 +354,7 @@ public class CUPSPrinter {
ArrayList printerNames = new ArrayList(); ArrayList printerNames = new ArrayList();
for (int i=0; i< responseMap.length; i++) { for (int i=0; i< responseMap.length; i++) {
AttributeClass attribClass = (AttributeClass) AttributeClass attribClass = (AttributeClass)
responseMap[i].get("printer-name"); responseMap[i].get("printer-uri-supported");
if (attribClass != null) { if (attribClass != null) {
String nameStr = attribClass.getStringValue(); String nameStr = attribClass.getStringValue();
......
...@@ -335,6 +335,38 @@ public class IPPPrintService implements PrintService, SunPrinterJobService { ...@@ -335,6 +335,38 @@ public class IPPPrintService implements PrintService, SunPrinterJobService {
} }
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. * Initialize mediaSizeNames, mediaTrays and other attributes.
...@@ -375,7 +407,7 @@ public class IPPPrintService implements PrintService, SunPrinterJobService { ...@@ -375,7 +407,7 @@ public class IPPPrintService implements PrintService, SunPrinterJobService {
return; return;
} catch (Exception e) { } catch (Exception e) {
IPPPrintService.debug_println(debugPrefix+ IPPPrintService.debug_println(debugPrefix+
" error creating CUPSPrinter"); " error creating CUPSPrinter e="+e);
} }
} }
...@@ -807,6 +839,18 @@ public class IPPPrintService implements PrintService, SunPrinterJobService { ...@@ -807,6 +839,18 @@ public class IPPPrintService implements PrintService, SunPrinterJobService {
docList.addAll(Arrays.asList(flavors)); 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") && if (mimeType.equals("text/plain") &&
addHostEncoding) { addHostEncoding) {
docList.add(Arrays.asList(textPlainHost)); docList.add(Arrays.asList(textPlainHost));
...@@ -820,11 +864,6 @@ public class IPPPrintService implements PrintService, SunPrinterJobService { ...@@ -820,11 +864,6 @@ public class IPPPrintService implements PrintService, SunPrinterJobService {
} else if (mimeType.equals("image/jpeg")) { } else if (mimeType.equals("image/jpeg")) {
jpgImagesAdded = true; jpgImagesAdded = true;
} else if (mimeType.indexOf("postscript") != -1) { } else if (mimeType.indexOf("postscript") != -1) {
docList.add(
DocFlavor.SERVICE_FORMATTED.PAGEABLE);
docList.add(
DocFlavor.SERVICE_FORMATTED.PRINTABLE);
psSupported = true; psSupported = true;
} }
break; break;
...@@ -841,7 +880,7 @@ public class IPPPrintService implements PrintService, SunPrinterJobService { ...@@ -841,7 +880,7 @@ public class IPPPrintService implements PrintService, SunPrinterJobService {
} }
// check if we need to add image DocFlavors // check if we need to add image DocFlavors
if (psSupported) { if (psSupported || isCupsPrinter) {
if (!jpgImagesAdded) { if (!jpgImagesAdded) {
docList.addAll(Arrays.asList(imageJPG)); docList.addAll(Arrays.asList(imageJPG));
} }
...@@ -1540,10 +1579,7 @@ public class IPPPrintService implements PrintService, SunPrinterJobService { ...@@ -1540,10 +1579,7 @@ public class IPPPrintService implements PrintService, SunPrinterJobService {
if (isCupsPrinter) { if (isCupsPrinter) {
try { try {
urlConnection = getIPPConnection( urlConnection = getIPPConnection(
new URL("http://"+ new URL(myURL+".ppd"));
CUPSPrinter.getServer()+":"+
CUPSPrinter.getPort()+
"/printers/"+printer+".ppd"));
InputStream is = urlConnection.getInputStream(); InputStream is = urlConnection.getInputStream();
if (is != null) { if (is != null) {
...@@ -1559,6 +1595,11 @@ public class IPPPrintService implements PrintService, SunPrinterJobService { ...@@ -1559,6 +1595,11 @@ public class IPPPrintService implements PrintService, SunPrinterJobService {
} }
} }
} catch (java.io.IOException e) { } 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
} }
} }
} }
......
...@@ -196,11 +196,20 @@ public class UnixPrintServiceLookup extends PrintServiceLookup ...@@ -196,11 +196,20 @@ public class UnixPrintServiceLookup extends PrintServiceLookup
// refreshes "printServices" // refreshes "printServices"
public synchronized void refreshServices() { 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(); getDefaultPrintService();
if (CUPSPrinter.isCupsRunning()) { 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 { } else {
if (isSysV()) { if (isSysV()) {
printers = getAllPrinterNamesSysV(); printers = getAllPrinterNamesSysV();
...@@ -236,12 +245,9 @@ public class UnixPrintServiceLookup extends PrintServiceLookup ...@@ -236,12 +245,9 @@ public class UnixPrintServiceLookup extends PrintServiceLookup
if (CUPSPrinter.isCupsRunning()) { if (CUPSPrinter.isCupsRunning()) {
try { try {
URL serviceURL = printerList.add(new IPPPrintService(printers[p],
new URL("http://"+ printerURIs[p],
CUPSPrinter.getServer()+":"+ true));
CUPSPrinter.getPort()+"/"+printers[p]);
printerList.add(new IPPPrintService( printers[p],
serviceURL));
} catch (Exception e) { } catch (Exception e) {
IPPPrintService.debug_println(debugPrefix+ IPPPrintService.debug_println(debugPrefix+
" getAllPrinters Exception "+ " getAllPrinters Exception "+
...@@ -265,12 +271,10 @@ public class UnixPrintServiceLookup extends PrintServiceLookup ...@@ -265,12 +271,10 @@ public class UnixPrintServiceLookup extends PrintServiceLookup
if (j == printServices.length) { // not found? if (j == printServices.length) { // not found?
if (CUPSPrinter.isCupsRunning()) { if (CUPSPrinter.isCupsRunning()) {
try { try {
URL serviceURL = printerList.add(new IPPPrintService(
new URL("http://"+ printers[p],
CUPSPrinter.getServer()+":"+ printerURIs[p],
CUPSPrinter.getPort()+"/"+printers[p]); true));
printerList.add(new IPPPrintService( printers[p],
serviceURL));
} catch (Exception e) { } catch (Exception e) {
IPPPrintService.debug_println(debugPrefix+ IPPPrintService.debug_println(debugPrefix+
" getAllPrinters Exception "+ " getAllPrinters Exception "+
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册