📄 cmsworkplaceeditormanager.java
字号:
* @param context the request context
* @param userAgent the user agent String that identifies the browser
* @return a valid editor URI for the resource type or null, if no editor matches
*/
public String getWidgetEditor(CmsRequestContext context, String userAgent) {
// step 1: check if the user specified a preferred editor for the resource type xmlpage
CmsUserSettings settings = new CmsUserSettings(context.currentUser());
String resourceType = CmsResourceTypeXmlPage.getStaticTypeName();
String preferredEditorSetting = settings.getPreferredEditor(resourceType);
if (preferredEditorSetting == null) {
// no preferred editor setting found for this resource type, look for mapped resource type preferred editor
Iterator i = m_editorConfigurations.iterator();
while (i.hasNext()) {
CmsWorkplaceEditorConfiguration currentConfig = (CmsWorkplaceEditorConfiguration)i.next();
String mapping = currentConfig.getMappingForResourceType(resourceType);
if (mapping != null) {
preferredEditorSetting = settings.getPreferredEditor(mapping);
}
if (preferredEditorSetting != null) {
break;
}
}
}
if (preferredEditorSetting != null) {
CmsWorkplaceEditorConfiguration preferredConf = filterPreferredEditor(preferredEditorSetting);
if (preferredConf != null && preferredConf.isWidgetEditor() && preferredConf.matchesBrowser(userAgent)) {
// return preferred editor only if it matches the current users browser
return preferredConf.getWidgetEditor();
}
}
// step 2: filter editors for the given resoure type
SortedMap filteredEditors = filterEditorsForResourceType(resourceType);
// step 3: check if one of the editors matches the current users browser
while (filteredEditors.size() > 0) {
// check editor configuration with highest ranking
Float key = (Float)filteredEditors.lastKey();
CmsWorkplaceEditorConfiguration conf = (CmsWorkplaceEditorConfiguration)filteredEditors.get(key);
if (conf.isWidgetEditor() && conf.matchesBrowser(userAgent)) {
return conf.getWidgetEditor();
}
filteredEditors.remove(key);
}
// no valid editor found
return null;
}
/**
* Returns the default editor URI for the current resource type.<p>
*
* @param context the request context
* @param resourceType the current resource type
* @param userAgent the user agent String that identifies the browser
* @return a valid default editor URI for the resource type or null, if no editor matches
*/
protected String getDefaultEditorUri(CmsRequestContext context, String resourceType, String userAgent) {
SortedMap filteredEditors = filterEditorsForResourceType(resourceType);
while (filteredEditors.size() > 0) {
// get the configuration with the lowest key value from the map
Float key = (Float)filteredEditors.firstKey();
CmsWorkplaceEditorConfiguration conf = (CmsWorkplaceEditorConfiguration)filteredEditors.get(key);
// match the found configuration with the current users browser
if (conf.matchesBrowser(userAgent)) {
return conf.getEditorUri();
}
filteredEditors.remove(key);
}
if (context == null) {
// this is just so that all parameters are used, signature should be identical to getEditorUri(...)
return null;
}
// no valid default editor found
return null;
}
/**
* Returns the editor configuration objects.<p>
*
* @return the editor configuration objects
*/
protected List getEditorConfigurations() {
return m_editorConfigurations;
}
/**
* Returns the editor URI for the current resource type.<p>
*
* @param context the request context
* @param resourceType the current resource type
* @param userAgent the user agent String that identifies the browser
* @return a valid editor URI for the resource type or null, if no editor matches
*/
protected String getEditorUri(CmsRequestContext context, String resourceType, String userAgent) {
// step 1: check if the user specified a preferred editor for the given resource type
CmsUserSettings settings = new CmsUserSettings(context.currentUser());
String preferredEditorSetting = settings.getPreferredEditor(resourceType);
if (preferredEditorSetting == null) {
// no preferred editor setting found for this resource type, look for mapped resource type preferred editor
Iterator i = m_editorConfigurations.iterator();
while (i.hasNext()) {
CmsWorkplaceEditorConfiguration currentConfig = (CmsWorkplaceEditorConfiguration)i.next();
String mapping = currentConfig.getMappingForResourceType(resourceType);
if (mapping != null) {
preferredEditorSetting = settings.getPreferredEditor(mapping);
}
if (preferredEditorSetting != null) {
break;
}
}
}
if (preferredEditorSetting != null) {
CmsWorkplaceEditorConfiguration preferredConf = filterPreferredEditor(preferredEditorSetting);
if (preferredConf != null && preferredConf.matchesBrowser(userAgent)) {
// return preferred editor only if it matches the current users browser
return preferredConf.getEditorUri();
}
}
// step 2: filter editors for the given resoure type
SortedMap filteredEditors = filterEditorsForResourceType(resourceType);
// step 3: check if one of the editors matches the current users browser
while (filteredEditors.size() > 0) {
// check editor configuration with highest ranking
Float key = (Float)filteredEditors.lastKey();
CmsWorkplaceEditorConfiguration conf = (CmsWorkplaceEditorConfiguration)filteredEditors.get(key);
if (conf.matchesBrowser(userAgent)) {
return conf.getEditorUri();
}
filteredEditors.remove(key);
}
// no valid editor found
return null;
}
/**
* Filters the matching editors for the given resource type from the list of all available editors.<p>
*
* @param resourceType the resource type to filter
* @return a map of filtered editor configurations sorted asceding by the ranking for the current resource type, with the (Float) ranking as key
*/
private SortedMap filterEditorsForResourceType(String resourceType) {
SortedMap filteredEditors = new TreeMap();
Iterator i = m_editorConfigurations.iterator();
while (i.hasNext()) {
CmsWorkplaceEditorConfiguration currentConfig = (CmsWorkplaceEditorConfiguration)i.next();
if (currentConfig.matchesResourceType(resourceType)) {
float key = currentConfig.getRankingForResourceType(resourceType);
if (key >= 0) {
filteredEditors.put(new Float(key), currentConfig);
}
}
}
return filteredEditors;
}
/**
* Filters the preferred editor from the list of all available editors.<p>
*
* @param preferredEditor the preferred editor identification String
* @return the preferred editor configuration object or null, if none is found
*/
private CmsWorkplaceEditorConfiguration filterPreferredEditor(String preferredEditor) {
if (m_preferredEditors.size() == 0) {
Iterator i = m_editorConfigurations.iterator();
while (i.hasNext()) {
CmsWorkplaceEditorConfiguration currentConfig = (CmsWorkplaceEditorConfiguration)i.next();
m_preferredEditors.put(currentConfig.getEditorUri(), currentConfig);
}
}
return (CmsWorkplaceEditorConfiguration)m_preferredEditors.get(preferredEditor);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -