📄 cmspropertytemplateone.java
字号:
// build navigation tree radio buttons
result.append(buildRadioButtons(CmsTemplateBean.PROPERTY_SHOW_NAVLEFT, ENABLE, null, editable));
// build navleft element search input
result.append(buildPropertySearchEntry(CmsTemplateBean.PROPERTY_NAVLEFT_ELEMENTURI, KEY_PREFIX
+ CmsTemplateBean.PROPERTY_NAVLEFT_ELEMENTURI, editable, messages));
// build side uri search input
result.append(buildPropertySearchEntry(CmsTemplateBean.PROPERTY_SIDE_URI, KEY_PREFIX
+ CmsTemplateBean.PROPERTY_SIDE_URI, editable, messages));
// build center layout selector
result.append(buildPropertySelectbox(
CmsTemplateContentListItem.DISPLAYAREA_CENTER,
CmsTemplateBean.PROPERTY_LAYOUT_CENTER,
KEY_PREFIX + CmsTemplateBean.PROPERTY_LAYOUT_CENTER,
editable));
// build right layout selector
result.append(buildPropertySelectbox(
CmsTemplateContentListItem.DISPLAYAREA_RIGHT,
CmsTemplateBean.PROPERTY_LAYOUT_RIGHT,
KEY_PREFIX + CmsTemplateBean.PROPERTY_LAYOUT_RIGHT,
editable));
// build configuration path search input
result.append(buildPropertySearchEntry(CmsTemplateBean.PROPERTY_CONFIGPATH, KEY_PREFIX
+ CmsTemplateBean.PROPERTY_CONFIGPATH, editable, messages));
result.append("</table>");
return result.toString();
}
/**
* Builds the JavaScript to set the property form values delayed.<p>
*
* The values of the properties are not inserted directly in the <input> tag,
* because there is a display issue when the property values are very long.
* This method creates JavaScript to set the property input field values delayed.
* On the JSP, the code which is created from this method has to be executed delayed after
* the creation of the html form, e.g. in the <body> tag with the attribute
* onload="window.setTimeout('doSet()',50);".<p>
*
* @return the JavaScript to set the property form values delayed
*/
public String buildSetFormValues() {
StringBuffer result = new StringBuffer(1024);
// loop over the default properties
for (int i = 0; i < DEFAULT_PROPERTIES.length; i++) {
String curProperty = DEFAULT_PROPERTIES[i];
// determine the shown value
String shownValue = "";
try {
shownValue = getCms().readPropertyObject(getParamResource(), curProperty, false).getValue();
} catch (CmsException e) {
e.printStackTrace();
}
if (!CmsStringUtil.isEmpty(shownValue)) {
// create the JS output for a single property if not empty
result.append("\tdocument.getElementById(\"");
result.append(PREFIX_VALUE);
result.append(curProperty);
result.append("\").value = \"");
result.append(CmsStringUtil.escapeJavaScript(shownValue));
result.append("\";\n");
}
}
return result.toString();
}
/**
* Returns the property value by searching all parent folders.<p>
*
* @param propertydef the property definition
*
* @return the property value by searching all parent folders
*/
public String getDefault(String propertydef) {
try {
String parentFolder = CmsResource.getParentFolder(getParamResource());
CmsProperty property = getCms().readPropertyObject(parentFolder, propertydef, true);
String propertyValue = property.getValue();
if (!CmsStringUtil.isEmpty(propertyValue)) {
return property.getValue();
}
} catch (CmsException e) {
if (LOG.isErrorEnabled()) {
LOG.error(e);
}
}
return "";
}
/**
* @see org.opencms.workplace.I_CmsDialogHandler#getDialogHandler()
*/
public String getDialogHandler() {
return CmsDialogSelector.DIALOG_PROPERTY;
}
/**
* @see org.opencms.workplace.I_CmsDialogHandler#getDialogUri(java.lang.String, CmsJspActionElement)
*/
public String getDialogUri(String resource, CmsJspActionElement jsp) {
try {
String templateOneDialog = MODULE_PATH + "dialogs/property.jsp";
boolean dialogPresent = jsp.getCmsObject().existsResource(templateOneDialog);
CmsResource res = jsp.getCmsObject().readResource(resource, CmsResourceFilter.ALL);
String template = jsp.getCmsObject().readPropertyObject(res, CmsPropertyDefinition.PROPERTY_TEMPLATE, true).getValue(
"");
if (!res.isFolder()
&& res.getTypeId() != CmsResourceTypeBinary.getStaticTypeId()
&& res.getTypeId() != CmsResourceTypePlain.getStaticTypeId()
&& res.getTypeId() != CmsResourceTypeImage.getStaticTypeId()) {
// file is no plain text, binary or image type, check "template" property
if (dialogPresent && TEMPLATE_ONE.equals(template)) {
// display special property dialog for files with "template one" as template
return templateOneDialog;
} else if (res.getTypeId() == CmsResourceTypeXmlPage.getStaticTypeId()) {
// show xmlpage property dialog for xmlpages not using "template one" as template
return PATH_WORKPLACE + "editors/dialogs/property.jsp";
}
}
if (dialogPresent
&& res.isFolder()
&& TEMPLATE_ONE.equals(template)
&& !res.getRootPath().startsWith(CmsResource.VFS_FOLDER_SYSTEM)) {
// display special property dialog also for folders but exclude the system folders
return templateOneDialog;
}
String resTypeName = OpenCms.getResourceManager().getResourceType(res.getTypeId()).getTypeName();
// get settings for resource type
CmsExplorerTypeSettings settings = getSettingsForType(resTypeName);
if (settings.isPropertiesEnabled()) {
// special properties for this type enabled, display customized dialog
return URI_PROPERTY_CUSTOM_DIALOG;
}
} catch (CmsException e) {
// should usually never happen
if (LOG.isErrorEnabled()) {
LOG.error(e);
}
}
return URI_PROPERTY_DIALOG;
}
/**
* 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
*/
protected boolean performEditOperation(HttpServletRequest request) throws CmsException {
boolean useTempfileProject = Boolean.valueOf(getParamUsetempfileproject()).booleanValue();
try {
if (useTempfileProject) {
switchToTempProject();
}
// loop over the default properties
for (int i = 0; i < DEFAULT_PROPERTIES.length; i++) {
String curProperty = DEFAULT_PROPERTIES[i];
String paramValue = request.getParameter(PREFIX_VALUE + curProperty);
String oldValue = request.getParameter(PREFIX_HIDDEN + curProperty);
writeProperty(curProperty, paramValue, oldValue);
}
// loop over all properties
for (int i = 0; i < ALL_PROPERTIES.length; i++) {
String curProperty = ALL_PROPERTIES[i];
String paramValue = request.getParameter(PREFIX_VALUE + curProperty);
String oldValue = request.getParameter(PREFIX_HIDDEN + curProperty);
writeProperty(curProperty, paramValue, oldValue);
}
// write the navigation properties
// get the navigation enabled parameter
String paramValue = request.getParameter("enablenav");
String oldValue = null;
if (Boolean.valueOf(paramValue).booleanValue()) {
// navigation enabled, update params
paramValue = request.getParameter("navpos");
if (!"-1".equals(paramValue)) {
// update the property only when it is different from "-1" (meaning no change)
oldValue = request.getParameter(PREFIX_HIDDEN + CmsPropertyDefinition.PROPERTY_NAVPOS);
writeProperty(CmsPropertyDefinition.PROPERTY_NAVPOS, paramValue, oldValue);
}
paramValue = request.getParameter(PREFIX_VALUE + CmsPropertyDefinition.PROPERTY_NAVTEXT);
oldValue = request.getParameter(PREFIX_HIDDEN + CmsPropertyDefinition.PROPERTY_NAVTEXT);
writeProperty(CmsPropertyDefinition.PROPERTY_NAVTEXT, paramValue, oldValue);
} else {
// navigation disabled, delete property values
writeProperty(CmsPropertyDefinition.PROPERTY_NAVPOS, null, null);
writeProperty(CmsPropertyDefinition.PROPERTY_NAVTEXT, null, null);
}
} finally {
if (useTempfileProject) {
switchToCurrentProject();
}
}
return true;
}
/**
* Builds the html for a single radio input property.<p>
*
* @param propertyName the name of the property
* @param propertyValue the value of the radio
* @param propertyText the nice name of the property
* @param JSToggleFunction the javascript toggle function or null
* @param editable indicates if the properties are editable
*
* @return the html for a single radio input property
*/
private StringBuffer buildPropertyRadioEntry(
String propertyName,
String propertyValue,
String propertyText,
String JSToggleFunction,
boolean editable) {
String disabled = "";
if (!editable) {
disabled = " disabled=\"disabled\"";
}
StringBuffer result = new StringBuffer(256);
// create "disabled" attribute if properties are not editable
// to do
String checked = "";
if (getActiveProperties().containsKey(propertyName)) {
// the property is used, so create text field with checkbox and hidden field
CmsProperty currentProperty = (CmsProperty)getActiveProperties().get(propertyName);
String propValue = currentProperty.getValue();
if (propValue != null) {
propValue = propValue.trim();
}
propValue = CmsEncoder.escapeXml(propValue);
if (propertyValue.equals(propValue)) {
checked = " checked=\"checked\"";
}
} else {
// check radio if param value is the default
if (propertyValue.equals(PARAM_DEFAULT)) {
checked = " checked=\"checked\"";
}
}
// javascript onclick event
String onclick = "";
if (JSToggleFunction != null) {
onclick = "onclick=\"" + JSToggleFunction + "();\" ";
}
result.append("<input ");
result.append(onclick);
result.append("type=\"radio\" ");
result.append("name=\"");
result.append(PREFIX_VALUE);
result.append(propertyName);
result.append("\" value=\"");
result.append(propertyValue);
result.append("\"");
result.append(checked);
result.append(disabled);
result.append(">");
result.append(" ");
result.append(propertyText);
return result;
}
/**
* Builds the html for a single search text input property row.<p>
*
* @param propertyName the name of the property
* @param propertyTitle the nice name of the property
* @param editable indicates if the properties are editable
* @param messages the messages to use for localization
*
* @return the html for a single text input property row
*/
private StringBuffer buildPropertySearchEntry(
String propertyName,
String propertyTitle,
boolean editable,
CmsMessages messages) {
StringBuffer result = new StringBuffer(256);
result.append(buildTableRowStart(key(propertyTitle)));
String disabled = "";
if (!editable) {
disabled = " disabled=\"disabled\"";
}
String propValue = "";
// the property is used, so create text field with checkbox and hidden field
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -