📄 cmsxmlcontenttypemanager.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/org/opencms/xml/CmsXmlContentTypeManager.java,v $
* Date : $Date: 2006/03/27 14:52:20 $
* Version: $Revision: 1.31 $
*
* 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.xml;
import org.opencms.file.CmsObject;
import org.opencms.i18n.CmsEncoder;
import org.opencms.main.CmsLog;
import org.opencms.main.CmsRuntimeException;
import org.opencms.main.OpenCms;
import org.opencms.security.CmsRole;
import org.opencms.security.CmsRoleViolationException;
import org.opencms.util.CmsStringUtil;
import org.opencms.widgets.I_CmsWidget;
import org.opencms.xml.content.I_CmsXmlContentHandler;
import org.opencms.xml.types.CmsXmlNestedContentDefinition;
import org.opencms.xml.types.I_CmsXmlSchemaType;
import java.io.UnsupportedEncodingException;
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.Set;
import org.apache.commons.collections.FastHashMap;
import org.apache.commons.logging.Log;
import org.dom4j.Document;
import org.dom4j.Element;
/**
* Manager class for registered OpenCms XML content types and content collectors.<p>
*
* @author Alexander Kandzior
*
* @version $Revision: 1.31 $
*
* @since 6.0.0
*/
public class CmsXmlContentTypeManager {
/** The log object for this class. */
private static final Log LOG = CmsLog.getLog(CmsXmlContentTypeManager.class);
/** Stores the initialized XML content handlers. */
private Map m_contentHandlers;
/** Stores the registered content widgets. */
private Map m_defaultWidgets;
/** Stores the registered content types. */
private Map m_registeredTypes;
/** Stores the registed content widgegts by class name. */
private Map m_registeredWidgets;
/** The alias names for the widgets. */
private Map m_widgetAliases;
/**
* Creates a new content type manager.<p>
*/
public CmsXmlContentTypeManager() {
// use the fast hash map implementation since there will be far more read then write accesses
m_registeredTypes = new HashMap();
m_defaultWidgets = new HashMap();
m_registeredWidgets = new HashMap();
m_widgetAliases = new HashMap();
FastHashMap fastMap = new FastHashMap();
fastMap.setFast(true);
m_contentHandlers = fastMap;
if (CmsLog.INIT.isInfoEnabled()) {
CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_START_CONTENT_CONFIG_0));
}
}
/**
* Returns a statically initialized instance of an XML content type manager (for test cases only).<p>
*
* @return a statically initialized instance of an XML content type manager
*/
public static CmsXmlContentTypeManager createTypeManagerForTestCases() {
CmsXmlContentTypeManager typeManager = new CmsXmlContentTypeManager();
typeManager.addWidget("org.opencms.widgets.CmsCalendarWidget", null);
typeManager.addWidget("org.opencms.widgets.CmsHtmlWidget", null);
typeManager.addWidget("org.opencms.widgets.CmsInputWidget", null);
typeManager.addSchemaType("org.opencms.xml.types.CmsXmlDateTimeValue", "org.opencms.widgets.CmsCalendarWidget");
typeManager.addSchemaType("org.opencms.xml.types.CmsXmlHtmlValue", "org.opencms.widgets.CmsHtmlWidget");
typeManager.addSchemaType("org.opencms.xml.types.CmsXmlLocaleValue", "org.opencms.widgets.CmsInputWidget");
typeManager.addSchemaType("org.opencms.xml.types.CmsXmlStringValue", "org.opencms.widgets.CmsInputWidget");
try {
typeManager.initialize(null);
} catch (CmsRoleViolationException e) {
// this should never happen
throw new CmsRuntimeException(Messages.get().container(Messages.ERR_INIT_TYPE_MANAGER_0));
}
return typeManager;
}
/**
* Adds a XML content schema type class to the registerd XML content types.<p>
*
* @param clazz the XML content schema type class to add
*
* @return the created instance of the XML content schema type
*
* @throws CmsXmlException in case the class is not an instance of {@link I_CmsXmlSchemaType}
*/
public I_CmsXmlSchemaType addContentType(Class clazz) throws CmsXmlException {
I_CmsXmlSchemaType type;
try {
type = (I_CmsXmlSchemaType)clazz.newInstance();
} catch (InstantiationException e) {
throw new CmsXmlException(Messages.get().container(Messages.ERR_INVALID_XCC_TYPE_REGISTERED_0));
} catch (IllegalAccessException e) {
throw new CmsXmlException(Messages.get().container(Messages.ERR_INVALID_XCC_TYPE_REGISTERED_0));
} catch (ClassCastException e) {
throw new CmsXmlException(Messages.get().container(Messages.ERR_INVALID_XCC_TYPE_REGISTERED_0));
}
m_registeredTypes.put(type.getTypeName(), type);
return type;
}
/**
* Adds a new XML content type schema class and XML widget to the manager by class names.<p>
*
* @param className class name of the XML content schema type class to add
* @param defaultWidget class name of the default XML widget class for the added XML content type
*/
public void addSchemaType(String className, String defaultWidget) {
Class classClazz;
// init class for schema type
try {
classClazz = Class.forName(className);
} catch (ClassNotFoundException e) {
LOG.error(
Messages.get().getBundle().key(Messages.LOG_XML_CONTENT_SCHEMA_TYPE_CLASS_NOT_FOUND_1, className),
e);
return;
}
// create the schema type and add it to the internal list
I_CmsXmlSchemaType type;
try {
type = addContentType(classClazz);
} catch (Exception e) {
LOG.error(Messages.get().getBundle().key(
Messages.LOG_INIT_XML_CONTENT_SCHEMA_TYPE_CLASS_ERROR_1,
classClazz.getName()), e);
return;
}
// add the editor widget for the schema type
I_CmsWidget widget = getWidget(defaultWidget);
if (widget == null) {
LOG.error(Messages.get().getBundle().key(
Messages.LOG_INIT_DEFAULT_WIDGET_FOR_CONTENT_TYPE_2,
defaultWidget,
type.getTypeName()));
return;
}
// store the registered default widget
m_defaultWidgets.put(type.getTypeName(), widget);
if (CmsLog.INIT.isInfoEnabled()) {
CmsLog.INIT.info(Messages.get().getBundle().key(
Messages.INIT_ADD_ST_USING_WIDGET_2,
type.getTypeName(),
widget.getClass().getName()));
}
}
/**
* Adds a XML content editor widget class, making this widget available for the XML content editor.<p>
*
* @param className the widget class to add
* @param aliasName the (optional) alias name to use for the widget class
*/
public void addWidget(String className, String aliasName) {
Class widgetClazz;
I_CmsWidget widget;
try {
widgetClazz = Class.forName(className);
widget = (I_CmsWidget)widgetClazz.newInstance();
} catch (Exception e) {
LOG.error(Messages.get().getBundle().key(Messages.LOG_XML_WIDGET_INITIALIZING_ERROR_1, className), e);
return;
}
m_registeredWidgets.put(widgetClazz.getName(), widget);
if (aliasName != null) {
m_widgetAliases.put(aliasName, widgetClazz.getName());
}
if (CmsLog.INIT.isInfoEnabled()) {
if (aliasName != null) {
CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_ADD_WIDGET_1, widgetClazz.getName()));
} else {
CmsLog.INIT.info(Messages.get().getBundle().key(
Messages.INIT_ADD_WIDGET_ALIAS_2,
widgetClazz.getName(),
aliasName));
}
}
}
/**
* Returns the XML content handler instance class for the specified class name.<p>
*
* Only one instance of an XML content handler class per content definition name will be generated,
* and that instance will be cached and re-used for all operations.<p>
*
* @param className the name of the XML content handler to return
* @param schemaLocation the schema location of the XML content definition that handler belongs to
*
* @return the XML content handler class
*
* @throws CmsXmlException if something goes wrong
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -