/** * Writes a property value for a resource, if the value was changed. * * <p> * * @param res the resource to write the property to * @param propName the name of the property definition * @param propValue the new value of the property * @param currentProperty the old property object * @throws CmsException if something goes wrong */ protected void writeProperty( CmsResource res, String propName, String propValue, CmsProperty currentProperty) throws CmsException { // check if current property is not the null property if (currentProperty.isNullProperty()) { // create new property object currentProperty = new CmsProperty(); currentProperty.setName(propName); } if (CmsStringUtil.isEmptyOrWhitespaceOnly(propValue)) { // parameter is empty, determine the value to delete boolean writeProperty = false; if (currentProperty.getStructureValue() != null) { currentProperty.setStructureValue(CmsProperty.DELETE_VALUE); currentProperty.setResourceValue(null); writeProperty = true; } else if (currentProperty.getResourceValue() != null) { currentProperty.setResourceValue(CmsProperty.DELETE_VALUE); currentProperty.setStructureValue(null); writeProperty = true; } if (writeProperty) { // write the updated property object getCms().writePropertyObject(getCms().getSitePath(res), currentProperty); } } else { // parameter is not empty, check if the value has changed if (!propValue.equals(currentProperty.getValue())) { if ((currentProperty.getStructureValue() == null) && (currentProperty.getResourceValue() == null)) { // new property, determine setting from OpenCms workplace configuration if (OpenCms.getWorkplaceManager().isDefaultPropertiesOnStructure()) { currentProperty.setStructureValue(propValue); currentProperty.setResourceValue(null); } else { currentProperty.setResourceValue(propValue); currentProperty.setStructureValue(null); } } else if (currentProperty.getStructureValue() != null) { // structure value has to be updated currentProperty.setStructureValue(propValue); currentProperty.setResourceValue(null); } else { // resource value has to be updated currentProperty.setResourceValue(propValue); currentProperty.setStructureValue(null); } // write the updated property object getCms().writePropertyObject(getCms().getSitePath(res), currentProperty); } } }