📄 cmsmodulexmlhandler.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/org/opencms/module/CmsModuleXmlHandler.java,v $
* Date : $Date: 2006/03/27 14:53:03 $
* Version: $Revision: 1.22 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about Alkacon Software GmbH, please see the
* company website: http://www.alkacon.com
*
* For further information about OpenCms, please see the
* project website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.opencms.module;
import org.opencms.configuration.CmsVfsConfiguration;
import org.opencms.configuration.CmsWorkplaceConfiguration;
import org.opencms.configuration.I_CmsConfigurationParameterHandler;
import org.opencms.configuration.I_CmsXmlConfiguration;
import org.opencms.db.CmsExportPoint;
import org.opencms.file.types.I_CmsResourceType;
import org.opencms.main.CmsLog;
import org.opencms.util.CmsDateUtil;
import org.opencms.util.CmsStringUtil;
import org.opencms.workplace.CmsWorkplace;
import org.opencms.workplace.explorer.CmsExplorerTypeSettings;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import org.apache.commons.digester.Digester;
import org.apache.commons.logging.Log;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
/**
* Adds the XML handler rules for import and export of a single module.<p>
*
* @author Alexander Kandzior
*
* @version $Revision: 1.22 $
*
* @since 6.0.0
*/
public class CmsModuleXmlHandler {
/** The "name" attribute. */
public static final String A_NAME = "name";
/** The "version" attribute. */
public static final String A_VERSION = "version";
/** The node name for the authoremail node. */
public static final String N_AUTHOREMAIL = "authoremail";
/** The node name for the authorname node. */
public static final String N_AUTHORNAME = "authorname";
/** The node name for the class node. */
public static final String N_CLASS = "class";
/** The node name for the datecreated node. */
public static final String N_DATECREATED = "datecreated";
/** The node name for the date installed node. */
public static final String N_DATEINSTALLED = "dateinstalled";
/** The node name for the dependencies node. */
public static final String N_DEPENDENCIES = "dependencies";
/** The node name for the dependency node. */
public static final String N_DEPENDENCY = "dependency";
/** The node name for the description node. */
public static final String N_DESCRIPTION = "description";
/** The node name for the group node. */
public static final String N_GROUP = "group";
/** The node name for a module. */
public static final String N_MODULE = "module";
/** The node name for the name node. */
public static final String N_NAME = "name";
/** The node name for the nicename node. */
public static final String N_NICENAME = "nicename";
/** The "param" node name for generic parameters. */
public static final String N_PARAM = "param";
/** The node name for the parameters node. */
public static final String N_PARAMETERS = "parameters";
/** The node name for the resources node. */
public static final String N_RESOURCES = "resources";
/** The node name for the user installed node. */
public static final String N_USERINSTALLED = "userinstalled";
/** The node name for the version node. */
public static final String N_VERSION = "version";
/** The log object for this class. */
private static final Log LOG = CmsLog.getLog(CmsModuleXmlHandler.class);
/** The list of dependencies for a module. */
private List m_dependencies;
/** The explorer type settings. */
private List m_explorerTypeSettings;
/** The list of export points for a module. */
private List m_exportPoints;
/** The generated module. */
private CmsModule m_module;
/** Indicates if the module was an old (5.0.x) style module. */
private boolean m_oldModule;
/** The module parameters. */
private Map m_parameters;
/** The list of resources for a module. */
private List m_resources;
/** The list of additional resource types. */
private List m_resourceTypes;
/**
* Public constructor, will be called by digester during import.<p>
*/
public CmsModuleXmlHandler() {
m_exportPoints = new ArrayList();
m_dependencies = new ArrayList();
m_resources = new ArrayList();
m_parameters = new HashMap();
m_resourceTypes = new ArrayList();
m_explorerTypeSettings = new ArrayList();
}
/**
* Adds the XML digester rules for a single module.<p>
*
* @param digester the digester to add the rules to
*/
public static void addXmlDigesterRules(Digester digester) {
// add class generation rule
digester.addObjectCreate("*/" + N_MODULE, CmsModuleXmlHandler.class);
digester.addSetNext("*/" + N_MODULE, "setModule");
// add rules for base module information
digester.addCallMethod("*/" + N_MODULE, "createdModule", 11);
digester.addCallParam("*/" + N_MODULE + "/" + N_NAME, 0);
digester.addCallParam("*/" + N_MODULE + "/" + N_NICENAME, 1);
digester.addCallParam("*/" + N_MODULE + "/" + N_GROUP, 2);
digester.addCallParam("*/" + N_MODULE + "/" + N_CLASS, 3);
digester.addCallParam("*/" + N_MODULE + "/" + N_DESCRIPTION, 4);
digester.addCallParam("*/" + N_MODULE + "/" + N_VERSION, 5);
digester.addCallParam("*/" + N_MODULE + "/" + N_AUTHORNAME, 6);
digester.addCallParam("*/" + N_MODULE + "/" + N_AUTHOREMAIL, 7);
digester.addCallParam("*/" + N_MODULE + "/" + N_DATECREATED, 8);
digester.addCallParam("*/" + N_MODULE + "/" + N_USERINSTALLED, 9);
digester.addCallParam("*/" + N_MODULE + "/" + N_DATEINSTALLED, 10);
// add rules for module dependencies
digester.addCallMethod("*/" + N_MODULE + "/" + N_DEPENDENCIES + "/" + N_DEPENDENCY, "addDependency", 2);
digester.addCallParam(
"*/" + N_MODULE + "/" + N_DEPENDENCIES + "/" + N_DEPENDENCY,
0,
I_CmsXmlConfiguration.A_NAME);
digester.addCallParam("*/" + N_MODULE + "/" + N_DEPENDENCIES + "/" + N_DEPENDENCY, 1, A_VERSION);
// add rules for the module export points
digester.addCallMethod("*/"
+ N_MODULE
+ "/"
+ I_CmsXmlConfiguration.N_EXPORTPOINTS
+ "/"
+ I_CmsXmlConfiguration.N_EXPORTPOINT, "addExportPoint", 2);
digester.addCallParam("*/"
+ N_MODULE
+ "/"
+ I_CmsXmlConfiguration.N_EXPORTPOINTS
+ "/"
+ I_CmsXmlConfiguration.N_EXPORTPOINT, 0, I_CmsXmlConfiguration.A_URI);
digester.addCallParam("*/"
+ N_MODULE
+ "/"
+ I_CmsXmlConfiguration.N_EXPORTPOINTS
+ "/"
+ I_CmsXmlConfiguration.N_EXPORTPOINT, 1, I_CmsXmlConfiguration.A_DESTINATION);
// add rules for the module resources
digester.addCallMethod(
"*/" + N_MODULE + "/" + N_RESOURCES + "/" + I_CmsXmlConfiguration.N_RESOURCE,
"addResource",
1);
digester.addCallParam(
"*/" + N_MODULE + "/" + N_RESOURCES + "/" + I_CmsXmlConfiguration.N_RESOURCE,
0,
I_CmsXmlConfiguration.A_URI);
// add rules for the module parameters
digester.addCallMethod(
"*/" + N_MODULE + "/" + N_PARAMETERS + "/" + I_CmsXmlConfiguration.N_PARAM,
"addParameter",
2);
digester.addCallParam(
"*/" + N_MODULE + "/" + N_PARAMETERS + "/" + I_CmsXmlConfiguration.N_PARAM,
0,
I_CmsXmlConfiguration.A_NAME);
digester.addCallParam("*/" + N_MODULE + "/" + N_PARAMETERS + "/" + I_CmsXmlConfiguration.N_PARAM, 1);
// generic <param> parameter rules
digester.addCallMethod(
"*/" + I_CmsXmlConfiguration.N_PARAM,
I_CmsConfigurationParameterHandler.ADD_PARAMETER_METHOD,
2);
digester.addCallParam("*/" + I_CmsXmlConfiguration.N_PARAM, 0, I_CmsXmlConfiguration.A_NAME);
digester.addCallParam("*/" + I_CmsXmlConfiguration.N_PARAM, 1);
// add resource type rules from VFS
CmsVfsConfiguration.addResourceTypeXmlRules(digester);
// add explorer type rules from workplace
CmsWorkplaceConfiguration.addExplorerTypeXmlRules(digester);
// finally add all rules for backward compatibility with OpenCms 5.0
addXmlDigesterRulesForVersion5Modules(digester);
}
/**
* Generates a detached XML element for a module.<p>
*
* @param module the module to genterate the XML element for
* @return the detached XML element for the module
*/
public static Element generateXml(CmsModule module) {
Document doc = DocumentHelper.createDocument();
Element moduleElement = doc.addElement(N_MODULE);
moduleElement.addElement(N_NAME).setText(module.getName());
if (!module.getName().equals(module.getNiceName())) {
moduleElement.addElement(N_NICENAME).addCDATA(module.getNiceName());
} else {
moduleElement.addElement(N_NICENAME);
}
if (CmsStringUtil.isNotEmpty(module.getGroup())) {
moduleElement.addElement(N_GROUP).setText(module.getGroup());
}
if (CmsStringUtil.isNotEmpty(module.getActionClass())) {
moduleElement.addElement(N_CLASS).setText(module.getActionClass());
} else {
moduleElement.addElement(N_CLASS);
}
if (CmsStringUtil.isNotEmpty(module.getDescription())) {
moduleElement.addElement(N_DESCRIPTION).addCDATA(module.getDescription());
} else {
moduleElement.addElement(N_DESCRIPTION);
}
moduleElement.addElement(N_VERSION).setText(module.getVersion().toString());
if (CmsStringUtil.isNotEmpty(module.getAuthorName())) {
moduleElement.addElement(N_AUTHORNAME).addCDATA(module.getAuthorName());
} else {
moduleElement.addElement(N_AUTHORNAME);
}
if (CmsStringUtil.isNotEmpty(module.getAuthorEmail())) {
moduleElement.addElement(N_AUTHOREMAIL).addCDATA(module.getAuthorEmail());
} else {
moduleElement.addElement(N_AUTHOREMAIL);
}
if (module.getDateCreated() != CmsModule.DEFAULT_DATE) {
moduleElement.addElement(N_DATECREATED).setText(CmsDateUtil.getHeaderDate(module.getDateCreated()));
} else {
moduleElement.addElement(N_DATECREATED);
}
if (CmsStringUtil.isNotEmpty(module.getUserInstalled())) {
moduleElement.addElement(N_USERINSTALLED).setText(module.getUserInstalled());
} else {
moduleElement.addElement(N_USERINSTALLED);
}
if (module.getDateInstalled() != CmsModule.DEFAULT_DATE) {
moduleElement.addElement(N_DATEINSTALLED).setText(CmsDateUtil.getHeaderDate(module.getDateInstalled()));
} else {
moduleElement.addElement(N_DATEINSTALLED);
}
Element dependenciesElement = moduleElement.addElement(N_DEPENDENCIES);
for (int i = 0; i < module.getDependencies().size(); i++) {
CmsModuleDependency dependency = (CmsModuleDependency)module.getDependencies().get(i);
dependenciesElement.addElement(N_DEPENDENCY).addAttribute(
I_CmsXmlConfiguration.A_NAME,
dependency.getName()).addAttribute(A_VERSION, dependency.getVersion().toString());
}
Element exportpointsElement = moduleElement.addElement(I_CmsXmlConfiguration.N_EXPORTPOINTS);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -