1 31 32 package org.opencms.workplace.commons; 33 34 import org.opencms.file.CmsObject; 35 import org.opencms.file.CmsProject; 36 import org.opencms.file.CmsProperty; 37 import org.opencms.file.CmsPropertyDefinition; 38 import org.opencms.file.CmsResource; 39 import org.opencms.file.CmsResourceFilter; 40 import org.opencms.jsp.CmsJspActionElement; 41 import org.opencms.main.CmsException; 42 import org.opencms.main.CmsLog; 43 import org.opencms.main.OpenCms; 44 import org.opencms.security.CmsPermissionSet; 45 import org.opencms.site.CmsSite; 46 import org.opencms.site.CmsSiteManager; 47 import org.opencms.staticexport.CmsLinkManager; 48 import org.opencms.util.CmsStringUtil; 49 import org.opencms.workplace.CmsDialog; 50 import org.opencms.workplace.CmsWorkplaceSettings; 51 52 import javax.servlet.http.HttpServletRequest ; 53 import javax.servlet.http.HttpServletResponse ; 54 import javax.servlet.jsp.JspException ; 55 import javax.servlet.jsp.PageContext ; 56 57 import org.apache.commons.logging.Log; 58 59 74 public class CmsSecure extends CmsDialog { 75 76 77 public static final int ACTION_CHSECEXP = 100; 78 79 80 public static final String DIALOG_TYPE = "secure"; 81 82 83 private static final Log LOG = CmsLog.getLog(CmsSecure.class); 84 85 86 private String m_paramExport; 87 88 89 private String m_paramExportname; 90 91 92 private String m_paramIntern; 93 94 95 private String m_paramSecure; 96 97 102 public CmsSecure(CmsJspActionElement jsp) { 103 104 super(jsp); 105 } 106 107 114 public CmsSecure(PageContext context, HttpServletRequest req, HttpServletResponse res) { 115 116 this(new CmsJspActionElement(context, req, res)); 117 } 118 119 124 public void actionChangeSecureExport() throws JspException { 125 126 getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this); 128 129 String filename = getParamResource(); 130 131 try { 132 checkLock(getParamResource()); 134 135 writeProperty(CmsPropertyDefinition.PROPERTY_EXPORT, getParamExport()); 137 writeProperty(CmsPropertyDefinition.PROPERTY_EXPORTNAME, getParamExportname()); 138 writeProperty(CmsPropertyDefinition.PROPERTY_SECURE, getParamSecure()); 139 140 CmsResource resource = getCms().readResource(filename, CmsResourceFilter.IGNORE_EXPIRATION); 142 if (resource.isInternal() && !Boolean.valueOf(getParamIntern()).booleanValue()) { 143 getCms().chflags(filename, resource.getFlags() & (~CmsResource.FLAG_INTERNAL)); 144 } else if (!resource.isInternal() && Boolean.valueOf(getParamIntern()).booleanValue()) { 145 getCms().chflags(filename, resource.getFlags() | CmsResource.FLAG_INTERNAL); 146 } 147 148 actionCloseDialog(); 149 } catch (Throwable e) { 150 includeErrorpage(this, e); 152 } 153 154 } 155 156 163 public String buildRadio(String propName) throws CmsException { 164 165 String propVal = readProperty(propName); 166 StringBuffer result = new StringBuffer ("<table border=\"0\"><tr>"); 167 result.append("<td><input type=\"radio\" value=\"true\" onClick=\"checkNoIntern()\" name=\"").append(propName).append( 168 "\" ").append(Boolean.valueOf(propVal).booleanValue() ? "checked=\"checked\"" : "").append("/></td><td id=\"tablelabel\">").append( 169 key(Messages.GUI_LABEL_TRUE_0)).append("</td>"); 170 result.append("<td><input type=\"radio\" value=\"false\" onClick=\"checkNoIntern()\" name=\"").append(propName).append( 171 "\" ").append(Boolean.valueOf(propVal).booleanValue() ? "" : "checked=\"checked\"").append("/></td><td id=\"tablelabel\">").append( 172 key(Messages.GUI_LABEL_FALSE_0)).append("</td>"); 173 result.append("<td><input type=\"radio\" value=\"\" onClick=\"checkNoIntern()\" name=\"").append(propName).append( 174 "\" ").append(CmsStringUtil.isEmpty(propVal) ? "checked=\"checked\"" : "").append( 175 "/></td><td id=\"tablelabel\">").append(getPropertyInheritanceInfo(propName)).append("</td></tr></table>"); 176 return result.toString(); 177 } 178 179 184 public String getParamExport() { 185 186 return m_paramExport; 187 } 188 189 194 public String getParamExportname() { 195 196 return m_paramExportname; 197 } 198 199 204 public String getParamIntern() { 205 206 return m_paramIntern; 207 } 208 209 214 public String getParamSecure() { 215 216 return m_paramSecure; 217 } 218 219 226 public String getPropertyInheritanceInfo(String propName) throws CmsException { 227 228 String folderName = CmsResource.getParentFolder(getParamResource()); 229 String folderPropVal = null; 230 while (CmsStringUtil.isNotEmpty(folderName)) { 231 CmsProperty prop = getCms().readPropertyObject(folderName, propName, false); 232 folderPropVal = prop.getValue(); 233 if (CmsStringUtil.isNotEmpty(folderPropVal)) { 234 break; 235 } 236 folderName = CmsResource.getParentFolder(folderName); 237 } 238 239 if (CmsStringUtil.isNotEmpty(folderPropVal)) { 240 return key(Messages.GUI_SECURE_INHERIT_FROM_2, new Object [] {folderPropVal, folderName}); 241 } else { 242 return key(Messages.GUI_SECURE_NOT_SET_0); 243 } 244 } 245 246 251 public String getResourceUrl() { 252 253 CmsObject cms = getCms(); 254 String uri = ""; 255 String serverPrefix = ""; 256 String vfsName = CmsLinkManager.getAbsoluteUri(getParamResource(), cms.getRequestContext().getUri()); 257 String secureResource = ""; 258 try { 259 if (resourceIsFolder()) { 260 vfsName = vfsName.concat("/"); 261 } 262 secureResource = getCms().readPropertyObject( 263 getParamResource(), 264 CmsPropertyDefinition.PROPERTY_SECURE, 265 true).getValue(); 266 } catch (CmsException e) { 267 if (LOG.isInfoEnabled()) { 268 LOG.info(e.getLocalizedMessage()); 269 } 270 } 271 CmsSite currentSite = CmsSiteManager.getCurrentSite(getCms()); 272 CmsProject currentProject = cms.getRequestContext().currentProject(); 273 try { 274 cms.getRequestContext().setCurrentProject(cms.readProject(CmsProject.ONLINE_PROJECT_ID)); 275 uri = OpenCms.getLinkManager().substituteLink(cms, getParamResource(), currentSite.getSiteRoot()); 276 } catch (CmsException e) { 277 if (LOG.isErrorEnabled()) { 278 LOG.error(e.getLocalizedMessage()); 279 } 280 } finally { 281 cms.getRequestContext().setCurrentProject(currentProject); 282 } 283 284 if (currentSite.equals(OpenCms.getSiteManager().getDefaultSite())) { 285 serverPrefix = OpenCms.getSiteManager().getWorkplaceServer(); 286 } else { 287 if (Boolean.valueOf(secureResource).booleanValue() && currentSite.hasSecureServer()) { 288 serverPrefix = currentSite.getSecureUrl(); 289 } else { 290 serverPrefix = currentSite.getUrl(); 291 } 292 } 293 if (!uri.startsWith(serverPrefix)) { 294 uri = serverPrefix + uri; 295 } 296 return uri; 297 } 298 299 304 public boolean exportUserHasReadPermission() { 305 String vfsName = getParamResource(); 306 CmsObject cms = getCms(); 307 try { 308 CmsObject exportCms = OpenCms.initCmsObject(OpenCms.getDefaultUsers().getUserExport()); 311 exportCms.getRequestContext().setSiteRoot(getCms().getRequestContext().getSiteRoot()); 312 return exportCms.hasPermissions(cms.readResource(vfsName, CmsResourceFilter.IGNORE_EXPIRATION), CmsPermissionSet.ACCESS_READ); 314 } catch (CmsException e) { 315 } 317 return false; 318 } 319 320 325 public String readInternProp() { 326 327 boolean internProp = false; 328 try { 329 internProp = getCms().readResource(getParamResource(), CmsResourceFilter.IGNORE_EXPIRATION).isInternal(); 330 } catch (CmsException e) { 331 if (LOG.isInfoEnabled()) { 332 LOG.info(e.getLocalizedMessage()); 333 } 334 } 335 return String.valueOf(internProp); 336 } 337 338 344 public String readProperty(String propertyName) { 345 346 String propVal = null; 347 try { 348 propVal = getCms().readPropertyObject(getParamResource(), propertyName, false).getValue(); 349 } catch (CmsException e) { 350 if (LOG.isInfoEnabled()) { 351 LOG.info(e.getLocalizedMessage()); 352 } 353 } 354 if (CmsStringUtil.isEmpty(propVal)) { 355 propVal = ""; 356 } 357 return propVal; 358 } 359 360 365 public boolean resourceIsFolder() throws CmsException { 366 367 return getCms().readResource(getParamResource(), CmsResourceFilter.IGNORE_EXPIRATION).isFolder(); 368 } 369 370 375 public void setParamExport(String value) { 376 377 m_paramExport = value; 378 } 379 380 385 public void setParamExportname(String value) { 386 387 m_paramExportname = value; 388 } 389 390 395 public void setParamIntern(String value) { 396 397 m_paramIntern = value; 398 } 399 400 405 public void setParamSecure(String value) { 406 407 m_paramSecure = value; 408 } 409 410 415 public boolean showExportSettings() { 416 417 return getSettings().getUserSettings().getDialogShowExportSettings(); 418 } 419 420 423 protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) { 424 425 fillParamValues(request); 427 428 if (! checkResourcePermissions(CmsPermissionSet.ACCESS_WRITE, false)) { 430 setParamAction(DIALOG_CANCEL); 432 } 433 434 setParamDialogtype(DIALOG_TYPE); 436 if (DIALOG_TYPE.equals(getParamAction())) { 438 setAction(ACTION_CHSECEXP); 439 } else if (DIALOG_CANCEL.equals(getParamAction())) { 440 setAction(ACTION_CANCEL); 441 } else { 442 setAction(ACTION_DEFAULT); 443 setParamTitle(key(Messages.GUI_SECURE_EXPORT_RESOURCE_1, new Object [] {CmsResource.getName(getParamResource())})); 445 } 446 } 447 448 455 protected void writeProperty(String propertyName, String propertyValue) throws CmsException { 456 457 if (CmsStringUtil.isEmpty(propertyValue)) { 458 propertyValue = CmsProperty.DELETE_VALUE; 459 } 460 461 CmsProperty newProp = new CmsProperty(); 462 newProp.setName(propertyName); 463 CmsProperty oldProp = getCms().readPropertyObject(getParamResource(), propertyName, false); 464 if (oldProp.isNullProperty()) { 465 if (OpenCms.getWorkplaceManager().isDefaultPropertiesOnStructure()) { 467 newProp.setStructureValue(propertyValue); 468 } else { 469 newProp.setResourceValue(propertyValue); 470 } 471 } else { 472 if (oldProp.getStructureValue() != null) { 473 newProp.setStructureValue(propertyValue); 474 newProp.setResourceValue(oldProp.getResourceValue()); 475 } else { 476 newProp.setResourceValue(propertyValue); 477 } 478 } 479 480 newProp.setAutoCreatePropertyDefinition(true); 481 482 String oldStructureValue = oldProp.getStructureValue(); 483 String newStructureValue = newProp.getStructureValue(); 484 if (CmsStringUtil.isEmpty(oldStructureValue)) { 485 oldStructureValue = CmsProperty.DELETE_VALUE; 486 } 487 if (CmsStringUtil.isEmpty(newStructureValue)) { 488 newStructureValue = CmsProperty.DELETE_VALUE; 489 } 490 491 String oldResourceValue = oldProp.getResourceValue(); 492 String newResourceValue = newProp.getResourceValue(); 493 if (CmsStringUtil.isEmpty(oldResourceValue)) { 494 oldResourceValue = CmsProperty.DELETE_VALUE; 495 } 496 if (CmsStringUtil.isEmpty(newResourceValue)) { 497 newResourceValue = CmsProperty.DELETE_VALUE; 498 } 499 500 if (!oldResourceValue.equals(newResourceValue) || !oldStructureValue.equals(newStructureValue)) { 502 getCms().writePropertyObject(getParamResource(), newProp); 503 } 504 505 } 506 } | Popular Tags |