xref: /titanic_50/usr/src/cmd/print/printmgr/com/sun/admin/pm/server/PrinterUtil.java (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * ident	"%Z%%M%	%I%	%E% SMI"
24  *
25  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms.
27  *
28  * PrinterUtil class
29  * Methods not associated with a printer instance.
30  */
31 
32 package com.sun.admin.pm.server;
33 
34 import java.io.*;
35 import java.util.*;
36 
37 public class  PrinterUtil {
38 
39     //
40     // main for testing
41     //
main(String[] args)42     public static void main(String[] args) {
43 	String dp = null;
44 	String devs[] = null;
45 	String printers[] = null;
46 
47 	try {
48         	NameService ns = new NameService("ldap");
49 //		checkRootPasswd("xxx");
50 		dp = getDefaultPrinter(ns);
51 		devs = getDeviceList();
52 		printers = getPrinterList(ns);
53 	}
54 	catch (Exception e)
55 	{
56 		System.out.println(e);
57 		System.exit(1);
58 	}
59 	System.out.println("Default printer is:	" + dp);
60 	for (int i = 0; i < devs.length; i++) {
61 		System.out.println(devs[i]);
62 	}
63 	for (int i = 0; i < printers.length; i += 3) {
64 		System.out.println("printername:        " + printers[i]);
65 		System.out.println("servername:         " + printers[i+1]);
66 		System.out.println("comment:            " + printers[i+2]);
67 	}
68 	System.exit(0);
69     }
70 
71     //
72     // Get the default printer for a specified name space
73     //
getDefaultPrinter( NameService ns)74     public synchronized static String getDefaultPrinter(
75 	NameService ns) throws Exception
76     {
77 	Debug.message("SVR: PrinterUtil.getDefaultPrinter()");
78 
79 	String nsarg = ns.getNameService();
80 	String ret = DoPrinterUtil.getDefault(nsarg);
81 	if (ret == null) {
82 		return (new String(""));
83 	}
84 	return (new String(ret));
85     }
86 
87     //
88     // Get a list of possible printer devices for this machine.
89     //
getDeviceList()90     public synchronized static String[] getDeviceList() throws Exception
91     {
92 	Debug.message("SVR: PrinterUtil.getDeviceList()");
93 
94 	String emptylist[] = new String[1];
95 	emptylist[0] = "";
96 
97 	String ret[] = DoPrinterUtil.getDevices();
98 	if (ret == null) {
99 		return (emptylist);
100 	}
101 	return (ret);
102     }
103 
104     //
105     // Get the list of supported Printer Makes (Manufacturers)
106     // If supported, a PPD file exists for this Make
107     //
getMakesList()108     public synchronized static String[] getMakesList() throws Exception
109     {
110 	Debug.message("SVR: PrinterUtil.getMakesList()");
111 
112 	String emptylist[] = new String[1];
113 	emptylist[0] = "";
114 
115 	String ret[] = DoPrinterUtil.getMakes();
116 	if (ret == null) {
117 		return (emptylist);
118 	}
119 	return (ret);
120     }
121 
getModelsList( String make)122     public synchronized static String[] getModelsList(
123 				String make) throws Exception
124 
125     {
126 	Debug.message("SVR: PrinterUtil.getModelsList()");
127 
128 	String emptylist[] = new String[1];
129 	emptylist[0] = "";
130 
131 	String ret[] = DoPrinterUtil.getModels(make);
132 	return (ret);
133     }
134 
getPPDList( String make, String model)135     public synchronized static String[] getPPDList(
136 		String make, String model) throws Exception
137 
138     {
139 	Debug.message("SVR: PrinterUtil.getPPDList()");
140 
141 	String emptylist[] = new String[1];
142 	emptylist[0] = "";
143 
144 	String ret[] = DoPrinterUtil.getPPDs(make, model);
145 	if (ret == null) {
146 		return (emptylist);
147 	}
148 	return (ret);
149     }
150 
getProbePrinter(String device)151     public synchronized static String[] getProbePrinter(String device)
152     {
153 	Debug.message("SVR: PrinterUtil.getProbePrinter()");
154 
155 	String ret[] = DoPrinterUtil.getProbe(device);
156 	return (ret);
157     }
158 
159 
160     //
161     // Get a list of printers in the specified name service.
162     //
getPrinterList( NameService ns)163     public synchronized static String[] getPrinterList(
164 	NameService ns) throws Exception
165     {
166 	Debug.message("SVR: PrinterUtil.getPrinterList()");
167 
168 	String emptylist[] = new String[1];
169 	emptylist[0] = "";
170 
171 	String nsarg = ns.getNameService();
172 	String[] ret = DoPrinterUtil.getList(nsarg);
173 	if (ret == null) {
174 		return (emptylist);
175 	}
176 	return (ret);
177     }
178 
179     //
180     // Does this printer already exist in the specified
181     // name service
182     //
exists( String name, NameService ns)183     public synchronized static boolean exists(
184 	String name,
185 	NameService ns) throws Exception
186     {
187 	Debug.message("SVR: PrinterUtil.exists()");
188 
189 	String nsname = ns.getNameService();
190 	return (DoPrinterUtil.exists(name, nsname));
191     }
192 
isLocal( String printername)193     public synchronized static boolean isLocal(
194 	String printername) throws Exception
195     {
196 	Debug.message("SVR: PrinterUtil.isLocal()");
197 
198 	return (DoPrinterUtil.isLocal(printername));
199     }
200 
checkRootPasswd( String passwd)201     public synchronized static void checkRootPasswd(
202 	String passwd) throws Exception
203     {
204 	DoPrinterNS.doCheckRootPasswd(passwd);
205     }
206 }
207