All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.ckeditor.CKEditorConfig Maven / Gradle / Ivy
/*
Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
For licensing, see http://ckeditor.com/license
*/
package com.ckeditor;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* CKEditor configuration class.
*/
public class CKEditorConfig implements Cloneable {
private Map config;
/**
* Default constructor.
*/
public CKEditorConfig() {
config = new HashMap();
}
/**
* Adds a Number parameter to the configuration.
* Usage:
* config.addConfigValue("width", 100);
* config.addConfigValue("dialog_backgroundCoverOpacity", 0.7);
* @param key configuration parameter key
* @param value configuration parameter value.
*/
public void addConfigValue(final String key, final Number value) {
config.put(key, value);
}
/**
* Adds a String parameter to the configuration.
* Usage:
* config.addConfigValue("baseHref", "http://www.example.com/path/");
* config.addConfigValue("toolbar", "[[ 'Source', '-', 'Bold', 'Italic' ]]");
* @param key configuration parameter key
* @param value configuration parameter value.
*/
public void addConfigValue(final String key, final String value) {
config.put(key, value);
}
/**
* Adds a Map parameter to the configuration.
* Usage:
* Map<String, Object> map = new HashMap<String, Object>();
* map.put("element", "span");
* map.put("styles", "{'background-color' : '#(color)'}");
* config.addConfigValue("colorButton_backStyle", map);
* @param key configuration parameter key
* @param value configuration parameter value.
*/
public void addConfigValue(final String key,
final Map value) {
config.put(key, value);
}
/**
* Adds a List parameter to the configuration.
* Usage:
*
List<List<String>> list = new ArrayList<List<String>>();
List<String> subList = new ArrayList<String>();
subList.add("Source");
subList.add("-");
subList.add("Bold");
subList.add("Italic");
list.add(subList);
config.addConfigValue("toolbar", list);
* @param key configuration parameter key
* @param value configuration parameter value.
*/
public void addConfigValue(final String key, final List value) {
config.put(key, value);
}
/**
* Adds a Boolean parameter to the configuration.
* Usage:
* config.addConfigValue("autoUpdateElement", true);
* @param key configuration parameter key
* @param value configuration parameter value.
*/
public void addConfigValue(final String key, final Boolean value) {
config.put(key, value);
}
/**
* Gets a configuration value by key.
* @param key configuration parameter key
* @return configuration parameter value.
*/
Object getConfigValue(final String key) {
return config.get(key);
}
/**
* @return all configuration values.
*/
Map getConfigValues() {
return config;
}
/**
* Removes a configuration value by key.
* Usage:
* config.removeConfigValue("toolbar");
* @param key configuration parameter key.
*/
public void removeConfigValue(final String key) {
config.remove(key);
}
/**
* Configure settings. Merge configuration and event handlers.
* @return setting configuration.
* @param eventHandler events
*/
CKEditorConfig configSettings(final EventHandler eventHandler) {
try {
CKEditorConfig cfg = (CKEditorConfig) this.clone();
if (eventHandler != null) {
for (String eventName : eventHandler.events.keySet()) {
Set set = eventHandler.events.get(eventName);
if (set.isEmpty()) {
continue;
} else if (set.size() == 1) {
Map hm = new HashMap();
for (String code : set) {
hm.put(eventName, "@@" + code);
}
cfg.addConfigValue("on", hm);
} else {
Map hm = new HashMap();
StringBuilder sb = new StringBuilder("@@function (ev){");
for (String code : set) {
sb.append("(");
sb.append(code);
sb.append(")(ev);");
}
sb.append("}");
hm.put(eventName, sb.toString());
cfg.addConfigValue("on", hm);
}
}
}
return cfg;
} catch (CloneNotSupportedException e) {
return null;
}
}
/**
* Checks if configuration is empty.
* @return true if the configuration is empty.
*/
public boolean isEmpty() {
return config.isEmpty();
}
/**
* Override.
*/
protected Object clone() throws CloneNotSupportedException {
CKEditorConfig cfg = (CKEditorConfig) super.clone();
cfg.config = new HashMap(this.config);
return cfg;
}
}