📄 cmsresourcetypexmlcontent.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/org/opencms/file/types/CmsResourceTypeXmlContent.java,v $
* Date : $Date: 2005/06/27 23:22:16 $
* 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.file.types;
import org.opencms.db.CmsSecurityManager;
import org.opencms.file.CmsFile;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsResource;
import org.opencms.file.CmsResourceFilter;
import org.opencms.loader.CmsXmlContentLoader;
import org.opencms.main.CmsException;
import org.opencms.main.OpenCms;
import org.opencms.security.CmsPermissionSet;
import org.opencms.xml.CmsXmlContentDefinition;
import org.opencms.xml.content.CmsXmlContent;
import org.opencms.xml.content.CmsXmlContentFactory;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;
/**
* Resource type descriptor for the type "xmlcontent".<p>
*
* @author Alexander Kandzior
*
* @version $Revision: 1.22 $
*
* @since 6.0.0
*/
public class CmsResourceTypeXmlContent extends A_CmsResourceType {
/** Configuration key for the (optional) schema. */
public static final String CONFIGURATION_SCHEMA = "schema";
/** The (optional) schema of this resource. */
private String m_schema;
/**
* @see org.opencms.file.types.A_CmsResourceType#addConfigurationParameter(java.lang.String, java.lang.String)
*/
public void addConfigurationParameter(String paramName, String paramValue) {
super.addConfigurationParameter(paramName, paramValue);
if (CONFIGURATION_SCHEMA.equalsIgnoreCase(paramName)) {
m_schema = paramValue.trim();
}
}
/**
* @see org.opencms.file.types.I_CmsResourceType#createResource(org.opencms.file.CmsObject, org.opencms.db.CmsSecurityManager, java.lang.String, byte[], java.util.List)
*/
public CmsResource createResource(
CmsObject cms,
CmsSecurityManager securityManager,
String resourcename,
byte[] content,
List properties) throws CmsException {
if ((m_schema != null) && ((content == null) || (content.length == 0))) {
// unmarshal the content definition for the new resource
CmsXmlContentDefinition contentDefinition = CmsXmlContentDefinition.unmarshal(cms, m_schema);
// read the default locale for the new resource
Locale locale = (Locale)OpenCms.getLocaleManager().getDefaultLocales(
cms,
CmsResource.getParentFolder(resourcename)).get(0);
// create the new content from the content defintion
CmsXmlContent newContent = CmsXmlContentFactory.createDocument(
cms,
locale,
OpenCms.getSystemInfo().getDefaultEncoding(),
contentDefinition);
// get the bytes from the created content
content = newContent.marshal();
}
// now create the resource using the super class
return super.createResource(cms, securityManager, resourcename, content, properties);
}
/**
* @see org.opencms.file.types.I_CmsResourceType#getCachePropertyDefault()
*/
public String getCachePropertyDefault() {
return "element;locale;";
}
/**
* @see org.opencms.file.types.A_CmsResourceType#getConfiguration()
*/
public Map getConfiguration() {
Map result = new TreeMap();
if (m_schema != null) {
result.put(CONFIGURATION_SCHEMA, m_schema);
}
Map additional = super.getConfiguration();
if (additional != null) {
result.putAll(additional);
}
return result;
}
/**
* @see org.opencms.file.types.I_CmsResourceType#getLoaderId()
*/
public int getLoaderId() {
return CmsXmlContentLoader.RESOURCE_LOADER_ID;
}
/**
* @see org.opencms.file.types.I_CmsResourceType#isDirectEditable()
*/
public boolean isDirectEditable() {
return true;
}
/**
* @see org.opencms.file.types.I_CmsResourceType#writeFile(org.opencms.file.CmsObject, CmsSecurityManager, CmsFile)
*/
public CmsFile writeFile(CmsObject cms, CmsSecurityManager securityManager, CmsFile resource) throws CmsException {
// check if the user has write access and if resource is locked
// done here so that all the XML operations are not performed if permissions not granted
securityManager.checkPermissions(
cms.getRequestContext(),
resource,
CmsPermissionSet.ACCESS_WRITE,
true,
CmsResourceFilter.ALL);
// read the xml content, use the encoding set in the property
CmsXmlContent xmlContent = CmsXmlContentFactory.unmarshal(cms, resource, false);
// call the content handler for post-processing
resource = xmlContent.getContentDefinition().getContentHandler().prepareForWrite(cms, xmlContent, resource);
// now write the file
return super.writeFile(cms, securityManager, resource);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -