提交 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 {
AttributeClass.ATTRIBUTES_NATURAL_LANGUAGE,
new AttributeClass("requested-attributes",
AttributeClass.TAG_KEYWORD,
"printer-name")
"printer-uri-supported")
};
if (IPPPrintService.writeIPPRequest(os,
......@@ -354,7 +354,7 @@ public class CUPSPrinter {
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();
......
......@@ -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.
......@@ -375,7 +407,7 @@ public class IPPPrintService implements PrintService, SunPrinterJobService {
return;
} catch (Exception e) {
IPPPrintService.debug_println(debugPrefix+
" error creating CUPSPrinter");
" error creating CUPSPrinter e="+e);
}
}
......@@ -807,6 +839,18 @@ public class IPPPrintService implements PrintService, SunPrinterJobService {
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 @@ public class IPPPrintService implements PrintService, SunPrinterJobService {
} 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 @@ public class IPPPrintService implements PrintService, SunPrinterJobService {
}
// check if we need to add image DocFlavors
if (psSupported) {
if (psSupported || isCupsPrinter) {
if (!jpgImagesAdded) {
docList.addAll(Arrays.asList(imageJPG));
}
......@@ -1540,10 +1579,7 @@ public class IPPPrintService implements PrintService, SunPrinterJobService {
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 @@ public class IPPPrintService implements PrintService, SunPrinterJobService {
}
}
} 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
// 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 @@ public class UnixPrintServiceLookup extends PrintServiceLookup
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 @@ public class UnixPrintServiceLookup extends PrintServiceLookup
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 "+
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册