*/
public static void main(String args[])
{
String arg;
Engine engine = null;
int i = 0;
// Read the command line
String strWebAppDir = "";
String strAction = "";
String strWarFileName = "";
String strPortletAppName = "";
String strPortalName = "jetspeed";
String applicationType = "webapp";
String strUserName = "";
String strPassword = "";
String strServer = "localhost";
String className = "org.apache.jetspeed.tools.pamanager.FileSystemPAM"; // default
Deployment deployer = null;
Registration registrator = null;
Lifecycle lifecycle = null;
int intServerPort = 8080;
String jetspeedPropertiesFile = System.getProperty("pam.jetspeed.properties", "/WEB-INF/conf/jetspeed.properties");
String appsDirectory = System.getProperty("pam.apps.directory", "/WEB-INF/apps/");
while (i < args.length && args[i].startsWith("-"))
{
arg = args[i++];
// use this type of check for arguments that require arguments
if (arg.equalsIgnoreCase("-PortletAppName"))
{
if (i < args.length)
strPortletAppName = args[i++];
}
else if (arg.equalsIgnoreCase("-Impl"))
{
if (i < args.length)
className = args[i++];
}
else if (arg.equalsIgnoreCase("-Action"))
{
if (i < args.length)
strAction = args[i++];
}
else if (arg.equalsIgnoreCase("-WebAppDir"))
{
if (i < args.length)
strWebAppDir = args[i++];
}
else if (arg.equalsIgnoreCase("-WarFileName"))
{
if (i < args.length)
strWarFileName = args[i++];
}
else if (arg.equalsIgnoreCase("-PortalName"))
{
if (i < args.length)
strPortalName = args[i++];
}
else if (arg.equalsIgnoreCase("-UserName"))
{
if (i < args.length)
strUserName = args[i++];
}
else if (arg.equalsIgnoreCase("-Password"))
{
if (i < args.length)
strPassword = args[i++];
}
else if (arg.equalsIgnoreCase("-Server"))
{
if (i < args.length)
strServer= args[i++];
}
else if (arg.equalsIgnoreCase("-ServerPort"))
{
if (i < args.length)
intServerPort = Integer.parseInt(args[i++]);
}
else if (arg.equalsIgnoreCase("-ApplicationType"))
{
if (i < args.length)
{
applicationType = args[i++];
}
}
else if (arg.equalsIgnoreCase("-h"))
{
helpScreen();
return;
}
else if (arg.equalsIgnoreCase("-?"))
{
helpScreen();
return;
}
}
// Portlet Application Name and action are required by all functions.
// Make sure that the values were defined from the command line.
if (strPortletAppName.length() == 0 || strAction.length() == 0)
{
System.out.println(
"\nPortlet Application Name and/or action are not defined."
+ "Please use '-PortletAppName appName' and/or '-Action deploy' from the command line\n");
helpScreen();
log.error("PAM Error: Invalid parameter(s) passed, cannot process PAM request.");
if (!log.isInfoEnabled())
{
logRequest(args, true);
}
return;
}
String strAppRoot = strWebAppDir + strPortalName;
try
{
// Start the registry service -- it's needed by many actions
Configuration properties =
(Configuration) new PropertiesConfiguration(strAppRoot + jetspeedPropertiesFile);
properties.setProperty(APPLICATION_ROOT_KEY, strAppRoot);
// Override the properties with PAM specifice settings
overrideProperties(strAppRoot, properties);
engine = Jetspeed.createEngine(properties, strAppRoot, null, SpringEngine.class);
}
catch (Exception e)
{
String msg = "PAM Error: Failed to create the Jetspeed Engine. Error: ";
System.out.println(msg + e.getMessage());
log.error(msg, e);
shutdownAndExit(engine);
}
logRequest(args, false);
try
{
System.out.println("Ready to run PAM implementation: " + className);
System.out.print("Supporting interfaces: Deployment");
// Class clas = Class.forName(className);
PortletRegistry portletRegistry = (PortletRegistry) engine.getComponentManager()
.getComponent(PortletRegistry.class);
deployer = (Deployment) engine.getComponentManager().getComponent("PAM");
if (deployer instanceof Registration)
{
System.out.print(", Registration");
registrator = (Registration)deployer;
}
if (deployer instanceof Lifecycle)
{
System.out.print(", Lifecycle");
lifecycle = (Lifecycle)deployer;
}
System.out.println();
}
catch (Exception e)
{
String msg = "PAM Error: Failed to create PAM implementation class object: " + className + " Error: ";
System.out.println(msg + e.getMessage());
log.error(msg, e);
shutdownAndExit(engine);
}
try
{
// Invoke the functions
if (strAction.compareToIgnoreCase("deploy") == 0)
{
// Make sure that the WarFileName and the ApplicationServer are defined
if (strWarFileName.length() == 0)
{
System.out.println(
"\nDeploy action requires the war file name. Use '-WarFileName file.war' to specify the file name");
log.error("PAM Error: Web application (WAR) file name not specified.");
shutdownAndExit(engine);
}
else
{
if (applicationType.equals("local"))
{
String portletAppRoot = strAppRoot + appsDirectory;
deploy(deployer, portletAppRoot, strWarFileName, strPortletAppName); // [RUN]
}
else
{
// Requires WebAppDir
if (strWebAppDir.length() == 0)
{
System.out.println(
"\nDeploy action requires the definition of the ApplicationServer or the Web application directory.");
log.error("PAM Deploy Error: Web application (WAR) directory name not specified.");
shutdownAndExit(engine);
}
// File deploy uses Directory and warfile
deploy(deployer, strWebAppDir, strWarFileName, strPortletAppName); // [RUN]
}
}
}
else if (strAction.compareToIgnoreCase("register") == 0)
{
// Requires WebAppDir
if (strWebAppDir.length() == 0)
{
System.out.println("\nRegister action requires the definition of the Web application directory.");
log.error("PAM Register Error: Web application (WAR) directory name not specified.");
shutdownAndExit(engine);
}
if (null == registrator)
{
String msg = "PAM Register Error: Registration interface not supported by implementation: " + className;
System.out.println("\n" + msg);
log.error(msg);
shutdownAndExit(engine);
}
register(registrator, strPortletAppName, strWarFileName); // [RUN]
}
else if (strAction.compareToIgnoreCase("unregister") == 0)
{
if (null == registrator)
{
String msg = "PAM Register Error: Registration interface not supported by implementation: " + className;
System.out.println("\n" + msg);
log.error(msg);
shutdownAndExit(engine);
}
// Application server can be null -- using Catalina as default
unregister(registrator, strPortletAppName); // [RUN]
}
else if (strAction.compareToIgnoreCase("undeploy") == 0)
{
undeploy(deployer, strWebAppDir, strPortletAppName, strServer, intServerPort, strUserName, strPassword); // [RUN]
}
else if (strAction.compareToIgnoreCase("start") == 0)
{
if (null == lifecycle)
{
String msg = "PAM Lifecycle Error: Lifecycle interface not supported by implementation: " + className;
System.out.println("\n" + msg);
log.error(msg);
shutdownAndExit(engine);
}
start(lifecycle, strPortletAppName, strServer, intServerPort, strUserName, strPassword); // [RUN]
}
else if (strAction.compareToIgnoreCase("stop") == 0)
{
stop(lifecycle, strPortletAppName, strServer, intServerPort, strUserName, strPassword); // [RUN]
}
else if (strAction.compareToIgnoreCase("reload") == 0)
{
if (null == lifecycle)
{
String msg = "PAM Lifecycle Error: Lifecycle interface not supported by implementation: " + className;
System.out.println("\n" + msg);
log.error(msg);
shutdownAndExit(engine);
}
// Application server can be null -- using Catalina as default
reload(lifecycle, strPortletAppName, strServer, intServerPort, strUserName, strPassword); // [RUN]
}
else
{
System.out.println("\nAction: " + strAction + " not recognized by the PortletApplicationManager.");
helpScreen();
}
}
catch (Exception e)
{
String msg = "PAM Error: Failed during execution of " + strAction + ", error = " + e.getMessage();
System.out.println(msg);
log.error(msg);
shutdownAndExit(engine);
}
try
{
if (engine != null)
{
engine.shutdown();
}
}
catch (JetspeedException e1)
{
System.out.println("Failed shutting down the engine. Error: " + e1.getMessage());