📄 a_cmsresourcetype.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/org/opencms/file/types/A_CmsResourceType.java,v $
* Date : $Date: 2006/03/27 14:52:48 $
* Version: $Revision: 1.42 $
*
* 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.file.types;
import org.opencms.configuration.CmsConfigurationCopyResource;
import org.opencms.configuration.CmsConfigurationException;
import org.opencms.db.CmsSecurityManager;
import org.opencms.file.CmsFile;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsProperty;
import org.opencms.file.CmsResource;
import org.opencms.file.CmsResourceFilter;
import org.opencms.file.CmsVfsException;
import org.opencms.lock.CmsLock;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import org.opencms.security.CmsPermissionSet;
import org.opencms.security.CmsSecurityException;
import org.opencms.staticexport.CmsLinkManager;
import org.opencms.util.CmsFileUtil;
import org.opencms.util.CmsMacroResolver;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
/**
* Base implementation for resource type classes.<p>
*
* @author Alexander Kandzior
* @author Thomas Weckert
*
* @version $Revision: 1.42 $
*
* @since 6.0.0
*/
public abstract class A_CmsResourceType implements I_CmsResourceType {
/** Macro for the folder path of the current resouce. */
public static final String MACRO_RESOURCE_FOLDER_PATH = "resource.folder.path";
/** Macro for the name of the current resouce. */
public static final String MACRO_RESOURCE_NAME = "resource.name";
/** Macro for the parent folder path of the current resouce. */
public static final String MACRO_RESOURCE_PARENT_PATH = "resource.parent.path";
/** Macro for the root path of the current resouce. */
public static final String MACRO_RESOURCE_ROOT_PATH = "resource.root.path";
/** Macro for the site path of the current resouce. */
public static final String MACRO_RESOURCE_SITE_PATH = "resource.site.path";
/** The log object for this class. */
private static final Log LOG = CmsLog.getLog(A_CmsResourceType.class);
/** Flag for showing that this is an additional resource type which defined in a module. */
protected boolean m_addititionalModuleResourceType;
/** The configured class name of this resource type. */
protected String m_className;
/** The list of resources to copy. */
protected List m_copyResources;
/** The list of configured default properties. */
protected List m_defaultProperties;
/** Indicates that the configuration of the resource type has been frozen. */
protected boolean m_frozen;
/** Contains the file extensions mapped to this resource type. */
protected List m_mappings;
/** The configured id of this resource type. */
protected int m_typeId;
/** The configured name of this resource type. */
protected String m_typeName;
/**
* Default constructor, used to initialize some member variables.<p>
*/
public A_CmsResourceType() {
m_typeId = -1;
m_mappings = new ArrayList();
m_defaultProperties = new ArrayList();
m_copyResources = new ArrayList();
}
/**
* @see org.opencms.configuration.I_CmsConfigurationParameterHandler#addConfigurationParameter(java.lang.String, java.lang.String)
*/
public void addConfigurationParameter(String paramName, String paramValue) {
// noop
}
/**
* Adds a new "copy resource" to this resource type,
* allowed only during the configuration phase.<p>
*
* The "copy resources" are copied to the specified location after
* a new resource of this type is created. Usually this feature is used to
* populate a newly created folder with some default resources.<p>
*
* If target is <code>null</code>, the macro {@link #MACRO_RESOURCE_FOLDER_PATH} is used as default.
* If type is <code>null</code>, the copy type {@link CmsResource#COPY_AS_NEW} is used as default.<p>
*
* @param source the source resource
* @param target the target resource (may contain macros)
* @param type the type of the copy, for example "as new", "as sibling" etc
*
* @throws CmsConfigurationException if the configuration is already frozen
*/
public void addCopyResource(String source, String target, String type) throws CmsConfigurationException {
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(
Messages.LOG_ADD_COPY_RESOURCE_4,
new Object[] {this, source, target, type}));
}
if (m_frozen) {
// configuration already frozen
throw new CmsConfigurationException(Messages.get().container(
Messages.ERR_CONFIG_FROZEN_3,
this.getClass().getName(),
getTypeName(),
new Integer(getTypeId())));
}
// create the copy resource object an add it to the list
CmsConfigurationCopyResource copyResource = new CmsConfigurationCopyResource(source, target, type);
m_copyResources.add(copyResource);
}
/**
* Adds a default property to this resource type,
* allowed only during the configuration phase.<p>
*
* @param property the default property to add
*
* @throws CmsConfigurationException if the configuration is already frozen
*/
public void addDefaultProperty(CmsProperty property) throws CmsConfigurationException {
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(Messages.LOG_ADD_DFLT_PROP_2, this, property));
}
if (m_frozen) {
// configuration already frozen
throw new CmsConfigurationException(Messages.get().container(
Messages.ERR_CONFIG_FROZEN_3,
this.getClass().getName(),
getTypeName(),
new Integer(getTypeId())));
}
m_defaultProperties.add(property);
}
/**
* @see org.opencms.file.types.I_CmsResourceType#addMappingType(java.lang.String)
*/
public void addMappingType(String mapping) {
// this configuration does not support parameters
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(Messages.LOG_ADD_MAPPING_TYPE_2, mapping, this));
}
if (m_mappings == null) {
m_mappings = new ArrayList();
}
m_mappings.add(mapping);
}
/**
* @see org.opencms.file.types.I_CmsResourceType#changeLastModifiedProjectId(org.opencms.file.CmsObject, CmsSecurityManager, CmsResource)
*/
public void changeLastModifiedProjectId(CmsObject cms, CmsSecurityManager securityManager, CmsResource resource)
throws CmsException {
securityManager.changeLastModifiedProjectId(cms.getRequestContext(), resource);
}
/**
* @see org.opencms.file.types.I_CmsResourceType#changeLock(org.opencms.file.CmsObject, CmsSecurityManager, CmsResource)
*/
public void changeLock(CmsObject cms, CmsSecurityManager securityManager, CmsResource resource) throws CmsException {
securityManager.changeLock(cms.getRequestContext(), resource);
}
/**
* @see org.opencms.file.types.I_CmsResourceType#chflags(org.opencms.file.CmsObject, CmsSecurityManager, CmsResource, int)
*/
public void chflags(CmsObject cms, CmsSecurityManager securityManager, CmsResource resource, int flags)
throws CmsException {
securityManager.chflags(cms.getRequestContext(), resource, flags);
}
/**
* @see org.opencms.file.types.I_CmsResourceType#chtype(org.opencms.file.CmsObject, CmsSecurityManager, CmsResource, int)
*/
public void chtype(CmsObject cms, CmsSecurityManager securityManager, CmsResource resource, int type)
throws CmsException {
securityManager.chtype(cms.getRequestContext(), resource, type);
}
/**
* @see org.opencms.file.types.I_CmsResourceType#copyResource(org.opencms.file.CmsObject, CmsSecurityManager, CmsResource, java.lang.String, int)
*/
public void copyResource(
CmsObject cms,
CmsSecurityManager securityManager,
CmsResource source,
String destination,
int siblingMode) throws CmsException {
securityManager.copyResource(
cms.getRequestContext(),
source,
cms.getRequestContext().addSiteRoot(destination),
siblingMode);
}
/**
* @see org.opencms.file.types.I_CmsResourceType#copyResourceToProject(org.opencms.file.CmsObject, CmsSecurityManager, CmsResource)
*/
public void copyResourceToProject(CmsObject cms, CmsSecurityManager securityManager, CmsResource resource)
throws CmsException {
securityManager.copyResourceToProject(cms.getRequestContext(), resource);
}
/**
* @see org.opencms.file.types.I_CmsResourceType#createResource(org.opencms.file.CmsObject, CmsSecurityManager, java.lang.String, byte[], List)
*/
public CmsResource createResource(
CmsObject cms,
CmsSecurityManager securityManager,
String resourcename,
byte[] content,
List properties) throws CmsException {
// initialize a macroresolver with the current user OpenCms context
CmsMacroResolver resolver = getMacroResolver(cms, resourcename);
// add the predefined property values from the XML configuration to the resource
List newProperties = processDefaultProperties(properties, resolver);
CmsResource result = securityManager.createResource(
cms.getRequestContext(),
cms.getRequestContext().addSiteRoot(resourcename),
getTypeId(),
content,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -