/*
* JFolder, Copyright 2001-2006 Gary Steinmetz
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jfolder.project.lifecycle;
//base classes
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
//project specific classes
import org.jfolder.common.UnexpectedSystemException;
import org.jfolder.common.utils.misc.MiscHelper;
import org.jfolder.services.config.ConfigServiceCaller;
import org.jfolder.services.config.ConfigServiceCallerFactory;
//other classes
/*public class GenericWeblogicFileProjectApplicationLifecycle
implements ProjectApplicationLifecycle {
private final static String INIT_JSP =
"<%\n"
+ " org.jfolder.workflow.web.client.SimpleWebClient client =\n"
+ " (org.jfolder.workflow.web.client.SimpleWebClient)"
+ "request.getAttribute(\"client\");\n"
+ " client.setPageContext(pageContext);\n"
+ " String goTo = \"/\" + client.getDestination() + \".jsp\";\n"
//+ " MiscHelper.println(\"Ab cd = \"
//+ client.getDestination());"
//+ " MiscHelper.println(\"About to dispatch to \" + goTo);"
+ "%>\n"
+ "<jsp:include page=\"<%= goTo%>\"/>\n";
//+ "<%\n"
//+ " MiscHelper.println(\"About to dispatch to \" + goTo);"
//+ "%>\n";
//private final static String INIT_JSP =
// "<%\n"
// + " SimpleWebClient client =\n"
// + " SimpleWebClient.newSimpleWebClient(pageContext);\n"
// + " request.setAttribute(\"client\", client);\n"
// + "%>\n"
// + "<jsp:include page=\"%= (\"/WEB-INF/jsps/apps/\""
// + " + inRequest.getServletPath() + \".jsp\")%\"/>"
// + "<%\n"
// + " client.saveChanges();\n"
// + "%>\n";
public void undeployApplication(String inContext) {
ConfigManager cm = ConfigManagerFactory.getConfigManager();
String deployLocation = cm.getMandatoryPropertyAttribute(
ConfigManagerPaths.XPATH_BASE_LOCATIONS, "deploy");
File finalDeployDir = new File(deployLocation);
File earFile = new File(finalDeployDir, inContext + ".ear");
earFile.delete();
cm.close();
}
public void deployApplication(ProjectApplication inApplication,
String inContextPath) {
ConfigManager cm = ConfigManagerFactory.getConfigManager();
String deployLocation = cm.getMandatoryPropertyAttribute(
ConfigManagerPaths.XPATH_BASE_LOCATIONS, "deploy");
File finalDeployDir = new File(deployLocation);
File pfDir = getJFolderDirectory(cm);
//MiscHelper.println("pfDir: " + pfDir.getAbsolutePath());
File assembleDir = new File(pfDir, "assemble");
//make assembly directory, but make sure it is empty
if (!assembleDir.exists()) {
assembleDir.mkdirs();
}
MiscHelper.deleteFileOrDirectory(assembleDir);
if (!assembleDir.exists()) {
assembleDir.mkdirs();
}
//create WEB-INF directory
File webInfDir = new File(assembleDir, "WEB-INF");
if (!webInfDir.exists()) {
webInfDir.mkdirs();
}
//create jsps directory
File jspsDir = new File(webInfDir, "jsps");
if (!jspsDir.exists()) {
jspsDir.mkdirs();
}
//create apps jsps directory
File appsJspsDir = new File(jspsDir, "apps");
if (!appsJspsDir.exists()) {
appsJspsDir.mkdirs();
}
//create core jsps directory
File coreJspsDir = new File(jspsDir, "core");
if (!coreJspsDir.exists()) {
coreJspsDir.mkdirs();
}
//create parent.jsp file
//File parentJspDir = new File(coreJspsDir,"parent.jsp");
File parentJspDir = new File(assembleDir,"parent.jsp");
MiscHelper.writeTextFile(parentJspDir, INIT_JSP);
//copy jsp pages
for (int i = 0; i < inApplication.getWebPageCount(); i++) {
ProjectWebPage wwp = inApplication.getWebPage(i);
String content = wwp.getContent();
//File wwpFile = new File(appsJspsDir, wwp.getName() + ".jsp");
File wwpFile = new File(assembleDir, wwp.getName() + ".jsp");
//MiscHelper.println("pfDir: " + wwpFile.getAbsolutePath());
MiscHelper.writeTextFile(wwpFile, content);
}
//copy web content
for (int i = 0; i < inApplication.getWebFileCount(); i++) {
ProjectWebFile wwf = inApplication.getWebFile(i);
byte content[] = wwf.getContent();
File wwfFile = new File(assembleDir, wwf.getName());
MiscHelper.writeBinaryFile(wwfFile, content);
}
String descriptor = getDeploymentDescriptor(inApplication);
File webFile = new File(webInfDir, "web.xml");
MiscHelper.writeTextFile(webFile, descriptor);
String weblogicWebDescriptor = getWeblogicDeploymentDescriptor();
File weblogicWebFile = new File(webInfDir, "weblogic.xml");
MiscHelper.writeTextFile(weblogicWebFile, weblogicWebDescriptor);
//copy lib file
//create lib directory
File libDir = new File(webInfDir, "lib");
if (!libDir.exists()) {
libDir.mkdirs();
}
File destJfolderJarFile = new File(libDir, "jfolder.jar");
File sourceLibDir = new File(pfDir, "lib");
if (!sourceLibDir.exists()) {
sourceLibDir.mkdirs();
}
File sourceJfolderJarFile =
new File(sourceLibDir, "jfolder.jar");
MiscHelper.writeBinaryFile(destJfolderJarFile,
MiscHelper.readBinaryFile(sourceJfolderJarFile));
//assemble war file
File deployDir = new File(pfDir, "deploy");
//make assembly directory, but make sure it is empty
if (!deployDir.exists()) {
deployDir.mkdirs();
}
MiscHelper.deleteFileOrDirectory(deployDir);
if (!deployDir.exists()) {
deployDir.mkdirs();
}
File warFile = new File(deployDir, "deploy.war");
createWarFile(assembleDir, warFile);
//create META-INF directory
File metaInfDir = new File(deployDir, "META-INF");
if (!metaInfDir.exists()) {
metaInfDir.mkdirs();
}
String earDescriptor = getAppDeploymentDescriptor(inContextPath);
File earFile = new File(metaInfDir, "application.xml");
MiscHelper.writeTextFile(earFile, earDescriptor);
File finalEarFile = new File(finalDeployDir, inContextPath + ".ear");
createWarFile(deployDir, finalEarFile);
cm.close();
}
private final static void createWarFile(File inSource, File inDest) {
try {
FileOutputStream fos = new FileOutputStream(inDest);
MiscHelper.zipDirectory(inSource, fos);
fos.flush();
fos.close();
}
catch (IOException ioe) {
throw new UnexpectedSystemException(ioe);
}
}
private final static String getDeploymentDescriptor(
ProjectApplication inApplication) {
final String START = "<!DOCTYPE web-app\n"
+ " PUBLIC \"-//Sun Microsystems, Inc."
+ "//DTD Web Application 2.3//EN\"\n"
+ " \"http://java.sun.com/dtd/web-app_2_3.dtd\">\n"
+ "\n"
+ "<web-app>\n";
final String END = " <ejb-ref>\n"
+ " <ejb-ref-name>ejb/jfolder/WorkflowLifecycle"
+ "</ejb-ref-name>\n"
+ " <ejb-ref-type>Session</ejb-ref-type>\n"
+ " <home>org.jfolder.workflow.lifecycle."
+ "WorkflowLifecycleHome</home>\n"
+ " <remote>org.jfolder.workflow.lifecycle."
+ "WorkflowLifecycleRemote</remote>\n"
+ " </ejb-ref>\n"
+ " <ejb-ref>\n"
+ " <ejb-ref-name>ejb/jfolder/ConfigManager"
+ "</ejb-ref-name>\n"
+ " <ejb-ref-type>Entity</ejb-ref-type>\n"
+ " <home>org.jfolder.workflow.config."
+ "ConfigManagerHome</home>\n"
+ " <remote>org.jfolder.workflow.config."
+ "ConfigManagerRemote</remote>\n"
+ " </ejb-ref>\n"
+ "</web-app>\n";
StringBuffer outValue = new StringBuffer();
outValue.append(START);
outValue.append(" <servlet>\n");
outValue.append(" <servlet-name>\n");
outValue.append(" BaseClientServlet\n");
outValue.append(" </servlet-name>\n");
//outValue.append(" <jsp-file>\n");
//outValue.append(" /WEB-INF/jsps/core/parent.jsp\n");
//outValue.append(" </jsp-file>\n");
outValue.append(" <servlet-class>\n");
outValue.append(
" org.jfolder.workflow.web.client.BaseClientServlet\n");
outValue.append(" </servlet-class>\n");
outValue.append(" </servlet>\n");
outValue.append(" <servlet-mapping>\n");
outValue.append(" <servlet-name>\n");
outValue.append(" BaseClientServlet\n");
outValue.append(" </servlet-name>\n");
outValue.append(" <url-pattern>/</url-pattern>\n");
outValue.append(" </servlet-mapping>\n");
//previous mappings
//for (int i = 0; i < inApplication.getWebPageCount(); i++) {
// WorkflowWebPage wwp = inApplication.getWebPage(i);
// String webPageName = wwp.getName();
// outValue.append(" <servlet>\n");
// outValue.append(" <servlet-name>\n");
// outValue.append(" " + webPageName + "\n");
// outValue.append(" </servlet-name>\n");
// outValue.append(" <jsp-file>\n");
// outValue.append(" /WEB-INF/jsps/"
// + (webPageName + ".jsp") + "\n");
// outValue.append(" </jsp-file>\n");
// outValue.append(" </servlet>\n");
//}
//for (int i = 0; i < inApplication.getWebPageCount(); i++) {
// WorkflowWebPage wwp = inApplication.getWebPage(i);
// String webPageName = wwp.getName();
// outValue.append(" <servlet-mapping>\n");
// outValue.append(" <servlet-name>\n");
// outValue.append(" " + webPageName + "\n");
// outValue.append(" </servlet-name>\n");
// outValue.append(" <url-pattern>\n");
// outValue.append(" /" + webPageName + "\n");
// outValue.append(" </url-pattern>\n");
// outValue.append(" </servlet-mapping>\n");
//}
outValue.append(END);
return outValue.toString();
}
private final static String getWeblogicDeploymentDescriptor() {
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<!DOCTYPE weblogic-web-app\n"
+ " PUBLIC \"-//BEA Systems, Inc.//DTD Web Application 7.0//EN\"\n"
+ " \"http://www.bea.com/servers/wls700/dtd/weblogic700-web-jar.dtd\">\n"
+ "\n"
+ "<weblogic-web-app>\n"
+ "<reference-descriptor>\n"
+ "<ejb-reference-description>\n"
+ " <ejb-ref-name>ejb/jfolder/WorkflowLifecycle</ejb-ref-name>\n"
+ " <jndi-name>jfolder/WorkflowLifecycle</jndi-name>\n"
+ "</ejb-reference-description>\n"
+ "\n"
+ "<ejb-reference-description>\n"
+ "<ejb-ref-name>ejb/jfolder/ConfigManager</ejb-ref-name>\n"
+ "<jndi-name>jfolder/ConfigManager</jndi-name>\n"
+ "</ejb-reference-description>\n"
+ "</reference-descriptor>\n"
+ "</weblogic-web-app>\n";
}
private final static String getAppDeploymentDescriptor(
String inContextPath) {
StringBuffer outValue = new StringBuffer();
outValue.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
outValue.append("<!DOCTYPE application\n");
outValue.append(" PUBLIC '-//Sun Microsystems, Inc."
+ "//DTD J2EE Application 1.3//EN' \n");
outValue.append(" 'http://java.sun.com/dtd/application_1_3.dtd'>\n");
outValue.append("\n");
outValue.append("<application>\n");
outValue.append(" <display-name>" + inContextPath
+ "</display-name>\n");
outValue.append(" <description>" + inContextPath
+ "</description>\n");
outValue.append("\n");
outValue.append(" <module>\n");
outValue.append(" <web>\n");
outValue.append(" <web-uri>deploy.war</web-uri>\n");
outValue.append(" <context-root>" + inContextPath
+ "</context-root>\n");
outValue.append(" </web>\n");
outValue.append(" </module>\n");
outValue.append("</application>\n");
return outValue.toString();
}
//TO DO: this is duplicated in GenericFileWorkflowApplicationSet
protected final static File getJFolderDirectory(ConfigManager inCm) {
File outValue = null;
//ConfigManager cm = ConfigManagerFactory.getConfigManager();
String baseDirName = inCm.getMandatoryPropertyAttribute(
ConfigManagerPaths.XPATH_BASE_LOCATIONS, "base");
String pfDirName = inCm.getMandatoryPropertyAttribute(
ConfigManagerPaths.XPATH_BASE_LOCATIONS, "pf");
File baseDir = new File(baseDirName);
outValue = new File(baseDir, pfDirName);
if (!outValue.exists()) {
outValue.mkdirs();
}
//cm.close();
return outValue;
}
}*/
|