/*
* 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;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
//project specific classes
import org.jfolder.common.UnexpectedSystemException;
import org.jfolder.common.tagging.ConceptTagPreferences;
import org.jfolder.common.tagging.ConceptTagProperties;
import org.jfolder.common.tagging.ConceptTagSetHolder;
import org.jfolder.common.utils.misc.MiscHelper;
import org.jfolder.common.utils.xml.LinearXPath;
import org.jfolder.config.instance.ConfigInstance;
import org.jfolder.config.instance.ConfigInstanceConfig;
import org.jfolder.services.config.ConfigService;
import org.jfolder.services.config.ConfigServiceCaller;
import org.jfolder.services.config.ConfigServiceCallerFactory;
//other classes
/*public class GenericJbossFileProjectLifecycle implements ProjectLifecycle {
//TO DO: this is duplicated in GenericFileWorkflowApplicationSet
private final static LinearXPath XPATH_LOCATIONS =
LinearXPath.r("locations");
public void undeployApplication(String inContext) {
ConfigService cs = ConfigServiceCallerFactory.getConfigService();
//ConfigLifecycle cm = ConfigLifecycleFactory.getConfigLifecycle();
ConfigInstanceConfig cic = cs.accessConfig(ConfigInstance.LOCATION);
String deployLocation = cic.getMandatoryPropertyAttribute(
ConfigInstance.STANDARD_CONTENT, XPATH_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, ConceptTagSetHolder inWebCtsh,
ConceptTagPreferences inCtp) {
ConfigService cs = ConfigServiceCallerFactory.getConfigService();
//ConfigLifecycle cm = ConfigLifecycleFactory.getConfigLifecycle();
ConfigInstanceConfig cic = cs.accessConfig(ConfigInstance.LOCATION);
//determine entries for 'compound' and 'static' types
//
String staticNamespace = inCtp.getStaticNamespace();
String staticName = inCtp.getStaticName();
//String staticClass = BaseStaticWebTag.class.getName();
String staticClass = "org.jfolder.web.page.BaseStaticWebTag";
String compoundNamespace = inCtp.getCompoundNamespace();
String compoundName = inCtp.getCompoundName();
//String compoundClass = BaseCompoundWebTag.class.getName();
String compoundClass = "org.jfolder.web.page.BaseCompoundWebTag";
boolean sameStaticCompoundNamespace =
staticNamespace.equals(compoundNamespace);
//
//ArrayList staticNameList = new ArrayList();
//ArrayList compoundNameList = new ArrayList();
HashMap staticNameAndClass = new HashMap();
HashMap compoundNameAndClass = new HashMap();
//
if (!sameStaticCompoundNamespace) {
//staticNameList.add(staticName);
//compoundNameList.add(compoundName);
staticNameAndClass.put(staticName, staticClass);
compoundNameAndClass.put(compoundName, compoundClass);
}
else {
//staticNameList.add(staticName);
//staticNameList.add(compoundName);
staticNameAndClass.put(staticName, staticClass);
staticNameAndClass.put(compoundName, compoundClass);
}
//
//
ArrayList webTagNamespaces = inWebCtsh.getRegisteredNameSpaces();
HashMap webTagLibs = new HashMap();
for (int i = 0; i < webTagNamespaces.size(); i++) {
String nextWebTagNamespace = (String)webTagNamespaces.get(i);
ArrayList nextWebTagNames =
inWebCtsh.getRegisteredNames(nextWebTagNamespace);
ArrayList nextAvailableWebTagNames = new ArrayList();
for (int j = 0; j < nextWebTagNames.size(); j++) {
String nextWebTagName = (String)nextWebTagNames.get(j);
String nextWebTagClass = inWebCtsh.getConceptTagClass(
nextWebTagNamespace, nextWebTagName).getName();
//MiscHelper.println("apps.GenJbProApp = " + nextWebTagClass);
//MiscHelper.println("isStudioOnly = "
// + inWebCtsh.isStudioOnly(nextWebTagClass));
ConceptTagProperties nextWebTagProps =
inWebCtsh.getConceptTagProperties(nextWebTagClass);
if (!nextWebTagProps.isActsAsText()) {
nextAvailableWebTagNames.add(nextWebTagName);
}
}
if (nextAvailableWebTagNames.size() > 0) {
webTagLibs.put(nextWebTagNamespace, nextAvailableWebTagNames);
}
}
String deployLocation = cic.getMandatoryPropertyAttribute(
ConfigInstance.STANDARD_CONTENT, XPATH_LOCATIONS, "deploy");
File finalDeployDir = new File(deployLocation);
File pfDir = getJFolderDirectory(cic);
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();
}
File tldsDir = new File(webInfDir, "tlds");
if (!tldsDir.exists()) {
tldsDir.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");
//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");
//
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);
}
//tab library deployment descriptors
Iterator webTagLibsIter = webTagLibs.keySet().iterator();
for (int i = 0; webTagLibsIter.hasNext(); i++) {
File nextTagLibFile = new File(tldsDir, "a" + i + ".tld");
String nextNamespace = (String)webTagLibsIter.next();
ArrayList nextNames = (ArrayList)webTagLibs.get(nextNamespace);
String nextTagLibDescriptor = getTagLibraryDescriptor(nextNamespace,
nextNames, inWebCtsh);
//MiscHelper.println("nextTagLibDescriptor= "
// + nextTagLibDescriptor);
MiscHelper.writeTextFile(nextTagLibFile, nextTagLibDescriptor);
}
//
if (!sameStaticCompoundNamespace) {
String staticTagLibDescriptor =
getTagLibraryDescriptor(staticNamespace, staticNameAndClass);
File staticTagLibFile = new File(tldsDir, "z" + 0 + ".tld");
MiscHelper.writeTextFile(staticTagLibFile, staticTagLibDescriptor);
//
String compoundTagLibDescriptor =
getTagLibraryDescriptor(
compoundNamespace, compoundNameAndClass);
File compoundTagLibFile = new File(tldsDir, "z" + 1 + ".tld");
MiscHelper.writeTextFile(
compoundTagLibFile, compoundTagLibDescriptor);
}
else {
//both static and compound in same HashMap, same namespace
String staticTagLibDescriptor =
getTagLibraryDescriptor(staticNamespace, staticNameAndClass);
File staticTagLibFile = new File(tldsDir, "z" + 0 + ".tld");
MiscHelper.writeTextFile(staticTagLibFile, staticTagLibDescriptor);
}
//
String descriptor = getDeploymentDescriptor(inApplication, webTagLibs,
staticNamespace, compoundNamespace, sameStaticCompoundNamespace);
File webFile = new File(webInfDir, "web.xml");
MiscHelper.writeTextFile(webFile, descriptor);
String jbossWebDescriptor = getJbossDeploymentDescriptor();
File jbossWebFile = new File(webInfDir, "jboss-web.xml");
MiscHelper.writeTextFile(jbossWebFile, jbossWebDescriptor);
//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 getTagLibraryDescriptor(String inNamespace,
ArrayList inNames, ConceptTagSetHolder inWebCtsh) {
String outValue = null;
HashMap nameAndClass = new HashMap();
for (int i = 0; i < inNames.size(); i++) {
String nextName = (String)inNames.get(i);
String nextClass = inWebCtsh.getConceptTagClass(
inNamespace, nextName).getName();
nameAndClass.put(nextName, nextClass);
}
outValue = getTagLibraryDescriptor(inNamespace, nameAndClass);
return outValue;
}
private final static String getTagLibraryDescriptor(String inNamespace,
HashMap inNameAndClass) {
String START = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
+ "<!DOCTYPE taglib\n"
+ " PUBLIC \"-//Sun Microsystems, Inc."
+ "//DTD JSP Tag Library 1.2//EN\"\n"
+ " \"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd\">\n"
+ "<taglib>\n"
+ " <tlib-version>1.0</tlib-version>\n"
+ " <jsp-version>1.2</jsp-version>\n"
+ " <short-name>" + inNamespace + "</short-name>\n";
String END = "</taglib>\n";
StringBuffer outValue = new StringBuffer();
outValue.append(START);
Iterator iter = inNameAndClass.keySet().iterator();
while (iter.hasNext()) {
String nextName = (String)iter.next();
String nextClass = (String)inNameAndClass.get(nextName);
outValue.append(" <tag>\n");
outValue.append(" <name>" + nextName + "</name>\n");
outValue.append(" <tag-class>" + nextClass
+ "</tag-class>\n");
outValue.append(" <body-content>JSP</body-content>\n");
outValue.append(" <description>" + nextName
+ "</description>\n");
outValue.append(" <attribute>\n");
outValue.append(" <name>constraint</name>\n");
outValue.append(" <required>false</required>\n");
outValue.append(" <rtexprvalue>false</rtexprvalue>\n");
outValue.append(" </attribute>\n");
outValue.append(" </tag>\n");
}
outValue.append(END);
return outValue.toString();
}
private final static String getDeploymentDescriptor(
ProjectApplication inApplication, HashMap inWebTagLibs,
String inStaticNamespace, String inCompoundNamespace,
boolean inSameStaticCompoundNamespace) {
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++) {
// ProjectWebPage 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/apps/"
// + (webPageName + ".jsp") + "\n");
// outValue.append(" </jsp-file>\n");
// outValue.append(" </servlet>\n");
//}
outValue.append(" <servlet>\n");
outValue.append(" <servlet-name>\n");
outValue.append(" "
+ ProjectApplicationServlet.class.getName() + "\n");
outValue.append(" </servlet-name>\n");
outValue.append(" <servlet-class>\n");
outValue.append(" "
+ ProjectApplicationServlet.class.getName() + "\n");
outValue.append(" </servlet-class>\n");
outValue.append(" </servlet>\n");
for (int i = 0; i < inApplication.getWebPageCount(); i++) {
ProjectWebPage wwp = inApplication.getWebPage(i);
String webPageName = wwp.getName();
outValue.append(" <servlet-mapping>\n");
outValue.append(" <servlet-name>\n");
outValue.append(" "
+ ProjectApplicationServlet.class.getName() + "\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");
}
Iterator webTagLibIter = inWebTagLibs.keySet().iterator();
for (int i = 0; webTagLibIter.hasNext(); i++) {
String nextNamespace = (String)webTagLibIter.next();
appendTagLibrary(outValue, nextNamespace, "a" + i + ".tld");
}
if (!inSameStaticCompoundNamespace) {
appendTagLibrary(outValue, inStaticNamespace, "z" + 0 + ".tld");
appendTagLibrary(outValue, inCompoundNamespace, "z" + 1 + ".tld");
}
else {
appendTagLibrary(outValue, inStaticNamespace, "z" + 0 + ".tld");
}
outValue.append(END);
return outValue.toString();
}
private final static void appendTagLibrary(StringBuffer inSb,
String inNamespace, String inFile) {
inSb.append(" <taglib>\n");
inSb.append(" <taglib-uri>\n");
inSb.append(" " + inNamespace + "\n");
inSb.append(" </taglib-uri>\n");
inSb.append(" <taglib-location>\n");
inSb.append(" /WEB-INF/tlds/" + inFile + "\n");
inSb.append(" </taglib-location>\n");
inSb.append(" </taglib>\n");
}
private final static String getJbossDeploymentDescriptor() {
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<!DOCTYPE jboss-web\n"
+ " PUBLIC \"-//JBoss//DTD Web Application 2.3//EN\"\n"
+ " \"http://www.jboss.org/j2ee/dtds/jboss-web_3_0.dtd\">\n"
+ "\n"
+ "<jboss-web>\n"
+ " <ejb-ref>\n"
+ " <ejb-ref-name>ejb/jfolder/WorkflowLifecycle"
+ "</ejb-ref-name>\n"
+ " <jndi-name>jfolder/WorkflowLifecycle</jndi-name>\n"
+ " </ejb-ref>\n"
+ " <ejb-ref>\n"
+ " <ejb-ref-name>ejb/jfolder/ConfigManager"
+ "</ejb-ref-name>\n"
+ " <jndi-name>jfolder/ConfigManager</jndi-name>\n"
+ " </ejb-ref>\n"
+ "</jboss-web>\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(
ConfigInstanceConfig inCic) {
File outValue = null;
//ConfigManager cm = ConfigManagerFactory.getConfigManager();
String baseDirName = inCic.getMandatoryPropertyAttribute(
ConfigInstance.STANDARD_CONTENT, XPATH_LOCATIONS, "base");
String pfDirName = inCic.getMandatoryPropertyAttribute(
ConfigInstance.STANDARD_CONTENT, XPATH_LOCATIONS,
"runtime-project");
File baseDir = new File(baseDirName);
outValue = new File(baseDir, pfDirName);
if (!outValue.exists()) {
outValue.mkdirs();
}
//cm.close();
return outValue;
}
}*/
|