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 * Printer class 29 * Printer object containing attributes and methods for 30 * updating printers. 31 */ 32 33 package com.sun.admin.pm.server; 34 35 public class Printer 36 { 37 // 38 // Printer object attributes 39 // 40 private String printername = null; 41 private String printertype = null; 42 private String printserver = null; 43 private String comment = null; 44 private String device = null; 45 private String make = null; 46 private String model = null; 47 private String ppd = null; 48 private String ppdfile = null; 49 private String notify = null; 50 private String protocol = null; 51 private String destination = null; 52 private String extensions = null; 53 private String[] file_contents = null; 54 private String[] user_allow_list = null; 55 private String[] user_deny_list = null; 56 private boolean use_ppd_file = true; 57 private boolean default_printer = false; 58 private String banner = null; 59 private boolean enable = true; 60 private boolean accept = true; 61 62 private String locale = null; // Possible future use 63 64 private NameService nscontext; 65 66 // 67 // Logs 68 // 69 private String warnlog = null; 70 private String errlog = null; 71 private String cmdlog = null; 72 73 // 74 // Constructors 75 // 76 public Printer() 77 { 78 Debug.message("SVR: Printer constructor called empty."); 79 nscontext = new NameService(); 80 PrinterDebug.printObj(nscontext); 81 } 82 public Printer(NameService ns) 83 { 84 Debug.message("SVR: Printer constructor called with NS."); 85 nscontext = ns; 86 PrinterDebug.printObj(ns); 87 } 88 89 // 90 // Is a printer local to this machine 91 // 92 public synchronized boolean isPrinterLocal(String printername) 93 throws Exception 94 { 95 Debug.message("SVR: Printer.isPrinterLocal()"); 96 return (DoPrinterUtil.isLocal(printername)); 97 } 98 99 // 100 // Get details of a printer. 101 // 102 public synchronized void getPrinterDetails() 103 throws Exception 104 { 105 Debug.message("SVR: Printer.getPrinterDetails()"); 106 107 if (printername == null) { 108 throw new pmInternalErrorException( 109 "Printer.getPrinterDetails(): printername must be set"); 110 } 111 DoPrinterView.view(this, nscontext); 112 } 113 114 // 115 // Add a local printer 116 // 117 public synchronized void addLocalPrinter() 118 throws Exception 119 { 120 Debug.message("SVR: Printer.addLocalPrinter()"); 121 122 if (printername == null) { 123 throw new pmInternalErrorException( 124 "Printer.addLocalPrinter(): printername must be set"); 125 } 126 if (printserver == null) { 127 Host h = new Host(); 128 printserver = h.getLocalHostName(); 129 h = null; 130 } 131 if (device == null) { 132 throw new pmInternalErrorException( 133 "Printer.addLocalPrinter(): device must be set"); 134 } 135 if ((pmMisc.isppdCachefile()) && use_ppd_file) { 136 if (make == null) { 137 throw new pmInternalErrorException( 138 "Printer.addLocalPrinter(): make must be set"); 139 } 140 if (model == null) { 141 throw new pmInternalErrorException( 142 "Printer.addLocalPrinter(): model must be set"); 143 } 144 if (ppd == null) { 145 throw new pmInternalErrorException( 146 "Printer.addLocalPrinter(): ppd file must be selected"); 147 } 148 } 149 150 151 PrinterDebug.printObj(this); 152 153 clearLogs(); 154 DoPrinterAdd.add(this, nscontext); 155 } 156 157 // 158 // Add access to a remote printer 159 // 160 public synchronized void addRemotePrinter() 161 throws Exception 162 { 163 Debug.message("SVR: Printer.addRemotePrinter()"); 164 165 if (printername == null) { 166 throw new pmInternalErrorException( 167 "Printer.addRemotePrinter(): printername must be set"); 168 } 169 if (printserver == null) { 170 throw new pmInternalErrorException( 171 "Printer.addRemotePrinter(): printserver must be set"); 172 } 173 PrinterDebug.printObj(this); 174 175 clearLogs(); 176 DoPrinterAdd.add(this, nscontext); 177 } 178 179 // 180 // Delete a printer 181 // 182 public synchronized void deletePrinter() 183 throws Exception 184 { 185 Debug.message("SVR: Printer.deletePrinter()"); 186 187 if (printername == null) { 188 throw new pmInternalErrorException( 189 "Printer.deletePrinter(): printername must be set"); 190 } 191 PrinterDebug.printObj(this); 192 193 clearLogs(); 194 DoPrinterDelete.delete(this, nscontext); 195 } 196 197 // 198 // Modify a printer 199 // 200 public synchronized void modifyPrinter() 201 throws Exception 202 { 203 Debug.message("SVR: Printer.modifyPrinter()"); 204 205 if (printername == null) { 206 throw new pmInternalErrorException( 207 "Printer.modifyPrinter(): printername must be set"); 208 } 209 PrinterDebug.printObj(this); 210 211 clearLogs(); 212 DoPrinterMod.modify(this, nscontext); 213 } 214 215 // 216 // Set list of commands executed 217 // 218 public synchronized void setCmdLog(String newcmds) 219 { 220 if (newcmds == null) { 221 return; 222 } 223 if (!newcmds.endsWith("\n")) { 224 newcmds = newcmds.concat("\n"); 225 } 226 if (cmdlog == null) { 227 cmdlog = new String(newcmds); 228 return; 229 } 230 cmdlog = cmdlog.concat(newcmds); 231 } 232 233 // 234 // Set an error message. 235 // 236 public synchronized void setErrorLog(String errs) 237 { 238 if (errs == null) { 239 return; 240 } 241 if (!errs.endsWith("\n")) { 242 errs = errs.concat("\n"); 243 } 244 if (errlog == null) { 245 errlog = new String(errs); 246 return; 247 } else { 248 errlog = errlog.concat(errs); 249 } 250 } 251 252 // 253 // Set an warning message. 254 // 255 public synchronized void setWarnLog(String warning) 256 { 257 if (warning == null) { 258 return; 259 } 260 if (!warning.endsWith("\n")) { 261 warning = warning.concat("\n"); 262 } 263 if (warnlog == null) { 264 warnlog = new String(warning); 265 return; 266 } else { 267 warnlog = warnlog.concat(warning); 268 } 269 } 270 271 // 272 // Get commands executed. 273 // 274 public String getCmdLog() 275 { 276 if (cmdlog == null) { 277 return (null); 278 } 279 return (new String(cmdlog.trim())); 280 } 281 282 // 283 // Get error messages 284 // 285 public String getErrorLog() 286 { 287 if (errlog == null) { 288 return (null); 289 } 290 return (new String(errlog.trim())); 291 } 292 293 // 294 // Get warning messages 295 // 296 public String getWarnLog() 297 { 298 if (warnlog == null) { 299 return (null); 300 } 301 return (new String(warnlog.trim())); 302 } 303 304 // 305 // Set printer attributes 306 // 307 public synchronized void setPrinterName(String arg) 308 { 309 printername = arg; 310 } 311 public synchronized void setPrinterType(String arg) 312 { 313 printertype = arg; 314 } 315 public synchronized void setPrintServer(String arg) 316 { 317 printserver = arg; 318 } 319 public synchronized void setComment(String arg) 320 { 321 comment = arg; 322 } 323 public synchronized void setMake(String arg) 324 { 325 make = arg; 326 } 327 public synchronized void setModel(String arg) 328 { 329 model = arg; 330 } 331 public synchronized void setPPD(String arg) 332 { 333 ppd = arg; 334 } 335 public synchronized void setPPDFile(String arg) 336 { 337 ppdfile = arg; 338 } 339 public synchronized void setDevice(String arg) 340 { 341 device = arg; 342 } 343 public synchronized void setUsePPD(boolean arg) 344 { 345 use_ppd_file = arg; 346 } 347 public synchronized void setNotify(String arg) 348 { 349 notify = arg; 350 } 351 public synchronized void setProtocol(String arg) 352 { 353 protocol = arg; 354 } 355 public synchronized void setDestination(String arg) 356 { 357 destination = arg; 358 } 359 public synchronized void setExtensions(String arg) 360 { 361 extensions = arg; 362 } 363 public synchronized void setFileContents(String[] arg) 364 { 365 file_contents = arg; 366 } 367 public synchronized void setUserAllowList(String[] arg) 368 { 369 user_allow_list = arg; 370 } 371 public synchronized void setUserDenyList(String[] arg) 372 { 373 user_deny_list = arg; 374 } 375 public synchronized void setIsDefaultPrinter(boolean arg) 376 { 377 default_printer = arg; 378 } 379 public synchronized void setBanner(String arg) 380 { 381 banner = arg; 382 } 383 public synchronized void setEnable(boolean arg) 384 { 385 enable = arg; 386 } 387 public synchronized void setAccept(boolean arg) 388 { 389 accept = arg; 390 } 391 public synchronized void setLocale(String arg) 392 { 393 locale = arg; 394 } 395 396 // 397 // Get printer attributes. 398 // 399 public String getPrinterName() 400 { 401 return (printername); 402 } 403 public String getPrinterType() 404 { 405 return (printertype); 406 } 407 public String getPrintServer() 408 { 409 return (printserver); 410 } 411 public String getComment() 412 { 413 return (comment); 414 } 415 public String getDevice() 416 { 417 return (device); 418 } 419 public boolean getUsePPD() 420 { 421 return (use_ppd_file); 422 } 423 public String getMake() 424 { 425 return (make); 426 } 427 public String getModel() 428 { 429 return (model); 430 } 431 public String getPPD() 432 { 433 return (ppd); 434 } 435 public String getPPDFile() 436 { 437 return (ppdfile); 438 } 439 public String getNotify() 440 { 441 return (notify); 442 } 443 public String getProtocol() 444 { 445 return (protocol); 446 } 447 public String getDestination() 448 { 449 return (destination); 450 } 451 public String getExtensions() 452 { 453 return (extensions); 454 } 455 public String[] getFileContents() 456 { 457 return (file_contents); 458 } 459 public String[] getUserAllowList() 460 { 461 return (user_allow_list); 462 } 463 public String[] getUserDenyList() 464 { 465 return (user_deny_list); 466 } 467 public boolean getIsDefaultPrinter() 468 { 469 return (default_printer); 470 } 471 public String getBanner() 472 { 473 return (banner); 474 } 475 public boolean getEnable() 476 { 477 return (enable); 478 } 479 public boolean getAccept() 480 { 481 return (accept); 482 } 483 public String getLocale() 484 { 485 return (locale); 486 } 487 488 protected void clearLogs() 489 { 490 warnlog = null; 491 errlog = null; 492 cmdlog = null; 493 } 494 495 // Hints for optimizing printer modifications 496 protected String modhints = ""; 497 } 498