提交 9080ea2e 编写于 作者: J jgodinez

8022536: closed/javax/print/TextFlavorTest.java fails

Reviewed-by: prr, jchen
上级 348a6f61
......@@ -237,8 +237,9 @@ public class CUPSPrinter {
/**
* Get CUPS default printer using IPP.
* Returns 2 values - index 0 is printer name, index 1 is the uri.
*/
public static String getDefaultPrinter() {
static String[] getDefaultPrinter() {
try {
URL url = new URL("http", getServer(), getPort(), "");
final HttpURLConnection urlConnection =
......@@ -264,8 +265,8 @@ public class CUPSPrinter {
AttributeClass.ATTRIBUTES_CHARSET,
AttributeClass.ATTRIBUTES_NATURAL_LANGUAGE,
new AttributeClass("requested-attributes",
AttributeClass.TAG_KEYWORD,
"printer-name")
AttributeClass.TAG_URI,
"printer-uri")
};
if (IPPPrintService.writeIPPRequest(os,
......@@ -273,6 +274,7 @@ public class CUPSPrinter {
attCl)) {
HashMap defaultMap = null;
String[] printerInfo = new String[2];
InputStream is = urlConnection.getInputStream();
HashMap[] responseMap = IPPPrintService.readIPPResponse(
is);
......@@ -293,21 +295,30 @@ public class CUPSPrinter {
* special behaviour for this built in.
*/
if (UnixPrintServiceLookup.isMac()) {
return UnixPrintServiceLookup.
printerInfo[0] = UnixPrintServiceLookup.
getDefaultPrinterNameSysV();
printerInfo[1] = null;
return (String[])printerInfo.clone();
} else {
return null;
}
}
AttributeClass attribClass = (AttributeClass)
defaultMap.get("printer-name");
if (attribClass != null) {
String nameStr = attribClass.getStringValue();
printerInfo[0] = attribClass.getStringValue();
attribClass = (AttributeClass)defaultMap.get("device-uri");
if (attribClass != null) {
printerInfo[1] = attribClass.getStringValue();
} else {
printerInfo[1] = null;
}
os.close();
urlConnection.disconnect();
return nameStr;
return (String [])printerInfo.clone();
}
}
os.close();
......@@ -322,7 +333,7 @@ public class CUPSPrinter {
/**
* Get list of all CUPS printers using IPP.
*/
public static String[] getAllPrinters() {
static String[] getAllPrinters() {
try {
URL url = new URL("http", getServer(), getPort(), "");
......
......@@ -366,6 +366,7 @@ public class IPPPrintService implements PrintService, SunPrinterJobService {
" IPPPrintService, myURL="+
myURL+" Exception= "+
e);
throw new IllegalArgumentException("invalid url");
}
isCupsPrinter = isCups;
......@@ -1145,6 +1146,8 @@ public class IPPPrintService implements PrintService, SunPrinterJobService {
// REMIND: check attribute values
return (T)PDLOverrideSupported.NOT_ATTEMPTED;
}
} else if (category == PrinterURI.class) {
return (T)(new PrinterURI(myURI));
} else {
return null;
}
......
......@@ -48,6 +48,7 @@ import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.PrintServiceAttribute;
import javax.print.attribute.PrintServiceAttributeSet;
import javax.print.attribute.standard.PrinterName;
import javax.print.attribute.standard.PrinterURI;
import java.io.File;
import java.io.FileReader;
import java.net.URL;
......@@ -203,6 +204,33 @@ public class UnixPrintServiceLookup extends PrintServiceLookup
}
}
private int addPrintServiceToList(ArrayList printerList, PrintService ps) {
int index = printerList.indexOf(ps);
// Check if PrintService with same name is already in the list.
if (CUPSPrinter.isCupsRunning() && index != -1) {
// Bug in Linux: Duplicate entry of a remote printer
// and treats it as local printer but it is returning wrong
// information when queried using IPP. Workaround is to remove it.
// Even CUPS ignores these entries as shown in lpstat or using
// their web configuration.
PrinterURI uri = (PrinterURI)ps.getAttribute(PrinterURI.class);
if (uri.getURI().getHost().equals("localhost")) {
IPPPrintService.debug_println(debugPrefix+"duplicate PrintService, ignoring the new local printer: "+ps);
return index; // Do not add this.
}
PrintService oldPS = (PrintService)(printerList.get(index));
uri = (PrinterURI)oldPS.getAttribute(PrinterURI.class);
if (uri.getURI().getHost().equals("localhost")) {
IPPPrintService.debug_println(debugPrefix+"duplicate PrintService, removing existing local printer: "+oldPS);
printerList.remove(oldPS);
} else {
return index;
}
}
printerList.add(ps);
return (printerList.size() - 1);
}
// refreshes "printServices"
public synchronized void refreshServices() {
......@@ -246,8 +274,7 @@ public class UnixPrintServiceLookup extends PrintServiceLookup
}
if ((defaultPrintService != null)
&& printers[p].equals(getPrinterDestName(defaultPrintService))) {
printerList.add(defaultPrintService);
defaultIndex = printerList.size() - 1;
defaultIndex = addPrintServiceToList(printerList, defaultPrintService);
} else {
if (printServices == null) {
IPPPrintService.debug_println(debugPrefix+
......@@ -255,9 +282,10 @@ public class UnixPrintServiceLookup extends PrintServiceLookup
if (CUPSPrinter.isCupsRunning()) {
try {
printerList.add(new IPPPrintService(printers[p],
printerURIs[p],
true));
addPrintServiceToList(printerList,
new IPPPrintService(printers[p],
printerURIs[p],
true));
} catch (Exception e) {
IPPPrintService.debug_println(debugPrefix+
" getAllPrinters Exception "+
......@@ -282,10 +310,10 @@ public class UnixPrintServiceLookup extends PrintServiceLookup
if (j == printServices.length) { // not found?
if (CUPSPrinter.isCupsRunning()) {
try {
printerList.add(new IPPPrintService(
printers[p],
printerURIs[p],
true));
addPrintServiceToList(printerList,
new IPPPrintService(printers[p],
printerURIs[p],
true));
} catch (Exception e) {
IPPPrintService.debug_println(debugPrefix+
" getAllPrinters Exception "+
......@@ -312,9 +340,7 @@ public class UnixPrintServiceLookup extends PrintServiceLookup
//if defaultService is not found in printerList
if (defaultIndex == -1 && defaultPrintService != null) {
//add default to the list
printerList.add(defaultPrintService);
defaultIndex = printerList.size() - 1;
defaultIndex = addPrintServiceToList(printerList, defaultPrintService);
}
printServices = (PrintService[])printerList.toArray(
......@@ -563,11 +589,14 @@ public class UnixPrintServiceLookup extends PrintServiceLookup
// clear defaultPrintService
defaultPrintService = null;
String psuri = null;
IPPPrintService.debug_println("isRunning ? "+
(CUPSPrinter.isCupsRunning()));
if (CUPSPrinter.isCupsRunning()) {
defaultPrinter = CUPSPrinter.getDefaultPrinter();
String[] printerInfo = CUPSPrinter.getDefaultPrinter();
defaultPrinter = printerInfo[0];
psuri = printerInfo[1];
} else {
if (isMac() || isSysV()) {
defaultPrinter = getDefaultPrinterNameSysV();
......@@ -590,12 +619,17 @@ public class UnixPrintServiceLookup extends PrintServiceLookup
if (defaultPrintService == null) {
if (CUPSPrinter.isCupsRunning()) {
try {
PrintService defaultPS =
new IPPPrintService(defaultPrinter,
PrintService defaultPS;
if (psuri != null) {
defaultPS = new IPPPrintService(defaultPrinter,
psuri, true);
} else {
defaultPS = new IPPPrintService(defaultPrinter,
new URL("http://"+
CUPSPrinter.getServer()+":"+
CUPSPrinter.getPort()+"/"+
defaultPrinter));
}
defaultPrintService = defaultPS;
} catch (Exception e) {
}
......
......@@ -23,7 +23,7 @@
/**
* @test
* @bug 800535
* @bug 800535 8022536
* @summary JDK7 Printing: CJK and Latin Text in string overlap
* @run main/manual=yesno PrintLatinCJKTest
*/
......@@ -49,6 +49,8 @@ public class PrintLatinCJKTest implements Printable, ActionListener {
private PageFormat pf;
static String info =
"To test 8022536, if a remote printer is the system default,"+
"it should show in the dialog as the selected printer.\n"+
"You need a printer for this test. If you have none, let "+
"the test pass. If there is a printer, press Print, send "+
"the output to the printer, and examine it. It should have "+
......
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
@test
@bug 6334074 8022536
@summary test supported text flavors reported properly
@run main TextFlavorTest
*/
import javax.print.*;
import javax.print.attribute.standard.*;
import javax.print.attribute.*;
import java.io.*;
public class TextFlavorTest {
public static void main(String[] args) throws Exception {
PrintService service[] =
PrintServiceLookup.lookupPrintServices(null, null);
if (service.length == 0) {
System.out.println("No print service found.");
return;
}
for (int y = 0; y < service.length; y ++) {
DocFlavor flavors[] = service[y].getSupportedDocFlavors();
if (flavors == null) continue;
for (int x = 0; x < flavors.length; x ++) {
if (!service[y].isDocFlavorSupported(flavors[x])) {
String msg = "DocFlavor " + flavors[x] +
" is not supported by service "+ service[y];
throw new RuntimeException(msg);
}
}
}
System.out.println("Test passed.");
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册