001: /**
002: * Copyright 2003 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */package com.sun.portal.wsrp.consumer.cli;
013:
014: import java.util.Set;
015: import java.util.List;
016: import java.util.Map;
017: import java.util.Iterator;
018: import java.util.HashMap;
019: import java.util.ArrayList;
020: import java.util.ResourceBundle;
021: import java.util.PropertyResourceBundle;
022: import java.util.Locale;
023: import java.util.logging.Level;
024: import java.util.logging.Logger;
025:
026: import com.iplanet.am.util.Debug;
027:
028: import java.io.File;
029: import java.io.BufferedReader;
030: import java.io.StringReader;
031: import java.io.FileReader;
032: import java.io.IOException;
033:
034: import com.sun.portal.desktop.context.DSAMEAdminDPContext;
035: import com.sun.portal.desktop.context.ContextError;
036:
037: import com.sun.portal.wsrp.consumer.producermanager.ProducerEntityManagerFactory;
038: import com.sun.portal.wsrp.consumer.producermanager.ProducerEntityManager;
039: import com.sun.portal.wsrp.consumer.common.WSRPConsumerException;
040: import com.sun.portal.log.common.PortalLogger;
041: import com.sun.portal.util.ResourceLoader;
042:
043: class PEACommand {
044: //
045: // subcommands
046: //
047: private static final String SUBCMD_LIST = "list";
048: private static final String SUBCMD_ADD = "add";
049: private static final String SUBCMD_UPDATE = "update";
050: private static final String SUBCMD_REMOVE = "remove";
051: private static final String SUBCMD_DEPLOY = "deploy";
052: private static final String SUBCMD_BATCH = "batch";
053:
054: private static final int LIST = 1;
055: private static final int ADD = 2;
056: private static final int UPDATE = 3;
057: private static final int REMOVE = 4;
058: private static final int DEPLOY = 5;
059: private static final int BATCH = 6;
060:
061: //
062: // options
063: //
064: protected static final String OPT_HELP = "help";
065: protected static final String OPT_UID = "runasdn";
066: protected static final String OPT_PASSWORD = "password";
067: protected static final String OPT_DN = "dn";
068: protected static final String OPT_PID = "pid";
069: protected static final String OPT_PURL = "purl";
070: protected static final String OPT_PNAME = "pname";
071: protected static final String OPT_REGHANDLE = "reghandle";
072: protected static final String OPT_TYPE = "type";
073: protected static final String OPT_RID = "rid";
074: protected static final String OPT_CHNAME = "chname";
075: protected static final String OPT_VERBOSE = "verbose";
076: protected static final String OPT_VERSION = "version";
077: protected static final String OPT_LOCALE = "locale";
078: protected static final String OPT_DRYRUN = "dry-run";
079: protected static final String OPT_CONT = "continue";
080: protected static final String OPT_FILE = "file";
081:
082: //
083: // default value for non-required options
084: //
085: public static final String OPT_DEFAULT = "*";
086:
087: //default value for the locale option
088: public static final String LOCALE_DEFAULT = Locale.getDefault()
089: .toString();
090:
091: //
092: // option values
093: //
094: protected int subcmd = -1;
095: protected String uid = null;
096: protected String password = null;
097: protected String dn = null;
098: protected String pid = null;
099: protected String purl = null;
100: protected String pname = null;
101: protected String identityPropagationType = null;
102: protected String reghandle = null;
103: protected String rid = null;
104: protected String type = null;
105: protected String chname = null;
106: protected String input = null;
107: protected boolean dryrun = false;
108: protected boolean verbose = false;
109: protected Locale locale = Locale.getDefault();
110: protected boolean cont = false;
111: protected String batchFile = null;
112: protected boolean batchMode = false;
113: protected boolean isPreAuthorized = false;
114:
115: private ProducerEntityManager pem = null;
116:
117: private static Logger logger = PortalLogger
118: .getLogger(PEACommand.class);
119:
120: PEACommand(CLIPParser cp, String[] args, boolean batchMode,
121: Debug debug) throws PEAException {
122:
123: this .batchMode = batchMode;
124: parse(cp, args);
125: }
126:
127: PEACommand(CLIPParser cp, String cmdEntry, boolean batchMode,
128: boolean isPreAuthorized, Debug debug) throws PEAException {
129:
130: String cmd = null;
131: BufferedReader br = null;
132: try {
133: br = new BufferedReader(new StringReader(cmdEntry));
134: cmd = br.readLine();
135:
136: } catch (IOException ioe) {
137: Object[] tokens = { cmdEntry };
138: throw new PEAException("errorParseBatch", ioe, tokens);
139: } finally {
140: try {
141: br.close();
142: } catch (IOException ioe) {
143: Object[] tokens = { cmdEntry };
144: throw new PEAException("errorParseBatch", ioe, tokens);
145: }
146: }
147:
148: List cmdList = new ArrayList();
149:
150: StringBuffer tokenBuf = new StringBuffer();
151: boolean isQuoted = false;
152: for (int i = 0; i < cmd.length(); i++) {
153: if (cmd.charAt(i) == '"') {
154: isQuoted = !isQuoted;
155: } else {
156: if (!isQuoted && cmd.charAt(i) == (' ')) {
157: if (tokenBuf.length() > 0) {
158: cmdList.add(tokenBuf.toString());
159: }
160: tokenBuf = new StringBuffer();
161: } else {
162: tokenBuf.append(cmd.charAt(i));
163: }
164: }
165: }
166: if (tokenBuf.length() > 0) {
167: cmdList.add(tokenBuf.toString());
168: }
169:
170: // check for unmatched quote
171: if (isQuoted) {
172: Object[] tokens = { cmdEntry };
173: throw new PEAException("errorUnmatchedQuote", tokens);
174: }
175:
176: String[] cmdArray = new String[cmdList.size()];
177: cmdList.toArray(cmdArray);
178:
179: this .batchMode = batchMode;
180: this .isPreAuthorized = isPreAuthorized;
181: parse(cp, cmdArray);
182: }
183:
184: protected void parse(CLIPParser cp, String[] argv)
185: throws PEAException {
186:
187: // version (before CLIP parsing begins)
188: if (cp.needsVersion(argv)) {
189: System.err.println(getVersionInfo());
190: System.exit(0);
191: }
192:
193: // help
194: if (cp.needsHelp(argv)) {
195: System.err.println(cp.getHelp(argv));
196: System.exit(0);
197: }
198:
199: Map options = null;
200: try {
201: options = cp.getOptions(argv);
202: } catch (CLIPException ce) {
203: throw new PEAException("errorCLIPParseError", ce);
204: }
205:
206: //
207: // FIXME(susu): for debugging purpose
208: //
209: /*
210: try {
211: System.out.println("------------------------------------------------------------------");
212: System.out.println("CLIP CONTENT (for debug purpose only): " + cp.toString(argv));
213: System.out.println("------------------------------------------------------------------");
214: } catch (CLIPException ce) {
215: ce.printStackTrace();
216: }
217: */
218:
219: try {
220: cp.verifyArguments(argv);
221: } catch (CLIPException ce) {
222: throw new PEAException("errorCLIPParseError", ce);
223: }
224:
225: // verbose
226: if (((String[]) options.get(OPT_VERBOSE))[0].equals("true")) {
227: verbose = true;
228: } else {
229: verbose = false;
230: }
231:
232: // get subcommad
233: String sc = null;
234: try {
235: sc = cp.getSubCommand(argv);
236: } catch (CLIPException ce) {
237: Object[] tokens = { sc };
238: throw new PEAException("errorInvalidSubCmd", ce, tokens);
239: }
240: if (sc.equals(SUBCMD_LIST)) {
241: subcmd = LIST;
242: } else if (sc.equals(SUBCMD_ADD)) {
243: subcmd = ADD;
244: } else if (sc.equals(SUBCMD_UPDATE)) {
245: subcmd = UPDATE;
246: } else if (sc.equals(SUBCMD_REMOVE)) {
247: subcmd = REMOVE;
248: } else if (sc.equals(SUBCMD_DEPLOY)) {
249: subcmd = DEPLOY;
250: } else if (sc.equals(SUBCMD_BATCH)) {
251: subcmd = BATCH;
252: }
253:
254: //
255: // get user credential
256: //
257: uid = ((String[]) options.get(OPT_UID))[0];
258: password = ((String[]) options.get(OPT_PASSWORD))[0];
259:
260: if (subcmd != BATCH) {
261: if (batchMode && !isAuthProvided() && !isPreAuthorized) {
262: throw new PEAException("errorNoAuth");
263: }
264: dn = ((String[]) options.get(OPT_DN))[0];
265: } else {
266: batchFile = ((String[]) options.get(OPT_FILE))[0];
267: }
268:
269: //
270: // get other options
271: //
272: if (subcmd == LIST || subcmd == UPDATE || subcmd == REMOVE
273: || subcmd == DEPLOY) {
274: String[] pids = ((String[]) options.get(OPT_PID));
275: if (pids != null & pids.length > 0) {
276: if (!pids[0].equals(OPT_DEFAULT)) {
277: pid = pids[0];
278: }
279: }
280: }
281:
282: if (subcmd == LIST) {
283: String[] purls = ((String[]) options.get(OPT_PURL));
284: if (purls != null & purls.length > 0) {
285: if (!purls[0].equals(OPT_DEFAULT)) {
286: purl = purls[0];
287: }
288: }
289: }
290:
291: if (subcmd == ADD) {
292: String[] purls = ((String[]) options.get(OPT_PURL));
293: if (purls != null & purls.length > 0) {
294: purl = purls[0];
295: }
296: String[] pnames = ((String[]) options.get(OPT_PNAME));
297: if (pnames != null & pnames.length > 0) {
298: if (!pnames[0].equals(OPT_DEFAULT)) {
299: pname = pnames[0];
300: }
301: }
302: String[] reghandles = ((String[]) options
303: .get(OPT_REGHANDLE));
304: if (reghandles != null & reghandles.length > 0) {
305: if (!reghandles[0].equals(OPT_DEFAULT)) {
306: reghandle = reghandles[0];
307: }
308: }
309: }
310:
311: if (subcmd == UPDATE) {
312: type = ((String[]) options.get(OPT_TYPE))[0];
313: }
314:
315: if (subcmd == DEPLOY) {
316: String[] rids = ((String[]) options.get(OPT_RID));
317: if (rids != null & rids.length > 0) {
318: if (!rids[0].equals(OPT_DEFAULT)) {
319: rid = rids[0];
320: }
321: }
322: String[] chnames = ((String[]) options.get(OPT_CHNAME));
323: if (chnames != null & chnames.length > 0) {
324: if (!chnames[0].equals(OPT_DEFAULT)) {
325: chname = chnames[0];
326: }
327: }
328: }
329:
330: //
331: // check for continuous mode
332: //
333: if (subcmd == DEPLOY || subcmd == BATCH) {
334: cont = ((String[]) options.get(OPT_CONT))[0].equals("true");
335: }
336:
337: //
338: // check for dryrun
339: //
340: if (subcmd == ADD || subcmd == DEPLOY) {
341: dryrun = ((String[]) options.get(OPT_DRYRUN))[0]
342: .equals("true");
343: }
344:
345: //
346: // get operand
347: //
348: if (subcmd == ADD || subcmd == UPDATE) {
349: String operands[] = null;
350: try {
351: operands = cp.getOperands(argv);
352: } catch (CLIPException ce) {
353: throw new PEAException("errorCLIPParseError", ce);
354: }
355: if (operands != null && operands.length > 0) {
356: input = operands[0];
357: }
358: if (subcmd == ADD) {
359: input = getFileInput(input);
360: }
361: }
362: }
363:
364: protected boolean isBatch() {
365: return (subcmd == BATCH);
366: }
367:
368: protected boolean isAuthProvided() {
369: boolean authProvided = !uid.equals(OPT_DEFAULT)
370: && !password.equals(OPT_DEFAULT);
371: return authProvided;
372: }
373:
374: protected void runCommand(Debug debug) throws PEAException {
375: ProducerEntityManager pem = getProducerEntityManager();
376: DSAMEAdminDPContext dadc = getDPContext();
377: runCommand(pem, dadc, debug);
378: }
379:
380: protected void runCommand(ProducerEntityManager pem,
381: DSAMEAdminDPContext dadc, Debug debug) throws PEAException {
382: //
383: // if auth info is provided and in batch-mode, re-authorize
384: //
385: if (batchMode && isAuthProvided()) {
386: pem = getProducerEntityManager();
387: }
388:
389: switch (subcmd) {
390: case LIST:
391: PEAList peal = new PEAList();
392: String res = peal.process(pem, dn, pid, purl, verbose);
393: System.out.println(res);
394: break;
395:
396: case ADD:
397: PEAAdd peaa = new PEAAdd();
398: String peId = peaa.process(pem, dn, purl, pname,
399: identityPropagationType, input, reghandle, verbose,
400: dryrun);
401:
402: if (!dryrun) {
403: if (verbose) {
404: Object tokens[] = { peId };
405: System.out.println(PEAUtil.getLocalizedString(
406: "msgSuccessAdd", tokens));
407: } else {
408: System.out.println(peId);
409: }
410: } else {
411: if (verbose) {
412: System.out.println(PEAUtil
413: .getLocalizedString("msgDryrunSuccess"));
414: }
415: }
416: break;
417:
418: case UPDATE:
419: PEAUpdate peau = new PEAUpdate();
420: peau.process(pem, dn, pid, type, input, verbose);
421:
422: if (verbose) {
423: System.out.println(PEAUtil
424: .getLocalizedString("msgSuccess"));
425: }
426: break;
427:
428: case REMOVE:
429: PEARemove pear = new PEARemove();
430: pear.process(pem, dn, pid, verbose);
431:
432: if (verbose) {
433: System.out.println(PEAUtil
434: .getLocalizedString("msgSuccess"));
435: }
436: break;
437:
438: case DEPLOY:
439: PEADeploy pead = new PEADeploy();
440: String chnames = pead.process(pem, dadc, dn, pid, rid,
441: chname, cont, verbose, dryrun, debug);
442: if (!dryrun) {
443: if (verbose) {
444: Object tokens[] = { chnames };
445: System.out.println(PEAUtil.getLocalizedString(
446: "msgSuccessDeploy", tokens));
447: } else {
448: System.out.println(chnames);
449: }
450: } else {
451: if (verbose) {
452: System.out.println(PEAUtil
453: .getLocalizedString("msgDryrunSuccess"));
454: }
455: }
456: break;
457:
458: default:
459: Object[] tokens = { new Integer(subcmd) };
460: throw new PEAException("errorInvalidSubCmd", tokens);
461: }
462: }
463:
464: protected ProducerEntityManager getProducerEntityManager()
465: throws PEAException {
466:
467: if (logger.isLoggable(Level.FINEST))
468: logger.log(Level.FINEST, "PSWS_CSPWCCL0005");
469: ProducerEntityManager pem = null;
470: try {
471: pem = ProducerEntityManagerFactory.getInstance()
472: .getProducerEntityManager(dn, uid, password);
473: } catch (WSRPConsumerException wce) {
474: throw new PEAException("errorInitPEM", wce);
475: }
476: return pem;
477: }
478:
479: protected DSAMEAdminDPContext getDPContext() throws PEAException {
480: if (logger.isLoggable(Level.FINEST))
481: logger.log(Level.FINEST, "PSWS_CSPWCCL0006");
482: DSAMEAdminDPContext dadc = null;
483:
484: String propertiesFile = System
485: .getProperty("desktop.propertiesFile");
486: if (propertiesFile == null) {
487: throw new PEAException("errorDesktopPropertiesFile");
488: }
489: try {
490: dadc = new DSAMEAdminDPContext();
491: dadc.init(uid, password, propertiesFile, ResourceLoader
492: .getInstance(System.getProperties()).getPortalId());
493: } catch (ContextError ce) {
494: throw new PEAException("errorInitDPCxt", ce);
495: }
496: return dadc;
497: }
498:
499: protected static CLIPParser getCLIPParser(boolean batchMode)
500: throws CLIPException {
501:
502: CLIPParser.SubCommand[] subCmds = null;
503:
504: CLIPParser.Option[] optsList = {
505: new CLIPParser.Option(OPT_HELP, "?",
506: CLIPParser.BOOLEAN, "false", PEAUtil
507: .getLocalizedString("optHelp")),
508: new CLIPParser.Option(OPT_UID, "u", CLIPParser.REGULAR,
509: (batchMode ? OPT_DEFAULT : null), PEAUtil
510: .getLocalizedString("optArgUID"),
511: PEAUtil.getLocalizedString("optUID")),
512: new CLIPParser.Option(OPT_PASSWORD, "w",
513: CLIPParser.REGULAR, (batchMode ? OPT_DEFAULT
514: : null), PEAUtil
515: .getLocalizedString("optArgPassword"),
516: PEAUtil.getLocalizedString("optPassword")),
517: new CLIPParser.Option(OPT_DN, "d", CLIPParser.REGULAR,
518: null, PEAUtil.getLocalizedString("optArgDN"),
519: PEAUtil.getLocalizedString("optDN")),
520: new CLIPParser.Option(OPT_PID, "p", CLIPParser.REGULAR,
521: OPT_DEFAULT, PEAUtil
522: .getLocalizedString("optArgPID"),
523: PEAUtil.getLocalizedString("optPID")),
524: new CLIPParser.Option(OPT_PURL, "r",
525: CLIPParser.REGULAR, OPT_DEFAULT, PEAUtil
526: .getLocalizedString("optArgPURL"),
527: PEAUtil.getLocalizedString("optPURL")),
528: new CLIPParser.Option(OPT_VERBOSE, "b",
529: CLIPParser.BOOLEAN, "false", PEAUtil
530: .getLocalizedString("optVerbose")),
531: new CLIPParser.Option(OPT_VERSION, "V",
532: CLIPParser.BOOLEAN, "false", PEAUtil
533: .getLocalizedString("optVersion")),
534: new CLIPParser.Option(OPT_LOCALE, "l",
535: CLIPParser.REGULAR, LOCALE_DEFAULT, PEAUtil
536: .getLocalizedString("optArgLocale"),
537: PEAUtil.getLocalizedString("optLocale")) };
538:
539: CLIPParser.SubCommand scList = new CLIPParser.SubCommand(
540: SUBCMD_LIST, optsList, 0, 0, PEAUtil
541: .getLocalizedString("helpList"), "");
542:
543: CLIPParser.Option[] optsAdd = {
544: new CLIPParser.Option(OPT_HELP, "?",
545: CLIPParser.BOOLEAN, "false", PEAUtil
546: .getLocalizedString("optHelp")),
547: new CLIPParser.Option(OPT_UID, "u", CLIPParser.REGULAR,
548: (batchMode ? OPT_DEFAULT : null), PEAUtil
549: .getLocalizedString("optArgUID"),
550: PEAUtil.getLocalizedString("optUID")),
551: new CLIPParser.Option(OPT_PASSWORD, "w",
552: CLIPParser.REGULAR, (batchMode ? OPT_DEFAULT
553: : null), PEAUtil
554: .getLocalizedString("optArgPassword"),
555: PEAUtil.getLocalizedString("optPassword")),
556: new CLIPParser.Option(OPT_DN, "d", CLIPParser.REGULAR,
557: null, PEAUtil.getLocalizedString("optArgDN"),
558: PEAUtil.getLocalizedString("optDN")),
559: new CLIPParser.Option(OPT_PURL, "r",
560: CLIPParser.REGULAR, null, PEAUtil
561: .getLocalizedString("optArgPURL"),
562: PEAUtil.getLocalizedString("optPURL")),
563: new CLIPParser.Option(OPT_PNAME, "n",
564: CLIPParser.REGULAR, OPT_DEFAULT, PEAUtil
565: .getLocalizedString("optArgPName"),
566: PEAUtil.getLocalizedString("optPName")),
567: new CLIPParser.Option(OPT_REGHANDLE, "g",
568: CLIPParser.REGULAR, OPT_DEFAULT, PEAUtil
569: .getLocalizedString("optArgRegHandle"),
570: PEAUtil.getLocalizedString("optRegHandle")),
571: new CLIPParser.Option(OPT_VERBOSE, "b",
572: CLIPParser.BOOLEAN, "false", PEAUtil
573: .getLocalizedString("optVerbose")),
574: new CLIPParser.Option(OPT_VERSION, "V",
575: CLIPParser.BOOLEAN, "false", PEAUtil
576: .getLocalizedString("optVersion")),
577: new CLIPParser.Option(OPT_LOCALE, "l",
578: CLIPParser.REGULAR, LOCALE_DEFAULT, PEAUtil
579: .getLocalizedString("optArgLocale"),
580: PEAUtil.getLocalizedString("optLocale")),
581: new CLIPParser.Option(OPT_DRYRUN, "y",
582: CLIPParser.BOOLEAN, "false", PEAUtil
583: .getLocalizedString("optDryrun")) };
584:
585: CLIPParser.SubCommand scAdd = new CLIPParser.SubCommand(
586: SUBCMD_ADD, optsAdd, 0, 1, PEAUtil
587: .getLocalizedString("helpAdd"), "");
588:
589: CLIPParser.Option[] optsUpdate = {
590: new CLIPParser.Option(OPT_HELP, "?",
591: CLIPParser.BOOLEAN, "false", PEAUtil
592: .getLocalizedString("optHelp")),
593: new CLIPParser.Option(OPT_UID, "u", CLIPParser.REGULAR,
594: (batchMode ? OPT_DEFAULT : null), PEAUtil
595: .getLocalizedString("optArgUID"),
596: PEAUtil.getLocalizedString("optUID")),
597: new CLIPParser.Option(OPT_PASSWORD, "w",
598: CLIPParser.REGULAR, (batchMode ? OPT_DEFAULT
599: : null), PEAUtil
600: .getLocalizedString("optArgPassword"),
601: PEAUtil.getLocalizedString("optPassword")),
602: new CLIPParser.Option(OPT_DN, "d", CLIPParser.REGULAR,
603: null, PEAUtil.getLocalizedString("optArgDN"),
604: PEAUtil.getLocalizedString("optDN")),
605: new CLIPParser.Option(OPT_PID, "p", CLIPParser.REGULAR,
606: OPT_DEFAULT, PEAUtil
607: .getLocalizedString("optArgPID"),
608: PEAUtil.getLocalizedString("optPID")),
609: new CLIPParser.Option(OPT_TYPE, "t",
610: CLIPParser.REGULAR, null, PEAUtil
611: .getLocalizedString("optArgType"),
612: PEAUtil.getLocalizedString("optType")),
613: new CLIPParser.Option(OPT_VERBOSE, "b",
614: CLIPParser.BOOLEAN, "false", PEAUtil
615: .getLocalizedString("optVerbose")),
616: new CLIPParser.Option(OPT_VERSION, "V",
617: CLIPParser.BOOLEAN, "false", PEAUtil
618: .getLocalizedString("optVersion")),
619: new CLIPParser.Option(OPT_LOCALE, "l",
620: CLIPParser.REGULAR, LOCALE_DEFAULT, PEAUtil
621: .getLocalizedString("optArgLocale"),
622: PEAUtil.getLocalizedString("optLocale")) };
623:
624: CLIPParser.SubCommand scUpdate = new CLIPParser.SubCommand(
625: SUBCMD_UPDATE, optsUpdate, 0, 1, PEAUtil
626: .getLocalizedString("helpUpdate"), "");
627:
628: CLIPParser.Option[] optsRemove = {
629: new CLIPParser.Option(OPT_HELP, "?",
630: CLIPParser.BOOLEAN, "false", PEAUtil
631: .getLocalizedString("optHelp")),
632: new CLIPParser.Option(OPT_UID, "u", CLIPParser.REGULAR,
633: (batchMode ? OPT_DEFAULT : null), PEAUtil
634: .getLocalizedString("optArgUID"),
635: PEAUtil.getLocalizedString("optUID")),
636: new CLIPParser.Option(OPT_PASSWORD, "w",
637: CLIPParser.REGULAR, (batchMode ? OPT_DEFAULT
638: : null), PEAUtil
639: .getLocalizedString("optArgPassword"),
640: PEAUtil.getLocalizedString("optPassword")),
641: new CLIPParser.Option(OPT_DN, "d", CLIPParser.REGULAR,
642: null, PEAUtil.getLocalizedString("optArgDN"),
643: PEAUtil.getLocalizedString("optDN")),
644: new CLIPParser.Option(OPT_PID, "p", CLIPParser.REGULAR,
645: null, PEAUtil.getLocalizedString("optArgPID"),
646: PEAUtil.getLocalizedString("optPID")),
647: new CLIPParser.Option(OPT_VERBOSE, "b",
648: CLIPParser.BOOLEAN, "false", PEAUtil
649: .getLocalizedString("optVerbose")),
650: new CLIPParser.Option(OPT_VERSION, "V",
651: CLIPParser.BOOLEAN, "false", PEAUtil
652: .getLocalizedString("optVersion")),
653: new CLIPParser.Option(OPT_LOCALE, "l",
654: CLIPParser.REGULAR, LOCALE_DEFAULT, PEAUtil
655: .getLocalizedString("optArgLocale"),
656: PEAUtil.getLocalizedString("optLocale")) };
657:
658: CLIPParser.SubCommand scRemove = new CLIPParser.SubCommand(
659: SUBCMD_REMOVE, optsRemove, 0, 0, PEAUtil
660: .getLocalizedString("helpRemove"), "");
661:
662: CLIPParser.Option[] optsDeploy = {
663: new CLIPParser.Option(OPT_HELP, "?",
664: CLIPParser.BOOLEAN, "false", PEAUtil
665: .getLocalizedString("optHelp")),
666: new CLIPParser.Option(OPT_UID, "u", CLIPParser.REGULAR,
667: (batchMode ? OPT_DEFAULT : null), PEAUtil
668: .getLocalizedString("optArgUID"),
669: PEAUtil.getLocalizedString("optUID")),
670: new CLIPParser.Option(OPT_PASSWORD, "w",
671: CLIPParser.REGULAR, (batchMode ? OPT_DEFAULT
672: : null), PEAUtil
673: .getLocalizedString("optArgPassword"),
674: PEAUtil.getLocalizedString("optPassword")),
675: new CLIPParser.Option(OPT_DN, "d", CLIPParser.REGULAR,
676: null, PEAUtil.getLocalizedString("optArgDN"),
677: PEAUtil.getLocalizedString("optDN")),
678: new CLIPParser.Option(OPT_PID, "p", CLIPParser.REGULAR,
679: OPT_DEFAULT, PEAUtil
680: .getLocalizedString("optArgPID"),
681: PEAUtil.getLocalizedString("optPID")),
682: new CLIPParser.Option(OPT_RID, "o", CLIPParser.REGULAR,
683: OPT_DEFAULT, PEAUtil
684: .getLocalizedString("optArgRID"),
685: PEAUtil.getLocalizedString("optRID")),
686: new CLIPParser.Option(OPT_CHNAME, "n",
687: CLIPParser.REGULAR, OPT_DEFAULT, PEAUtil
688: .getLocalizedString("optArgChName"),
689: PEAUtil.getLocalizedString("optChName")),
690: new CLIPParser.Option(OPT_CONT, "c",
691: CLIPParser.BOOLEAN, "false", PEAUtil
692: .getLocalizedString("optCont")),
693: new CLIPParser.Option(OPT_VERBOSE, "b",
694: CLIPParser.BOOLEAN, "false", PEAUtil
695: .getLocalizedString("optVerbose")),
696: new CLIPParser.Option(OPT_VERSION, "V",
697: CLIPParser.BOOLEAN, "false", PEAUtil
698: .getLocalizedString("optVersion")),
699: new CLIPParser.Option(OPT_LOCALE, "l",
700: CLIPParser.REGULAR, LOCALE_DEFAULT, PEAUtil
701: .getLocalizedString("optArgLocale"),
702: PEAUtil.getLocalizedString("optLocale")),
703: new CLIPParser.Option(OPT_DRYRUN, "y",
704: CLIPParser.BOOLEAN, "false", PEAUtil
705: .getLocalizedString("optDryrun")) };
706:
707: CLIPParser.SubCommand scDeploy = new CLIPParser.SubCommand(
708: SUBCMD_DEPLOY, optsDeploy, 0, 0, PEAUtil
709: .getLocalizedString("helpDeploy"), "");
710:
711: if (!batchMode) {
712: CLIPParser.Option[] optsBatch = {
713: new CLIPParser.Option(OPT_HELP, "?",
714: CLIPParser.BOOLEAN, "false", PEAUtil
715: .getLocalizedString("optHelp")),
716: new CLIPParser.Option(OPT_UID, "u",
717: CLIPParser.REGULAR, OPT_DEFAULT, PEAUtil
718: .getLocalizedString("optArgUID"),
719: PEAUtil.getLocalizedString("optUID")),
720: new CLIPParser.Option(
721: OPT_PASSWORD,
722: "w",
723: CLIPParser.REGULAR,
724: OPT_DEFAULT,
725: PEAUtil
726: .getLocalizedString("optArgPassword"),
727: PEAUtil.getLocalizedString("optPassword")),
728: new CLIPParser.Option(OPT_CONT, "c",
729: CLIPParser.BOOLEAN, "false", PEAUtil
730: .getLocalizedString("optCont")),
731: new CLIPParser.Option(OPT_FILE, "f",
732: CLIPParser.REGULAR, null, PEAUtil
733: .getLocalizedString("optArgFile"),
734: PEAUtil.getLocalizedString("optFile")),
735: new CLIPParser.Option(OPT_VERBOSE, "b",
736: CLIPParser.BOOLEAN, "false", PEAUtil
737: .getLocalizedString("optVerbose")),
738: new CLIPParser.Option(OPT_VERSION, "V",
739: CLIPParser.BOOLEAN, "false", PEAUtil
740: .getLocalizedString("optVersion")),
741: new CLIPParser.Option(OPT_LOCALE, "l",
742: CLIPParser.REGULAR, LOCALE_DEFAULT,
743: PEAUtil.getLocalizedString("optArgLocale"),
744: PEAUtil.getLocalizedString("optLocale")) };
745: CLIPParser.SubCommand scBatch = new CLIPParser.SubCommand(
746: SUBCMD_BATCH, optsBatch, 0, 0, PEAUtil
747: .getLocalizedString("helpBatch"), "");
748:
749: //
750: // TBD: batch mode yet to be implemented
751: //
752: //CLIPParser.SubCommand[] sc =
753: // { scList, scAdd, scUpdate, scRemove, scDeploy, scBatch };
754: CLIPParser.SubCommand[] sc = { scList, scAdd, scUpdate,
755: scRemove, scDeploy };
756:
757: subCmds = sc;
758: } else {
759: // batch within batch not allowed
760: CLIPParser.SubCommand[] sc = { scList, scAdd, scRemove };
761: subCmds = sc;
762: }
763:
764: return new CLIPParser(PEAMain.COMMANDNAME, subCmds, PEAUtil
765: .getLocalizedString("helpCmd"));
766: }
767:
768: public static String getFileInput(String filename)
769: throws PEAException {
770:
771: String in = null;
772: if (filename != null) {
773: File f = new File(filename);
774: StringBuffer buf = new StringBuffer();
775: BufferedReader br = null;
776: try {
777: br = new BufferedReader(new FileReader(filename));
778: String line = null;
779: while ((line = br.readLine()) != null) {
780: buf.append(line + "\n");
781: }
782: } catch (IOException ioe) {
783: Object[] tokens = { filename };
784: throw new PEAException("errorFileRead", ioe, tokens);
785: } finally {
786: try {
787: br.close();
788: } catch (IOException ioe) {
789: Object[] tokens = { filename };
790: throw new PEAException("errorFileRead", ioe, tokens);
791: }
792: }
793: in = buf.toString();
794: }
795: return in;
796: }
797:
798: private String getVersionInfo() {
799: ResourceBundle prodRB = PropertyResourceBundle
800: .getBundle("PSversion");
801: StringBuffer vinfo = new StringBuffer();
802: vinfo.append(PEAMain.COMMANDNAME).append(" (").append(
803: prodRB.getString("productname")).append(" ").append(
804: prodRB.getString("productversion")).append(") ")
805: .append(PEAMain.COMMANDVERSION);
806: vinfo.append("\n").append(prodRB.getString("copyright"));
807: return vinfo.toString();
808: }
809: }
|