1 23 24 28 package org.infoglue.cms.applications.contenttool.actions; 29 30 import java.util.ArrayList ; 31 import java.util.HashMap ; 32 import java.util.Iterator ; 33 import java.util.List ; 34 35 import org.apache.log4j.Logger; 36 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction; 37 import org.infoglue.cms.controllers.kernel.impl.simple.ContentControllerProxy; 38 import org.infoglue.cms.controllers.kernel.impl.simple.ContentVersionController; 39 import org.infoglue.cms.controllers.kernel.impl.simple.ContentVersionControllerProxy; 40 import org.infoglue.cms.controllers.kernel.impl.simple.DigitalAssetController; 41 import org.infoglue.cms.controllers.kernel.impl.simple.LanguageController; 42 import org.infoglue.cms.controllers.kernel.impl.simple.RepositoryController; 43 import org.infoglue.cms.entities.content.ContentVO; 44 import org.infoglue.cms.entities.content.ContentVersionVO; 45 import org.infoglue.cms.entities.content.DigitalAssetVO; 46 import org.infoglue.cms.entities.management.ContentTypeDefinitionVO; 47 import org.infoglue.cms.entities.management.LanguageVO; 48 import org.infoglue.cms.exception.Bug; 49 import org.infoglue.cms.exception.ConstraintException; 50 import org.infoglue.cms.exception.SystemException; 51 import org.infoglue.deliver.util.MathHelper; 52 53 54 public class ViewAssetListAction extends InfoGlueAbstractAction 55 { 56 private final static Logger logger = Logger.getLogger(ViewAssetListAction.class.getName()); 57 58 63 private static final long serialVersionUID = 1707633990701035545L; 64 65 public ContentTypeDefinitionVO contentTypeDefinitionVO; 66 private Integer maxResultCount = new Integer (20); public List availableLanguages = null; 68 69 private Integer languageId; 70 private Integer repositoryId; 71 private ContentVO contentVO; 72 public List attributes = null; 73 74 private List repositories; 75 private List filters; 76 private String filter = ""; 77 78 private String assetKey = null; 79 private boolean treatAsLink = false; 80 private boolean showLeafs =false; 81 82 private HashMap contentMap = new HashMap (); 83 84 public ViewAssetListAction() 85 { 86 this(new ContentVO()); 87 } 88 89 public ViewAssetListAction(ContentVO contentVO) 90 { 91 this.contentVO = contentVO; 92 } 93 94 private void createContentIdList(ContentVO parent) throws ConstraintException, SystemException 95 { 96 contentMap.put(parent.getContentId(), parent.getName()); 97 98 List children = ContentControllerProxy.getController().getContentChildrenVOList(parent.getContentId()); 99 for(Iterator i=children.iterator();i.hasNext();) 100 { 101 ContentVO cvo = (ContentVO) i.next(); 102 createContentIdList(cvo); 103 } 104 } 105 106 protected void initialize(Integer contentId, Integer languageId) throws Exception 107 { 108 this.contentVO = ContentControllerProxy.getController().getACContentVOWithId(this.getInfoGluePrincipal(), contentId); 109 createContentIdList(this.contentVO); 110 } 111 112 public String doExecute() throws Exception 113 { 114 if(getContentId() != null && getContentId().intValue() != -1) 115 this.initialize(getContentId(), this.languageId); 116 117 return "success"; 118 } 119 120 public String doBrowser() throws Exception 121 { 122 this.repositories = RepositoryController.getController().getAuthorizedRepositoryVOList(this.getInfoGluePrincipal(), true); 123 124 127 128 filters = new ArrayList (); 129 filters.add(new FilterVO("All", "")); 130 filters.add(new FilterVO("Images", "image/.*")); 131 filters.add(new FilterVO("GIF Images", ".*gif")); 132 filters.add(new FilterVO("JPEG Images", ".*jpeg")); 133 filters.add(new FilterVO("PNG Images", ".*png")); 134 filters.add(new FilterVO("Documents", ".*word.*|.*excel.*|.*pdf.*")); 135 filters.add(new FilterVO("compressed", ".*compressed")); 136 137 return "browser"; 138 } 139 140 141 public String getContentPath(Integer contentId) throws ConstraintException, SystemException, Bug, Exception 142 { 143 ContentVO contentVO = ContentControllerProxy.getController().getACContentVOWithId(this.getInfoGluePrincipal(), contentId); 144 StringBuffer ret = new StringBuffer (); 145 146 while (contentVO.getParentContentId() != null) 147 { 148 try 149 { 150 contentVO = ContentControllerProxy.getController().getContentVOWithId(contentVO.getParentContentId()); 151 } 152 catch (SystemException e) 153 { 154 e.printStackTrace(); 155 } 156 catch (Bug e) 157 { 158 e.printStackTrace(); 159 } 160 ret.insert(0, "" + contentVO.getContentId() + ","); 161 } 162 ret.append("" + contentId); 163 return ret.toString(); 164 } 165 166 167 public MathHelper getMathHelper() 168 { 169 return new MathHelper(); 170 } 171 172 public java.lang.Integer getContentId() 173 { 174 return this.contentVO.getContentId(); 175 } 176 177 public void setContentId(java.lang.Integer contentId) 178 { 179 this.contentVO.setContentId(contentId); 180 } 181 182 public java.lang.Integer getContentTypeDefinitionId() 183 { 184 return this.contentTypeDefinitionVO.getContentTypeDefinitionId(); 185 } 186 187 public String getContentTypeDefinitionName() 188 { 189 return this.contentTypeDefinitionVO.getName(); 190 } 191 192 public void setLanguageId(Integer languageId) 193 { 194 this.languageId = languageId; 195 } 196 197 public java.lang.Integer getLanguageId() 198 { 199 return this.languageId; 200 } 201 202 public String getName() 203 { 204 return this.contentVO.getName(); 205 } 206 207 public java.lang.Integer getRepositoryId() 208 { 209 if(this.contentVO != null && this.contentVO.getRepositoryId() != null) 210 return this.contentVO.getRepositoryId(); 211 else 212 return this.repositoryId; 213 } 214 215 public List getAvailableLanguages() 216 { 217 return this.availableLanguages; 218 } 219 220 223 public List getInheritedDigitalAssets() 224 { 225 List digitalAssets = new ArrayList (); 226 227 try 228 { 229 for(Iterator i = contentMap.keySet().iterator();i.hasNext();) 230 { 231 Integer _contentId = (Integer ) i.next(); 232 DigitalAssetCollection collection = new DigitalAssetCollection(_contentId, (String ) contentMap.get(_contentId)); 233 collection.setContentPath(getContentPath(_contentId)); 234 235 if(filter.length() > 0) 236 { 237 for(Iterator assetIterator=DigitalAssetController.getDigitalAssetVOList(_contentId, this.languageId, true).iterator();assetIterator.hasNext();) 238 { 239 DigitalAssetVO digitalAssetVO = (DigitalAssetVO) assetIterator.next(); 240 if(digitalAssetVO.getAssetContentType().matches(filter)) 241 { 242 collection.getAssets().add(digitalAssetVO); 243 } 244 } 245 } 246 else 247 { 248 collection.getAssets().addAll(DigitalAssetController.getDigitalAssetVOList(_contentId, this.languageId, true)); 249 } 250 251 252 ContentVersionVO contentVersionVO = getLatestContentVersionVO(_contentId); 253 if(contentVersionVO != null) 254 { 255 collection.setContentVersionId(contentVersionVO.getContentVersionId()); 256 collection.setLocked(ContentVersionVO.WORKING_STATE.compareTo(contentVersionVO.getStateId())!=0); 257 } 258 259 digitalAssets.add(collection); 260 } 261 } 262 catch(Exception e) 263 { 264 logger.warn("We could not fetch the list of digitalAssets: " + e.getMessage(), e); 265 } 266 267 return digitalAssets; 268 } 269 270 271 275 276 public String getDigitalAssetUrl(Integer digitalAssetId) throws Exception 277 { 278 String imageHref = null; 279 try 280 { 281 imageHref = DigitalAssetController.getDigitalAssetUrl(digitalAssetId); 282 } 283 catch(Exception e) 284 { 285 logger.warn("We could not get the url of the digitalAsset: " + e.getMessage(), e); 286 imageHref = e.getMessage(); 287 } 288 289 return imageHref; 290 } 291 292 293 297 298 public String getDigitalAssetThumbnailUrl(Integer digitalAssetId) throws Exception 299 { 300 String imageHref = null; 301 try 302 { 303 imageHref = DigitalAssetController.getDigitalAssetThumbnailUrl(digitalAssetId); 304 } 305 catch(Exception e) 306 { 307 logger.warn("We could not get the url of the thumbnail: " + e.getMessage(), e); 308 imageHref = e.getMessage(); 309 } 310 311 return imageHref; 312 } 313 314 315 319 320 public String getDigitalAssetUrl(Integer contentId, Integer languageId) throws Exception 321 { 322 String imageHref = null; 323 try 324 { 325 imageHref = DigitalAssetController.getDigitalAssetUrl(contentId, languageId); 326 } 327 catch(Exception e) 328 { 329 logger.warn("We could not get the url of the digitalAsset: " + e.getMessage(), e); 330 imageHref = e.getMessage(); 331 } 332 333 return imageHref; 334 } 335 336 337 341 342 public String getDigitalAssetThumbnailUrl(Integer contentId, Integer languageId) throws Exception 343 { 344 String imageHref = null; 345 try 346 { 347 imageHref = DigitalAssetController.getDigitalAssetThumbnailUrl(contentId, languageId); 348 } 349 catch(Exception e) 350 { 351 logger.warn("We could not get the url of the thumbnail: " + e.getMessage(), e); 352 imageHref = e.getMessage(); 353 } 354 355 return imageHref; 356 } 357 358 359 public void setRepositoryId(Integer repositoryId) 360 { 361 this.repositoryId = repositoryId; 362 } 363 364 public List getRepositories() 365 { 366 return repositories; 367 } 368 369 public String getAssetKey() 370 { 371 return assetKey; 372 } 373 374 public void setAssetKey(String assetKey) 375 { 376 this.assetKey = assetKey; 377 } 378 379 public boolean getTreatAsLink() 380 { 381 return treatAsLink; 382 } 383 384 public void setTreatAsLink(boolean treatAsLink) 385 { 386 this.treatAsLink = treatAsLink; 387 } 388 389 public ContentVO getContentVO() 390 { 391 return contentVO; 392 } 393 394 395 protected ContentVersionVO getLatestContentVersionVO(Integer contentId) throws SystemException, Exception 396 { 397 Integer contentVersionId = null; 398 ContentVersionVO contentVersionVO = null; 399 contentVersionVO = ContentVersionController.getContentVersionController().getLatestActiveContentVersionVO(contentId, languageId); 400 401 Integer usedRepositoryId = this.repositoryId; 402 if(this.repositoryId == null && this.contentVO != null) 403 usedRepositoryId = this.contentVO.getRepositoryId(); 404 405 LanguageVO masterLanguageVO = LanguageController.getController().getMasterLanguage(usedRepositoryId); 406 contentVersionVO = ContentVersionController.getContentVersionController().getLatestActiveContentVersionVO(contentId, masterLanguageVO.getId()); 407 408 if(contentVersionVO != null) 409 contentVersionId = contentVersionVO.getContentVersionId(); 410 411 412 if(contentVersionId != null) 413 contentVersionVO = ContentVersionControllerProxy.getController().getACContentVersionVOWithId(this.getInfoGluePrincipal(), contentVersionId); 414 415 return contentVersionVO; 416 417 425 426 } 427 428 public class FilterVO 429 { 430 private String name = null; 431 private String value = null; 432 public FilterVO(String name, String value) { 433 super(); 434 this.name = name; 435 this.value = value; 436 } 437 public String getName() { 438 return name; 439 } 440 public void setName(String name) { 441 this.name = name; 442 } 443 public String getValue() { 444 return value; 445 } 446 public void setValue(String value) { 447 this.value = value; 448 } 449 } 450 451 public class DigitalAssetCollection 452 { 453 List assets = new ArrayList (); 454 String contentPath = null; 455 Integer contentId = null; 456 Integer contentVersionId = null; 457 boolean locked = false; 458 Integer languageId = null; 459 String contentName = null; 460 461 462 public DigitalAssetCollection(Integer contentId, String contentName) 463 { 464 this.contentId = contentId; 465 this.contentName = contentName; 466 } 467 public List getAssets() 468 { 469 return assets; 470 } 471 public void setAssets(List assets) 472 { 473 this.assets = assets; 474 } 475 public Integer getContentId() 476 { 477 return contentId; 478 } 479 public void setContentId(Integer contentId) 480 { 481 this.contentId = contentId; 482 } 483 public String getContentName() 484 { 485 return contentName; 486 } 487 public void setContentName(String contentName) 488 { 489 this.contentName = contentName; 490 } 491 public String getContentPath() 492 { 493 return contentPath; 494 } 495 public void setContentPath(String contentPath) 496 { 497 this.contentPath = contentPath; 498 } 499 public Integer getContentVersionId() { 500 return contentVersionId; 501 } 502 public void setContentVersionId(Integer contentVersionId) { 503 this.contentVersionId = contentVersionId; 504 } 505 public Integer getLanguageId() { 506 return languageId; 507 } 508 public void setLanguageId(Integer languageId) { 509 this.languageId = languageId; 510 } 511 public boolean isLocked() { 512 return locked; 513 } 514 public void setLocked(boolean locked) { 515 this.locked = locked; 516 } 517 518 } 519 520 public boolean isShowLeafs() { 521 return showLeafs; 522 } 523 524 public void setShowLeafs(boolean showLeafs) { 525 this.showLeafs = showLeafs; 526 } 527 528 public List getFilters() { 529 return filters; 530 } 531 532 public String getFilter() { 533 return filter; 534 } 535 536 public void setFilter(String filter) { 537 this.filter = filter; 538 } 539 540 } 541 | Popular Tags |