📄 cmssecure.java
字号:
String uri = "";
String serverPrefix = "";
String vfsName = CmsLinkManager.getAbsoluteUri(getParamResource(), cms.getRequestContext().getUri());
String secureResource = "";
try {
if (resourceIsFolder()) {
vfsName = vfsName.concat("/");
}
secureResource = getCms().readPropertyObject(
getParamResource(),
CmsPropertyDefinition.PROPERTY_SECURE,
true).getValue();
} catch (CmsException e) {
if (LOG.isInfoEnabled()) {
LOG.info(e.getLocalizedMessage());
}
}
CmsSite currentSite = CmsSiteManager.getCurrentSite(getCms());
CmsProject currentProject = cms.getRequestContext().currentProject();
try {
cms.getRequestContext().setCurrentProject(cms.readProject(CmsProject.ONLINE_PROJECT_ID));
uri = OpenCms.getLinkManager().substituteLink(cms, getParamResource(), currentSite.getSiteRoot());
} catch (CmsException e) {
if (LOG.isErrorEnabled()) {
LOG.error(e.getLocalizedMessage());
}
} finally {
cms.getRequestContext().setCurrentProject(currentProject);
}
if (currentSite.equals(OpenCms.getSiteManager().getDefaultSite())) {
serverPrefix = OpenCms.getSiteManager().getWorkplaceServer();
} else {
if (Boolean.valueOf(secureResource).booleanValue() && currentSite.hasSecureServer()) {
serverPrefix = currentSite.getSecureUrl();
} else {
serverPrefix = currentSite.getUrl();
}
}
if (!uri.startsWith(serverPrefix)) {
uri = serverPrefix + uri;
}
return uri;
}
/**
* Returns true if the export user has read permission on a specified resource.<p>
*
* @return true, if the export user has the permission to read the resource
*/
public boolean exportUserHasReadPermission() {
String vfsName = getParamResource();
CmsObject cms = getCms();
try {
// static export must always be checked with the export users permissions,
// not the current users permissions
CmsObject exportCms = OpenCms.initCmsObject(OpenCms.getDefaultUsers().getUserExport());
exportCms.getRequestContext().setSiteRoot(getCms().getRequestContext().getSiteRoot());
// let's look up if the export user has the permission to read
return exportCms.hasPermissions(cms.readResource(vfsName, CmsResourceFilter.IGNORE_EXPIRATION), CmsPermissionSet.ACCESS_READ);
} catch (CmsException e) {
// ignore this exception
}
return false;
}
/**
* Returns value of the the intern property of the resource.
*
* @return the value of the intern property of the resource
*/
public String readInternProp() {
boolean internProp = false;
try {
internProp = getCms().readResource(getParamResource(), CmsResourceFilter.IGNORE_EXPIRATION).isInternal();
} catch (CmsException e) {
if (LOG.isInfoEnabled()) {
LOG.info(e.getLocalizedMessage());
}
}
return String.valueOf(internProp);
}
/**
* Returns value of the property of the resource.
*
* @param propertyName the name of the property to read
* @return the value of the secure property of the resource
*/
public String readProperty(String propertyName) {
String propVal = null;
try {
propVal = getCms().readPropertyObject(getParamResource(), propertyName, false).getValue();
} catch (CmsException e) {
if (LOG.isInfoEnabled()) {
LOG.info(e.getLocalizedMessage());
}
}
if (CmsStringUtil.isEmpty(propVal)) {
propVal = "";
}
return propVal;
}
/**
* returns if the resource to be changed is a folder.
* @return true if the resource is a folder
* @throws CmsException if the reading of the resource fails
*/
public boolean resourceIsFolder() throws CmsException {
return getCms().readResource(getParamResource(), CmsResourceFilter.IGNORE_EXPIRATION).isFolder();
}
/**
* Sets the value of the export parameter.<p>
*
* @param value for the export parameter
*/
public void setParamExport(String value) {
m_paramExport = value;
}
/**
* Sets the value of the exportname parameter.<p>
*
* @param value for the exportname parameter
*/
public void setParamExportname(String value) {
m_paramExportname = value;
}
/**
* Sets the value of the intern parameter.<p>
*
* @param value for the intern parameter
*/
public void setParamIntern(String value) {
m_paramIntern = value;
}
/**
* Sets the value of the secure parameter.<p>
*
* @param value for the secure parameter
*/
public void setParamSecure(String value) {
m_paramSecure = value;
}
/**
* Determines whether to show the export settings dialog depending on the users settings.<p>
*
* @return true if dialogs should be shown, otherwise false
*/
public boolean showExportSettings() {
return getSettings().getUserSettings().getDialogShowExportSettings();
}
/**
* @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 the resource properties
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_CHSECEXP);
} else if (DIALOG_CANCEL.equals(getParamAction())) {
setAction(ACTION_CANCEL);
} else {
setAction(ACTION_DEFAULT);
// build title for chnav dialog
setParamTitle(key(Messages.GUI_SECURE_EXPORT_RESOURCE_1, new Object[] {CmsResource.getName(getParamResource())}));
}
}
/**
* Writes a property value for a resource.<p>
*
* @param propertyName the name of the property
* @param propertyValue the new value of the property
* @throws CmsException if something goes wrong
*/
protected void writeProperty(String propertyName, String propertyValue) throws CmsException {
if (CmsStringUtil.isEmpty(propertyValue)) {
propertyValue = CmsProperty.DELETE_VALUE;
}
CmsProperty newProp = new CmsProperty();
newProp.setName(propertyName);
CmsProperty oldProp = getCms().readPropertyObject(getParamResource(), propertyName, false);
if (oldProp.isNullProperty()) {
// property value was not already set
if (OpenCms.getWorkplaceManager().isDefaultPropertiesOnStructure()) {
newProp.setStructureValue(propertyValue);
} else {
newProp.setResourceValue(propertyValue);
}
} else {
if (oldProp.getStructureValue() != null) {
newProp.setStructureValue(propertyValue);
newProp.setResourceValue(oldProp.getResourceValue());
} else {
newProp.setResourceValue(propertyValue);
}
}
newProp.setAutoCreatePropertyDefinition(true);
String oldStructureValue = oldProp.getStructureValue();
String newStructureValue = newProp.getStructureValue();
if (CmsStringUtil.isEmpty(oldStructureValue)) {
oldStructureValue = CmsProperty.DELETE_VALUE;
}
if (CmsStringUtil.isEmpty(newStructureValue)) {
newStructureValue = CmsProperty.DELETE_VALUE;
}
String oldResourceValue = oldProp.getResourceValue();
String newResourceValue = newProp.getResourceValue();
if (CmsStringUtil.isEmpty(oldResourceValue)) {
oldResourceValue = CmsProperty.DELETE_VALUE;
}
if (CmsStringUtil.isEmpty(newResourceValue)) {
newResourceValue = CmsProperty.DELETE_VALUE;
}
// change property only if it has been changed
if (!oldResourceValue.equals(newResourceValue) || !oldStructureValue.equals(newStructureValue)) {
getCms().writePropertyObject(getParamResource(), newProp);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -