1 23 24 package org.infoglue.deliver.controllers.kernel.impl.simple; 25 26 import java.io.File ; 27 import java.util.ArrayList ; 28 import java.util.Collection ; 29 import java.util.Collections ; 30 import java.util.Date ; 31 import java.util.Iterator ; 32 import java.util.List ; 33 import java.util.Vector ; 34 35 import org.apache.log4j.Logger; 36 import org.exolab.castor.jdo.Database; 37 import org.exolab.castor.jdo.OQLQuery; 38 import org.exolab.castor.jdo.QueryResults; 39 import org.infoglue.cms.applications.common.VisualFormatter; 40 import org.infoglue.cms.controllers.kernel.impl.simple.AccessRightController; 41 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeController; 42 import org.infoglue.cms.entities.content.Content; 43 import org.infoglue.cms.entities.content.ContentCategoryVO; 44 import org.infoglue.cms.entities.content.ContentVO; 45 import org.infoglue.cms.entities.content.ContentVersion; 46 import org.infoglue.cms.entities.content.ContentVersionVO; 47 import org.infoglue.cms.entities.content.DigitalAsset; 48 import org.infoglue.cms.entities.content.impl.simple.ContentImpl; 49 import org.infoglue.cms.entities.content.impl.simple.ContentVersionImpl; 50 import org.infoglue.cms.entities.content.impl.simple.MediumContentImpl; 51 import org.infoglue.cms.entities.content.impl.simple.SmallContentImpl; 52 import org.infoglue.cms.entities.management.ContentTypeDefinitionVO; 53 import org.infoglue.cms.entities.management.LanguageVO; 54 import org.infoglue.cms.entities.management.Repository; 55 import org.infoglue.cms.entities.structure.SiteNode; 56 import org.infoglue.cms.entities.structure.SiteNodeVO; 57 import org.infoglue.cms.entities.structure.impl.simple.SiteNodeImpl; 58 import org.infoglue.cms.exception.SystemException; 59 import org.infoglue.cms.security.InfoGluePrincipal; 60 import org.infoglue.cms.util.CmsPropertyHandler; 61 import org.infoglue.deliver.applications.databeans.DeliveryContext; 62 import org.infoglue.deliver.controllers.kernel.URLComposer; 63 import org.infoglue.deliver.util.CacheController; 64 import org.infoglue.deliver.util.NullObject; 65 66 67 public class ContentDeliveryController extends BaseDeliveryController 68 { 69 private final static Logger logger = Logger.getLogger(ContentDeliveryController.class.getName()); 70 71 private URLComposer urlComposer = null; 72 private VisualFormatter formatter = new VisualFormatter(); 73 74 77 78 private ContentDeliveryController() 79 { 80 urlComposer = URLComposer.getURLComposer(); 81 } 82 83 86 87 public static ContentDeliveryController getContentDeliveryController() 88 { 89 return new ContentDeliveryController(); 90 } 91 92 96 97 private Integer getOperatingMode() 98 { 99 Integer operatingMode = new Integer (0); try 101 { 102 operatingMode = new Integer (CmsPropertyHandler.getOperatingMode()); 103 } 105 catch(Exception e) 106 { 107 logger.warn("We could not get the operating mode from the propertyFile:" + e.getMessage(), e); 108 } 109 return operatingMode; 110 } 111 112 113 116 117 public ContentVO getContentVO(Integer contentId, Database db) throws SystemException, Exception 118 { 119 ContentVO contentVO = null; 120 121 contentVO = (ContentVO)getVOWithId(SmallContentImpl.class, contentId, db); 122 123 return contentVO; 124 } 125 126 129 130 public ContentVO getContentVO(Database db, Integer contentId, DeliveryContext deliveryContext) throws SystemException, Exception 131 { 132 deliveryContext.addUsedContent("content_" + contentId); 133 134 ContentVO contentVO = (ContentVO)getVOWithId(SmallContentImpl.class, contentId, db); 135 136 return contentVO; 137 } 138 139 140 144 145 public ContentVersionVO getContentVersionVO(Database db, Integer siteNodeId, Integer contentId, Integer languageId, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception 146 { 147 ContentVersionVO contentVersionVO = null; 148 149 SiteNodeVO siteNodeVO = (SiteNodeVO)getVOWithId(SiteNodeImpl.class, siteNodeId, db); 150 String contentVersionKey = "contentVersionVO_" + siteNodeVO.getRepositoryId() + "_" + contentId + "_" + languageId + "_" + useLanguageFallback; 151 logger.info("contentVersionKey:" + contentVersionKey); 152 contentVersionVO = (ContentVersionVO)CacheController.getCachedObjectFromAdvancedCache("contentVersionCache", contentVersionKey); 153 154 if(contentVersionVO != null) 155 { 156 } 158 else 159 { 160 ContentVersion contentVersion = this.getContentVersion(siteNodeId, contentId, languageId, db, useLanguageFallback, deliveryContext, infoGluePrincipal); 161 162 if(contentVersion != null) 163 { 164 contentVersionVO = contentVersion.getValueObject(); 165 166 CacheController.cacheObjectInAdvancedCache("contentVersionCache", contentVersionKey, contentVersionVO, new String []{"contentVersion_" + contentVersionVO.getId(), "content_" + contentVersionVO.getContentId()}, true); 167 } 168 169 } 170 171 if(contentVersionVO != null) 172 deliveryContext.addUsedContentVersion("contentVersion_" + contentVersionVO.getId()); 173 174 return contentVersionVO; 175 } 176 177 178 182 183 private ContentVersion getContentVersion(Integer siteNodeId, Integer contentId, Integer languageId, Database db, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception 184 { 185 if(contentId == null || contentId.intValue() < 1) 186 return null; 187 188 ContentVersion contentVersion = null; 189 190 MediumContentImpl content = (MediumContentImpl)getObjectWithId(MediumContentImpl.class, contentId, db); 191 boolean isValidContent = isValidContent(infoGluePrincipal, content, languageId, useLanguageFallback, false, db, deliveryContext); 192 if(isValidContent) 193 { 194 contentVersion = getContentVersion(content, languageId, getOperatingMode(), deliveryContext, db); 195 if(contentVersion == null && useLanguageFallback) 196 { 197 logger.info("Did not find it in requested languge... lets check the masterlanguage...."); 198 199 Integer masterLanguageId = LanguageDeliveryController.getLanguageDeliveryController().getMasterLanguageForSiteNode(db, siteNodeId).getLanguageId(); 200 if(languageId != null && !languageId.equals(masterLanguageId)) 201 { 202 contentVersion = getContentVersion(content, masterLanguageId, getOperatingMode(), deliveryContext, db); 203 } 204 } 205 } 206 207 return contentVersion; 208 } 209 210 211 214 269 270 private ContentVersion getContentVersion(Content content, Integer languageId, Integer operatingMode, DeliveryContext deliveryContext, Database db) throws Exception 271 { 272 ContentVersion contentVersion = null; 273 274 logger.info("content:" + content.getId()); 275 logger.info("operatingMode:" + operatingMode); 276 logger.info("languageId:" + languageId); 277 278 String versionKey = "" + content.getId() + "_" + languageId + "_" + operatingMode + "_contentVersionId"; 279 281 Object object = CacheController.getCachedObjectFromAdvancedCache("contentVersionCache", versionKey); 282 if(object instanceof NullObject) 284 { 285 logger.info("There was an cached parentSiteNodeVO but it was null:" + object); 286 } 287 else if(object != null) 288 { 289 Integer contentVersionId = (Integer )object; 290 logger.info("There was a cached content version id:" + contentVersionId); 291 contentVersion = (ContentVersion)getObjectWithId(ContentVersionImpl.class, contentVersionId, db); 293 logger.info("contentVersion read"); 295 } 296 else 297 { 298 OQLQuery oql = db.getOQLQuery( "SELECT cv FROM org.infoglue.cms.entities.content.impl.simple.ContentVersionImpl cv WHERE cv.contentId = $1 AND cv.language.languageId = $2 AND cv.stateId >= $3 AND cv.isActive = $4 ORDER BY cv.contentVersionId desc"); 300 oql.bind(content.getId()); 301 oql.bind(languageId); 302 oql.bind(operatingMode); 303 oql.bind(true); 304 305 QueryResults results = oql.execute(Database.ReadOnly); 306 307 if (results.hasMore()) 308 { 309 contentVersion = (ContentVersion)results.next(); 310 logger.info("found one:" + contentVersion.getId()); 311 312 CacheController.cacheObjectInAdvancedCache("contentVersionCache", versionKey, contentVersion.getId(), new String []{"contentVersion_" + contentVersion.getId(), "content_" + contentVersion.getValueObject().getContentId()}, true); 314 } 315 else 316 { 317 CacheController.cacheObjectInAdvancedCache("contentVersionCache", versionKey, new NullObject(), new String []{"content_" + content.getId()}, true); 318 } 319 320 results.close(); 321 oql.close(); 322 } 323 324 if(contentVersion != null) 325 deliveryContext.addUsedContentVersion("contentVersion_" + contentVersion.getId()); 326 327 logger.info("end getContentVersion"); 328 329 return contentVersion; 330 } 331 332 333 337 338 public String getContentAttribute(Database db, Integer contentId, Integer languageId, String attributeName, Integer siteNodeId, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infogluePrincipal, boolean escapeHTML) throws SystemException, Exception 339 { 340 return getContentAttribute(db, contentId, languageId, attributeName, siteNodeId, useLanguageFallback, deliveryContext, infogluePrincipal, escapeHTML, null); 341 } 342 343 347 348 public String getContentAttribute(Database db, Integer contentId, Integer languageId, String attributeName, Integer siteNodeId, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infogluePrincipal, boolean escapeHTML, List usedContentVersionId) throws SystemException, Exception 349 { 350 352 String attributeKey = "" + contentId + "_" + languageId + "_" + attributeName + "_" + siteNodeId + "_" + useLanguageFallback + "_" + escapeHTML; 353 String versionKey = attributeKey + "_contentVersionId"; 354 356 359 String attribute = (String )CacheController.getCachedObjectFromAdvancedCache("contentAttributeCache", attributeKey); 360 Integer contentVersionId = (Integer )CacheController.getCachedObjectFromAdvancedCache("contentVersionCache", versionKey); 361 362 try 363 { 364 365 if(attribute != null) 366 { 367 } 371 else 372 { 373 376 ContentVersionVO contentVersionVO = getContentVersionVO(db, siteNodeId, contentId, languageId, useLanguageFallback, deliveryContext, infogluePrincipal); 377 378 if (contentVersionVO != null) 379 { 380 logger.info("found one:" + contentVersionVO); 381 attribute = getAttributeValue(db, contentVersionVO, attributeName, escapeHTML); 382 contentVersionId = contentVersionVO.getId(); 383 } 384 else 385 attribute = ""; 386 387 CacheController.cacheObjectInAdvancedCache("contentAttributeCache", attributeKey, attribute, new String []{"contentVersion_" + contentVersionId, "content_" + contentId}, true); 388 if(contentVersionId != null) 389 CacheController.cacheObjectInAdvancedCache("contentVersionCache", versionKey, contentVersionId, new String []{"contentVersion_" + contentVersionId, "content_" + contentId}, true); 390 } 391 392 deliveryContext.addUsedContentVersion("contentVersion_" + contentVersionId); 394 395 if(usedContentVersionId != null && contentVersionId != null) 396 usedContentVersionId.add(contentVersionId); 397 398 } 399 catch(Exception e) 400 { 401 e.printStackTrace(); 402 throw e; 403 } 404 405 return (attribute == null) ? "" : attribute; 406 } 407 408 409 413 414 public String getContentAttribute(Database db, ContentVersionVO contentVersionVO, String attributeName, boolean escapeHTML) throws SystemException, Exception 415 { 416 String attribute = getAttributeValue(db, contentVersionVO, attributeName, escapeHTML); 417 418 return attribute; 419 } 420 421 438 public List findContentVersionVOsForCategory(Database db, Integer categoryId, String attributeName, InfoGluePrincipal infoGluePrincipal, Integer siteNodeId, Integer languageId, boolean useLanguageFallback, DeliveryContext deliveryContext) throws SystemException, Exception 439 { 440 deliveryContext.addUsedContent("selectiveCacheUpdateNonApplicable"); 441 442 List results = findContentCategories(db, categoryId, attributeName); 443 List versions = findContentVersionsForCategories(results, db); 444 445 for (Iterator iter = versions.iterator(); iter.hasNext();) 447 { 448 ContentVersion version = (ContentVersion) iter.next(); 449 if(!isValidContentVersion(version, infoGluePrincipal, siteNodeId, languageId, useLanguageFallback, db, deliveryContext)) 450 iter.remove(); 451 } 452 453 return toVOList(versions); 454 } 455 456 463 private List findContentCategories(Database db, Integer categoryId, String attributeName) throws SystemException, Exception 464 { 465 StringBuffer oql = new StringBuffer (); 466 oql.append("SELECT c FROM org.infoglue.cms.entities.content.impl.simple.ContentCategoryImpl c "); 467 oql.append("WHERE c.category.categoryId = $1 AND c.attributeName = $2"); 468 469 ArrayList params = new ArrayList (); 470 params.add(categoryId); 471 params.add(attributeName); 472 return toVOList(executeQuery(db, oql.toString(), params)); 473 } 474 475 486 private List findContentVersionsForCategories(List contentCategories, Database db) throws Exception 487 { 488 if(contentCategories.isEmpty()) 489 return Collections.EMPTY_LIST; 490 491 497 498 StringBuffer oql = new StringBuffer (); 499 oql.append("SELECT c FROM org.infoglue.cms.entities.content.impl.simple.ContentVersionImpl c ") 500 .append("WHERE c.contentVersionId IN LIST ").append(toVersionIdList(contentCategories)); 501 502 ArrayList params = new ArrayList (); 503 return executeQuery(db, oql.toString(), params); 506 } 507 508 513 private boolean isValidContentVersion(ContentVersion version, InfoGluePrincipal infoGluePrincipal, Integer siteNodeId, Integer languageId, boolean useLanguageFallback, Database db, DeliveryContext deliveryContext) throws Exception 514 { 515 Integer contentId = version.getValueObject().getContentId(); 517 logger.info("contentId:" + contentId); 518 519 Content content = (MediumContentImpl)getObjectWithId(MediumContentImpl.class, contentId, db); 520 522 ContentVersionVO mostRecentVersion = getContentVersionVO(db, siteNodeId, content.getContentId(), languageId, useLanguageFallback, deliveryContext, infoGluePrincipal); 523 boolean isProperVersion = (mostRecentVersion != null) && (mostRecentVersion.getId().equals(version.getId())); 524 525 boolean isValidContent = isValidContent(infoGluePrincipal, content, languageId, useLanguageFallback, false, db, deliveryContext); 526 527 return isProperVersion && isValidContent; 528 } 529 530 533 private String toVersionIdList(List results) 534 { 535 StringBuffer ids = new StringBuffer ("("); 536 for(Iterator iter = results.iterator(); iter.hasNext();) 537 ids.append(((ContentCategoryVO) iter.next()).getContentVersionId() + (iter.hasNext()? ", " : "")); 538 ids.append(")"); 539 return ids.toString(); 540 } 541 542 543 546 547 public Collection getAssetKeys(Database db, Integer contentId, Integer languageId, Integer siteNodeId, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception 548 { 549 Collection assetKeys = new ArrayList (); 550 551 ContentVersion contentVersion = getContentVersion(siteNodeId, contentId, languageId, db, useLanguageFallback, deliveryContext, infoGluePrincipal); 552 if (contentVersion != null) 553 { 554 Collection assets = contentVersion.getDigitalAssets(); 555 Iterator keysIterator = assets.iterator(); 556 while(keysIterator.hasNext()) 557 { 558 DigitalAsset asset = (DigitalAsset)keysIterator.next(); 559 String assetKey = asset.getAssetKey(); 560 assetKeys.add(assetKey); 561 } 562 } 563 564 return assetKeys; 565 } 566 567 568 576 private DigitalAsset getLanguageIndependentAsset(Integer contentId, Integer languageId, Integer siteNodeId, Database db, String assetKey, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception 577 { 578 DigitalAsset asset = null; 579 582 List langs = LanguageDeliveryController.getLanguageDeliveryController().getAvailableLanguages(db, siteNodeId); 586 Iterator lit = langs.iterator(); 587 while (lit.hasNext()) 588 { 589 LanguageVO langVO = (LanguageVO) lit.next(); 590 if (langVO.getLanguageId().compareTo(languageId)!=0) 591 { 592 ContentVersion contentVersion = getContentVersion(siteNodeId, contentId, langVO.getLanguageId(), db, false, deliveryContext, infoGluePrincipal); 593 if (contentVersion != null) 594 { 595 DigitalAsset digitalAsset = 596 (assetKey == null) ? getLatestDigitalAsset(contentVersion) :getDigitalAssetWithKey(contentVersion, assetKey); 597 598 if(digitalAsset != null) 599 { 600 asset = digitalAsset; 601 break; 602 } 603 } 604 } 605 } 606 return asset; 607 } 608 609 private String getLanguageIndependentAssetUrl(Integer contentId, Integer languageId, Integer siteNodeId, Database db, String assetKey, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception 610 { 611 String assetUrl = ""; 612 assetUrl = urlComposer.composeDigitalAssetUrl("", "", deliveryContext); 613 614 DigitalAsset digitalAsset = getLanguageIndependentAsset(contentId, languageId, siteNodeId, db, assetKey, deliveryContext, infoGluePrincipal); 615 if(digitalAsset != null) 616 { 617 String fileName = digitalAsset.getDigitalAssetId() + "_" + digitalAsset.getAssetFileName(); 618 619 int i = 0; 620 File masterFile = null; 621 String filePath = CmsPropertyHandler.getProperty("digitalAssetPath." + i); 622 while(filePath != null) 623 { 624 try 625 { 626 if(masterFile == null) 627 masterFile = DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(digitalAsset, fileName, filePath); 628 else 629 DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(masterFile, fileName, filePath); 630 } 631 catch(Exception e) 632 { 633 logger.warn("An file could not be written:" + e.getMessage(), e); 634 } 635 636 i++; 637 filePath = CmsPropertyHandler.getProperty("digitalAssetPath." + i); 638 } 639 642 SiteNode siteNode = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, contentId).getSiteNode(db, siteNodeId); 643 String dnsName = CmsPropertyHandler.getWebServerAddress(); 644 if(siteNode != null && siteNode.getRepository().getDnsName() != null && !siteNode.getRepository().getDnsName().equals("")) 645 dnsName = siteNode.getRepository().getDnsName(); 646 647 assetUrl = urlComposer.composeDigitalAssetUrl(dnsName, fileName, deliveryContext); 649 } 650 return assetUrl; 651 } 652 653 654 private String getLanguageIndependentAssetThumbnailUrl(Integer contentId, Integer languageId, Integer siteNodeId, Database db, String assetKey, int width, int height, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception 655 { 656 String assetUrl = ""; 657 assetUrl = urlComposer.composeDigitalAssetUrl("", "", deliveryContext); 658 659 DigitalAsset digitalAsset = getLanguageIndependentAsset(contentId, languageId, siteNodeId, db, assetKey, deliveryContext, infoGluePrincipal); 660 if(digitalAsset != null) 661 { 662 String fileName = digitalAsset.getAssetFileName(); 663 String thumbnailFileName = "thumbnail_" + width + "_" + height + "_" + fileName; 664 665 int i = 0; 666 File masterFile = null; 667 String filePath = CmsPropertyHandler.getProperty("digitalAssetPath." + i); 668 while(filePath != null) 669 { 670 if(masterFile == null) 671 masterFile = DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAssetThumbnail(fileName, thumbnailFileName, filePath, width, height); 672 else 673 DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAssetThumbnail(fileName, thumbnailFileName, filePath, width, height); 674 675 i++; 676 filePath = CmsPropertyHandler.getProperty("digitalAssetPath." + i); 677 } 678 679 682 SiteNode siteNode = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, contentId).getSiteNode(db, siteNodeId); 683 String dnsName = CmsPropertyHandler.getWebServerAddress(); 684 if(siteNode != null && siteNode.getRepository().getDnsName() != null && !siteNode.getRepository().getDnsName().equals("")) 685 dnsName = siteNode.getRepository().getDnsName(); 686 687 assetUrl = urlComposer.composeDigitalAssetUrl(dnsName, thumbnailFileName, deliveryContext); 689 } 690 return assetUrl; 691 } 692 693 694 698 699 public Integer getDigitalAssetId(Database db, Integer contentId, Integer languageId, String assetKey, Integer siteNodeId, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception 700 { 701 Integer digitalAssetId = null; 702 703 ContentVersion contentVersion = getContentVersion(siteNodeId, contentId, languageId, db, useLanguageFallback, deliveryContext, infoGluePrincipal); 704 if (contentVersion != null) 705 { 706 DigitalAsset digitalAsset = getDigitalAssetWithKey(contentVersion, assetKey); 707 708 if(digitalAsset != null) 709 { 710 digitalAssetId = digitalAsset.getId(); 711 } 712 } 713 714 return digitalAssetId; 715 } 716 717 722 723 public String getAssetUrl(Database db, Integer contentId, Integer languageId, Integer siteNodeId, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception 724 { 725 String assetCacheKey = "" + languageId + "_" + contentId + "_" + siteNodeId + "_" + useLanguageFallback; 726 logger.info("assetCacheKey:" + assetCacheKey); 727 String cacheName = "assetUrlCache"; 728 String cachedAssetUrl = (String )CacheController.getCachedObject(cacheName, assetCacheKey); 729 if(cachedAssetUrl != null) 730 { 731 logger.info("There was an cached cachedAssetUrl:" + cachedAssetUrl); 732 return cachedAssetUrl; 733 } 734 735 String assetUrl = ""; 736 737 ContentVersion contentVersion = getContentVersion(siteNodeId, contentId, languageId, db, useLanguageFallback, deliveryContext, infoGluePrincipal); 738 if (contentVersion != null) 739 { 740 DigitalAsset digitalAsset = getLatestDigitalAsset(contentVersion); 741 742 if(digitalAsset != null) 743 { 744 String fileName = digitalAsset.getDigitalAssetId() + "_" + digitalAsset.getAssetFileName(); 745 746 int i = 0; 747 File masterFile = null; 748 String filePath = CmsPropertyHandler.getProperty("digitalAssetPath." + i); 749 while(filePath != null) 750 { 751 try 752 { 753 if(masterFile == null) 754 masterFile = DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(digitalAsset, fileName, filePath); 755 else 756 DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(masterFile, fileName, filePath); 757 } 758 catch(Exception e) 759 { 760 logger.warn("An file could not be written:" + e.getMessage(), e); 761 } 762 763 i++; 764 filePath = CmsPropertyHandler.getProperty("digitalAssetPath." + i); 765 } 766 767 770 SiteNode siteNode = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, contentId).getSiteNode(db, siteNodeId); 771 String dnsName = CmsPropertyHandler.getWebServerAddress(); 772 if(siteNode != null && siteNode.getRepository().getDnsName() != null && !siteNode.getRepository().getDnsName().equals("")) 773 dnsName = siteNode.getRepository().getDnsName(); 774 775 assetUrl = urlComposer.composeDigitalAssetUrl(dnsName, fileName, deliveryContext); 777 } 778 else 779 { 780 assetUrl = getLanguageIndependentAssetUrl(contentId, languageId, siteNodeId, db, null, deliveryContext, infoGluePrincipal); 781 } 782 } 783 784 CacheController.cacheObject(cacheName, assetCacheKey, assetUrl); 785 786 return assetUrl; 787 } 788 789 790 791 796 797 public String getAssetUrl(Database db, Integer contentId, Integer languageId, String assetKey, Integer siteNodeId, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception 798 { 799 SiteNodeVO siteNodeVO = SiteNodeController.getController().getSiteNodeVOWithId(siteNodeId, db); 800 String assetCacheKey = "" + languageId + "_" + contentId + "_" + siteNodeVO.getRepositoryId() + "_" + assetKey + "_" + useLanguageFallback + "_" + deliveryContext.getUseFullUrl(); 802 logger.info("assetCacheKey:" + assetCacheKey); 803 805 String cacheName = "assetUrlCache"; 806 String cachedAssetUrl = (String )CacheController.getCachedObject(cacheName, assetCacheKey); 807 if(cachedAssetUrl != null) 808 { 809 logger.info("There was an cached cachedAssetUrl:" + cachedAssetUrl); 810 return cachedAssetUrl; 811 } 812 813 String assetUrl = ""; 814 assetUrl = urlComposer.composeDigitalAssetUrl("", "", deliveryContext); 815 816 ContentVersion contentVersion = getContentVersion(siteNodeId, contentId, languageId, db, useLanguageFallback, deliveryContext, infoGluePrincipal); 817 ContentVO contentVO = this.getContentVO(db, contentId, deliveryContext); 818 if (contentVersion != null) 819 { 820 DigitalAsset digitalAsset = getDigitalAssetWithKey(contentVersion, assetKey); 821 822 if(digitalAsset != null) 823 { 824 String fileName = digitalAsset.getDigitalAssetId() + "_" + digitalAsset.getAssetFileName(); 825 826 int i = 0; 827 File masterFile = null; 828 String filePath = CmsPropertyHandler.getProperty("digitalAssetPath." + i); 829 while(filePath != null) 831 { 832 try 833 { 834 if(masterFile == null) 835 masterFile = DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(digitalAsset, fileName, filePath); 836 else 837 DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(masterFile, fileName, filePath); 838 } 839 catch(Exception e) 840 { 841 logger.warn("An file could not be written:" + e.getMessage(), e); 842 } 843 844 i++; 845 filePath = CmsPropertyHandler.getProperty("digitalAssetPath." + i); 846 } 848 849 852 SiteNode siteNode = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, contentId).getSiteNode(db, siteNodeId); 853 String dnsName = CmsPropertyHandler.getWebServerAddress(); 854 if(siteNode != null && siteNode.getRepository().getDnsName() != null && !siteNode.getRepository().getDnsName().equals("")) 855 dnsName = siteNode.getRepository().getDnsName(); 856 857 assetUrl = urlComposer.composeDigitalAssetUrl(dnsName, fileName, deliveryContext); 859 } 860 else if(useLanguageFallback) 861 { 862 assetUrl = getLanguageIndependentAssetUrl(contentId, languageId, siteNodeId, db, assetKey, deliveryContext, infoGluePrincipal); 863 } 864 } 865 else if(useLanguageFallback && languageId.intValue() != LanguageDeliveryController.getLanguageDeliveryController().getMasterLanguageForRepository(contentVO.getRepositoryId(), db).getId().intValue()) 866 { 867 contentVersion = this.getContentVersion(siteNodeId, contentId, languageId, db, useLanguageFallback, deliveryContext, infoGluePrincipal); 868 869 logger.info("contentVersion:" + contentVersion); 870 if(contentVersion != null) 871 { 872 DigitalAsset digitalAsset = getDigitalAssetWithKey(contentVersion, assetKey); 873 874 if(digitalAsset != null) 875 { 876 String fileName = digitalAsset.getDigitalAssetId() + "_" + digitalAsset.getAssetFileName(); 877 878 int i = 0; 879 File masterFile = null; 880 String filePath = CmsPropertyHandler.getProperty("digitalAssetPath." + i); 881 while(filePath != null) 883 { 884 try 885 { 886 if(masterFile == null) 887 masterFile = DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(digitalAsset, fileName, filePath); 888 else 889 DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(masterFile, fileName, filePath); 890 } 891 catch(Exception e) 892 { 893 logger.warn("An file could not be written:" + e.getMessage(), e); 894 } 895 896 i++; 897 filePath = CmsPropertyHandler.getProperty("digitalAssetPath." + i); 898 } 900 901 904 SiteNode siteNode = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, contentId).getSiteNode(db, siteNodeId); 905 String dnsName = CmsPropertyHandler.getWebServerAddress(); 906 if(siteNode != null && siteNode.getRepository().getDnsName() != null && !siteNode.getRepository().getDnsName().equals("")) 907 dnsName = siteNode.getRepository().getDnsName(); 908 909 assetUrl = urlComposer.composeDigitalAssetUrl(dnsName, fileName, deliveryContext); 911 } 912 else if(useLanguageFallback) 913 { 914 assetUrl = getLanguageIndependentAssetUrl(contentId, languageId, siteNodeId, db, assetKey, deliveryContext, infoGluePrincipal); 915 } 916 } 917 } 918 919 CacheController.cacheObject(cacheName, assetCacheKey, assetUrl); 920 921 return assetUrl; 922 } 923 924 925 926 931 932 public String getAssetThumbnailUrl(Database db, Integer contentId, Integer languageId, Integer siteNodeId, boolean useLanguageFallback, int width, int height, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception 933 { 934 String assetCacheKey = "" + languageId + "_" + contentId + "_" + siteNodeId + "_" + useLanguageFallback + "_" + width + "_" + height; 935 logger.info("assetCacheKey:" + assetCacheKey); 936 String cacheName = "assetThumbnailUrlCache"; 937 String cachedAssetUrl = (String )CacheController.getCachedObject(cacheName, assetCacheKey); 938 if(cachedAssetUrl != null) 939 { 940 logger.info("There was an cached cachedAssetUrl:" + cachedAssetUrl); 941 return cachedAssetUrl; 942 } 943 944 String assetUrl = ""; 945 946 ContentVersion contentVersion = getContentVersion(siteNodeId, contentId, languageId, db, useLanguageFallback, deliveryContext, infoGluePrincipal); 947 if (contentVersion != null) 948 { 949 DigitalAsset digitalAsset = getLatestDigitalAsset(contentVersion); 950 951 if(digitalAsset != null) 952 { 953 String fileName = digitalAsset.getDigitalAssetId() + "_" + digitalAsset.getAssetFileName(); 954 String thumbnailFileName = "thumbnail_" + width + "_" + height + "_" + fileName; 955 956 int i = 0; 957 File masterFile = null; 958 File masterThumbFile = null; 959 String filePath = CmsPropertyHandler.getProperty("digitalAssetPath." + i); 960 while(filePath != null) 961 { 962 try 963 { 964 if(masterFile == null) 965 masterFile = DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(digitalAsset, fileName, filePath); 966 else 967 DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(masterFile, fileName, filePath); 968 969 if(masterThumbFile == null) 970 masterThumbFile = DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAssetThumbnail(fileName, thumbnailFileName, filePath, width, height); 971 else 972 DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAssetThumbnail(fileName, thumbnailFileName, filePath, width, height); 973 } 974 catch(Exception e) 975 { 976 logger.warn("An file could not be written:" + e.getMessage(), e); 977 } 978 979 i++; 980 filePath = CmsPropertyHandler.getProperty("digitalAssetPath." + i); 981 } 982 983 987 SiteNode siteNode = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, contentId).getSiteNode(db, siteNodeId); 988 String dnsName = CmsPropertyHandler.getWebServerAddress(); 989 if(siteNode != null && siteNode.getRepository().getDnsName() != null && !siteNode.getRepository().getDnsName().equals("")) 990 dnsName = siteNode.getRepository().getDnsName(); 991 992 assetUrl = urlComposer.composeDigitalAssetUrl(dnsName, thumbnailFileName, deliveryContext); 994 } 995 else 996 { 997 assetUrl = getLanguageIndependentAssetThumbnailUrl(contentId, languageId, siteNodeId, db, null, width, height, deliveryContext, infoGluePrincipal); 998 } 999 } 1000 1001 CacheController.cacheObject(cacheName, assetCacheKey, assetUrl); 1002 1003 return assetUrl; 1004 } 1005 1006 1007 1008 1013 1014 public String getAssetThumbnailUrl(Database db, Integer contentId, Integer languageId, String assetKey, Integer siteNodeId, boolean useLanguageFallback, int width, int height, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception 1015 { 1016 String assetCacheKey = "" + languageId + "_" + contentId + "_" + siteNodeId + "_" + assetKey + "_" + useLanguageFallback + "_" + width + "_" + height; 1017 logger.info("assetCacheKey:" + assetCacheKey); 1018 String cacheName = "assetThumbnailUrlCache"; 1019 String cachedAssetUrl = (String )CacheController.getCachedObject(cacheName, assetCacheKey); 1020 if(cachedAssetUrl != null) 1021 { 1022 logger.info("There was an cached cachedAssetUrl:" + cachedAssetUrl); 1023 return cachedAssetUrl; 1024 } 1025 1026 String assetUrl = ""; 1027 1028 ContentVersion contentVersion = getContentVersion(siteNodeId, contentId, languageId, db, useLanguageFallback, deliveryContext, infoGluePrincipal); 1029 if (contentVersion != null) 1030 { 1031 DigitalAsset digitalAsset = getDigitalAssetWithKey(contentVersion, assetKey); 1032 1033 if(digitalAsset != null) 1034 { 1035 String fileName = digitalAsset.getDigitalAssetId() + "_" + digitalAsset.getAssetFileName(); 1036 String thumbnailFileName = "thumbnail_" + width + "_" + height + "_" + fileName; 1037 1038 int i = 0; 1039 File masterFile = null; 1040 File masterThumbFile = null; 1041 String filePath = CmsPropertyHandler.getProperty("digitalAssetPath." + i); 1042 while(filePath != null) 1043 { 1044 try 1045 { 1046 if(masterFile == null) 1047 masterFile = DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(digitalAsset, fileName, filePath); 1048 else 1049 DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(digitalAsset, fileName, filePath); 1050 1051 if(masterThumbFile == null) 1052 masterThumbFile = DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAssetThumbnail(fileName, thumbnailFileName, filePath, width, height); 1053 else 1054 DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAssetThumbnail(fileName, thumbnailFileName, filePath, width, height); 1055 } 1056 catch(Exception e) 1057 { 1058 logger.warn("An file could not be written:" + e.getMessage(), e); 1059 } 1060 1061 i++; 1062 filePath = CmsPropertyHandler.getProperty("digitalAssetPath." + i); 1063 } 1064 1065 1069 SiteNode siteNode = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, contentId).getSiteNode(db, siteNodeId); 1070 String dnsName = CmsPropertyHandler.getWebServerAddress(); 1071 if(siteNode != null && siteNode.getRepository().getDnsName() != null && !siteNode.getRepository().getDnsName().equals("")) 1072 dnsName = siteNode.getRepository().getDnsName(); 1073 1074 assetUrl = urlComposer.composeDigitalAssetUrl(dnsName, thumbnailFileName, deliveryContext); 1076 } 1077 else 1078 { 1079 assetUrl = getLanguageIndependentAssetThumbnailUrl(contentId, languageId, siteNodeId, db, assetKey, width, height, deliveryContext, infoGluePrincipal); 1080 } 1081 1082 } 1083 1084 CacheController.cacheObject(cacheName, assetCacheKey, assetUrl); 1085 1086 return assetUrl; 1087 } 1088 1089 1090 1091 1094 1095 public Integer getAssetFileSize(Database db, Integer contentId, Integer languageId, Integer siteNodeId, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception 1096 { 1097 return getAssetFileSize(db, contentId, languageId, null, siteNodeId, useLanguageFallback, deliveryContext, infoGluePrincipal); 1098 } 1099 1100 public Integer getAssetFileSize(Database db, Integer contentId, Integer languageId, String assetKey, Integer siteNodeId, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception 1101 { 1102 Integer fileSize = null; 1103 1104 ContentVersion contentVersion = getContentVersion(siteNodeId, contentId, languageId, db, useLanguageFallback, deliveryContext, infoGluePrincipal); 1105 if (contentVersion != null) 1106 { 1107 DigitalAsset digitalAsset = 1108 (assetKey == null) ? getLatestDigitalAsset(contentVersion) : getDigitalAssetWithKey(contentVersion, assetKey); 1109 1110 if(digitalAsset == null) 1111 digitalAsset = getLanguageIndependentAsset(contentId, languageId, siteNodeId, db, assetKey, deliveryContext, infoGluePrincipal); 1112 1113 if(digitalAsset != null) 1114 { 1115 fileSize = digitalAsset.getAssetFileSize(); 1116 } 1117 } 1118 1119 return fileSize; 1120 } 1121 1122 1123 1127 1128 public String getArchiveBaseUrl(Database db, Integer contentId, Integer languageId, String assetKey, Integer siteNodeId, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception 1129 { 1130 String archiveBaseUrl = null; 1131 1132 ContentVersion contentVersion = getContentVersion(siteNodeId, contentId, languageId, db, useLanguageFallback, deliveryContext, infoGluePrincipal); 1133 if (contentVersion != null) 1134 { 1135 DigitalAsset digitalAsset = getDigitalAssetWithKey(contentVersion, assetKey); 1136 1137 if(digitalAsset != null) 1138 { 1139 String fileName = digitalAsset.getAssetFileName(); 1140 1141 int i = 0; 1142 File masterFile = null; 1143 String filePath = CmsPropertyHandler.getProperty("digitalAssetPath." + i); 1144 while(filePath != null) 1145 { 1146 File unzipDirectory = new File (filePath + File.separator + fileName.substring(0, fileName.lastIndexOf("."))); 1147 unzipDirectory.mkdirs(); 1148 1149 if(masterFile == null) 1150 masterFile = DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpAndUnzipDigitalAsset(digitalAsset, fileName, filePath, unzipDirectory); 1151 else 1152 DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpAndUnzipDigitalAsset(masterFile, fileName, filePath, unzipDirectory); 1153 1154 i++; 1155 filePath = CmsPropertyHandler.getProperty("digitalAssetPath." + i); 1156 } 1157 1158 1163 SiteNode siteNode = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, contentId).getSiteNode(db, siteNodeId); 1164 String dnsName = CmsPropertyHandler.getWebServerAddress(); 1165 if(siteNode != null && siteNode.getRepository().getDnsName() != null && !siteNode.getRepository().getDnsName().equals("")) 1166 dnsName = siteNode.getRepository().getDnsName(); 1167 1168 archiveBaseUrl = urlComposer.composeDigitalAssetUrl(dnsName, fileName.substring(0, fileName.lastIndexOf(".")), deliveryContext); 1170 } 1171 } 1172 1173 return archiveBaseUrl; 1174 } 1175 1176 public Vector getArchiveEntries(Database db, Integer contentId, Integer languageId, String assetKey, Integer siteNodeId, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception 1177 { 1178 Vector entries = null; 1179 1180 ContentVersion contentVersion = getContentVersion(siteNodeId, contentId, languageId, db, useLanguageFallback, deliveryContext, infoGluePrincipal); 1181 if (contentVersion != null) 1182 { 1183 DigitalAsset digitalAsset = getDigitalAssetWithKey(contentVersion, assetKey); 1184 1185 if(digitalAsset != null) 1186 { 1187 String fileName = digitalAsset.getAssetFileName(); 1188 1189 int i = 0; 1190 File masterFile = null; 1191 String filePath = CmsPropertyHandler.getProperty("digitalAssetPath." + i); 1192 while(filePath != null) 1193 { 1194 File unzipDirectory = new File (filePath + File.separator + fileName.substring(0, fileName.lastIndexOf("."))); 1195 unzipDirectory.mkdirs(); 1196 1197 if(masterFile == null) 1198 { 1199 entries = DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpAndGetZipEntries(digitalAsset, fileName, filePath, unzipDirectory); 1200 masterFile = new File (filePath + File.separator + fileName); 1201 } 1202 else 1203 { 1204 entries = DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpAndGetZipEntries(masterFile, fileName, filePath, unzipDirectory); 1205 } 1206 1207 i++; 1208 filePath = CmsPropertyHandler.getProperty("digitalAssetPath." + i); 1209 } 1210 1211 } 1216 } 1217 1218 return entries; 1219 } 1220 1221 1222 1223 1226 1227 private DigitalAsset getDigitalAssetWithKey(ContentVersion contentVersion, String assetKey) 1228 { 1229 Collection digitalAssets = contentVersion.getDigitalAssets(); 1230 Iterator iterator = digitalAssets.iterator(); 1231 1232 while(iterator.hasNext()) 1233 { 1234 DigitalAsset currentDigitalAsset = (DigitalAsset)iterator.next(); 1235 1236 if(currentDigitalAsset != null && currentDigitalAsset.getAssetKey().equalsIgnoreCase(assetKey)) 1237 { 1238 return currentDigitalAsset; 1239 } 1240 } 1241 1242 return null; 1243 } 1244 1245 1248 1249 private DigitalAsset getLatestDigitalAsset(ContentVersion contentVersion) 1250 { 1251 Collection digitalAssets = contentVersion.getDigitalAssets(); 1252 Iterator iterator = digitalAssets.iterator(); 1253 1254 DigitalAsset digitalAsset = null; 1255 while(iterator.hasNext()) 1256 { 1257 DigitalAsset currentDigitalAsset = (DigitalAsset)iterator.next(); 1258 if(digitalAsset == null || currentDigitalAsset.getDigitalAssetId().intValue() > digitalAsset.getDigitalAssetId().intValue()) 1259 digitalAsset = currentDigitalAsset; 1260 } 1261 return digitalAsset; 1262 } 1263 1264 1265 1266 1267 1271 public String getAttributeValue(Database db, ContentVersionVO contentVersionVO, String key, boolean escapeHTML) 1272 { 1273 String value = ""; 1274 if(contentVersionVO != null) 1275 { 1276 try 1277 { 1278 String xml = contentVersionVO.getVersionValue(); 1279 1280 int startTagIndex = xml.indexOf("<" + key + ">"); 1281 int endTagIndex = xml.indexOf("]]></" + key + ">"); 1282 1283 if(startTagIndex > 0 && startTagIndex < xml.length() && endTagIndex > startTagIndex && endTagIndex < xml.length()) 1284 value = xml.substring(startTagIndex + key.length() + 11, endTagIndex); 1285 1286 if(escapeHTML) 1287 value = formatter.escapeHTML(value); 1288 1289 1312 } 1313 catch(Exception e) 1314 { 1315 logger.error("An error occurred so we should not return the attribute value:" + e, e); 1316 } 1317 } 1318 1319 return value; 1320 } 1321 1322 1323 1326 1327 public List getChildContents(Database db, InfoGluePrincipal infoGluePrincipal, Integer contentId, Integer languageId, boolean useLanguageFallback, boolean includeFolders, DeliveryContext deliveryContext) throws SystemException, Exception 1328 { 1329 List childContents = new ArrayList (); 1330 1331 getChildContents(infoGluePrincipal, childContents, contentId, languageId, useLanguageFallback, 0, false, includeFolders, 1, db, deliveryContext); 1332 1333 return childContents; 1334 } 1335 1336 1337 1340 1341 public List getSortedChildContents(InfoGluePrincipal infoGluePrincipal, Integer languageId, Integer contentId, Integer siteNodeId, Database db, boolean searchRecursive, Integer maximumNumberOfLevels, String sortAttribute, String sortOrder, boolean useLanguageFallback, boolean includeFolders, DeliveryContext deliveryContext) throws SystemException, Exception 1342 { 1343 1344 String sortedChildContentsKey = "" + infoGluePrincipal.getName() + "_" + languageId + "_" + contentId + "_" + siteNodeId + "_" + searchRecursive + "_" + maximumNumberOfLevels + "_" + sortAttribute + "_" + sortOrder + "_" + useLanguageFallback + "_" + includeFolders; 1345 logger.info("sortedChildContentsKey:" + sortedChildContentsKey); 1346 String cacheName = "sortedChildContentsCache"; 1347 List cachedSortedContentVOList = (List )CacheController.getCachedObject(cacheName, sortedChildContentsKey); 1348 if(cachedSortedContentVOList != null) 1349 { 1350 logger.info("There was an cached content cachedSortedContentVOList:" + cachedSortedContentVOList.size()); 1351 return cachedSortedContentVOList; 1352 } 1353 1354 List sortedContentVOList = new ArrayList (); 1355 1356 List unsortedChildren = getChildContents(infoGluePrincipal, languageId, useLanguageFallback, contentId, siteNodeId, searchRecursive, maximumNumberOfLevels, db, includeFolders, deliveryContext); 1357 1358 List sortedContents = sortContents(db, unsortedChildren, languageId, siteNodeId, sortAttribute, sortOrder, useLanguageFallback, includeFolders, deliveryContext, infoGluePrincipal); 1359 1360 Iterator boundContentsIterator = sortedContents.iterator(); 1361 while(boundContentsIterator.hasNext()) 1362 { 1363 Content content = (Content)boundContentsIterator.next(); 1364 sortedContentVOList.add(content.getValueObject()); 1365 } 1366 1367 CacheController.cacheObject(cacheName, sortedChildContentsKey, sortedContentVOList); 1368 1369 return sortedContentVOList; 1370 } 1371 1372 1373 1374 1377 1378 public ContentTypeDefinitionVO getContentTypeDefinitionVO(Database db, Integer contentId) throws SystemException, Exception 1379 { 1380 ContentTypeDefinitionVO contentTypeDefinitionVO = null; 1381 1382 Content content = (Content)getObjectWithId(ContentImpl.class, contentId, db); 1383 contentTypeDefinitionVO = content.getContentTypeDefinition().getValueObject(); 1384 1385 return contentTypeDefinitionVO; 1386 } 1387 1388 1389 1393 1394 private List getChildContents(InfoGluePrincipal infoGluePrincipal, Integer languageId, boolean useLanguageFallback, Integer contentId, Integer siteNodeId, boolean searchRecursive, Integer maximumNumberOfLevels, Database db, boolean includeFolders, DeliveryContext deliveryContext) throws SystemException, Exception 1395 { 1396 List contents = new ArrayList (); 1397 1398 getChildContents(infoGluePrincipal, contents, contentId, languageId, useLanguageFallback, 0, searchRecursive, maximumNumberOfLevels.intValue(), db, includeFolders, deliveryContext); 1399 1400 return contents; 1401 } 1402 1403 1404 1407 1408 private void getChildContents(InfoGluePrincipal infoGluePrincipal, List contents, Integer contentId, Integer languageId, boolean useLanguageFallback, int currentLevel, boolean searchRecursive, int maximumNumberOfLevels, Database db, boolean includeFolders, DeliveryContext deliveryContext) throws SystemException, Exception 1409 { 1410 1433 1434 deliveryContext.addUsedContent("selectiveCacheUpdateNonApplicable"); 1435 1436 OQLQuery oql = db.getOQLQuery("SELECT content FROM org.infoglue.cms.entities.content.impl.simple.ContentImpl content WHERE content.parentContent.contentId = $1 ORDER BY content.contentId"); 1437 oql.bind(contentId); 1438 1439 QueryResults results = oql.execute(Database.ReadOnly); 1440 1441 while (results.hasMore()) 1442 { 1443 Content content = (Content)results.next(); 1444 1445 if(searchRecursive && currentLevel < maximumNumberOfLevels) 1446 getChildContents(infoGluePrincipal, contents, content.getContentId(), languageId, useLanguageFallback, currentLevel + 1, searchRecursive, maximumNumberOfLevels, db, includeFolders, deliveryContext); 1447 1448 if(isValidContent(infoGluePrincipal, content, languageId, useLanguageFallback, includeFolders, db, deliveryContext)) 1449 { 1450 contents.add(content); 1451 } 1452 } 1453 1454 results.close(); 1455 oql.close(); 1456 } 1457 1458 1459 1462 1463 private void getChildContents(InfoGluePrincipal infoGluePrincipal, List contents, Integer contentId, Integer languageId, boolean useLanguageFallback, int currentLevel, boolean searchRecursive, boolean includeFolders, int maximumNumberOfLevels, Database db, DeliveryContext deliveryContext) throws SystemException, Exception 1464 { 1465 deliveryContext.addUsedContent("selectiveCacheUpdateNonApplicable"); 1466 1467 OQLQuery oql = db.getOQLQuery( "SELECT content FROM org.infoglue.cms.entities.content.impl.simple.ContentImpl content WHERE content.parentContent.contentId = $1 ORDER BY content.contentId"); 1468 oql.bind(contentId); 1469 1470 QueryResults results = oql.execute(Database.ReadOnly); 1471 1472 while (results.hasMore()) 1473 { 1474 Content content = (Content)results.next(); 1475 1476 if(searchRecursive && currentLevel < maximumNumberOfLevels) 1477 getChildContents(infoGluePrincipal, contents, content.getContentId(), languageId, useLanguageFallback, currentLevel + 1, searchRecursive, includeFolders, maximumNumberOfLevels, db, deliveryContext); 1478 1479 if(content.getIsBranch().booleanValue() && includeFolders && isValidContent(infoGluePrincipal, content, languageId, useLanguageFallback, includeFolders, db, deliveryContext)) 1480 { 1481 contents.add(content); 1482 } 1483 else if(isValidContent(infoGluePrincipal, content, languageId, useLanguageFallback, includeFolders, db, deliveryContext)) 1484 { 1485 contents.add(content); 1486 } 1487 } 1488 1489 results.close(); 1490 oql.close(); 1491 } 1492 1493 1496 1497 private boolean isValidOnDates(Date publishDate, Date expireDate) 1498 { 1499 boolean isValid = true; 1500 Date now = new Date (); 1501 1502 if(publishDate.after(now) || expireDate.before(now)) 1503 isValid = false; 1504 1505 return isValid; 1506 } 1507 1508 1512 1523 1527 1528 public boolean isValidContent(Database db, Integer contentId, Integer languageId, boolean useLanguageFallback, boolean includeFolders, InfoGluePrincipal infoGluePrincipal, DeliveryContext deliveryContext) throws Exception 1529 { 1530 boolean isValidContent = false; 1531 1532 Content content = (Content)getObjectWithId(ContentImpl.class, contentId, db); 1533 isValidContent = isValidContent(infoGluePrincipal, content, languageId, useLanguageFallback, includeFolders, db, deliveryContext); 1534 1535 return isValidContent; 1536 } 1537 1538 1542 1543 public boolean isValidContent(InfoGluePrincipal infoGluePrincipal, Content content, Integer languageId, boolean useLanguageFallBack, boolean includeFolders, Database db, DeliveryContext deliveryContext) throws Exception 1544 { 1545 boolean isValidContent = false; 1546 if(infoGluePrincipal == null) 1547 throw new SystemException("There was no anonymous user found in the system. There must be - add the user anonymous/anonymous and try again."); 1548 1549 if(content.getContentTypeDefinition() != null && content.getContentTypeDefinition().getName().equalsIgnoreCase("Meta info")) 1550 return true; 1551 1552 logger.info("content:" + content.getName()); 1553 1554 Integer protectedContentId = getProtectedContentId(db, content); 1555 logger.info("IsProtected:" + protectedContentId); 1556 1557 if(protectedContentId != null && !AccessRightController.getController().getIsPrincipalAuthorized(db, infoGluePrincipal, "Content.Read", protectedContentId.toString())) 1558 { 1559 return false; 1560 } 1561 1562 if(includeFolders && content.getIsBranch().booleanValue() && isValidOnDates(content.getPublishDateTime(), content.getExpireDateTime())) 1563 { 1564 isValidContent = true; 1565 } 1566 else if(isValidOnDates(content.getPublishDateTime(), content.getExpireDateTime())) 1567 { 1568 ContentVersion contentVersion = getContentVersion(content, languageId, getOperatingMode(), deliveryContext, db); 1569 1570 Integer repositoryId = null; 1571 Repository repository = content.getRepository(); 1572 if(repository == null) 1573 { 1574 if(content instanceof MediumContentImpl) 1575 repositoryId = ((MediumContentImpl)content).getRepositoryId(); 1576 else if(content instanceof SmallContentImpl) 1577 repositoryId = ((SmallContentImpl)content).getRepositoryId(); 1578 } 1579 else 1580 { 1581 repositoryId = repository.getId(); 1582 } 1583 1584 if(contentVersion == null && useLanguageFallBack && repositoryId != null) 1585 { 1586 LanguageVO masterLanguage = LanguageDeliveryController.getLanguageDeliveryController().getMasterLanguageForRepository(repositoryId, db); 1587 if(masterLanguage != null && !masterLanguage.getId().equals(languageId)) 1588 contentVersion = getContentVersion(content, masterLanguage.getId(), getOperatingMode(), deliveryContext, db); 1589 } 1590 1591 if(contentVersion != null) 1592 isValidContent = true; 1593 1594 1605 } 1606 1607 if(isValidContent && !content.getExpireDateTime().before(new Date ())) 1608 { 1609 Date expireDateTimeCandidate = content.getExpireDateTime(); 1610 if(CacheController.expireDateTime == null || expireDateTimeCandidate.before(CacheController.expireDateTime)) 1611 { 1612 CacheController.expireDateTime = expireDateTimeCandidate; 1613 } 1614 } 1615 else if(content.getPublishDateTime().after(new Date ())) { 1617 Date publishDateTimeCandidate = content.getPublishDateTime(); 1618 if(CacheController.publishDateTime == null || publishDateTimeCandidate.after(CacheController.publishDateTime)) 1619 { 1620 CacheController.publishDateTime = publishDateTimeCandidate; 1621 } 1622 } 1623 1624 return isValidContent; 1625 } 1626 1627 1628 1629 1632 1633 public Integer getProtectedContentId(Database db, Integer contentId) throws SystemException, Exception 1634 { 1635 Integer protectedContentId = null; 1636 1637 Content content = (Content)getObjectWithId(ContentImpl.class, contentId, db); 1638 protectedContentId = getProtectedContentId(db, content); 1639 1640 return protectedContentId; 1641 } 1642 1643 1644 1647 1648 public Integer getProtectedContentId(Database db, Content content) 1649 { 1650 Integer protectedContentId = null; 1651 1652 try 1653 { 1654 logger.info("content:" + content.getId() + ":" + content.getIsProtected()); 1655 1656 if(content != null && content.getIsProtected() != null) 1657 { 1658 if(content.getIsProtected().intValue() == ContentVO.NO.intValue()) 1659 protectedContentId = null; 1660 else if(content.getIsProtected().intValue() == ContentVO.YES.intValue()) 1661 protectedContentId = content.getId(); 1662 else if(content.getIsProtected().intValue() == ContentVO.INHERITED.intValue()) 1663 { 1664 Content parentContent = null; if(content instanceof MediumContentImpl) 1666 { 1667 Integer parentContentId = ((MediumContentImpl)content).getParentContentId(); 1668 if(parentContentId != null) 1669 parentContent = (MediumContentImpl)getObjectWithId(MediumContentImpl.class, parentContentId, db); 1670 } 1671 else if(content instanceof SmallContentImpl) 1672 { 1673 Integer parentContentId = ((SmallContentImpl)content).getParentContentId(); 1674 if(parentContentId != null) 1675 parentContent = (SmallContentImpl)getObjectWithId(SmallContentImpl.class, parentContentId, db); 1676 } 1677 else if(content instanceof ContentImpl) 1678 { 1679 parentContent = content.getParentContent(); 1680 } 1681 1682 if(parentContent != null) 1683 { 1684 protectedContentId = getProtectedContentId(db, parentContent); 1685 } 1686 } 1687 } 1688 1689 } 1690 catch(Exception e) 1691 { 1692 logger.warn("An error occurred trying to get if the siteNodeVersion has disabled pageCache:" + e.getMessage(), e); 1693 } 1694 1695 return protectedContentId; 1696 } 1697 1698 1699 1702 1703 public List sortContents(Database db, Collection contents, Integer languageId, Integer siteNodeId, String sortAttributeName, String sortOrder, boolean useLanguageFallback, boolean includeFolders, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) 1704 { 1705 List sortedContents = new ArrayList (); 1706 1707 try 1708 { 1709 Iterator iterator = contents.iterator(); 1710 while(iterator.hasNext()) 1711 { 1712 Content content = (Content)iterator.next(); 1713 if(includeFolders || content.getIsBranch().booleanValue() == false) 1714 { 1715 int index = 0; 1716 Iterator sortedListIterator = sortedContents.iterator(); 1717 while(sortedListIterator.hasNext()) 1718 { 1719 Content sortedContent = (Content)sortedListIterator.next(); 1720 1721 if(sortAttributeName.equalsIgnoreCase("name")) 1723 { 1724 String name = content.getName(); 1725 String sortedName = sortedContent.getName(); 1726 if(name != null && sortedName != null && sortOrder.equalsIgnoreCase("asc") && name.compareTo(sortedName) < 0) 1727 { 1728 break; 1729 } 1730 else if(name != null && sortedName != null && sortOrder.equalsIgnoreCase("desc") && name.compareTo(sortedName) > 0) 1731 { 1732 break; 1733 } 1734 } 1735 else if(sortAttributeName.equalsIgnoreCase("publishDateTime")) 1737 { 1738 Date date = content.getPublishDateTime(); 1739 Date sortedDate = sortedContent.getPublishDateTime(); 1740 if(date != null && sortedDate != null && sortOrder.equalsIgnoreCase("asc") && date.before(sortedDate)) 1741 { 1742 break; 1743 } 1744 else if(date != null && sortedDate != null && sortOrder.equalsIgnoreCase("desc") && date.after(sortedDate)) 1745 { 1746 break; 1747 } 1748 } 1749 else if(sortAttributeName.equalsIgnoreCase("expireDateTime")) 1750 { 1751 Date date = content.getExpireDateTime(); 1752 Date sortedDate = sortedContent.getExpireDateTime(); 1753 if(date != null && sortedDate != null && sortOrder.equalsIgnoreCase("asc") && date.before(sortedDate)) 1754 { 1755 break; 1756 } 1757 else if(date != null && sortedDate != null && sortOrder.equalsIgnoreCase("desc") && date.after(sortedDate)) 1758 { 1759 break; 1760 } 1761 } 1762 else 1763 { 1764 String contentAttribute = this.getContentAttribute(db, content.getId(), languageId, sortAttributeName, siteNodeId, useLanguageFallback, deliveryContext, infoGluePrincipal, false); 1765 String sortedContentAttribute = this.getContentAttribute(db, sortedContent.getId(), languageId, sortAttributeName, siteNodeId, useLanguageFallback, deliveryContext, infoGluePrincipal, false); 1766 if(contentAttribute != null && sortedContentAttribute != null && sortOrder.equalsIgnoreCase("asc") && contentAttribute.compareTo(sortedContentAttribute) < 0) 1767 { 1768 break; 1769 } 1770 else if(contentAttribute != null && sortedContentAttribute != null && sortOrder.equalsIgnoreCase("desc") && contentAttribute.compareTo(sortedContentAttribute) > 0) 1771 { 1772 break; 1773 } 1774 } 1775 index++; 1776 } 1777 sortedContents.add(index, content); 1778 } 1779 } 1780 } 1781 catch(Exception e) 1782 { 1783 logger.warn("The sorting of contents failed:" + e.getMessage(), e); 1784 } 1785 1786 return sortedContents; 1787 } 1788 1789 1790} | Popular Tags |