KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.List JavaDoc;
14
15 import org.eclipse.help.internal.base.*;
16
17 /**
18  * This is a standalone help system. It takes care of launching the eclipse with
19  * its help system implementation, and controling it. This class can be used
20  * instantiated and used in a Java program, or can be launched from command line
21  * to execute single help action.
22  *
23  * Usage as a Java component:
24  * <ul>
25  * <li>create an instantance of this class and then hold onto this instance for
26  * the duration of your application</li>
27  * <li>call start()</li>
28  * <li>call displayHelp(...) or displayContext(..) any number of times</li>
29  * <li>at the end, call shutdown().</li>
30  * </ul>
31  */

32 public class StandaloneHelp extends EclipseController {
33     // ID of the application to run
34
private static final String JavaDoc HELP_APPLICATION_ID = HelpBasePlugin.PLUGIN_ID
35             + ".helpApplication"; //$NON-NLS-1$
36

37     /**
38      * Constructs help system
39      *
40      * @param args
41      * array of String options and their values Option
42      * <code>-eclipseHome dir</code> specifies Eclipse installation
43      * directory. It must be provided, when current directory is not
44      * the same as Eclipse installation directory. Additionally, most
45      * options accepted by Eclipse execuable are supported.
46      */

47     public StandaloneHelp(String JavaDoc[] args) {
48         super(HELP_APPLICATION_ID, args);
49     }
50
51     /**
52      * @see org.eclipse.help.standalone.Infocenter#main(String[])
53      */

54     public static void main(String JavaDoc[] args) {
55         try {
56             StandaloneHelp help = new StandaloneHelp(args);
57
58             List JavaDoc helpCommand = Options.getHelpCommand();
59
60             if (help.executeCommand(helpCommand)) {
61                 return;
62             }
63             printMainUsage();
64         } catch (Exception JavaDoc e) {
65             e.printStackTrace();
66         }
67     }
68
69     /**
70      * @see org.eclipse.help.standalone.Help#displayContext(java.lang.String,int,int)
71      */

72     public void displayContext(String JavaDoc contextId, int x, int y) {
73     }
74
75     /**
76      * @see org.eclipse.help.standalone.Help#displayContextInfopop(java.lang.String,int,int)
77      */

78     public void displayContextInfopop(String JavaDoc contextId, int x, int y) {
79     }
80
81     /**
82      * @see org.eclipse.help.standalone.Help#displayHelp()
83      */

84     public void displayHelp() throws Exception JavaDoc {
85         sendHelpCommand("displayHelp", new String JavaDoc[0]); //$NON-NLS-1$
86
}
87
88     /**
89      * @see org.eclipse.help.standalone.Help#displayHelp(java.lang.String)
90      */

91     public void displayHelp(String JavaDoc href) throws Exception JavaDoc {
92         sendHelpCommand("displayHelp", new String JavaDoc[]{"href=" + href}); //$NON-NLS-1$ //$NON-NLS-2$
93
}
94
95     /**
96      * @return true if commands contained a known command and it was executed
97      */

98     private boolean executeCommand(List JavaDoc helpCommands) throws Exception JavaDoc {
99
100         if (helpCommands.size() <= 0) {
101             return false;
102         }
103         String JavaDoc command = (String JavaDoc) helpCommands.get(0);
104
105         if ("start".equalsIgnoreCase(command)) { //$NON-NLS-1$
106
start();
107             return true;
108         } else if ("shutdown".equalsIgnoreCase(command)) { //$NON-NLS-1$
109
shutdown();
110             return true;
111         } else if ("displayHelp".equalsIgnoreCase(command)) { //$NON-NLS-1$
112
if (helpCommands.size() >= 2) {
113                 displayHelp((String JavaDoc) helpCommands.get(1));
114             } else {
115                 displayHelp();
116             }
117             return true;
118         } else if (CMD_INSTALL.equalsIgnoreCase(command)
119                 || CMD_ENABLE.equalsIgnoreCase(command)
120                 || CMD_DISABLE.equalsIgnoreCase(command)
121                 || CMD_UNINSTALL.equalsIgnoreCase(command)
122                 || CMD_UPDATE.equalsIgnoreCase(command)
123                 || CMD_SEARCH.equalsIgnoreCase(command)
124                 || CMD_LIST.equalsIgnoreCase(command)
125                 || CMD_ADDSITE.equalsIgnoreCase(command)
126                 || CMD_REMOVESITE.equalsIgnoreCase(command)
127                 || CMD_APPLY.equalsIgnoreCase(command)) {
128             return executeUpdateCommand(command);
129         } else if ("displayContext".equalsIgnoreCase(command)) { //$NON-NLS-1$
130
if (helpCommands.size() >= 4) {
131                 displayContext((String JavaDoc) helpCommands.get(1), Integer
132                         .parseInt((String JavaDoc) helpCommands.get(2)), Integer
133                         .parseInt((String JavaDoc) helpCommands.get(3)));
134
135                 return true;
136             }
137         } else if ("displayContextInfopop".equalsIgnoreCase(command)) { //$NON-NLS-1$
138
if (helpCommands.size() >= 4) {
139                 displayContextInfopop((String JavaDoc) helpCommands.get(1), Integer
140                         .parseInt((String JavaDoc) helpCommands.get(2)), Integer
141                         .parseInt((String JavaDoc) helpCommands.get(3)));
142                 return true;
143             }
144         }
145
146         return false;
147     }
148
149     /**
150      * Prints usage of this class as a program.
151      */

152     private static void printMainUsage() {
153         System.out.println("Parameters syntax:"); //$NON-NLS-1$
154
System.out.println();
155         System.out
156                 .println("-command start | shutdown | (displayHelp [href]) [-eclipsehome eclipseInstallPath] [-host helpServerHost] [-port helpServerPort] [platform options] [-vmargs [Java VM arguments]]"); //$NON-NLS-1$
157
System.out.println();
158         System.out.println("where:"); //$NON-NLS-1$
159
System.out.println(" href is the URL of the help resource to display,"); //$NON-NLS-1$
160
System.out
161                 .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$
162
System.out
163                 .println(" helpServerHost specifies host name of the interface that help server will use,"); //$NON-NLS-1$
164
System.out
165                 .println(" helpServerPort specifies port number that help server will use,"); //$NON-NLS-1$
166
System.out
167                 .println(" platform options are other options that are supported by Eclipse Executable."); //$NON-NLS-1$
168
}
169 }
170
Popular Tags