1 23 24 package org.infoglue.cms.applications.contenttool.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.ContentController; 34 import org.infoglue.cms.controllers.kernel.impl.simple.ContentVersionController; 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.entities.content.ContentVO; 38 import org.infoglue.cms.entities.content.ContentVersion; 39 import org.infoglue.cms.entities.content.ContentVersionVO; 40 import org.infoglue.cms.entities.management.RepositoryVO; 41 import org.infoglue.cms.entities.structure.SiteNodeVO; 42 import org.infoglue.cms.util.CmsPropertyHandler; 43 44 49 50 public class ViewContentToolToolBarAction extends InfoGlueAbstractAction 51 { 52 private final static Logger logger = Logger.getLogger(ViewContentToolToolBarAction.class.getName()); 53 54 private static final long serialVersionUID = 1L; 55 56 private String title = ""; 57 private String name = ""; 58 private String toolbarKey = ""; 59 private String url = ""; 60 private Boolean isBranch = new Boolean (false); 61 62 private Integer repositoryId = null; 64 private Integer siteNodeId = null; 65 private Integer languageId = null; 66 private Integer contentId = null; 67 private Integer contentVersionId = null; 68 private Integer lastPublishedContentVersionId = null; 69 private String languageName = ""; 70 71 private ContentVO contentVO = null; 72 73 public String doExecute() throws Exception 74 { 75 if(this.contentId != null) 76 { 77 this.contentVO = ContentController.getContentController().getContentVOWithId(this.contentId); 78 } 79 80 if(this.repositoryId == null && this.contentId != null) 81 { 82 this.repositoryId = ContentController.getContentController().getContentVOWithId(this.contentId).getRepositoryId(); 83 SiteNodeVO rootSiteNodeVO = SiteNodeController.getController().getRootSiteNodeVO(this.repositoryId); 84 if(rootSiteNodeVO != null) 85 this.siteNodeId = rootSiteNodeVO.getId(); 86 } 87 88 return "success"; 89 } 90 91 public Integer getRepositoryId() 92 { 93 return this.repositoryId; 94 } 95 96 public void setRepositoryId(Integer repositoryId) 97 { 98 this.repositoryId = repositoryId; 99 } 100 101 public Integer getContentId() 102 { 103 return this.contentId; 104 } 105 106 public void setContentId(Integer contentId) 107 { 108 this.contentId = contentId; 109 } 110 111 public Integer getContentVersionId() 112 { 113 return this.contentVersionId; 114 } 115 116 public void setContentVersionId(Integer contentVersionId) 117 { 118 this.contentVersionId = contentVersionId; 119 } 120 121 public Integer getLanguageId() 122 { 123 return this.languageId; 124 } 125 126 public void setLanguageId(Integer languageId) 127 { 128 this.languageId = languageId; 129 } 130 131 public String getTitle() 132 { 133 return this.title; 134 } 135 136 public void setTitle(String title) 137 { 138 this.title = title; 139 } 140 141 public String getName() 142 { 143 return this.name; 144 } 145 146 public void setName(String name) 147 { 148 this.name = name; 149 } 150 151 public Boolean getIsBranch() 152 { 153 return this.isBranch; 154 } 155 156 public void setIsBranch(Boolean isBranch) 157 { 158 this.isBranch = isBranch; 159 } 160 161 public String getToolbarKey() 162 { 163 return this.toolbarKey; 164 } 165 166 public void setToolbarKey(String toolbarKey) 167 { 168 this.toolbarKey = toolbarKey; 169 } 170 171 public void setUrl(String url) 172 { 173 this.url = url; 174 } 175 176 public String getUrl() 177 { 178 return this.url; 179 } 180 181 public List getButtons() 182 { 183 logger.info("Title:" + this.title); 184 logger.info("toolbarKey:" + this.toolbarKey); 185 186 if(this.toolbarKey.equalsIgnoreCase("content details")) 187 { 188 if(this.isBranch.booleanValue()) 189 return getBranchContentButtons(); 190 else 191 return getContentButtons(); 192 } 193 else if(this.toolbarKey.equalsIgnoreCase("content version")) 194 { 195 return this.getContentVersionButtons(); 196 } 197 else if(this.toolbarKey.equalsIgnoreCase("ContentVersionHistory")) 198 { 199 return this.getContentVersionHistoryButtons(); 200 } 201 202 return null; 203 } 204 205 208 209 private boolean hasAnyPublishedVersion() 210 { 211 boolean hasPublishedVersion = false; 212 213 try 214 { 215 ContentVersion contentVersion = ContentVersionController.getContentVersionController().getLatestPublishedContentVersion(this.contentId); 216 if(contentVersion != null) 217 { 218 hasPublishedVersion = true; 219 lastPublishedContentVersionId = contentVersion.getContentVersionId(); 220 this.repositoryId = contentVersion.getOwningContent().getRepository().getId(); 221 this.name = contentVersion.getOwningContent().getName(); 222 this.languageName = contentVersion.getLanguage().getName(); 223 this.contentId = contentVersion.getOwningContent().getId(); 224 this.languageId = contentVersion.getLanguage().getId(); 225 } 226 } 227 catch(Exception e){} 228 229 return hasPublishedVersion; 230 } 231 232 235 236 private boolean hasPublishedVersion() 237 { 238 boolean hasPublishedVersion = false; 239 240 try 241 { 242 ContentVersion contentVersion = ContentVersionController.getContentVersionController().getLatestPublishedContentVersion(this.contentId, this.languageId); 243 if(contentVersion != null) 244 { 245 hasPublishedVersion = true; 246 lastPublishedContentVersionId = contentVersion.getContentVersionId(); 247 this.repositoryId = contentVersion.getOwningContent().getRepository().getId(); 248 this.name = contentVersion.getOwningContent().getName(); 249 this.languageName = contentVersion.getLanguage().getName(); 250 this.contentId = contentVersion.getOwningContent().getId(); 251 this.languageId = contentVersion.getLanguage().getId(); 252 } 253 } 254 catch(Exception e){} 255 256 return hasPublishedVersion; 257 } 258 259 260 263 264 private boolean isReadOnly() 265 { 266 boolean isReadOnly = false; 267 268 try 269 { 270 ContentVersionVO contentVersion = ContentVersionController.getContentVersionController().getContentVersionVOWithId(this.contentVersionId); 271 if(contentVersion != null && (contentVersion.getStateId().intValue() == 1 || contentVersion.getStateId().intValue() == 2 || contentVersion.getStateId().intValue() == 3)) 272 { 273 isReadOnly = true; 274 } 275 } 276 catch(Exception e){} 277 278 return isReadOnly; 279 } 280 281 282 private List getBranchContentButtons() 283 { 284 List buttons = new ArrayList (); 285 286 try 287 { 288 buttons.add(new ImageButton("CreateContent!input.action?isBranch=false&parentContentId=" + this.contentId + "&repositoryId=" + this.repositoryId, getLocalizedString(getSession().getLocale(), "images.contenttool.buttons.newContent"), "tool.contenttool.newContent.header")); 289 buttons.add(new ImageButton("CreateContent!input.action?isBranch=true&parentContentId=" + this.contentId + "&repositoryId=" + this.repositoryId, getLocalizedString(getSession().getLocale(), "images.contenttool.buttons.newContentFolder"), "tool.contenttool.newContentFolder.header")); 290 291 ImageButton moveButton = getMoveButton(); 292 moveButton.getSubButtons().add(getMoveMultipleButton()); 293 buttons.add(moveButton); 294 295 buttons.add(getDeleteButton()); 296 buttons.add(getPublishButton()); 297 ImageButton unpublishButton = getUnpublishButton(); 300 ImageButton unpublishAllButton = getUnpublishAllButton(); 301 unpublishButton.getSubButtons().add(unpublishAllButton); 302 303 buttons.add(unpublishButton); 304 306 buttons.add(getExecuteTaskButton()); 307 if(this.contentVO.getIsProtected().intValue() == ContentVO.YES.intValue()) 308 buttons.add(getAccessRightsButton()); 309 310 buttons.add(new ImageButton("ViewContentVersionHistory.action?contentId=" + this.contentId, getLocalizedString(getSession().getLocale(), "images.contenttool.buttons.viewHistory"), "History", new Integer (22), new Integer (80))); 311 312 buttons.add(getSyncTreeButton()); 313 314 buttons.add(new ImageButton("ViewContentProperties.action?contentId=" + this.contentId, getLocalizedString(getSession().getLocale(), "images.global.buttons.editProperties"), "Edit Properties", new Integer (22), new Integer (80))); 315 316 } 317 catch(Exception e) 318 { 319 logger.warn("Exception when generating buttons:" + e.getMessage(), e); 320 } 321 322 return buttons; 323 } 324 325 private List getContentButtons() 326 { 327 List buttons = new ArrayList (); 328 try 329 { 330 buttons.add(getDeleteButton()); 331 332 ImageButton moveButton = getMoveButton(); 333 moveButton.getSubButtons().add(getMoveMultipleButton()); 334 buttons.add(moveButton); 335 336 buttons.add(getPublishButton()); 337 if(hasAnyPublishedVersion()) 338 { 339 ImageButton unpublishButton = getUnpublishButton(); 340 ImageButton unpublishAllButton = getUnpublishAllButton(); 341 unpublishButton.getSubButtons().add(unpublishAllButton); 342 343 buttons.add(unpublishButton); 344 } 345 346 buttons.add(getExecuteTaskButton()); 347 348 if(this.contentVO.getIsProtected().intValue() == ContentVO.YES.intValue()) 349 buttons.add(getAccessRightsButton()); 350 351 buttons.add(new ImageButton("ViewContentVersionHistory.action?contentId=" + this.contentId, getLocalizedString(getSession().getLocale(), "images.contenttool.buttons.viewHistory"), "History", new Integer (22), new Integer (80))); 352 353 buttons.add(getSyncTreeButton()); 354 355 } 356 catch(Exception e) 357 { 358 logger.warn("Exception when generating buttons:" + e.getMessage(), e); 359 } 360 361 return buttons; 362 } 363 364 365 private List getContentVersionButtons() 366 { 367 List buttons = new ArrayList (); 368 369 try 370 { 371 boolean latest = true; 372 if(this.contentVersionId != null) 373 { 374 ContentVersionVO currentContentVersionVO = ContentVersionController.getContentVersionController().getContentVersionVOWithId(this.contentVersionId); 375 ContentVersionVO latestContentVersionVO = ContentVersionController.getContentVersionController().getLatestActiveContentVersionVO(currentContentVersionVO.getContentId(), currentContentVersionVO.getLanguageId()); 376 if(currentContentVersionVO.getId().intValue() != latestContentVersionVO.getId().intValue()) 377 latest = false; 378 } 379 380 buttons.add(getCoverButton()); 381 382 if(latest) 383 { 384 buttons.add(getDeleteButton()); 385 386 if(this.contentVersionId != null) 387 { 388 if(!isReadOnly()) 389 buttons.add(new ImageButton(true, "javascript:openPopup('ViewDigitalAsset.action?contentVersionId=" + this.contentVersionId + "', 'FileUpload', 'width=400,height=200,resizable=no');", getLocalizedString(getSession().getLocale(), "images.contenttool.buttons.newAsset"), "tool.contenttool.uploadDigitalAsset.header")); 390 391 if(this.siteNodeId != null) 392 { 393 RepositoryVO repositoryVO = RepositoryController.getController().getRepositoryVOWithId(this.repositoryId); 394 395 String dnsName = repositoryVO.getDnsName(); 396 397 String workingUrl = null; 398 399 String keyword = "working="; 400 int startIndex = (dnsName == null) ? -1 : dnsName.indexOf(keyword); 401 if(startIndex != -1) 402 { 403 int endIndex = dnsName.indexOf(",", startIndex); 404 if(endIndex > -1) 405 dnsName = dnsName.substring(startIndex, endIndex); 406 else 407 dnsName = dnsName.substring(startIndex); 408 409 workingUrl = dnsName.split("=")[1] + CmsPropertyHandler.getComponentRendererUrl() + "ViewPage.action"; 410 } 411 else 412 { 413 workingUrl = CmsPropertyHandler.getPreviewDeliveryUrl(); 414 } 415 416 ImageButton previewSiteButton = new ImageButton(true, "javascript:openPopup('" + workingUrl + "?siteNodeId=" + this.siteNodeId + "&languageId=" + this.languageId + "', 'SitePreview', 'width=800,height=600,resizable=yes,toolbar=yes,scrollbars=yes,status=yes,location=yes,menubar=yes');", getLocalizedString(getSession().getLocale(), "images.contenttool.buttons.previewSite"), "tool.contenttool.previewSite.header"); 417 ImageButton previewContentButton = new ImageButton(true, "javascript:openPopup('ViewContentVersion!preview.action?contentVersionId=" + this.contentVersionId + "&contentId=" + this.contentId + "&languageId=" + this.languageId + "', 'ContentPreview', 'width=800,height=600,resizable=yes,toolbar=yes,scrollbars=yes,status=yes,location=yes,menubar=yes');", getLocalizedString(getSession().getLocale(), "images.contenttool.buttons.previewContent"), "tool.contenttool.previewContent.header"); 418 previewSiteButton.getSubButtons().add(previewContentButton); 419 420 buttons.add(previewSiteButton); 421 } 422 423 if(hasPublishedVersion()) 424 { 425 ImageButton unpublishButton = getUnpublishButton(); 426 ImageButton unpublishAllButton = getUnpublishAllButton(); 427 unpublishButton.getSubButtons().add(unpublishAllButton); 428 429 buttons.add(unpublishButton); 430 } 431 432 if(this.contentVO.getIsProtected().intValue() == ContentVO.YES.intValue()) 433 buttons.add(getContentVersionAccessRightsButton()); 434 435 if(!isReadOnly()) 436 buttons.add(getPublishButton()); 437 } 438 buttons.add(getSyncTreeButton()); 439 } 440 else 441 { 442 buttons.add(getDeleteVersionButton()); 443 } 444 } 445 catch(Exception e) 446 { 447 logger.warn("Exception when generating buttons:" + e.getMessage(), e); 448 } 449 450 return buttons; 451 } 452 453 454 455 private List getContentVersionHistoryButtons() 456 { 457 List buttons = new ArrayList (); 458 459 try 460 { 461 buttons.add(getCompareButton()); 462 } 463 catch(Exception e) 464 { 465 logger.warn("Exception when generating buttons:" + e.getMessage(), e); 466 } 467 468 return buttons; 469 } 470 471 private ImageButton getCompareButton() 472 { 473 return new ImageButton(true, "javascript:compareVersions('contentVersion');", getLocalizedString(getSession().getLocale(), "images.contenttool.buttons.compareVersions"), "tool.contenttool.compareVersions.header"); 474 475 } 477 478 479 private ImageButton getCoverButton() 480 { 481 try 482 { 483 return new ImageButton("ViewContent.action?contentId=" + this.contentId + "&stay=true", getLocalizedString(getSession().getLocale(), "images.contenttool.buttons.contentCover"), "tool.contenttool.contentDetailsHeader"); 484 } 485 catch(Exception e){} 486 487 return null; 488 } 489 490 private ImageButton getUnpublishButton() 491 { 492 try 493 { 494 return new ImageButton("UnpublishContentVersion!input.action?contentId=" + this.contentId, getLocalizedString(getSession().getLocale(), "images.contenttool.buttons.unpublishVersion"), "tool.contenttool.unpublishVersion.header"); 495 } 496 catch(Exception e){} 497 498 return null; 499 } 500 501 private ImageButton getUnpublishAllButton() 502 { 503 try 504 { 505 return new ImageButton("UnpublishContentVersion!inputChooseContents.action?contentId=" + this.contentId, getLocalizedString(getSession().getLocale(), "images.contenttool.buttons.unpublishAllVersion"), "tool.contenttool.unpublishAllVersion.header"); 506 } 507 catch(Exception e){} 508 509 return null; 510 511 } 513 514 private ImageButton getDeleteButton() 515 { 516 try 517 { 518 String url = "Confirm.action?header=tool.contenttool.deleteContent.header&yesDestination=" + URLEncoder.encode(URLEncoder.encode("DeleteContent.action?contentId=" + this.contentId + "&repositoryId=" + this.repositoryId + "&changeTypeId=4", "UTF-8"), "UTF-8") + "&noDestination=" + URLEncoder.encode(URLEncoder.encode("ViewContent.action?title=Content&contentId=" + this.contentId + "&repositoryId=" + this.repositoryId, "UTF-8"), "UTF-8") + "&message=tool.contenttool.deleteContent.text"; 519 return new ImageButton(url, getLocalizedString(getSession().getLocale(), "images.contenttool.buttons.deleteContent"), "tool.contenttool.deleteContent.header"); 520 } 521 catch(Exception e){e.printStackTrace();} 522 523 return null; 524 } 525 526 private ImageButton getDeleteVersionButton() 527 { 528 try 529 { 530 String url = "Confirm.action?header=tool.contenttool.deleteContentVersion.header&yesDestination=" + URLEncoder.encode(URLEncoder.encode("DeleteContentVersion.action?contentVersionId=" + this.contentVersionId + "&repositoryId=" + this.repositoryId + "&contentId=" + this.contentId, "UTF-8"), "UTF-8") + "&noDestination=" + URLEncoder.encode(URLEncoder.encode("ViewContentVersionHistory.action", "UTF-8"), "UTF-8") + "&message=tool.contenttool.deleteContentVersion.text"; 531 return new ImageButton(url, getLocalizedString(getSession().getLocale(), "images.contenttool.buttons.deleteContentVersion"), "tool.contenttool.deleteContentVersion.header"); 532 } 533 catch(Exception e){e.printStackTrace();} 534 535 return null; 536 } 537 538 private ImageButton getMoveButton() 539 { 540 return new ImageButton(true, "javascript:openPopup('ViewContentTree.action?contentId=" + this.contentId + "&repositoryId=" + this.repositoryId + "&hideLeafs=true', 'MoveContent', 'width=400,height=600,resizable=no');", getLocalizedString(getSession().getLocale(), "images.contenttool.buttons.moveContent"), "tool.contenttool.moveContent.header"); 541 } 542 543 private ImageButton getMoveMultipleButton() 544 { 545 return new ImageButton(true, "javascript:openPopup('MoveMultipleContent!input.action?contentId=" + this.contentId + "&repositoryId=" + this.repositoryId + "', 'MoveMultipleContent', 'width=400,height=600,resizable=no');", getLocalizedString(getSession().getLocale(), "images.contenttool.buttons.moveMultipleContent"), "tool.contenttool.moveMultipleContent.header"); 546 } 547 548 private ImageButton getSyncTreeButton() 549 { 550 return new ImageButton(true, "javascript:parent.frames['main'].syncWithTree();", getLocalizedString(getSession().getLocale(), "images.contenttool.buttons.revealInTree"), "tool.contenttool.revealInTree.header"); 551 } 552 553 private ImageButton getPublishButton() 554 { 555 return new ImageButton("ViewListContentVersion.action?contentId=" + this.contentId, getLocalizedString(getSession().getLocale(), "images.contenttool.buttons.publishContent"), "tool.contenttool.publishContent.header"); 556 } 557 558 private ImageButton getExecuteTaskButton() 559 { 560 return new ImageButton(true, "javascript:openPopup('ViewExecuteTask.action?contentId=" + this.contentId + "', 'ExecuteTask', 'width=400,height=600,resizable=yes,scrollbars=yes');", getLocalizedString(getSession().getLocale(), "images.global.buttons.executeTask"), "tool.common.executeTask.header"); 561 } 562 563 private ImageButton getAccessRightsButton() throws Exception 564 { 565 String returnAddress = URLEncoder.encode(URLEncoder.encode("ViewContent.action?contentId=" + this.contentId + "&repositoryId=" + this.repositoryId + "&stay=true", "UTF-8"), "UTF-8"); 566 return new ImageButton("ViewAccessRights.action?interceptionPointCategory=Content&extraParameters=" + this.contentId +"&colorScheme=ContentTool&returnAddress=" + returnAddress, getLocalizedString(getSession().getLocale(), "images.contenttool.buttons.contentAccessRights"), "tool.contenttool.contentAccessRights.header"); 568 } 569 570 private ImageButton getContentVersionAccessRightsButton() throws Exception 571 { 572 String returnAddress = URLEncoder.encode(URLEncoder.encode("ViewContentVersion.action?contentVersionId=" + this.contentVersionId + "&contentId=" + contentId + "&languageId=" + languageId, "UTF-8"), "UTF-8"); 573 return new ImageButton("ViewAccessRights.action?interceptionPointCategory=ContentVersion&extraParameters=" + this.contentVersionId +"&colorScheme=ContentTool&returnAddress=" + returnAddress, getLocalizedString(getSession().getLocale(), "images.contenttool.buttons.contentAccessRights"), "tool.contenttool.contentVersionAccessRights.header"); 574 } 575 576 } 577 | Popular Tags |