1 23 24 package org.infoglue.cms.applications.structuretool.actions; 25 26 import java.net.URLEncoder ; 27 import java.util.ArrayList ; 28 import java.util.List ; 29 30 import org.apache.log4j.Logger; 31 import org.infoglue.cms.applications.common.ImageButton; 32 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction; 33 import org.infoglue.cms.controllers.kernel.impl.simple.ContentVersionController; 34 import org.infoglue.cms.controllers.kernel.impl.simple.LanguageController; 35 import org.infoglue.cms.controllers.kernel.impl.simple.RepositoryController; 36 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeController; 37 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeVersionController; 38 import org.infoglue.cms.entities.content.ContentVersionVO; 39 import org.infoglue.cms.entities.management.LanguageVO; 40 import org.infoglue.cms.entities.management.RepositoryVO; 41 import org.infoglue.cms.entities.structure.SiteNodeVO; 42 import org.infoglue.cms.entities.structure.SiteNodeVersion; 43 import org.infoglue.cms.entities.structure.SiteNodeVersionVO; 44 import org.infoglue.cms.util.CmsPropertyHandler; 45 46 51 52 public class ViewStructureToolToolBarAction extends InfoGlueAbstractAction 53 { 54 private final static Logger logger = Logger.getLogger(ViewStructureToolToolBarAction.class.getName()); 55 56 private static final long serialVersionUID = 1L; 57 58 private String title = ""; 59 private String name = ""; 60 private String toolbarKey = ""; 61 private String url = ""; 62 private Boolean isBranch = new Boolean (false); 63 64 private Integer repositoryId = null; 66 private Integer siteNodeId = null; 67 private Integer siteNodeVersionId = null; 68 private Integer lastPublishedSiteNodeVersionId = null; 69 private Integer metaInfoAvailableServiceBindingId = null; 70 private SiteNodeVersionVO siteNodeVersionVO = null; 72 73 77 78 public String doExecute() throws Exception 79 { 80 try 81 { 82 if(siteNodeVersionId != null) 83 { 84 this.siteNodeVersionVO = SiteNodeVersionController.getController().getSiteNodeVersionVOWithId(siteNodeVersionId); 85 86 103 } 104 else if(siteNodeId != null) 105 { 106 this.siteNodeVersionVO = SiteNodeVersionController.getController().getLatestActiveSiteNodeVersionVO(siteNodeId); 107 this.siteNodeVersionId = this.siteNodeVersionVO.getSiteNodeVersionId(); 108 109 126 } 127 } 128 catch(Exception e) 129 { 130 e.printStackTrace(); 131 } 132 133 return "success"; 134 } 135 136 public Integer getRepositoryId() 137 { 138 return this.repositoryId; 139 } 140 141 public void setRepositoryId(Integer repositoryId) 142 { 143 this.repositoryId = repositoryId; 144 } 145 146 public Integer getSiteNodeId() 147 { 148 return this.siteNodeId; 149 } 150 151 public void setSiteNodeId(Integer siteNodeId) 152 { 153 this.siteNodeId = siteNodeId; 154 } 155 156 public Integer getSiteNodeVersionId() 157 { 158 return this.siteNodeVersionId; 159 } 160 161 public void setSiteNodeVersionId(Integer siteNodeVersionId) 162 { 163 this.siteNodeVersionId = siteNodeVersionId; 164 } 165 166 public String getTitle() 167 { 168 return this.title; 169 } 170 171 public void setTitle(String title) 172 { 173 this.title = title; 174 } 175 176 public String getName() 177 { 178 return this.name; 179 } 180 181 public void setName(String name) 182 { 183 this.name = name; 184 } 185 186 public Boolean getIsBranch() 187 { 188 return this.isBranch; 189 } 190 191 public void setIsBranch(Boolean isBranch) 192 { 193 this.isBranch = isBranch; 194 } 195 196 public String getToolbarKey() 197 { 198 return this.toolbarKey; 199 } 200 201 public void setToolbarKey(String toolbarKey) 202 { 203 this.toolbarKey = toolbarKey; 204 } 205 206 public void setUrl(String url) 207 { 208 this.url = url; 209 } 210 211 public String getUrl() 212 { 213 return this.url; 214 } 215 216 219 220 private boolean isReadOnly() 221 { 222 boolean isReadOnly = false; 223 224 try 225 { 226 if(this.siteNodeVersionVO != null && (this.siteNodeVersionVO.getStateId().intValue() == 1 || this.siteNodeVersionVO.getStateId().intValue() == 2 || this.siteNodeVersionVO.getStateId().intValue() == 3)) 228 { 229 isReadOnly = true; 230 } 231 } 232 catch(Exception e){} 233 234 return isReadOnly; 235 } 236 237 public List getButtons() 238 { 239 logger.info("Title:" + this.title); 240 logger.info("toolbarKey:" + this.toolbarKey); 241 try 242 { 243 if(this.toolbarKey.equalsIgnoreCase("tool.structuretool.siteNodeDetailsHeader") || this.toolbarKey.equalsIgnoreCase("tool.structuretool.siteNodeComponentsHeader")) 244 { 245 if(this.isBranch.booleanValue()) 246 return getBranchSiteNodeButtons(); 247 else 248 return getSiteNodeButtons(); 249 } 250 else if(this.toolbarKey.equalsIgnoreCase("tool.structuretool.siteNodeVersionHeader")) 251 { 252 return this.getSiteNodeVersionButtons(); 253 } 254 } 255 catch(Exception e) 256 { 257 e.printStackTrace(); 258 logger.warn("Exception when generating buttons:" + e.getMessage(), e); 259 } 260 261 return null; 262 } 263 264 265 268 269 private boolean hasPublishedVersion() 270 { 271 boolean hasPublishedVersion = false; 272 273 try 274 { 275 SiteNodeVersion siteNodeVersion = SiteNodeVersionController.getLatestPublishedSiteNodeVersion(this.siteNodeId); 276 if(siteNodeVersion != null) 277 { 278 hasPublishedVersion = true; 279 lastPublishedSiteNodeVersionId = siteNodeVersion.getId(); 280 this.repositoryId = siteNodeVersion.getOwningSiteNode().getRepository().getId(); 281 this.name = siteNodeVersion.getOwningSiteNode().getName(); 282 this.siteNodeId = siteNodeVersion.getOwningSiteNode().getId(); 283 } 284 } 285 catch(Exception e) 286 { 287 logger.warn("Exception when generating buttons:" + e.getMessage(), e); 288 } 289 290 return hasPublishedVersion; 291 } 292 293 294 295 private List getBranchSiteNodeButtons() throws Exception 296 { 297 List buttons = new ArrayList (); 298 buttons.add(new ImageButton(this.getCMSBaseUrl() + "/CreateSiteNode!input.action?isBranch=true&parentSiteNodeId=" + this.siteNodeId + "&repositoryId=" + this.repositoryId, getLocalizedString(getSession().getLocale(), "images.structuretool.buttons.newSiteNode"), "New SiteNode")); 299 300 ImageButton moveButton = getMoveButton(); 301 moveButton.getSubButtons().add(getMoveMultipleButton()); 302 buttons.add(moveButton); 303 304 307 if(!hasPublishedVersion()) 308 buttons.add(new ImageButton(this.getCMSBaseUrl() + "/Confirm.action?header=tool.structuretool.deleteSiteNode.header&yesDestination=" + URLEncoder.encode(URLEncoder.encode("DeleteSiteNode.action?siteNodeId=" + this.siteNodeId + "&repositoryId=" + this.repositoryId + "&changeTypeId=4", "UTF-8"), "UTF-8") + "&noDestination=" + URLEncoder.encode(URLEncoder.encode("ViewSiteNode.action?title=SiteNode&siteNodeId=" + this.siteNodeId + "&repositoryId=" + this.repositoryId, "UTF-8"), "UTF-8") + "&message=tool.structuretool.deleteSiteNode.message", getLocalizedString(getSession().getLocale(), "images.structuretool.buttons.deleteSiteNode"), "Delete SiteNode")); 309 310 313 if(this.siteNodeVersionVO != null && this.siteNodeVersionVO.getStateId().equals(SiteNodeVersionVO.WORKING_STATE)) 315 buttons.add(new ImageButton(true, "javascript:openPopup('ViewAndCreateContentForServiceBinding.action?siteNodeId=" + this.siteNodeId + "&repositoryId=" + this.repositoryId + "&siteNodeVersionId=" + this.siteNodeVersionVO.getId() + "', 'PageProperties', 'width=400,height=525,resizable=no,status=yes,scrollbars=yes');", getLocalizedString(getSession().getLocale(), "images.structuretool.buttons.editSiteNodeProperties"), "Edit siteNode properties")); 316 else 317 buttons.add(new ImageButton(true, "javascript:openPopupWithOptionalParameter('ViewAndCreateContentForServiceBinding.action?siteNodeId=" + this.siteNodeId + "&repositoryId=" + this.repositoryId + "&siteNodeVersionId=" + this.siteNodeVersionVO.getId() + "', 'PageProperties', 'width=400,height=525,resizable=no,status=yes,scrollbars=yes', '" + getLocalizedString(getSession().getLocale(), "tool.structuretool.changeSiteNodeStateToWorkingQuestion") + "', 'changeStateToWorking=true');", getLocalizedString(getSession().getLocale(), "images.structuretool.buttons.editSiteNodeProperties"), "Edit siteNode properties")); 318 319 buttons.add(getPreviewButtons()); 320 321 if(hasPublishedVersion()) 322 { 323 ImageButton unpublishButton = new ImageButton(this.getCMSBaseUrl() + "/UnpublishSiteNodeVersion!input.action?siteNodeId=" + this.siteNodeId + "&siteNodeVersionId=" + this.siteNodeVersionId, getLocalizedString(getSession().getLocale(), "images.structuretool.buttons.unpublishVersion"), "tool.contenttool.unpublishVersion.header"); 324 ImageButton unpublishAllButton = new ImageButton(this.getCMSBaseUrl() + "/UnpublishSiteNodeVersion!inputChooseSiteNodes.action?siteNodeId=" + this.siteNodeId + "&siteNodeVersionId=" + this.siteNodeVersionId, getLocalizedString(getSession().getLocale(), "images.structuretool.buttons.unpublishAllVersion"), "tool.contenttool.unpublishAllVersion.header"); 325 unpublishButton.getSubButtons().add(unpublishAllButton); 326 327 buttons.add(unpublishButton); 328 } 329 330 ImageButton coverButton = new ImageButton(this.getCMSBaseUrl() + "/ViewSiteNode.action?siteNodeId=" + this.siteNodeId + "&repositoryId=" + this.repositoryId + "&stay=true", getLocalizedString(getSession().getLocale(), "images.structuretool.buttons.siteNodeCover"), "SiteNode Cover"); 331 coverButton.getSubButtons().add(getSimplePageComponentsButton()); 332 buttons.add(coverButton); 333 334 if(!isReadOnly()) 335 { 336 ImageButton pageComponentsButton = getViewPageComponentsButton(); 337 pageComponentsButton.getSubButtons().add(getSimplePageComponentsButton()); 338 buttons.add(pageComponentsButton); 339 } 340 341 buttons.add(getPublishButton()); 342 343 buttons.add(getExecuteTaskButton()); 344 345 if(this.siteNodeVersionVO.getIsProtected().intValue() == SiteNodeVersionVO.YES.intValue()) 346 buttons.add(getAccessRightsButton()); 347 348 return buttons; 349 } 350 351 private ImageButton getPreviewButtons() throws Exception 352 { 353 RepositoryVO repositoryVO = RepositoryController.getController().getRepositoryVOWithId(this.repositoryId); 354 355 String dnsName = repositoryVO.getDnsName(); 356 357 String workingUrl = null; 358 359 String keyword = "working="; 360 int startIndex = (dnsName == null) ? -1 : dnsName.indexOf(keyword); 361 if(startIndex != -1) 362 { 363 int endIndex = dnsName.indexOf(",", startIndex); 364 if(endIndex > -1) 365 dnsName = dnsName.substring(startIndex, endIndex); 366 else 367 dnsName = dnsName.substring(startIndex); 368 369 workingUrl = dnsName.split("=")[1] + CmsPropertyHandler.getComponentRendererUrl() + "ViewPage.action"; 370 } 371 else 372 { 373 workingUrl = CmsPropertyHandler.getPreviewDeliveryUrl(); 374 } 375 376 ImageButton imageButton = new ImageButton(true, "javascript:openPopup('" + workingUrl + "?siteNodeId=" + this.siteNodeId + "&repositoryName=" + URLEncoder.encode(repositoryVO.getName(), "UTF-8") + "&cmsUserName=" + URLEncoder.encode(this.getInfoGluePrincipal().getName(), "UTF-8") + "' , 'SiteNode', 'width=800,height=600,resizable=yes,toolbar=yes,scrollbars=yes,status=yes,location=yes,menubar=yes');", getLocalizedString(getSession().getLocale(), "images.structuretool.buttons.previewSiteNode"), "Preview siteNode"); 377 378 379 return imageButton; 380 } 381 382 private List getSiteNodeButtons() throws Exception 383 { 384 List buttons = new ArrayList (); 385 buttons.add(new ImageButton("Confirm.action?header=Delete%20siteNode&yesDestination=" + URLEncoder.encode(URLEncoder.encode("DeleteSiteNode.action?siteNodeId=" + this.siteNodeId + "&repositoryId=" + this.repositoryId + "&changeTypeId=4", "UTF-8"), "UTF-8") + "&noDestination=" + URLEncoder.encode(URLEncoder.encode("ViewSiteNode.action?title=SiteNode&siteNodeId=" + this.siteNodeId + "&repositoryId=" + this.repositoryId, "UTF-8"), "UTF-8") + "&message=" + URLEncoder.encode("Do you really want to delete the siteNode " + this.name + " and all its children", "UTF-8"), getLocalizedString(getSession().getLocale(), "images.structuretool.buttons.deleteSiteNode"), "Delete SiteNode")); 386 buttons.add(getMoveButton()); 387 buttons.add(getMoveMultipleButton()); 388 buttons.add(getPublishButton()); 389 return buttons; 390 } 391 392 private List getSiteNodeVersionButtons() throws Exception 393 { 394 List buttons = new ArrayList (); 395 if(this.siteNodeVersionId != null) 396 { 397 buttons.add(new ImageButton(true, "javascript:openPopup('ViewSiteNodeVersion!preview.action?siteNodeVersionId=" + this.siteNodeVersionId + "&siteNodeId=" + this.siteNodeId + "', 'SiteNodePreview', 'width=600,height=600,resizable=yes');", getLocalizedString(getSession().getLocale(), "images.structuretool.buttons.previewSiteNode"), "Preview siteNode version")); 398 } 399 400 return buttons; 401 } 402 403 private ImageButton getMoveButton() throws Exception 404 { 405 return new ImageButton(true, "javascript:openPopup('ViewSiteNodeTree.action?siteNodeId=" + this.siteNodeId + "&repositoryId=" + this.repositoryId + "&hideLeafs=true', 'SiteNode', 'width=400,height=600,resizable=no');", getLocalizedString(getSession().getLocale(), "images.structuretool.buttons.moveSiteNode"), "Move siteNode"); 406 } 407 408 private ImageButton getMoveMultipleButton() 409 { 410 return new ImageButton(true, "javascript:openPopup('MoveMultipleSiteNodes!input.action?siteNodeId=" + this.siteNodeId + "&repositoryId=" + this.repositoryId + "', 'MoveMultipleSiteNodes', 'width=400,height=600,resizable=no');", getLocalizedString(getSession().getLocale(), "images.structuretool.buttons.moveMultipleSiteNodes"), "tool.structuretool.moveMultipleSiteNodes.header"); 411 } 412 413 private ImageButton getViewPageComponentsButton() throws Exception 414 { 415 try 416 { 417 boolean isMetaInfoInWorkingState = false; 418 LanguageVO masterLanguageVO = LanguageController.getController().getMasterLanguage(this.repositoryId); 419 Integer languageId = masterLanguageVO.getLanguageId(); 420 421 434 SiteNodeVO siteNodeVO = SiteNodeController.getController().getSiteNodeVOWithId(siteNodeId); 435 if(siteNodeVO.getMetaInfoContentId() != null && siteNodeVO.getMetaInfoContentId().intValue() != -1) 436 { 437 ContentVersionVO contentVersionVO = ContentVersionController.getContentVersionController().getLatestActiveContentVersionVO(siteNodeVO.getMetaInfoContentId(), languageId); 438 if(contentVersionVO.getStateId().equals(ContentVersionVO.WORKING_STATE)) 439 isMetaInfoInWorkingState = true; 440 } 441 442 logger.info("isMetaInfoInWorkingState:" + isMetaInfoInWorkingState); 443 if(isMetaInfoInWorkingState) 444 return new ImageButton(CmsPropertyHandler.getComponentRendererUrl() + "ViewPage!renderDecoratedPage.action?siteNodeId=" + this.siteNodeId + "&languageId=" + masterLanguageVO.getId() + "&contentId=-1" + "&cmsUserName=" + URLEncoder.encode(this.getInfoGluePrincipal().getName(), "UTF-8"), getLocalizedString(getSession().getLocale(), "images.structuretool.buttons.siteNodeComponents"), "Site Node Components"); 445 else 447 return new ImageButton(true, "javascript:alert('Cannot edit this page. You must first set the meta info to working. Do this by entering node properties and changing the state to working.');", getLocalizedString(getSession().getLocale(), "images.structuretool.buttons.siteNodeComponents"), "Site Node Components"); 448 } 449 catch(Exception e) 450 { 451 return new ImageButton(true, "javascript:alert('Cannot edit this page. You must first assign a metainfo content. Do this by entering node properties and fill in the information requested.');", getLocalizedString(getSession().getLocale(), "images.structuretool.buttons.siteNodeComponents"), "Site Node Components"); 452 } 453 } 454 455 private ImageButton getSimplePageComponentsButton() throws Exception 456 { 457 try 458 { 459 boolean isMetaInfoInWorkingState = false; 460 LanguageVO masterLanguageVO = LanguageController.getController().getMasterLanguage(this.repositoryId); 461 Integer languageId = masterLanguageVO.getLanguageId(); 462 463 476 477 SiteNodeVO siteNodeVO = SiteNodeController.getController().getSiteNodeVOWithId(siteNodeId); 478 if(siteNodeVO.getMetaInfoContentId() != null && siteNodeVO.getMetaInfoContentId().intValue() != -1) 479 { 480 ContentVersionVO contentVersionVO = ContentVersionController.getContentVersionController().getLatestActiveContentVersionVO(siteNodeVO.getMetaInfoContentId(), languageId); 481 if(contentVersionVO.getStateId().equals(ContentVersionVO.WORKING_STATE)) 482 isMetaInfoInWorkingState = true; 483 } 484 485 logger.info("isMetaInfoInWorkingState:" + isMetaInfoInWorkingState); 486 if(isMetaInfoInWorkingState) 487 return new ImageButton(CmsPropertyHandler.getComponentRendererUrl() + "ViewPage!renderDecoratedPage.action?siteNodeId=" + this.siteNodeId + "&languageId=" + masterLanguageVO.getId() + "&contentId=-1&showSimple=true" + "&cmsUserName=" + URLEncoder.encode(this.getInfoGluePrincipal().getName(), "UTF-8"), getLocalizedString(getSession().getLocale(), "images.structuretool.buttons.siteNodeStructure"), "Site Node Structure"); 488 else 490 return new ImageButton(true, "javascript:alert('Cannot edit this page. You must first set the meta info to working. Do this by entering node properties and changing the state to working.');", getLocalizedString(getSession().getLocale(), "images.structuretool.buttons.siteNodeStructure"), "Site Node Structure"); 491 } 492 catch(Exception e) 493 { 494 return new ImageButton(true, "javascript:alert('Cannot edit this page. You must first assign a metainfo content. Do this by entering node properties and fill in the information requested.');", getLocalizedString(getSession().getLocale(), "images.structuretool.buttons.siteNodeStructure"), "Site Node Structure"); 495 } 496 } 497 498 private ImageButton getExecuteTaskButton() 499 { 500 return new ImageButton(true, "javascript:openPopup('ViewExecuteTask.action?contentId=" + this.siteNodeId + "', 'SiteNode', 'width=400,height=600,resizable=yes,scrollbars=yes');", getLocalizedString(getSession().getLocale(), "images.global.buttons.executeTask"), "tool.common.executeTask.header"); 501 } 502 503 private ImageButton getPublishButton() 504 { 505 return new ImageButton(this.getCMSBaseUrl() + "/ViewListSiteNodeVersion.action?siteNodeId=" + this.siteNodeId + "&repositoryId=" + this.repositoryId, getLocalizedString(getSession().getLocale(), "images.structuretool.buttons.publishSiteNode"), "tool.structuretool.publishSiteNode.header"); 506 } 507 508 private ImageButton getAccessRightsButton() throws Exception 509 { 510 String returnAddress = URLEncoder.encode(URLEncoder.encode("ViewSiteNode.action?siteNodeId=" + this.siteNodeId + "&repositoryId=" + this.repositoryId + "&stay=true", "UTF-8"), "UTF-8"); 511 return new ImageButton(this.getCMSBaseUrl() + "/ViewAccessRights.action?interceptionPointCategory=SiteNodeVersion&extraParameters=" + this.siteNodeVersionId +"&colorScheme=StructureTool&returnAddress=" + returnAddress, getLocalizedString(getSession().getLocale(), "images.structuretool.buttons.siteNodeAccessRights"), "Site Node Access Rights"); 512 } 513 514 public String getStateDescription() 515 { 516 String state = ""; 517 518 if(this.siteNodeVersionVO != null) 519 { 520 if(this.siteNodeVersionVO.getStateId().equals(SiteNodeVersionVO.WORKING_STATE)) 521 state = "<span style=\"color:#333333; font-weight: strong;\">(" + getLocalizedString(getSession().getLocale(), "tool.contenttool.state.working") + ")</span>"; 522 else if(this.siteNodeVersionVO.getStateId().equals(SiteNodeVersionVO.FINAL_STATE)) 523 state = "<span style=\"color:#AAAAAA; font-weight: strong;\">(" + getLocalizedString(getSession().getLocale(), "tool.contenttool.state.final") + ")</span>"; 524 else if(this.siteNodeVersionVO.getStateId().equals(SiteNodeVersionVO.PUBLISH_STATE)) 525 state = "<span style=\"color:#888888; font-weight: normal;\">(" + getLocalizedString(getSession().getLocale(), "tool.contenttool.state.publish") + ")</span>"; 526 else if(this.siteNodeVersionVO.getStateId().equals(SiteNodeVersionVO.PUBLISHED_STATE)) 527 state = "<span style=\"color:#666666; font-weight: normal;\">(" + getLocalizedString(getSession().getLocale(), "tool.contenttool.state.published") + ")</span>"; 528 } 529 530 return state; 531 } 532 543 } 544 | Popular Tags |