KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > internal > standalone > StandaloneInfocenter


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.help.internal.standalone;
12
13 import java.net.Authenticator JavaDoc;
14 import java.net.HttpURLConnection JavaDoc;
15 import java.net.PasswordAuthentication JavaDoc;
16 import java.util.List JavaDoc;
17
18 import org.eclipse.help.internal.base.*;
19
20 /**
21  * This program is used to start or stop Eclipse Infocenter application.
22  */

23 public class StandaloneInfocenter extends EclipseController {
24     // ID of the application to run
25
private static final String JavaDoc INFOCENTER_APPLICATION_ID = HelpBasePlugin.PLUGIN_ID
26             + ".infocenterApplication"; //$NON-NLS-1$
27

28     /**
29      * Constructs help system
30      *
31      * @param args
32      * array of String options and their values Option
33      * <code>-eclipseHome dir</code> specifies Eclipse installation
34      * directory. It must be provided, when current directory is not
35      * the same as Eclipse installation directory. Additionally, most
36      * options accepted by Eclipse execuable are supported.
37      */

38     public StandaloneInfocenter(String JavaDoc[] args) {
39         super(INFOCENTER_APPLICATION_ID, args);
40     }
41
42     /**
43      * @see org.eclipse.help.standalone.Infocenter#main(String[])
44      */

45     public static void main(String JavaDoc[] args) {
46         try {
47             StandaloneInfocenter infocenter = new StandaloneInfocenter(args);
48
49             List JavaDoc helpCommand = Options.getHelpCommand();
50
51             final String JavaDoc adminId = Options.getAdminId();
52             final String JavaDoc adminPassword = Options.getAdminPassword();
53             Authenticator.setDefault(new Authenticator JavaDoc() {
54                 protected PasswordAuthentication JavaDoc getPasswordAuthentication() {
55                     return new PasswordAuthentication JavaDoc(adminId, adminPassword.toCharArray());
56                 }
57             });
58             HttpURLConnection.setFollowRedirects(true);
59             
60             if (infocenter.executeCommand(helpCommand)) {
61                 return;
62             }
63             printMainUsage();
64         } catch (Exception JavaDoc e) {
65             e.printStackTrace();
66         }
67     }
68
69     /**
70      * @return true if commands contained a known command and it was executed
71      */

72     private boolean executeCommand(List JavaDoc helpCommand) throws Exception JavaDoc {
73         if (helpCommand.size() <= 0) {
74             return false;
75         }
76         String JavaDoc command = (String JavaDoc) helpCommand.get(0);
77         if ("start".equalsIgnoreCase(command)) { //$NON-NLS-1$
78
start();
79             return true;
80         } else if ("shutdown".equalsIgnoreCase(command)) { //$NON-NLS-1$
81
shutdown();
82             return true;
83         } else if (CMD_INSTALL.equalsIgnoreCase(command)
84                 || CMD_ENABLE.equalsIgnoreCase(command)
85                 || CMD_DISABLE.equalsIgnoreCase(command)
86                 || CMD_UNINSTALL.equalsIgnoreCase(command)
87                 || CMD_UPDATE.equalsIgnoreCase(command)
88                 || CMD_SEARCH.equalsIgnoreCase(command)
89                 || CMD_LIST.equalsIgnoreCase(command)
90                 || CMD_ADDSITE.equalsIgnoreCase(command)
91                 || CMD_REMOVESITE.equalsIgnoreCase(command)
92                 || CMD_APPLY.equalsIgnoreCase(command)) {
93             return executeUpdateCommand(command);
94         }
95         return false;
96     }
97
98     /**
99      * Prints usage of this class as a program.
100      */

101     private static void printMainUsage() {
102         System.out.println("Parameters syntax:"); //$NON-NLS-1$
103
System.out.println();
104         System.out
105                 .println("-command start | shutdown | [update command [update parameters]] [-eclipsehome eclipseInstallPath] [-host helpServerHost] [-port helpServerPort] [-adminId administratorUserId] [-adminPassword administratorPassword] [-trustStoreLocation trustStoreLocation] [-trustStorePassword trustStorePassword][-noexec] [platform options] [-vmargs [Java VM arguments]]"); //$NON-NLS-1$
106
System.out.println();
107         System.out.println("where:"); //$NON-NLS-1$
108
System.out
109                 .println(" eclipseInstallPath specifies Eclipse installation directory; this directory is a parent to \"plugins\" directory and eclipse executable; the option must be provided, when current directory from which infocenter is launched, is not the same as Eclipse installation directory,"); //$NON-NLS-1$
110
System.out
111                 .println(" helpServerHost specifies host name of the interface that help server will use,"); //$NON-NLS-1$
112
System.out
113                 .println(" helpServerPort specifies port number that help server will use,"); //$NON-NLS-1$
114
System.out
115                 .println(" administratorUserId specifies the administrator user id to use when secure access is enabled"); //$NON-NLS-1$
116
System.out
117                 .println(" administratorPassword specifies the administrator password to use when secure access is enabled"); //$NON-NLS-1$
118
System.out
119                 .println(" trustStoreLocation specifies the location of the truststore file to use when secure access is enabled"); //$NON-NLS-1$
120
System.out
121                 .println(" trustStorePassword specifies the password of the truststore file when secure access is enabled"); //$NON-NLS-1$
122
System.out
123                 .println(" noexec option indicates that Eclipse executable should not be used, "); //$NON-NLS-1$
124
System.out
125                 .println(" platform options are other options that are supported by Eclipse Executable,"); //$NON-NLS-1$
126
System.out
127                 .println(" update command is one of install, update, enable, disable, uninstall, search, listFeatures, addSite, removeSite, or apply,"); //$NON-NLS-1$
128
System.out
129                 .println(" update parameters are -featureId, -version, -from, -to, -verifyOnly as required by update commands used."); //$NON-NLS-1$
130
}
131
132 }
133
Popular Tags