📄 cmsadminmodulecreate.java
字号:
try {
cms.createResource(C_VFS_PATH_MODULES, packagename, C_TYPE_FOLDER_NAME);
}catch(CmsException e) {
if(e.getType() != CmsException.C_FILE_EXISTS) {
// couldn't create Module
templateDocument.setData("details", Utils.getStackTrace(e));
return startProcessing(cms, templateDocument, elementName, parameters, "errorProject");
}else {
try {
cms.readFolder(C_VFS_PATH_MODULES + packagename + "/");
}catch(CmsException ex) {
// folder exist but is deleted
templateDocument.setData("details", "Sorry, you have to publish this Project and create a new one.\n" + Utils.getStackTrace(e));
return startProcessing(cms, templateDocument, elementName, parameters, "errorProject");
}
}
}
long createDateLong = 0;
try {
createDateLong = dateFormat.parse(createDate).getTime();
}catch(Exception exc) {
createDateLong = (new Date()).getTime();
}
String type = isSimpleModule?CmsRegistry.C_MODULE_TYPE_SIMPLE:CmsRegistry.C_MODULE_TYPE_TRADITIONAL;
HashMap exportPoints = new HashMap();
if (mustExportClasses) {
exportPoints.put(I_CmsWpConstants.C_VFS_PATH_MODULES + packagename +"/classes/", "WEB-INF/classes/");
}
if (mustExportLib) {
exportPoints.put(I_CmsWpConstants.C_VFS_PATH_MODULES + packagename +"/lib/", "WEB-INF/lib/");
}
reg.createModule(packagename, getStringValue(modulename), getStringValue(description), getStringValue(author), type, exportPoints, createDateLong, v);
reg.setModuleAuthorEmail(packagename, getStringValue(email));
reg.setModuleMaintenanceEventClass(packagename, getStringValue(maintenance));
reg.setModulePublishClass(packagename, getStringValue(publishclass));
String modulePath = C_VFS_PATH_MODULES + packagename + "/";
// as default don't export any module data
cms.writeProperty(modulePath, C_PROPERTY_EXPORT, "false");
if (mustExportClasses) {
// create the class folder, will get exportet to the "real" file system
tryToCreateFolder(cms, modulePath, "classes");
// create all package folders beneth class folder
Vector cFolders = new Vector();
String workString = packagename;
while(workString.lastIndexOf('.') > -1) {
cFolders.addElement(workString.substring(workString.lastIndexOf('.') + 1));
workString = workString.substring(0, workString.lastIndexOf('.'));
}
tryToCreateFolder(cms, modulePath+"classes/", workString);
workString = modulePath + "classes/" + workString + "/";
for(int i = cFolders.size() - 1;i >= 0;i--) {
tryToCreateFolder(cms, workString, (String)cFolders.elementAt(i));
workString = workString + (String)cFolders.elementAt(i) + "/";
}
}
if (mustExportLib) {
// create the lib folder, will get exportet to the "real" file system
tryToCreateFolder(cms, modulePath, "lib");
}
// create the templates folder
tryToCreateFolder(cms, modulePath, I_CmsWpConstants.C_VFS_DIR_TEMPLATES);
// create the "default_bodies" folder
tryToCreateFolder(cms, modulePath, I_CmsWpConstants.C_VFS_DIR_DEFAULTBODIES);
if (! isSimpleModule) {
// traditional module type, create more directories
tryToCreateFolder(cms, modulePath, "contenttemplates");
tryToCreateFolder(cms, modulePath, "frametemplates");
// create "elements" folder
tryToCreateFolder(cms, modulePath, "elements");
tryToCreateFolder(cms, modulePath, "doc");
reg.setModuleDocumentPath(packagename, modulePath + "doc/index.html");
}
// initialize if we need a 'locales' subdirectory in our new module
boolean needsLocaleDir = !isSimpleModule;
if("checked".equals(view)) {
reg.setModuleView(packagename, packagename.replace('.', '_') + ".view", modulePath + "view/index.html");
tryToCreateFolder(cms, modulePath, "view");
needsLocaleDir = true;
}
if("checked".equals(adminpoint)) {
tryToCreateFolder(cms, modulePath, "administration");
// create "pics" folder (required for workplace extension images)
tryToCreateFolder(cms, modulePath, "pics");
needsLocaleDir = true;
}
if (needsLocaleDir) {
// create "locales" folder (required for workplace extension resource files)
tryToCreateFolder(cms, modulePath, I_CmsWpConstants.C_VFS_DIR_LOCALES);
tryToCreateFolder(cms, modulePath + I_CmsWpConstants.C_VFS_DIR_LOCALES, I_CmsWpConstants.C_DEFAULT_LANGUAGE);
}
try {
cms.getRequestContext().getResponse().sendCmsRedirect(getConfigFile(cms).getWorkplaceAdministrationPath() + "module/index.html");
}catch(Exception e) {
throw new CmsException("Redirect fails :system/workplace/administration/module/index.html", CmsException.C_UNKNOWN_EXCEPTION, e);
}
return null;
}
}else {
if("fromerrorpage".equals(step)) {
Hashtable sessionData = (Hashtable)session.getValue(C_SESSION_DATA);
session.removeValue(C_SESSION_DATA);
templateDocument.setData(C_PACKETNAME, "");
templateDocument.setData(C_VERSION, (String)sessionData.get(C_VERSION));
templateDocument.setData(C_MODULENAME, (String)sessionData.get(C_MODULENAME));
templateDocument.setData(C_DESCRIPTION, (String)sessionData.get(C_DESCRIPTION));
templateDocument.setData(C_VIEW, (String)sessionData.get(C_VIEW));
templateDocument.setData(C_ADMINPOINT, (String)sessionData.get(C_ADMINPOINT));
templateDocument.setData(C_MAINTENANCE, (String)sessionData.get(C_MAINTENANCE));
templateDocument.setData(C_PUBLISHCLASS, (String)sessionData.get(C_PUBLISHCLASS));
templateDocument.setData(C_AUTHOR, (String)sessionData.get(C_AUTHOR));
templateDocument.setData(C_EMAIL, (String)sessionData.get(C_EMAIL));
templateDocument.setData(C_DATE, (String)sessionData.get(C_DATE));
templateDocument.setData(C_MODULE_TYPE, (String)sessionData.get(C_MODULE_TYPE));
templateSelector = "";
}
}
}
// Now load the template file and start the processing
return startProcessing(cms, templateDocument, elementName, parameters, templateSelector);
}
/**
* returns the String or "" if it is null.
* Creation date: (29.10.00 16:05:38)
* @return java.lang.String
* @param param java.lang.String
*/
private String getStringValue(String param) {
if(param == null) {
return "";
}
return param;
}
/**
* Indicates if the results of this class are cacheable.
*
* @param cms CmsObject Object for accessing system resources
* @param templateFile Filename of the template file
* @param elementName Element name of this template in our parent template.
* @param parameters Hashtable with all template class parameters.
* @param templateSelector template section that should be processed.
* @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
*/
public boolean isCacheable(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) {
return false;
}
/**
* Insert the method's description here.
* Creation date: (03.11.00 08:23:13)
* @param param com.opencms.file.CmsObject
* @param folder java.lang.String
* @param newFolder java.lang.String
*/
private void tryToCreateFolder(CmsObject cms, String folder, String newFolder) {
try {
cms.createResource(folder, newFolder, C_TYPE_FOLDER_NAME);
}catch(Exception e) {
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -