📄 cmspropertyadvanced.java
字号:
result.append("\">");
// build hidden input field for resource value
result.append("<input type=\"hidden\" name=\"");
result.append(PREFIX_RESOURCE);
result.append(propName);
result.append("\" id=\"");
result.append(PREFIX_RESOURCE);
result.append(propName);
result.append("\" value=\"");
result.append(CmsEncoder.escapeXml(valueResource));
result.append("\"></td>\n");
result.append("\t<td class=\"textcenter\">");
if (!"".equals(propValue)) {
// show checkbox only for non empty value
String prefix = PREFIX_RESOURCE;
if (structurePanelName.equals(activeTab)) {
prefix = PREFIX_STRUCTURE;
}
result.append("<input type=\"checkbox\" name=\"");
result.append(PREFIX_USEPROPERTY);
result.append(propName);
result.append("\" id=\"");
result.append(PREFIX_USEPROPERTY);
result.append(propName);
result.append("\" value=\"true\"");
result.append(disabled);
result.append(" checked=\"checked\" onClick=\"toggleDelete('");
result.append(propName);
result.append("', '");
result.append(prefix);
result.append("', '");
result.append(activeTab);
result.append("');\">");
} else {
result.append(" ");
}
result.append("</td>\n");
result.append("</tr>\n");
return result;
}
/**
* Creates a list of String arrays containing the property names and values.<p>
*
* The list items consist of the following Strings:
* <ol>
* <li>The name of the property</li>
* <li>The currently active property value</li>
* <li>The value of the structure</li>
* <li>The value of the resource</li>
* </ol>
*
* @return the list of property values in display order
*/
private List getPropertyValues() {
// check if list has to be generated
if (m_propertyValues == null) {
// get currently active tab
String activeTab = getActiveTabName();
String structurePanelName = key(Messages.GUI_PROPERTIES_INDIVIDUAL_0);
// get all properties for the resource
List propertyDef = new ArrayList();
try {
propertyDef = getCms().readAllPropertyDefinitions();
} catch (CmsException e) {
// should usually never happen
if (LOG.isInfoEnabled()) {
LOG.info(e.getLocalizedMessage());
}
}
m_propertyValues = new ArrayList(propertyDef.size());
// get all used properties for the resource
Map activeProperties = null;
if (!m_tabSwitched) {
try {
activeProperties = CmsPropertyAdvanced.getPropertyMap(getCms().readPropertyObjects(
getParamResource(),
false));
} catch (CmsException e) {
// should usually never happen
if (LOG.isInfoEnabled()) {
LOG.info(e.getLocalizedMessage());
}
activeProperties = new HashMap();
}
}
// iterate over all possible properties for the resource
Iterator i = propertyDef.iterator();
while (i.hasNext()) {
CmsPropertyDefinition currentPropertyDef = (CmsPropertyDefinition)i.next();
String propName = CmsEncoder.escapeXml(currentPropertyDef.getName());
String propValue = "";
String valueStructure = "";
String valueResource = "";
if (m_tabSwitched) {
// switched the tab, get values from hidden fields
if (structurePanelName.equals(activeTab)) {
// structure form
propValue = getJsp().getRequest().getParameter(PREFIX_STRUCTURE + propName);
valueStructure = getJsp().getRequest().getParameter(PREFIX_STRUCTURE + propName);
if (!isEditable()) {
// values from disabled fields are not posted
valueResource = getJsp().getRequest().getParameter(PREFIX_RESOURCE + propName);
} else {
valueResource = getJsp().getRequest().getParameter(PREFIX_VALUE + propName);
}
} else {
// resource form
propValue = getJsp().getRequest().getParameter(PREFIX_RESOURCE + propName);
if (!isEditable()) {
// values from disabled fields are not posted
valueStructure = getJsp().getRequest().getParameter(PREFIX_STRUCTURE + propName);
} else {
valueStructure = getJsp().getRequest().getParameter(PREFIX_VALUE + propName);
}
valueResource = getJsp().getRequest().getParameter(PREFIX_RESOURCE + propName);
if (valueStructure != null
&& !"".equals(valueStructure.trim())
&& valueStructure.equals(valueResource)) {
// the resource value was shown in the input field, set structure value to empty String
valueStructure = "";
}
}
} else {
// initial call of edit form, get property values from database
CmsProperty currentProperty = (CmsProperty)activeProperties.get(propName);
if (currentProperty == null) {
currentProperty = new CmsProperty();
}
if (structurePanelName.equals(activeTab)) {
// show the structure properties
propValue = currentProperty.getStructureValue();
} else {
// show the resource properties
propValue = currentProperty.getResourceValue();
}
valueStructure = currentProperty.getStructureValue();
valueResource = currentProperty.getResourceValue();
// check values for null
if (propValue == null) {
propValue = "";
}
if (valueStructure == null) {
valueStructure = "";
}
if (valueResource == null) {
valueResource = "";
}
}
// remove unnecessary blanks from values
propValue = propValue.trim();
valueStructure = valueStructure.trim();
valueResource = valueResource.trim();
String[] property = new String[] {propName, propValue, valueStructure, valueResource};
m_propertyValues.add(property);
}
}
// return the filled list
return m_propertyValues;
}
/**
* Performs the definition of a new property.<p>
*
* @return true, if the new property was created, otherwise false
* @throws CmsException if creation is not successful
*/
private boolean performDefineOperation() throws CmsException {
boolean useTempfileProject = Boolean.valueOf(getParamUsetempfileproject()).booleanValue();
try {
if (useTempfileProject) {
switchToTempProject();
}
String newProperty = getParamNewproperty();
if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(newProperty)) {
getCms().createPropertyDefinition(newProperty);
return true;
} else {
throw new CmsException(Messages.get().container(Messages.ERR_INVALID_PROP_0));
}
} finally {
if (useTempfileProject) {
switchToCurrentProject();
}
}
}
/**
* Performs the editing of the resources properties.<p>
*
* @param request the HttpServletRequest
* @return true, if the properties were successfully changed, otherwise false
* @throws CmsException if editing is not successful
*/
private boolean performDialogOperation(HttpServletRequest request) throws CmsException {
List propertyDef = getCms().readAllPropertyDefinitions();
boolean useTempfileProject = Boolean.valueOf(getParamUsetempfileproject()).booleanValue();
try {
if (useTempfileProject) {
switchToTempProject();
}
Map activeProperties = getPropertyMap(getCms().readPropertyObjects(getParamResource(), false));
String activeTab = getActiveTabName();
List propertiesToWrite = new ArrayList();
// check all property definitions of the resource for new values
Iterator i = propertyDef.iterator();
while (i.hasNext()) {
CmsPropertyDefinition curPropDef = (CmsPropertyDefinition)i.next();
String propName = CmsEncoder.escapeXml(curPropDef.getName());
String valueStructure = null;
String valueResource = null;
if (key(Messages.GUI_PROPERTIES_INDIVIDUAL_0).equals(activeTab)) {
// get parameters from the structure tab
valueStructure = request.getParameter(PREFIX_VALUE + propName);
valueResource = request.getParameter(PREFIX_RESOURCE + propName);
if (valueStructure != null
&& !"".equals(valueStructure.trim())
&& valueStructure.equals(valueResource)) {
// the resource value was shown/entered in input field, set structure value to empty String
valueStructure = "";
}
} else {
// get parameters from the resource tab
valueStructure = request.getParameter(PREFIX_STRUCTURE + propName);
valueResource = request.getParameter(PREFIX_VALUE + propName);
}
// check values for blanks and null
if (valueStructure != null) {
valueStructure = valueStructure.trim();
}
if (valueResource != null) {
valueResource = valueResource.trim();
}
// create new CmsProperty object to store
CmsProperty newProperty = new CmsProperty();
newProperty.setName(curPropDef.getName());
newProperty.setStructureValue(valueStructure);
newProperty.setResourceValue(valueResource);
// get the old property values
CmsProperty oldProperty = (CmsProperty)activeProperties.get(curPropDef.getName());
if (oldProperty == null) {
// property was not set, create new empty property object
oldProperty = new CmsProperty();
oldProperty.setName(curPropDef.getName());
}
boolean writeStructureValue = false;
boolean writeResourceValue = false;
String oldValue = oldProperty.getStructureValue();
String newValue = newProperty.getStructureValue();
// write the structure value if the existing structure value is not null and we want to delete the structure value
writeStructureValue = (oldValue != null && newProperty.isDeleteStructureValue());
// or if we want to write a value which is neither the delete value or an empty value
writeStructureValue |= !newValue.equals(oldValue)
&& !"".equalsIgnoreCase(newValue)
&& !CmsProperty.DELETE_VALUE.equalsIgnoreCase(newValue);
// set the structure value explicitly to null to leave it as is in the database
if (!writeStructureValue) {
newProperty.setStructureValue(null);
}
oldValue = oldProperty.getResourceValue();
newValue = newProperty.getResourceValue();
// write the resource value if the existing resource value is not null and we want to delete the resource value
writeResourceValue = (oldValue != null && newProperty.isDeleteResourceValue());
// or if we want to write a value which is neither the delete value or an empty value
writeResourceValue |= !newValue.equals(oldValue)
&& !"".equalsIgnoreCase(newValue)
&& !CmsProperty.DELETE_VALUE.equalsIgnoreCase(newValue);
// set the resource value explicitly to null to leave it as is in the database
if (!writeResourceValue) {
newProperty.setResourceValue(null);
}
if (writeStructureValue || writeResourceValue) {
// add property to list only if property values have changed
propertiesToWrite.add(newProperty);
}
}
if (propertiesToWrite.size() > 0) {
// lock resource if autolock is enabled
checkLock(getParamResource());
//write the new property values
getCms().writePropertyObjects(getParamResource(), propertiesToWrite);
}
} finally {
if (useTempfileProject) {
switchToCurrentProject();
}
}
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -