📄 cmschnav.java
字号:
/**
* Performs the navigation change.<p>
*
* @throws JspException if including a JSP subelement is not successful
*/
public void actionChangeNav() throws JspException {
// save initialized instance of this class in request attribute for included sub-elements
getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this);
// get request parameters
String filename = getParamResource();
// do not use #getParamNavText since it is decoded, see CmsWorkplace#fillParamValues(HttpServletRequest)
String newText = getJsp().getRequest().getParameter(PARAM_NAVTEXT);
String selectedPosString = getParamNavpos();
try {
// lock resource if autolock is enabled
checkLock(getParamResource());
// save the new NavText if not null
if (newText != null) {
CmsProperty newNavText = new CmsProperty();
newNavText.setName(CmsPropertyDefinition.PROPERTY_NAVTEXT);
CmsProperty oldNavText = getCms().readPropertyObject(
filename,
CmsPropertyDefinition.PROPERTY_NAVTEXT,
false);
if (oldNavText.isNullProperty()) {
// property value was not already set
if (OpenCms.getWorkplaceManager().isDefaultPropertiesOnStructure()) {
newNavText.setStructureValue(newText);
} else {
newNavText.setResourceValue(newText);
}
} else {
if (oldNavText.getStructureValue() != null) {
newNavText.setStructureValue(newText);
newNavText.setResourceValue(oldNavText.getResourceValue());
} else {
newNavText.setResourceValue(newText);
}
}
String oldStructureValue = oldNavText.getStructureValue();
String newStructureValue = newNavText.getStructureValue();
if (CmsStringUtil.isEmpty(oldStructureValue)) {
oldStructureValue = CmsProperty.DELETE_VALUE;
}
if (CmsStringUtil.isEmpty(newStructureValue)) {
newStructureValue = CmsProperty.DELETE_VALUE;
}
String oldResourceValue = oldNavText.getResourceValue();
String newResourceValue = newNavText.getResourceValue();
if (CmsStringUtil.isEmpty(oldResourceValue)) {
oldResourceValue = CmsProperty.DELETE_VALUE;
}
if (CmsStringUtil.isEmpty(newResourceValue)) {
newResourceValue = CmsProperty.DELETE_VALUE;
}
// change nav text only if it has been changed
if (!oldResourceValue.equals(newResourceValue) || !oldStructureValue.equals(newStructureValue)) {
getCms().writePropertyObject(getParamResource(), newNavText);
}
}
// determine the selected position
float selectedPos = -1;
try {
selectedPos = Float.parseFloat(selectedPosString);
} catch (Exception e) {
// can usually be ignored
if (LOG.isInfoEnabled()) {
LOG.info(e.getLocalizedMessage());
}
}
// only update the position if a change is requested
if (selectedPos != -1) {
CmsProperty newNavPos = new CmsProperty();
newNavPos.setName(CmsPropertyDefinition.PROPERTY_NAVPOS);
CmsProperty oldNavPos = getCms().readPropertyObject(
filename,
CmsPropertyDefinition.PROPERTY_NAVPOS,
false);
if (oldNavPos.isNullProperty()) {
// property value was not already set
if (OpenCms.getWorkplaceManager().isDefaultPropertiesOnStructure()) {
newNavPos.setStructureValue(selectedPosString);
} else {
newNavPos.setResourceValue(selectedPosString);
}
} else {
if (oldNavPos.getStructureValue() != null) {
newNavPos.setStructureValue(selectedPosString);
newNavPos.setResourceValue(oldNavPos.getResourceValue());
} else {
newNavPos.setResourceValue(selectedPosString);
}
}
getCms().writePropertyObject(filename, newNavPos);
}
} catch (Throwable e) {
// error during chnav, show error dialog
includeErrorpage(this, e);
}
// chnav operation was successful, return to workplace
actionCloseDialog();
}
/**
* Builds the HTML for the select box of the navigation position.<p>
*
* @return the HTML for a navigation position select box
*/
public String buildNavPosSelector() {
return buildNavPosSelector(getCms(), getParamResource(), null, getMessages());
}
/**
* Returns the escaped NavText property value of the current resource.<p>
*
* @return the NavText property value of the current resource
*/
public String getCurrentNavText() {
try {
String navText = getCms().readPropertyObject(
getParamResource(),
CmsPropertyDefinition.PROPERTY_NAVTEXT,
false).getValue();
if (navText == null) {
navText = "";
}
return CmsEncoder.escapeXml(navText);
} catch (CmsException e) {
// can usually be ignored
if (LOG.isInfoEnabled()) {
LOG.info(e.getLocalizedMessage());
}
return "";
}
}
/**
* Returns the value of the navigation position parameter,
* or null if this parameter was not provided.<p>
*
* The navigation position parameter defines the new value for
* the NavPos property.<p>
*
* @return the value of the target parameter
*/
public String getParamNavpos() {
return m_paramNavpos;
}
/**
* Returns the value of the navigation text parameter,
* or null if this parameter was not provided.<p>
*
* The navigation text parameter defines the new value for
* the NavText property.<p>
*
* @return the value of the target parameter
*/
public String getParamNavtext() {
return m_paramNavtext;
}
/**
* Sets the value of the navigation position parameter.<p>
*
* @param value the value to set
*/
public void setParamNavpos(String value) {
m_paramNavpos = value;
}
/**
* Sets the value of the navigation text parameter.<p>
*
* @param value the value to set
*/
public void setParamNavtext(String value) {
m_paramNavtext = value;
}
/**
* @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
*/
protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) {
// fill the parameter values in the get/set methods
fillParamValues(request);
// check the required permissions to change navigation of the resource
if (!checkResourcePermissions(CmsPermissionSet.ACCESS_WRITE, false)) {
// no write permissions for the resource, set cancel action to close dialog
setParamAction(DIALOG_CANCEL);
}
// set the dialog type
setParamDialogtype(DIALOG_TYPE);
// set the action for the JSP switch
if (DIALOG_TYPE.equals(getParamAction())) {
setAction(ACTION_CHNAV);
} else if (DIALOG_LOCKS_CONFIRMED.equals(getParamAction())) {
setAction(ACTION_LOCKS_CONFIRMED);
} else if (DIALOG_CANCEL.equals(getParamAction())) {
setAction(ACTION_CANCEL);
} else {
setAction(ACTION_DEFAULT);
// build title for chnav dialog
setParamTitle(key(Messages.GUI_CHNAV_1, new Object[] {CmsResource.getName(getParamResource())}));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -