📄 cmsworkplaceeditormanager.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/editors/CmsWorkplaceEditorManager.java,v $
* Date : $Date: 2006/03/27 14:52:49 $
* Version: $Revision: 1.10 $
*
* 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.workplace.editors;
import org.opencms.db.CmsUserSettings;
import org.opencms.file.CmsFile;
import org.opencms.file.CmsFolder;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsRequestContext;
import org.opencms.file.CmsResourceFilter;
import org.opencms.file.types.CmsResourceTypeXmlPage;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import org.opencms.util.CmsStringUtil;
import org.opencms.workplace.explorer.CmsExplorerTypeSettings;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import org.apache.commons.logging.Log;
/**
* The editor manager stores information about all available configured editors in OpenCms.<p>
*
* This class provides methods and constants to select the right editor according to:
* <ul>
* <li>the user preferences</li>
* <li>the users current browser</li>
* <li>the resource type</li>
* <li>the editor rankings</li>
* </ul>
* <p>
*
* @author Andreas Zahner
*
* @version $Revision: 1.10 $
*
* @since 6.0.0
*/
public class CmsWorkplaceEditorManager {
/** The filename of the editor configuration XML file. */
public static final String EDITOR_CONFIGURATION_FILENAME = "editor_configuration.xml";
/** The filename of the editor JSP. */
public static final String EDITOR_FILENAME = "editor.jsp";
/** The log object for this class. */
private static final Log LOG = CmsLog.getLog(CmsWorkplaceEditorManager.class);
private List m_editorConfigurations;
private Map m_preferredEditors;
/**
* Creates a new editor manager.<p>
*
* @param cms an OpenCms context object that must have been initialized with "Admin" permissions
*/
public CmsWorkplaceEditorManager(CmsObject cms) {
// get all subfolders of the workplace editor folder
List editorFolders = new ArrayList();
try {
editorFolders = cms.getSubFolders(CmsEditor.PATH_EDITORS);
} catch (CmsException e) {
LOG.error(Messages.get().getBundle().key(Messages.LOG_READ_EDITIR_FOLDER_FAILED_1, CmsEditor.PATH_EDITORS));
// can not throw exception here since then OpenCms would not even start in shell mode (runlevel 2)
editorFolders = new ArrayList();
}
m_editorConfigurations = new ArrayList(editorFolders.size());
// try to read the configuration files and create configuration objects for valid configurations
Iterator i = editorFolders.iterator();
while (i.hasNext()) {
CmsFolder currentFolder = (CmsFolder)i.next();
String folderName = CmsEditor.PATH_EDITORS + currentFolder.getName();
if (!folderName.endsWith("/")) {
folderName += "/";
}
CmsFile configFile = null;
try {
configFile = cms.readFile(
folderName + EDITOR_CONFIGURATION_FILENAME,
CmsResourceFilter.IGNORE_EXPIRATION);
} catch (CmsException e) {
// no configuration file present, ignore this folder
if (LOG.isInfoEnabled()) {
LOG.info(e);
}
continue;
}
// get the file contents
byte[] xmlData = configFile.getContents();
CmsWorkplaceEditorConfiguration editorConfig = new CmsWorkplaceEditorConfiguration(xmlData, folderName
+ EDITOR_FILENAME);
if (editorConfig.isValidConfiguration()) {
m_editorConfigurations.add(editorConfig);
}
}
m_preferredEditors = new HashMap(m_editorConfigurations.size());
}
/**
* Returns a map of configurable editors for the workplace preferences dialog.<p>
*
* This map has the resource type name as key, the value is a sorted map with
* the ranking as key and a CmsWorkplaceEditorConfiguration object as value.<p>
*
* @return configurable editors for the workplace preferences dialog
*/
public Map getConfigurableEditors() {
Map configurableEditors = new HashMap();
Iterator i = m_editorConfigurations.iterator();
while (i.hasNext()) {
CmsWorkplaceEditorConfiguration currentConfig = (CmsWorkplaceEditorConfiguration)i.next();
// get all resource types specified for the current editor configuration
Iterator k = currentConfig.getResourceTypes().keySet().iterator();
while (k.hasNext()) {
// key is the current resource type of the configuration
String key = (String)k.next();
// check if the current resource type is only a reference to another resource type
CmsExplorerTypeSettings settings = OpenCms.getWorkplaceManager().getExplorerTypeSetting(key);
if (CmsStringUtil.isNotEmpty(settings.getReference())) {
// skip this resource type
continue;
}
if (currentConfig.getMappingForResourceType(key) == null) {
// editor is configurable for specified resource type
SortedMap editorConfigs = (SortedMap)configurableEditors.get(key);
if (editorConfigs == null) {
// no configuration map present for resource type, create one
editorConfigs = new TreeMap();
}
// put the current editor configuration to the resource map with ranking value as key
editorConfigs.put(new Float(currentConfig.getRankingForResourceType(key)), currentConfig);
// put the resource map to the result map with resource type as key
configurableEditors.put(key, editorConfigs);
}
}
}
return configurableEditors;
}
/**
* Returns the editor URI for the current resource type.<p>
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -