cmsproperty.java
来自「找了很久才找到到源代码」· Java 代码 · 共 1,248 行 · 第 1/4 页
JAVA
1,248 行
* Sets the value of this property attached to the resource record.<p>
*
* @param resourceValue the value of this property attached to the resource record
*/
public void setResourceValue(String resourceValue) {
checkFrozen();
m_resourceValue = resourceValue;
m_resourceValueList = null;
}
/**
* Sets the value of this property attached to the resource record from the given list of Strings.<p>
*
* The value will be created from the individual values of the given list, which are appended
* using the <code>|</code> char as delimiter.<p>
*
* @param valueList the list of value (Strings) to attach to the resource record
*/
public void setResourceValueList(List valueList) {
checkFrozen();
if (valueList != null) {
m_resourceValueList = new ArrayList(valueList);
m_resourceValueList = Collections.unmodifiableList(m_resourceValueList);
m_resourceValue = createValueFromList(m_resourceValueList);
} else {
m_resourceValueList = null;
m_resourceValue = null;
}
}
/**
* Sets the value of this property attached to the resource record from the given map of Strings.<p>
*
* The value will be created from the individual values of the given map, which are appended
* using the <code>|</code> char as delimiter, the map keys and values are separated by a <code>=</code>.<p>
*
* @param valueMap the map of key/value (Strings) to attach to the resource record
*/
public void setResourceValueMap(Map valueMap) {
checkFrozen();
if (valueMap != null) {
m_resourceValueMap = new HashMap(valueMap);
m_resourceValueMap = Collections.unmodifiableMap(m_resourceValueMap);
m_resourceValue = createValueFromMap(m_resourceValueMap);
} else {
m_resourceValueMap = null;
m_resourceValue = null;
}
}
/**
* Sets the value of this property attached to the structure record.<p>
*
* @param structureValue the value of this property attached to the structure record
*/
public void setStructureValue(String structureValue) {
checkFrozen();
m_structureValue = structureValue;
m_structureValueList = null;
}
/**
* Sets the value of this property attached to the structure record from the given list of Strings.<p>
*
* The value will be created from the individual values of the given list, which are appended
* using the <code>|</code> char as delimiter.<p>
*
* @param valueList the list of value (Strings) to attach to the structure record
*/
public void setStructureValueList(List valueList) {
checkFrozen();
if (valueList != null) {
m_structureValueList = new ArrayList(valueList);
m_structureValueList = Collections.unmodifiableList(m_structureValueList);
m_structureValue = createValueFromList(m_structureValueList);
} else {
m_structureValueList = null;
m_structureValue = null;
}
}
/**
* Sets the value of this property attached to the structure record from the given map of Strings.<p>
*
* The value will be created from the individual values of the given map, which are appended
* using the <code>|</code> char as delimiter, the map keys and values are separated by a <code>=</code>.<p>
*
* @param valueMap the map of key/value (Strings) to attach to the structure record
*/
public void setStructureValueMap(Map valueMap) {
checkFrozen();
if (valueMap != null) {
m_structureValueMap = new HashMap(valueMap);
m_structureValueMap = Collections.unmodifiableMap(m_structureValueMap);
m_structureValue = createValueFromMap(m_structureValueMap);
} else {
m_structureValueMap = null;
m_structureValue = null;
}
}
/**
* Sets the value of this property as either shared or
* individual value.<p>
*
* If the given type equals {@link CmsProperty#TYPE_SHARED} then
* the value is set as a shared (resource) value, otherwise it
* is set as individual (structure) value.<p>
*
* @param value the value to set
* @param type the value type to set
*/
public void setValue(String value, String type) {
checkFrozen();
setAutoCreatePropertyDefinition(true);
if (TYPE_SHARED.equalsIgnoreCase(type)) {
// set the provided value as shared (resource) value
setResourceValue(value);
} else {
// set the provided value as individual (structure) value
setStructureValue(value);
}
}
/**
* Returns a string representation of this property object.<p>
*
* @see java.lang.Object#toString()
*/
public String toString() {
StringBuffer strBuf = new StringBuffer();
strBuf.append("[").append(getClass().getName()).append(": ");
strBuf.append("name: '").append(m_name).append("'");
strBuf.append(", value: '").append(getValue()).append("'");
strBuf.append(", structure value: '").append(m_structureValue).append("'");
strBuf.append(", resource value: '").append(m_resourceValue).append("'");
strBuf.append(", frozen: ").append(m_frozen);
strBuf.append("]");
return strBuf.toString();
}
/**
* Checks if this property is frozen, that is read only.<p>
*/
private void checkFrozen() {
if (m_frozen) {
throw new CmsRuntimeException(Messages.get().container(Messages.ERR_PROPERTY_FROZEN_1, toString()));
}
}
/**
* Returns the list value representation for the given String.<p>
*
* The given value is split along the <code>|</code> char.<p>
*
* @param value the value to create the list representation for
*
* @return the list value representation for the given String
*/
private List createListFromValue(String value) {
if (value == null) {
return null;
}
List result = CmsStringUtil.splitAsList(value, VALUE_LIST_DELIMITER);
if (value.indexOf(VALUE_LIST_DELIMITER_REPLACEMENT) != -1) {
List tempList = new ArrayList(result.size());
Iterator i = result.iterator();
while (i.hasNext()) {
String item = (String)i.next();
tempList.add(rebuildDelimiter(item, VALUE_LIST_DELIMITER, VALUE_LIST_DELIMITER_REPLACEMENT));
}
result = tempList;
}
return result;
}
/**
* Returns the map value representation for the given String.<p>
*
* The given value is split along the <code>|</code> char, the map keys and values are separated by a <code>=</code>.<p>
*
* @param value the value to create the map representation for
*
* @return the map value representation for the given String
*/
private Map createMapFromValue(String value) {
if (value == null) {
return null;
}
List entries = createListFromValue(value);
Iterator i = entries.iterator();
Map result = new HashMap(entries.size());
boolean rebuildDelimiters = false;
if (value.indexOf(VALUE_MAP_DELIMITER_REPLACEMENT) != -1) {
rebuildDelimiters = true;
}
while (i.hasNext()) {
String entry = (String)i.next();
int index = entry.indexOf(VALUE_MAP_DELIMITER);
if (index != -1) {
String key = entry.substring(0, index);
String val = "";
if (index + 1 < entry.length()) {
val = entry.substring(index + 1);
}
if (CmsStringUtil.isNotEmpty(key)) {
if (rebuildDelimiters) {
key = rebuildDelimiter(key, VALUE_MAP_DELIMITER, VALUE_MAP_DELIMITER_REPLACEMENT);
val = rebuildDelimiter(val, VALUE_MAP_DELIMITER, VALUE_MAP_DELIMITER_REPLACEMENT);
}
result.put(key, val);
}
}
}
return result;
}
/**
* Returns the single String value representation for the given value list.<p>
*
* @param valueList the value list to create the single String value for
*
* @return the single String value representation for the given value list
*/
private String createValueFromList(List valueList) {
if (valueList == null) {
return null;
}
StringBuffer result = new StringBuffer(valueList.size() * 32);
Iterator i = valueList.iterator();
while (i.hasNext()) {
result.append(replaceDelimiter(i.next().toString(), VALUE_LIST_DELIMITER, VALUE_LIST_DELIMITER_REPLACEMENT));
if (i.hasNext()) {
result.append(VALUE_LIST_DELIMITER);
}
}
return result.toString();
}
/**
* Returns the single String value representation for the given value map.<p>
*
* @param valueMap the value map to create the single String value for
*
* @return the single String value representation for the given value map
*/
private String createValueFromMap(Map valueMap) {
if (valueMap == null) {
return null;
}
StringBuffer result = new StringBuffer(valueMap.size() * 32);
Iterator i = valueMap.entrySet().iterator();
while (i.hasNext()) {
Map.Entry entry = (Map.Entry)i.next();
String key = entry.getKey().toString();
String value = entry.getValue().toString();
key = replaceDelimiter(key, VALUE_LIST_DELIMITER, VALUE_LIST_DELIMITER_REPLACEMENT);
key = replaceDelimiter(key, VALUE_MAP_DELIMITER, VALUE_MAP_DELIMITER_REPLACEMENT);
value = replaceDelimiter(value, VALUE_LIST_DELIMITER, VALUE_LIST_DELIMITER_REPLACEMENT);
value = replaceDelimiter(value, VALUE_MAP_DELIMITER, VALUE_MAP_DELIMITER_REPLACEMENT);
result.append(key);
result.append(VALUE_MAP_DELIMITER);
result.append(value);
if (i.hasNext()) {
result.append(VALUE_LIST_DELIMITER);
}
}
return result.toString();
}
/**
* Rebuilds the given delimiter character from the replacement string.<p>
*
* @param value the string that is scanned
* @param delimiter the delimiter character to rebuild
* @param delimiterReplacement the replacement string for the delimiter character
* @return the substituted string
*/
private String rebuildDelimiter(String value, char delimiter, String delimiterReplacement) {
return CmsStringUtil.substitute(value, delimiterReplacement, String.valueOf(delimiter));
}
/**
* Replaces the given delimiter character with the replacement string.<p>
*
* @param value the string that is scanned
* @param delimiter the delimiter character to replace
* @param delimiterReplacement the replacement string for the delimiter character
* @return the substituted string
*/
private String replaceDelimiter(String value, char delimiter, String delimiterReplacement) {
return CmsStringUtil.substitute(value, String.valueOf(delimiter), delimiterReplacement);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?