jdk/src/solaris/classes/sun/print/UnixPrintServiceLookup.java
changeset 22584 eed64ee05369
parent 21780 aa006e1a6eb9
child 22607 ba232b417248
equal deleted inserted replaced
22583:e7d5af0b11e9 22584:eed64ee05369
     1 /*
     1 /*
     2  * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   198             refreshServices();
   198             refreshServices();
   199         }
   199         }
   200         if (printServices == null) {
   200         if (printServices == null) {
   201             return new PrintService[0];
   201             return new PrintService[0];
   202         } else {
   202         } else {
   203             return (PrintService[])printServices.clone();
   203             return printServices.clone();
   204         }
   204         }
   205     }
   205     }
   206 
   206 
   207     private int addPrintServiceToList(ArrayList printerList, PrintService ps) {
   207     private int addPrintServiceToList(ArrayList printerList, PrintService ps) {
   208         int index = printerList.indexOf(ps);
   208         int index = printerList.indexOf(ps);
   211             // Bug in Linux: Duplicate entry of a remote printer
   211             // Bug in Linux: Duplicate entry of a remote printer
   212             // and treats it as local printer but it is returning wrong
   212             // and treats it as local printer but it is returning wrong
   213             // information when queried using IPP. Workaround is to remove it.
   213             // information when queried using IPP. Workaround is to remove it.
   214             // Even CUPS ignores these entries as shown in lpstat or using
   214             // Even CUPS ignores these entries as shown in lpstat or using
   215             // their web configuration.
   215             // their web configuration.
   216             PrinterURI uri = (PrinterURI)ps.getAttribute(PrinterURI.class);
   216             PrinterURI uri = ps.getAttribute(PrinterURI.class);
   217             if (uri.getURI().getHost().equals("localhost")) {
   217             if (uri.getURI().getHost().equals("localhost")) {
   218                 IPPPrintService.debug_println(debugPrefix+"duplicate PrintService, ignoring the new local printer: "+ps);
   218                 IPPPrintService.debug_println(debugPrefix+"duplicate PrintService, ignoring the new local printer: "+ps);
   219                 return index;  // Do not add this.
   219                 return index;  // Do not add this.
   220             }
   220             }
   221             PrintService oldPS = (PrintService)(printerList.get(index));
   221             PrintService oldPS = (PrintService)(printerList.get(index));
   222             uri = (PrinterURI)oldPS.getAttribute(PrinterURI.class);
   222             uri = oldPS.getAttribute(PrinterURI.class);
   223             if (uri.getURI().getHost().equals("localhost")) {
   223             if (uri.getURI().getHost().equals("localhost")) {
   224                 IPPPrintService.debug_println(debugPrefix+"duplicate PrintService, removing existing local printer: "+oldPS);
   224                 IPPPrintService.debug_println(debugPrefix+"duplicate PrintService, removing existing local printer: "+oldPS);
   225                 printerList.remove(oldPS);
   225                 printerList.remove(oldPS);
   226             } else {
   226             } else {
   227                 return index;
   227                 return index;
   408             return null;
   408             return null;
   409         }
   409         }
   410         /* check if all printers are already available */
   410         /* check if all printers are already available */
   411         if (printServices != null) {
   411         if (printServices != null) {
   412             for (PrintService printService : printServices) {
   412             for (PrintService printService : printServices) {
   413                 PrinterName printerName =
   413                 PrinterName printerName = printService.getAttribute(PrinterName.class);
   414                     (PrinterName)printService.getAttribute(PrinterName.class);
       
   415                 if (printerName.getValue().equals(name)) {
   414                 if (printerName.getValue().equals(name)) {
   416                     return printService;
   415                     return printService;
   417                 }
   416                 }
   418             }
   417             }
   419         }
   418         }
   462             /* To avoid execing a unix command  see if the client is asking
   461             /* To avoid execing a unix command  see if the client is asking
   463              * for the default printer by name, since we already have that
   462              * for the default printer by name, since we already have that
   464              * initialised.
   463              * initialised.
   465              */
   464              */
   466 
   465 
   467             PrinterName defName =
   466             PrinterName defName = defService.getAttribute(PrinterName.class);
   468                 (PrinterName)defService.getAttribute(PrinterName.class);
       
   469 
   467 
   470             if (defName != null && name.equals(defName)) {
   468             if (defName != null && name.equals(defName)) {
   471                 if (matchesAttributes(defService, serviceSet)) {
   469                 if (matchesAttributes(defService, serviceSet)) {
   472                     services = new PrintService[1];
   470                     services = new PrintService[1];
   473                     services[0] = defService;
   471                     services[0] = defService;