UnixPrintServiceLookup.java revision 5089
2362N/A * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * Remind: This class uses solaris commands. We also need a linux 0N/A /* Remind: the current implementation is static, as its assumed 0N/A * its preferable to minimise creation of PrintService instances. 0N/A * Later we should add logic to add/remove services on the fly which 0N/A * will take a hit of needing to regather the list of services. 0N/A * can be used to force the printing code to poll or not poll 0N/A * for PrintServices. 0N/A /* The system property "sun.java2d.print.minRefreshTime" 0N/A * can be used to specify minimum refresh time (in seconds) 0N/A * for polling PrintServices. The default is 120. 0N/A "/usr/sbin/lpc status | grep -E '^[ 0-9a-zA-Z_-]*@' | awk -F'@' '{print $1}'" 4632N/A "/usr/sbin/lpc status all | grep -E '^[ 0-9a-zA-Z_-]*@' | awk -F'@' '{print $1}' | sort" 0N/A "| grep : | sed -ne 's/://p'",
0N/A "| grep -E '^[ 0-9a-zA-Z_-]*@' | awk -F'@' '{print $1}'" 0N/A // start the printer listener thread 0N/A /* Want the PrintService which is default print service to have 0N/A * equality of reference with the equivalent in list of print services 0N/A * This isn't required by the API and there's a risk doing this will 0N/A * lead people to assume its guaranteed. 0N/A // refreshes "printServices" 293N/A /* excludes the default printer */ 0N/A " getAllPrinters Exception "+
0N/A " getAllPrinters Exception "+
0N/A // Look for deleted services and invalidate these 0N/A //if defaultService is not found in printerList 0N/A //add default to the list 0N/A // swap default with the first in the list 0N/A /* This checks for validity of the printer name before passing as 0N/A * parameter to a shell command. 0N/A c ==
'-' || c ==
'_' || c ==
'.' || c ==
'/') {
0N/A /* On a network with many (hundreds) of network printers, it 0N/A * can save several seconds if you know all you want is a particular 0N/A * printer, to ask for that printer rather than retrieving all printers. 0N/A /* Typically expect that if a service attribute is specified that 0N/A * its a printer name and there ought to be only one match. 0N/A * Directly retrieve that service and confirm 0N/A * that it meets the other requirements. 0N/A * If printer name isn't mentioned then go a slow path checking 0N/A * all printers if they meet the reqiremements. 0N/A /* To avoid execing a unix command see if the client is asking 0N/A * for the default printer by name, since we already have that 0N/A /* Its not the default service */ 0N/A /* specified service attributes don't include a name.*/ 0N/A * If service attributes are specified then there must be additional 0N/A // We only need to compare 1 PrintService because all 0N/A // UnixPrintServices are the same anyway. We will not use 0N/A // default PrintService because it might be null. 0N/A * return empty array as don't support multi docs 0N/A // clear defaultPrintService 0N/A public synchronized void 0N/A /* This method isn't used in most cases because we rely on code in 0N/A * javax.print.PrintServiceLookup. This is needed just for the cases 0N/A * where those interfaces are by-passed. 0N/A synchronized (
this) {
0N/A boolean done =
false;
// in case of interrupt. 0N/A // promptly close all streams. 0N/A // compute new refresh time 1 printer = 1 sec