/*
* JFolder, Copyright 2001-2006 Gary Steinmetz
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jfolder.workflow.lifecycle;
//base classes
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
//project specific classes
import org.jfolder.common.UnexpectedSystemException;
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.project.model.ProjectApplication;
import org.jfolder.project.model.ProjectApplicationSet;
import org.jfolder.services.config.ConfigServiceCaller;
import org.jfolder.services.config.ConfigServiceCallerFactory;
//other classes
/*public class GenericFileProjectApplicationSet
implements ProjectApplicationSet {
private final static LinearXPath XPATH_LOCATIONS =
LinearXPath.r("locations");
private File userDir = null;
private ArrayList applications = null;
protected GenericFileProjectApplicationSet(File inDir) {
this.applications = new ArrayList();
this.userDir = inDir;
}
protected void load() {
for (int i = 0; i < this.applications.size(); i++) {
GenericFileProjectApplication gfwa =
(GenericFileProjectApplication)this.applications.get(i);
gfwa.load();
}
}
protected void store() {
//MiscHelper.println("About to save apps - "
//+ this.applications.size());
for (int i = 0; i < this.applications.size(); i++) {
GenericFileProjectApplication gfwa =
(GenericFileProjectApplication)this.applications.get(i);
gfwa.store();
}
}
protected void registerApplication(GenericFileProjectApplication inGfwa) {
this.applications.add(inGfwa);
}
public int getApplicationCount() {
return this.applications.size();
}
public ProjectApplication getApplication(int inIndex) {
return (ProjectApplication)this.applications.get(inIndex);
}
public ProjectApplication getApplication(String inName) {
ProjectApplication outValue = null;
for (int i = 0; i < this.getApplicationCount(); i++) {
ProjectApplication nextWp = this.getApplication(i);
if (inName.equalsIgnoreCase(nextWp.getName())) {
outValue = nextWp;
break;
}
}
return outValue;
}
public boolean isApplicationPresent(String inName) {
return (this.getApplication(inName) != null);
}
public void removeApplication(String inApp) {
//MiscHelper.println("removeApplication before = "
// + this.getApplicationCount());
if (isApplicationPresent(inApp)) {
//String appName = getApplication(inApp).getName();
//File appDir = new File(
// getApplicationsDirectory(this.userDir.getName()), appName);
//MiscHelper.deleteFileOrDirectory(appDir);
//boolean result = appDir.delete();
//MiscHelper.println("appDir = " + appDir.getAbsolutePath());
//MiscHelper.println("result = " + result);
for (int i = 0; i < this.getApplicationCount(); i++) {
ProjectApplication nextWp = this.getApplication(i);
if (inApp.equalsIgnoreCase(nextWp.getName())) {
this.applications.remove(i);
break;
}
}
}
//MiscHelper.println("removeApplication after = "
// + this.getApplicationCount());
}
public void duplicateApplication(String inSource, String inDestination) {
if (this.isApplicationPresent(inSource)
&& !this.isApplicationPresent(inDestination)) {
}
}
public void createDefaultApplication(String inDestination) {
if (!isApplicationPresent(inDestination)) {
GenericFileProjectApplication gfwa =
new GenericFileProjectApplication(
new File(this.userDir, inDestination));
registerApplication(gfwa);
}
}
protected final static File getRuntimeProjectSubDir(String inSub) {
File outValue = null;
ConfigServiceCaller csc =
ConfigServiceCallerFactory.getConfigServiceCaller();
//ConfigLifecycle cm = ConfigLifecycleFactory.getConfigLifecycle();
ConfigInstanceConfig cic = csc.accessConfig(ConfigInstance.LOCATION);
File dir = getRuntimeProjectDir(cic);
outValue = new File(dir, inSub);
if (!outValue.exists()) {
outValue.mkdirs();
}
//cm.close();
return outValue;
}
protected final static File getRuntimeProjectDir(
ConfigInstanceConfig inCic) {
File outValue = null;
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();
}
return outValue;
}
public void importApplication(String inApplication, InputStream inIs) {
//File tempDir =
// BaseDBWorkflowLifecycleBean.getRuntimeProjectBaseSubDir("temp");
//MiscHelper.deleteFileOrDirectory(tempDir);
//tempDir.mkdirs();
try {
File appDir = new File(this.userDir, inApplication);
MiscHelper.parseZipInfo(inIs, appDir);
registerApplication(new GenericFileProjectApplication(appDir));
}
catch (IOException ioe) {
throw new UnexpectedSystemException(ioe);
}
}
public void exportApplication(String inApplication, OutputStream inOs) {
//File tempDir =
// BaseDBWorkflowLifecycleBean.getRuntimeProjectBaseSubDir("temp");
//MiscHelper.deleteFileOrDirectory(tempDir);
//tempDir.mkdirs();
try {
File appDir = new File(this.userDir, inApplication);
MiscHelper.zipDirectory(appDir, inOs);
}
catch (IOException ioe) {
throw new UnexpectedSystemException(ioe);
}
}
}*/
|