PageRenderTime 54ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/src/java/org/infoglue/deliver/controllers/kernel/impl/simple/ContentDeliveryController.java

https://github.com/aboutyang/infoglue
Java | 3613 lines | 2299 code | 593 blank | 721 comment | 760 complexity | dc6f44cf19efa087332add80067292b0 MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.1, BSD-3-Clause, GPL-2.0
  1. /* ===============================================================================
  2. *
  3. * Part of the InfoGlue Content Management Platform (www.infoglue.org)
  4. *
  5. * ===============================================================================
  6. *
  7. * Copyright (C)
  8. *
  9. * This program is free software; you can redistribute it and/or modify it under
  10. * the terms of the GNU General Public License version 2, as published by the
  11. * Free Software Foundation. See the file LICENSE.html for more information.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
  15. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
  19. * Place, Suite 330 / Boston, MA 02111-1307 / USA.
  20. *
  21. * ===============================================================================
  22. */
  23. package org.infoglue.deliver.controllers.kernel.impl.simple;
  24. import java.io.File;
  25. import java.io.FileOutputStream;
  26. import java.io.ObjectOutputStream;
  27. import java.net.URLDecoder;
  28. import java.util.ArrayList;
  29. import java.util.Collection;
  30. import java.util.Collections;
  31. import java.util.Date;
  32. import java.util.Enumeration;
  33. import java.util.HashMap;
  34. import java.util.Iterator;
  35. import java.util.List;
  36. import java.util.Map;
  37. import java.util.Set;
  38. import java.util.Vector;
  39. import org.apache.log4j.Category;
  40. import org.apache.log4j.Level;
  41. import org.apache.log4j.Logger;
  42. import org.exolab.castor.jdo.Database;
  43. import org.exolab.castor.jdo.OQLQuery;
  44. import org.exolab.castor.jdo.QueryResults;
  45. import org.infoglue.cms.applications.common.VisualFormatter;
  46. import org.infoglue.cms.controllers.kernel.impl.simple.AccessRightController;
  47. import org.infoglue.cms.controllers.kernel.impl.simple.ContentCategoryController;
  48. import org.infoglue.cms.controllers.kernel.impl.simple.ContentController;
  49. import org.infoglue.cms.controllers.kernel.impl.simple.ContentTypeDefinitionController;
  50. import org.infoglue.cms.controllers.kernel.impl.simple.DigitalAssetController;
  51. import org.infoglue.cms.controllers.kernel.impl.simple.RepositoryController;
  52. import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeController;
  53. import org.infoglue.cms.controllers.kernel.impl.simple.UserControllerProxy;
  54. import org.infoglue.cms.entities.content.Content;
  55. import org.infoglue.cms.entities.content.ContentCategory;
  56. import org.infoglue.cms.entities.content.ContentCategoryVO;
  57. import org.infoglue.cms.entities.content.ContentVO;
  58. import org.infoglue.cms.entities.content.ContentVersion;
  59. import org.infoglue.cms.entities.content.ContentVersionVO;
  60. import org.infoglue.cms.entities.content.DigitalAssetVO;
  61. import org.infoglue.cms.entities.content.SmallestContentVersion;
  62. import org.infoglue.cms.entities.content.SmallestContentVersionVO;
  63. import org.infoglue.cms.entities.content.impl.simple.ContentImpl;
  64. import org.infoglue.cms.entities.content.impl.simple.ContentVersionImpl;
  65. import org.infoglue.cms.entities.content.impl.simple.MediumContentImpl;
  66. import org.infoglue.cms.entities.content.impl.simple.SmallContentImpl;
  67. import org.infoglue.cms.entities.content.impl.simple.SmallContentVersionImpl;
  68. import org.infoglue.cms.entities.content.impl.simple.SmallDigitalAssetImpl;
  69. import org.infoglue.cms.entities.management.ContentTypeDefinitionVO;
  70. import org.infoglue.cms.entities.management.LanguageVO;
  71. import org.infoglue.cms.entities.management.RepositoryVO;
  72. import org.infoglue.cms.entities.management.impl.simple.AccessRightGroupImpl;
  73. import org.infoglue.cms.entities.management.impl.simple.AccessRightImpl;
  74. import org.infoglue.cms.entities.management.impl.simple.AccessRightRoleImpl;
  75. import org.infoglue.cms.entities.management.impl.simple.AccessRightUserImpl;
  76. import org.infoglue.cms.entities.management.impl.simple.ContentTypeDefinitionImpl;
  77. import org.infoglue.cms.entities.structure.SiteNode;
  78. import org.infoglue.cms.entities.structure.SiteNodeVO;
  79. import org.infoglue.cms.entities.structure.impl.simple.SmallSiteNodeImpl;
  80. import org.infoglue.cms.exception.SystemException;
  81. import org.infoglue.cms.security.InfoGluePrincipal;
  82. import org.infoglue.cms.util.CmsPropertyHandler;
  83. import org.infoglue.deliver.applications.databeans.DeliveryContext;
  84. import org.infoglue.deliver.controllers.kernel.URLComposer;
  85. import org.infoglue.deliver.util.CacheController;
  86. import org.infoglue.deliver.util.NullObject;
  87. import org.infoglue.deliver.util.RequestAnalyser;
  88. import org.infoglue.deliver.util.Timer;
  89. public class ContentDeliveryController extends BaseDeliveryController
  90. {
  91. private final static Logger logger = Logger.getLogger(ContentDeliveryController.class.getName());
  92. private URLComposer urlComposer = null;
  93. private VisualFormatter formatter = new VisualFormatter();
  94. /**
  95. * Private constructor to enforce factory-use
  96. */
  97. private ContentDeliveryController()
  98. {
  99. urlComposer = URLComposer.getURLComposer();
  100. }
  101. /**
  102. * Factory method
  103. */
  104. public static ContentDeliveryController getContentDeliveryController()
  105. {
  106. return new ContentDeliveryController();
  107. }
  108. /**
  109. * This method returns which mode the delivery-engine is running in.
  110. * The mode is important to be able to show working, preview and published data separate.
  111. */
  112. private Integer getOperatingMode(DeliveryContext deliveryContext)
  113. {
  114. Integer operatingMode = new Integer(0); //Default is working
  115. try
  116. {
  117. operatingMode = new Integer(CmsPropertyHandler.getOperatingMode());
  118. if(!deliveryContext.getOperatingMode().equals(CmsPropertyHandler.getOperatingMode()))
  119. operatingMode = new Integer(deliveryContext.getOperatingMode());
  120. //logger.info("Operating mode is:" + operatingMode);
  121. }
  122. catch(Exception e)
  123. {
  124. logger.warn("We could not get the operating mode from the propertyFile:" + e.getMessage(), e);
  125. }
  126. return operatingMode;
  127. }
  128. /**
  129. * This method return a contentVO
  130. */
  131. public ContentVO getContentVO(Database db, Integer contentId, DeliveryContext deliveryContext) throws SystemException, Exception
  132. {
  133. if(contentId == null || contentId.intValue() < 1)
  134. return null;
  135. if(deliveryContext != null)
  136. deliveryContext.addUsedContent(CacheController.getPooledString(1, contentId));
  137. String key = "" + contentId;
  138. ContentVO contentVO = (ContentVO)CacheController.getCachedObjectFromAdvancedCache("contentCache", key);
  139. if(contentVO != null)
  140. {
  141. //logger.info("There was an cached contentVO:" + contentVO);
  142. }
  143. else
  144. {
  145. contentVO = (ContentVO)getVOWithId(SmallContentImpl.class, contentId, db);
  146. if(contentVO != null)
  147. CacheController.cacheObjectInAdvancedCache("contentCache", key, contentVO, new String[]{CacheController.getPooledString(1, contentId)}, true);
  148. }
  149. return contentVO;
  150. }
  151. public ContentVO getContentWithPath(Integer repositoryId, String path, InfoGluePrincipal principal, Database db) throws SystemException, Exception
  152. {
  153. ContentVO content = getRootContentVO(repositoryId, db);
  154. logger.info("content:" + content);
  155. final String paths[] = path.split("/");
  156. if(path.equals(""))
  157. return content;
  158. for(int i=0; i<paths.length; ++i)
  159. {
  160. final String name = paths[i];
  161. final ContentVO childContent = getChildWithName(content.getId(), name, db);
  162. if(childContent != null)
  163. content = childContent;
  164. else if(childContent == null)
  165. throw new SystemException("There exists no content with the path [" + path + "].");
  166. }
  167. return content;
  168. }
  169. /**
  170. * This method returns the root contentVO for the specified repository.
  171. * If the repositoryName is null we fetch the name of the master repository.
  172. */
  173. public ContentVO getRootContentVO(Integer repositoryId, Database db) throws SystemException, Exception
  174. {
  175. ContentVO contentVO = null;
  176. String key = "" + repositoryId;
  177. logger.info("key in getRootContentVO:" + key);
  178. contentVO = (ContentVO)CacheController.getCachedObject("rootContentCache", key);
  179. if(contentVO != null)
  180. {
  181. logger.info("There was an cached master root contentVO:" + contentVO.getName());
  182. }
  183. else
  184. {
  185. logger.info("Fetching the root contentVO for the repository " + repositoryId);
  186. OQLQuery oql = db.getOQLQuery( "SELECT c FROM org.infoglue.cms.entities.content.impl.simple.ContentImpl c WHERE is_undefined(c.parentContent) AND c.repository = $1");
  187. oql.bind(repositoryId);
  188. QueryResults results = oql.execute(Database.ReadOnly);
  189. if (results.hasMore())
  190. {
  191. contentVO = ((Content)results.next()).getValueObject();
  192. logger.info("The root contentVO was found:" + contentVO.getName());
  193. }
  194. results.close();
  195. oql.close();
  196. logger.info("contentVO:" + contentVO);
  197. CacheController.cacheObject("rootContentCache", key, contentVO);
  198. }
  199. return contentVO;
  200. }
  201. /**
  202. *
  203. */
  204. private ContentVO getChildWithName(Integer parentContentId, String name, Database db) throws Exception
  205. {
  206. String key = "childContents" + parentContentId + "_" + name;
  207. ContentVO contentVO = (ContentVO)CacheController.getCachedObjectFromAdvancedCache("contentCache", key);
  208. if(contentVO != null)
  209. {
  210. //logger.info("There was an cached contentVO:" + contentVO);
  211. }
  212. else
  213. {
  214. OQLQuery oql = db.getOQLQuery("SELECT c FROM org.infoglue.cms.entities.content.impl.simple.SmallContentImpl c WHERE c.parentContentId = $1 AND c.name = $2");
  215. oql.bind(parentContentId);
  216. oql.bind(name);
  217. QueryResults results = oql.execute(Database.ReadOnly);
  218. if(results.hasMore())
  219. {
  220. contentVO = ((Content)results.next()).getValueObject();
  221. }
  222. results.close();
  223. oql.close();
  224. if(contentVO != null)
  225. CacheController.cacheObjectInAdvancedCache("contentCache", key, contentVO, new String[]{CacheController.getPooledString(1, contentVO.getId()),CacheController.getPooledString(1, parentContentId)}, true);
  226. }
  227. return contentVO;
  228. }
  229. /**
  230. * This method returns that contentVersionVO which matches the parameters sent in and which
  231. * also has the correct state for this delivery-instance.
  232. */
  233. public ContentVersionVO getContentVersionVO(Database db, Integer siteNodeId, Integer contentId, Integer languageId, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception
  234. {
  235. ContentVersionVO contentVersionVO = null;
  236. SiteNodeVO siteNodeVO = SiteNodeController.getController().getSiteNodeVOWithId(siteNodeId, db);
  237. String contentVersionKey = "contentVersionVO_" + siteNodeVO.getRepositoryId() + "_" + contentId + "_" + languageId + "_" + useLanguageFallback;
  238. contentVersionVO = (ContentVersionVO)CacheController.getCachedObjectFromAdvancedCache("contentVersionCache", contentVersionKey);
  239. if(contentVersionVO != null)
  240. {
  241. //logger.info("There was an cached contentVersionVO:" + contentVersionVO.getContentVersionId());
  242. }
  243. else
  244. {
  245. contentVersionVO = this.getContentVersionVO(siteNodeId, contentId, languageId, db, useLanguageFallback, deliveryContext, infoGluePrincipal);
  246. if(contentVersionVO != null)
  247. {
  248. CacheController.cacheObjectInAdvancedCache("contentVersionCache", contentVersionKey, contentVersionVO, new String[]{CacheController.getPooledString(2, contentVersionVO.getId()), CacheController.getPooledString(1, contentVersionVO.getContentId())}, true);
  249. }
  250. }
  251. if(contentVersionVO != null && deliveryContext != null)
  252. deliveryContext.addUsedContentVersion(CacheController.getPooledString(2, contentVersionVO.getId()));
  253. return contentVersionVO;
  254. }
  255. /**
  256. * This method returns that contentVersionVO which matches the parameters sent in and which
  257. * also has the correct state for this delivery-instance.
  258. */
  259. public SmallestContentVersionVO getSmallestContentVersionVO(Database db, Integer siteNodeId, Integer contentId, Integer languageId, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception
  260. {
  261. SmallestContentVersionVO contentVersionVO = null;
  262. SiteNodeVO siteNodeVO = SiteNodeController.getController().getSiteNodeVOWithId(siteNodeId, db);
  263. String contentVersionKey = "smallestContentVersionVO_" + siteNodeVO.getRepositoryId() + "_" + contentId + "_" + languageId + "_" + useLanguageFallback;
  264. if(logger.isInfoEnabled())
  265. logger.info("contentVersionKey:" + contentVersionKey);
  266. contentVersionVO = (SmallestContentVersionVO)CacheController.getCachedObjectFromAdvancedCache("contentVersionCache", contentVersionKey);
  267. if(contentVersionVO != null)
  268. {
  269. //logger.info("There was an cached contentVersionVO:" + contentVersionVO.getContentVersionId());
  270. }
  271. else
  272. {
  273. contentVersionVO = this.getSmallestContentVersionVO(siteNodeId, contentId, languageId, db, useLanguageFallback, deliveryContext, infoGluePrincipal);
  274. if(contentVersionVO != null)
  275. {
  276. //contentVersionVO = contentVersion.getValueObject();
  277. CacheController.cacheObjectInAdvancedCache("contentVersionCache", contentVersionKey, contentVersionVO, new String[]{CacheController.getPooledString(2, contentVersionVO.getId()), CacheController.getPooledString(1, contentVersionVO.getContentId())}, true);
  278. }
  279. }
  280. if(contentVersionVO != null && deliveryContext != null)
  281. deliveryContext.addUsedContentVersion(CacheController.getPooledString(2, contentVersionVO.getId()));
  282. return contentVersionVO;
  283. }
  284. /**
  285. * This method returns that contentVersion which matches the parameters sent in and which
  286. * also has the correct state for this delivery-instance.
  287. */
  288. private ContentVersion getContentVersion(Integer siteNodeId, Integer contentId, Integer languageId, Database db, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception
  289. {
  290. if(contentId == null || contentId.intValue() < 1)
  291. return null;
  292. ContentVersion contentVersion = null;
  293. //MediumContentImpl content = (MediumContentImpl)getObjectWithId(MediumContentImpl.class, contentId, db);
  294. ContentVO content = ContentController.getContentController().getSmallContentVOWithId(contentId, db, deliveryContext);
  295. boolean isValidContent = isValidContent(infoGluePrincipal, content, languageId, useLanguageFallback, false, db, deliveryContext);
  296. if(isValidContent)
  297. {
  298. contentVersion = getContentVersion(content, languageId, getOperatingMode(deliveryContext), deliveryContext, db);
  299. if(contentVersion == null && useLanguageFallback)
  300. {
  301. Integer masterLanguageId = LanguageDeliveryController.getLanguageDeliveryController().getMasterLanguageForSiteNode(db, siteNodeId).getLanguageId();
  302. if(languageId != null && !languageId.equals(masterLanguageId))
  303. {
  304. contentVersion = getContentVersion(content, masterLanguageId, getOperatingMode(deliveryContext), deliveryContext, db);
  305. }
  306. //Added fallback to the content repository master language... useful for mixing components between sites
  307. if(languageId != null && contentVersion == null && useLanguageFallback)
  308. {
  309. Integer contentMasterLanguageId = LanguageDeliveryController.getLanguageDeliveryController().getMasterLanguageForRepository(db, content.getRepositoryId()).getLanguageId();
  310. if(languageId != null && !languageId.equals(contentMasterLanguageId) && !masterLanguageId.equals(contentMasterLanguageId))
  311. {
  312. contentVersion = getContentVersion(content, contentMasterLanguageId, getOperatingMode(deliveryContext), deliveryContext, db);
  313. }
  314. }
  315. }
  316. }
  317. return contentVersion;
  318. }
  319. /**
  320. * This method returns that contentVersion which matches the parameters sent in and which
  321. * also has the correct state for this delivery-instance.
  322. */
  323. private SmallestContentVersionVO getSmallestContentVersionVO(Integer siteNodeId, Integer contentId, Integer languageId, Database db, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception
  324. {
  325. if(contentId == null || contentId.intValue() < 1)
  326. return null;
  327. SmallestContentVersionVO contentVersion = null;
  328. //MediumContentImpl content = (MediumContentImpl)getObjectWithId(MediumContentImpl.class, contentId, db);
  329. ContentVO content = getContentVO(db, contentId, deliveryContext); //ContentController.getContentController().getSmallContentVOWithId(contentId, db);
  330. boolean isValidContent = isValidContent(infoGluePrincipal, content, languageId, useLanguageFallback, false, db, deliveryContext);
  331. if(isValidContent)
  332. {
  333. contentVersion = getSmallestContentVersionVO(contentId, languageId, getOperatingMode(deliveryContext), deliveryContext, db);
  334. if(contentVersion == null && useLanguageFallback)
  335. {
  336. Integer masterLanguageId = null;
  337. if(siteNodeId != null)
  338. masterLanguageId = LanguageDeliveryController.getLanguageDeliveryController().getMasterLanguageForSiteNode(db, siteNodeId).getLanguageId();
  339. else
  340. masterLanguageId = LanguageDeliveryController.getLanguageDeliveryController().getMasterLanguageForRepository(db, content.getRepositoryId()).getLanguageId();
  341. if(languageId == null || (languageId != null && !languageId.equals(masterLanguageId)))
  342. {
  343. contentVersion = getSmallestContentVersionVO(contentId, masterLanguageId, getOperatingMode(deliveryContext), deliveryContext, db);
  344. }
  345. //Added fallback to the content repository master language... useful for mixing components between sites
  346. if(languageId != null && contentVersion == null && useLanguageFallback)
  347. {
  348. Integer contentMasterLanguageId = LanguageDeliveryController.getLanguageDeliveryController().getMasterLanguageForRepository(db, content.getRepositoryId()).getLanguageId();
  349. if(languageId != null && !languageId.equals(contentMasterLanguageId) && !masterLanguageId.equals(contentMasterLanguageId))
  350. {
  351. contentVersion = getSmallestContentVersionVO(contentId, contentMasterLanguageId, getOperatingMode(deliveryContext), deliveryContext, db);
  352. }
  353. }
  354. }
  355. }
  356. return contentVersion;
  357. }
  358. /**
  359. * This method returns that contentVersion which matches the parameters sent in and which
  360. * also has the correct state for this delivery-instance.
  361. */
  362. private ContentVersionVO getContentVersionVO(Integer siteNodeId, Integer contentId, Integer languageId, Database db, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception
  363. {
  364. if(contentId == null || contentId.intValue() < 1)
  365. return null;
  366. Timer t = new Timer();
  367. ContentVersionVO contentVersion = null;
  368. //MediumContentImpl content = (MediumContentImpl)getObjectWithId(MediumContentImpl.class, contentId, db);
  369. ContentVO content = getContentVO(db, contentId, deliveryContext);
  370. boolean isValidContent = isValidContent(infoGluePrincipal, content, languageId, useLanguageFallback, false, db, deliveryContext);
  371. //deliveryContext.addDebugInformation("isValidContent:" + isValidContent);
  372. if(isValidContent)
  373. {
  374. contentVersion = getContentVersionVO(contentId, languageId, getOperatingMode(deliveryContext), deliveryContext, db);
  375. //deliveryContext.addDebugInformation("contentVersion:" + contentVersion);
  376. if(contentVersion == null && useLanguageFallback)
  377. {
  378. Integer masterLanguageId = LanguageDeliveryController.getLanguageDeliveryController().getMasterLanguageForSiteNode(db, siteNodeId).getLanguageId();
  379. //deliveryContext.addDebugInformation("masterLanguageId:" + masterLanguageId);
  380. if(languageId != null && !languageId.equals(masterLanguageId))
  381. {
  382. contentVersion = getContentVersionVO(contentId, masterLanguageId, getOperatingMode(deliveryContext), deliveryContext, db);
  383. }
  384. //Added fallback to the content repository master language... useful for mixing components between sites
  385. if(languageId != null && contentVersion == null && useLanguageFallback)
  386. {
  387. Integer contentMasterLanguageId = LanguageDeliveryController.getLanguageDeliveryController().getMasterLanguageForRepository(db, content.getRepositoryId()).getLanguageId();
  388. //deliveryContext.addDebugInformation("contentMasterLanguageId:" + contentMasterLanguageId);
  389. if(languageId != null && !languageId.equals(contentMasterLanguageId) && !masterLanguageId.equals(contentMasterLanguageId))
  390. {
  391. contentVersion = getContentVersionVO(contentId, contentMasterLanguageId, getOperatingMode(deliveryContext), deliveryContext, db);
  392. }
  393. }
  394. }
  395. }
  396. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getContentVersionVO in delivery took (micro)", t.getElapsedTimeNanos() / 1000);
  397. /*
  398. if(content.getContentTypeDefinitionId().intValue() == 2 || content.getContentTypeDefinitionId().intValue() == 100000)
  399. {
  400. logger.error("Investigate...");
  401. Thread.dumpStack();
  402. }
  403. */
  404. return contentVersion;
  405. }
  406. /**
  407. * This method returns that contentVersion which matches the parameters sent in and which
  408. * also has the correct state for this delivery-instance.
  409. */
  410. public ContentVersionVO getContentVersionVOInState(Integer contentId, Integer languageId, Integer stateId, Database db, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception
  411. {
  412. if(contentId == null || contentId.intValue() < 1)
  413. return null;
  414. ContentVersionVO contentVersion = null;
  415. //MediumContentImpl content = (MediumContentImpl)getObjectWithId(MediumContentImpl.class, contentId, db);
  416. ContentVO content = ContentController.getContentController().getSmallContentVOWithId(contentId, db, deliveryContext);
  417. boolean isValidContent = isValidContent(infoGluePrincipal, content, languageId, false, false, db, deliveryContext);
  418. if(isValidContent)
  419. {
  420. contentVersion = getContentVersionVO(contentId, languageId, stateId, deliveryContext, db);
  421. }
  422. return contentVersion;
  423. }
  424. /**
  425. * This method returns that contentVersion which matches the parameters sent in and which
  426. * also has the correct state for this delivery-instance.
  427. */
  428. public List getContentVersionVOList(Database db, Integer siteNodeId, Integer contentId, Integer languageId, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception
  429. {
  430. if(contentId == null || contentId.intValue() < 1)
  431. return null;
  432. List contentVersionVOList = new ArrayList();
  433. boolean useLanguageFallback = false;
  434. if(languageId == null)
  435. useLanguageFallback = true;
  436. //MediumContentImpl content = (MediumContentImpl)getObjectWithId(MediumContentImpl.class, contentId, db);
  437. ContentVO content = ContentController.getContentController().getSmallContentVOWithId(contentId, db, deliveryContext);
  438. boolean isValidContent = isValidContent(infoGluePrincipal, content, languageId, useLanguageFallback, false, db, deliveryContext);
  439. if(isValidContent)
  440. {
  441. contentVersionVOList = getContentVersionVOList(content, languageId, getOperatingMode(deliveryContext), deliveryContext, db);
  442. }
  443. return contentVersionVOList;
  444. }
  445. /**
  446. * This method gets a contentVersion with a state and a language which is active.
  447. */
  448. private ContentVersion getContentVersion(ContentVO content, Integer languageId, Integer operatingMode, DeliveryContext deliveryContext, Database db) throws Exception
  449. {
  450. ContentVersion contentVersion = null;
  451. String versionKey = "" + content.getId() + "_" + languageId + "_" + operatingMode + "_contentVersionId";
  452. //logger.info("versionKey:" + versionKey);
  453. Object object = CacheController.getCachedObjectFromAdvancedCache("contentVersionIdCache", versionKey);
  454. if(object instanceof NullObject)
  455. {
  456. logger.info("There was an cached parentSiteNodeVO but it was null:" + object);
  457. }
  458. else if(object != null)
  459. {
  460. Integer contentVersionId = (Integer)object;
  461. contentVersion = (ContentVersion)getObjectWithId(ContentVersionImpl.class, contentVersionId, db);
  462. //logger.info("Loaded the version from cache instead of querying it:" + contentVersionId);
  463. }
  464. else
  465. {
  466. //logger.info("Querying for verson: " + versionKey);
  467. 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");
  468. oql.bind(content.getId());
  469. oql.bind(languageId);
  470. oql.bind(operatingMode);
  471. oql.bind(true);
  472. QueryResults results = oql.execute(Database.ReadOnly);
  473. if (results.hasMore())
  474. {
  475. contentVersion = (ContentVersion)results.next();
  476. CacheController.cacheObjectInAdvancedCache("contentVersionIdCache", versionKey, contentVersion.getId(), new String[]{CacheController.getPooledString(2, contentVersion.getId()), CacheController.getPooledString(1, contentVersion.getValueObject().getContentId())}, true);
  477. }
  478. else
  479. {
  480. CacheController.cacheObjectInAdvancedCache("contentVersionIdCache", versionKey, new NullObject(), new String[]{CacheController.getPooledString(1, content.getId())}, true);
  481. }
  482. results.close();
  483. oql.close();
  484. }
  485. if(contentVersion != null)
  486. deliveryContext.addUsedContentVersion(CacheController.getPooledString(2, contentVersion.getId()));
  487. return contentVersion;
  488. }
  489. /**
  490. * This method gets a contentVersion with a state and a language which is active.
  491. */
  492. private ContentVersionVO getContentVersionVO(Integer contentId, Integer languageId, Integer operatingMode, DeliveryContext deliveryContext, Database db) throws Exception
  493. {
  494. ContentVersionVO contentVersionVO = null;
  495. String versionKey = "" + contentId + "_" + languageId + "_" + operatingMode + "_contentVersionVO";
  496. Object object = CacheController.getCachedObjectFromAdvancedCache("contentVersionCache", versionKey);
  497. if(object instanceof NullObject)
  498. {
  499. logger.info("There was an cached contentVersionVO but it was null:" + object);
  500. }
  501. else if(object != null)
  502. {
  503. if(object instanceof SmallestContentVersionVO)
  504. {
  505. logger.warn("Object was instanceof SmallestContentVersionVO for key:" + versionKey);
  506. contentVersionVO = (ContentVersionVO)getVOWithId(SmallContentVersionImpl.class, ((SmallestContentVersionVO)object).getId(), db);
  507. CacheController.cacheObjectInAdvancedCache("contentVersionCache", versionKey, contentVersionVO, new String[]{CacheController.getPooledString(2, contentVersionVO.getId()), CacheController.getPooledString(1, contentVersionVO.getContentId())}, true);
  508. }
  509. else
  510. {
  511. contentVersionVO = (ContentVersionVO)object;
  512. }
  513. }
  514. else
  515. {
  516. Timer t = new Timer();
  517. String smallVersionKey = "" + contentId + "_" + languageId + "_" + operatingMode + "_smallestContentVersionVO";
  518. Object smallestContentVersionVOCandidate = CacheController.getCachedObjectFromAdvancedCache("contentVersionCache", smallVersionKey);
  519. if(smallestContentVersionVOCandidate instanceof NullObject)
  520. {
  521. //logger.info("There was an cached content version but it was null:" + smallestContentVersionVOCandidate);
  522. }
  523. else if(smallestContentVersionVOCandidate != null)
  524. {
  525. if(smallestContentVersionVOCandidate instanceof SmallestContentVersionVO)
  526. {
  527. contentVersionVO = (ContentVersionVO)getVOWithId(SmallContentVersionImpl.class, ((SmallestContentVersionVO)smallestContentVersionVOCandidate).getId(), db);
  528. CacheController.cacheObjectInAdvancedCache("contentVersionCache", versionKey, contentVersionVO, new String[]{CacheController.getPooledString(2, contentVersionVO.getId()), CacheController.getPooledString(1, contentVersionVO.getContentId())}, true);
  529. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("Getting SmallContentVersionImpl", t.getElapsedTime());
  530. }
  531. else
  532. {
  533. logger.warn("Object was instanceof ContentVersionVO for key:" + versionKey);
  534. contentVersionVO = (ContentVersionVO)smallestContentVersionVOCandidate;
  535. }
  536. CacheController.cacheObjectInAdvancedCache("contentVersionCache", versionKey, contentVersionVO, new String[]{CacheController.getPooledString(2, contentVersionVO.getId()), CacheController.getPooledString(1, contentVersionVO.getContentId())}, true);
  537. }
  538. else
  539. {
  540. //logger.info("Querying for verson: " + versionKey);
  541. OQLQuery oql = db.getOQLQuery( "SELECT cv FROM org.infoglue.cms.entities.content.impl.simple.SmallContentVersionImpl cv WHERE cv.contentId = $1 AND cv.languageId = $2 AND cv.stateId >= $3 AND cv.isActive = $4 ORDER BY cv.contentVersionId desc");
  542. oql.bind(contentId);
  543. oql.bind(languageId);
  544. oql.bind(operatingMode);
  545. oql.bind(true);
  546. QueryResults results = oql.execute(Database.ReadOnly);
  547. if (results.hasMore())
  548. {
  549. ContentVersion contentVersion = (ContentVersion)results.next();
  550. contentVersionVO = contentVersion.getValueObject();
  551. CacheController.cacheObjectInAdvancedCache("contentVersionCache", versionKey, contentVersionVO, new String[]{CacheController.getPooledString(2, contentVersionVO.getId()), CacheController.getPooledString(1, contentVersionVO.getContentId())}, true);
  552. }
  553. else
  554. {
  555. CacheController.cacheObjectInAdvancedCache("contentVersionCache", versionKey, new NullObject(), new String[]{CacheController.getPooledString(1, contentId)}, true);
  556. }
  557. results.close();
  558. oql.close();
  559. }
  560. if(logger.isInfoEnabled())
  561. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getContentVersionVO(Integer contentId, Integer languageId, Integer operatingMode, DeliveryContext deliveryContext, Database db)", t.getElapsedTimeNanos() / 1000);
  562. }
  563. if(contentVersionVO != null)
  564. deliveryContext.addUsedContentVersion(CacheController.getPooledString(2, contentVersionVO.getId()));
  565. return contentVersionVO;
  566. }
  567. /**
  568. * This method gets a contentVersion with a state and a language which is active.
  569. */
  570. private SmallestContentVersionVO getSmallestContentVersionVO(Integer contentId, Integer languageId, Integer operatingMode, DeliveryContext deliveryContext, Database db) throws Exception
  571. {
  572. //Timer t = new Timer();
  573. SmallestContentVersionVO contentVersionVO = null;
  574. String versionKey = "" + contentId + "_" + languageId + "_" + operatingMode + "_smallestContentVersionVO";
  575. //String versionVOKey = "" + contentId + "_" + languageId + "_" + operatingMode + "_contentVersionVO";
  576. Object object = CacheController.getCachedObjectFromAdvancedCache("contentVersionCache", versionKey);
  577. if(object instanceof NullObject)
  578. {
  579. logger.info("There was an cached SmallestContentVersionVO but it was null:" + object);
  580. }
  581. else if(object != null)
  582. {
  583. contentVersionVO = (SmallestContentVersionVO)object;
  584. }
  585. else
  586. {
  587. //logger.info("Querying for verson: " + versionKey);
  588. OQLQuery oql = db.getOQLQuery( "SELECT cv FROM org.infoglue.cms.entities.content.impl.simple.SmallestContentVersionImpl cv WHERE cv.contentId = $1 AND cv.languageId = $2 AND cv.stateId >= $3 AND cv.isActive = $4 ORDER BY cv.contentVersionId desc");
  589. oql.bind(contentId);
  590. oql.bind(languageId);
  591. oql.bind(operatingMode);
  592. oql.bind(true);
  593. QueryResults results = oql.execute(Database.ReadOnly);
  594. if (results.hasMore())
  595. {
  596. SmallestContentVersion contentVersion = (SmallestContentVersion)results.next();
  597. contentVersionVO = contentVersion.getValueObject();
  598. CacheController.cacheObjectInAdvancedCache("contentVersionCache", versionKey, contentVersionVO, new String[]{CacheController.getPooledString(2, contentVersionVO.getId()), CacheController.getPooledString(1, contentVersionVO.getContentId())}, true);
  599. }
  600. else
  601. {
  602. CacheController.cacheObjectInAdvancedCache("contentVersionCache", versionKey, new NullObject(), new String[]{CacheController.getPooledString(1, contentId)}, true);
  603. }
  604. results.close();
  605. oql.close();
  606. }
  607. if(contentVersionVO != null)
  608. deliveryContext.addUsedContentVersion(CacheController.getPooledString(2, contentVersionVO.getId()));
  609. return contentVersionVO;
  610. }
  611. private List getContentVersionVOList(Content content, Integer languageId, Integer operatingMode, DeliveryContext deliveryContext, Database db) throws Exception
  612. {
  613. List contentVersionVOList = new ArrayList();
  614. 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");
  615. if(languageId == null)
  616. oql = db.getOQLQuery( "SELECT cv FROM org.infoglue.cms.entities.content.impl.simple.ContentVersionImpl cv WHERE cv.contentId = $1 AND cv.stateId >= $2 AND cv.isActive = $3 ORDER BY cv.contentVersionId desc");
  617. oql.bind(content.getId());
  618. if(languageId != null)
  619. oql.bind(languageId);
  620. oql.bind(operatingMode);
  621. oql.bind(true);
  622. QueryResults results = oql.execute(Database.ReadOnly);
  623. ContentVersion contentVersion;
  624. while(results.hasMore())
  625. {
  626. contentVersion = (ContentVersion)results.next();
  627. if(contentVersion != null)
  628. deliveryContext.addUsedContentVersion(CacheController.getPooledString(2, contentVersion.getId()));
  629. contentVersionVOList.add(contentVersion.getValueObject());
  630. }
  631. results.close();
  632. oql.close();
  633. return contentVersionVOList;
  634. }
  635. private List getContentVersionVOList(ContentVO content, Integer languageId, Integer operatingMode, DeliveryContext deliveryContext, Database db) throws Exception
  636. {
  637. List contentVersionVOList = new ArrayList();
  638. 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");
  639. if(languageId == null)
  640. oql = db.getOQLQuery( "SELECT cv FROM org.infoglue.cms.entities.content.impl.simple.ContentVersionImpl cv WHERE cv.contentId = $1 AND cv.stateId >= $2 AND cv.isActive = $3 ORDER BY cv.contentVersionId desc");
  641. oql.bind(content.getId());
  642. if(languageId != null)
  643. oql.bind(languageId);
  644. oql.bind(operatingMode);
  645. oql.bind(true);
  646. QueryResults results = oql.execute(Database.ReadOnly);
  647. ContentVersion contentVersion;
  648. while(results.hasMore())
  649. {
  650. contentVersion = (ContentVersion)results.next();
  651. if(contentVersion != null)
  652. deliveryContext.addUsedContentVersion(CacheController.getPooledString(2, contentVersion.getId()));
  653. contentVersionVOList.add(contentVersion.getValueObject());
  654. }
  655. results.close();
  656. oql.close();
  657. return contentVersionVOList;
  658. }
  659. /**
  660. * This is the most common way of getting attributes from a content.
  661. * It selects the correct contentVersion depending on the language and then gets the attribute in the xml associated.
  662. */
  663. public String getContentAttribute(Database db, Integer contentId, Integer languageId, String attributeName, Integer siteNodeId, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infogluePrincipal, boolean escapeHTML) throws SystemException, Exception
  664. {
  665. return getContentAttribute(db, contentId, languageId, attributeName, siteNodeId, useLanguageFallback, deliveryContext, infogluePrincipal, escapeHTML, false, null);
  666. }
  667. /**
  668. * This is the most common way of getting attributes from a content.
  669. * It selects the correct contentVersion depending on the language and then gets the attribute in the xml associated.
  670. */
  671. public String getContentAttribute(Database db, Integer contentId, Integer languageId, String attributeName, Integer siteNodeId, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infogluePrincipal, boolean escapeHTML, boolean isMetaInfoQuery) throws SystemException, Exception
  672. {
  673. return getContentAttribute(db, contentId, languageId, attributeName, siteNodeId, useLanguageFallback, deliveryContext, infogluePrincipal, escapeHTML, isMetaInfoQuery, null);
  674. }
  675. /**
  676. * This is the most common way of getting attributes from a content.
  677. * It selects the correct contentVersion depending on the language and then gets the attribute in the xml associated.
  678. */
  679. public String getContentAttribute(Database db, Integer contentId, Integer languageId, String attributeName, Integer siteNodeId, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infogluePrincipal, boolean escapeHTML, Set usedContentVersionId) throws SystemException, Exception
  680. {
  681. return getContentAttribute(db, contentId, languageId, attributeName, siteNodeId, useLanguageFallback, deliveryContext, infogluePrincipal, escapeHTML, false, usedContentVersionId);
  682. }
  683. /**
  684. * This method return true if the user logged in has access to the content sent in.
  685. */
  686. /*
  687. public boolean getHasUserContentAccess(Database db, InfoGluePrincipal infoGluePrincipal, Integer contentId)
  688. {
  689. boolean hasUserContentAccess = true;
  690. try
  691. {
  692. if(contentId != null)
  693. {
  694. logger.info("IsProtected:" + protectedContentId);
  695. if(protectedContentId != null && !AccessRightController.getController().getIsPrincipalAuthorized(infoGluePrincipal, "Content.Read", protectedContentId.toString()))
  696. {
  697. hasUserContentAccess = false;
  698. }
  699. }
  700. }
  701. catch(Exception e)
  702. {
  703. logger.warn("An error occurred trying to get determine if content:" + contentId + " has a localized version:" + e.getMessage());
  704. }
  705. return hasUserContentAccess;
  706. }
  707. */
  708. public boolean getHasUserContentAccess(Database db, InfoGluePrincipal infoGluePrincipal, Integer contentId)
  709. {
  710. String key = "" + infoGluePrincipal.getName() + "_" + contentId + "_HasUserContentAccess";
  711. logger.info("key:" + key);
  712. Boolean hasUserContentAccess = (Boolean)CacheController.getCachedObjectFromAdvancedCache("personalAuthorizationCache", key);
  713. if(hasUserContentAccess != null)
  714. {
  715. //logger.info("Cached");
  716. return hasUserContentAccess.booleanValue();
  717. }
  718. else
  719. {
  720. hasUserContentAccess = true;
  721. //logger.info("----- not Cached");
  722. try
  723. {
  724. if(contentId != null)
  725. {
  726. Integer protectedContentId = ContentDeliveryController.getContentDeliveryController().getProtectedContentId(db, getContentVO(db, contentId, null));
  727. //Integer protectedContentId = ContentDeliveryController.getContentDeliveryController().getProtectedContentId(db, contentId);
  728. logger.info("IsProtected:" + protectedContentId);
  729. if(protectedContentId != null && !AccessRightController.getController().getIsPrincipalAuthorized(db, infoGluePrincipal, "Content.Read", protectedContentId.toString()))
  730. {
  731. hasUserContentAccess = false;
  732. }
  733. }
  734. }
  735. catch(Exception e)
  736. {
  737. logger.warn("An error occurred trying to get determine if user was allowed read access to:" + contentId + ":" + e.getMessage());
  738. }
  739. CacheController.cacheObjectInAdvancedCache("personalAuthorizationCache", key, new Boolean(hasUserContentAccess));
  740. }
  741. return hasUserContentAccess;
  742. }
  743. /**
  744. * This is the most common way of getting attributes from a content.
  745. * It selects the correct contentVersion depending on the language and then gets the attribute in the xml associated.
  746. */
  747. public String getContentAttribute(Database db, Integer contentId, Integer languageId, String attributeName, Integer siteNodeId, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infogluePrincipal, boolean escapeHTML, boolean isMetaInfoQuery, Set usedContentVersionId) throws SystemException, Exception
  748. {
  749. if(contentId == null || contentId.intValue() < 1)
  750. return "";
  751. boolean isTemplateQuery = false;
  752. if(attributeName.equalsIgnoreCase("Template") || attributeName.equalsIgnoreCase("PreTemplate") || attributeName.equalsIgnoreCase("ComponentLabels"))
  753. isTemplateQuery = true;
  754. if(attributeName.equalsIgnoreCase("ComponentStructure"))
  755. isMetaInfoQuery = true;
  756. deliveryContext.addDebugInformation("getContentAttribute with params:");
  757. deliveryContext.addDebugInformation(" contentId: " + contentId);
  758. deliveryContext.addDebugInformation(" languageId: " + languageId);
  759. deliveryContext.addDebugInformation(" attributeName: " + attributeName);
  760. deliveryContext.addDebugInformation(" siteNodeId: " + siteNodeId);
  761. deliveryContext.addDebugInformation(" useLanguageFallback: " + useLanguageFallback);
  762. deliveryContext.addDebugInformation(" infogluePrincipal: " + infogluePrincipal);
  763. //logger.info("usedContentVersionId:" + usedContentVersionId);
  764. //String enforceRigidContentAccess = CmsPropertyHandler.getEnforceRigidContentAccess();
  765. //if(enforceRigidContentAccess != null && enforceRigidContentAccess.equalsIgnoreCase("true") && !isMetaInfoQuery)
  766. //Added this check as mandatory - otherwise we could have situations where values got caches for users not authorized to see them or cached empty.
  767. if(!isMetaInfoQuery && !isTemplateQuery)
  768. {
  769. //logger.info("Enforcing getHasUserContentAccess for attributeName:" + contentId + ":" + languageId + ":" + attributeName);
  770. boolean hasUserContentAccess = getHasUserContentAccess(db, infogluePrincipal, contentId);
  771. deliveryContext.addDebugInformation("hasUserContentAccess: " + hasUserContentAccess);
  772. if(!hasUserContentAccess)
  773. {
  774. return "";
  775. }
  776. }
  777. StringBuilder attributeKeySB = new StringBuilder();
  778. StringBuilder versionKeySB = new StringBuilder();
  779. if(!isMetaInfoQuery && !isTemplateQuery)
  780. attributeKeySB.append("")
  781. .append(contentId).append("_")
  782. .append(languageId).append("_")
  783. .append(attributeName).append("_")
  784. .append(siteNodeId).append("_")
  785. .append(useLanguageFallback).append("_")
  786. .append(escapeHTML);
  787. else
  788. attributeKeySB.append("")
  789. .append(contentId).append("_")
  790. .append(languageId).append("_")
  791. .append(attributeName).append("_")
  792. .append(useLanguageFallback).append("_")
  793. .append(escapeHTML);
  794. if(!isMetaInfoQuery && !isTemplateQuery)
  795. versionKeySB.append("")
  796. .append(contentId).append("_")
  797. .append(languageId).append("_")
  798. .append(siteNodeId).append("_");
  799. else
  800. versionKeySB.append("")
  801. .append(contentId).append("_")
  802. .append(languageId).append("_");
  803. String attributeKey = attributeKeySB.toString();
  804. String versionKey = versionKeySB.append("_contentVersionId").toString();
  805. deliveryContext.addDebugInformation("attributeKey: " + attributeKey);
  806. String matcher = "";
  807. String cacheName = "contentAttributeCache" + matcher;
  808. String contentVersionIdCacheName = "contentVersionIdCache" + matcher;
  809. String attribute = (String)CacheController.getCachedObjectFromAdvancedCache(cacheName, attributeKey);
  810. if(attribute != null)
  811. deliveryContext.addDebugInformation("cachedAttribute: " + attribute.length());
  812. else
  813. deliveryContext.addDebugInformation("cachedAttribute: null");
  814. Integer contentVersionId = null;
  815. try
  816. {
  817. if(attribute != null)
  818. {
  819. contentVersionId = (Integer)CacheController.getCachedObjectFromAdvancedCache(contentVersionIdCacheName, versionKey);
  820. //logger.info("There was an cached content attribute:" + attribute);
  821. }
  822. else
  823. {
  824. ContentVersionVO contentVersionVO = getContentVersionVO(db, siteNodeId, contentId, languageId, useLanguageFallback, deliveryContext, infogluePrincipal);
  825. deliveryContext.addDebugInformation("contentVersionVO:" + contentVersionVO);
  826. if(contentVersionVO != null)
  827. {
  828. deliveryContext.addDebugInformation("contentVersionVO.versionValue:" + contentVersionVO.getVersionValue().length());
  829. attribute = getAttributeValue(db, contentVersionVO, attributeName, escapeHTML);
  830. contentVersionId = contentVersionVO.getId();
  831. }
  832. else
  833. {
  834. attribute = "";
  835. }
  836. String groupKey1 = CacheController.getPooledString(2, contentVersionId);
  837. String groupKey2 = CacheController.getPooledString(1, contentId);
  838. CacheController.cacheObjectInAdvancedCache(cacheName, attributeKey, attribute, new String[]{groupKey1, groupKey2}, true);
  839. if(contentVersionId != null)
  840. {
  841. CacheController.cacheObjectInAdvancedCache(contentVersionIdCacheName, versionKey, contentVersionId, new String[]{groupKey1, groupKey2}, true);
  842. }
  843. }
  844. if(deliveryContext != null)
  845. {
  846. if(contentVersionId != null)
  847. deliveryContext.addUsedContentVersion(CacheController.getPooledString(2, contentVersionId));
  848. if(isMetaInfoQuery && contentVersionId != null)
  849. deliveryContext.getUsedPageMetaInfoContentVersionIdSet().add(contentVersionId);
  850. if(attributeName.equals("ComponentStructure") && contentVersionId != null)
  851. deliveryContext.getUsedPageComponentsMetaInfoContentVersionIdSet().add(contentVersionId);
  852. //We don't want to add meta info relations without more data
  853. if(!attributeName.equals("ComponentStructure"))
  854. {
  855. deliveryContext.addUsedContent(CacheController.getPooledString(1, contentId) + "_" + attributeName);
  856. }
  857. }
  858. if(usedContentVersionId != null && contentVersionId != null)
  859. usedContentVersionId.add(contentVersionId);
  860. }
  861. catch(Exception e)
  862. {
  863. throw e;
  864. }
  865. return (attribute == null) ? "" : attribute;
  866. }
  867. /**
  868. * This is the most common way of getting attributes from a content.
  869. * It selects the correct contentVersion depending on the language and then gets the attribute in the xml associated.
  870. */
  871. public String getContentAttribute(Database db, ContentVersionVO contentVersionVO, String attributeName, boolean escapeHTML) throws SystemException, Exception
  872. {
  873. String attribute = getAttributeValue(db, contentVersionVO, attributeName, escapeHTML);
  874. return attribute;
  875. }
  876. /**
  877. * Find all ContentVersionVOs that are related to the provided Category.
  878. *
  879. * TODO: Right now this method depends on the ContentVersion having an owningContent
  880. * TODO: This is potentially bad from a performance standpoint app-wide, so a workaround may
  881. * TODO: be to look up each Content for the ContentVersions after we have done everything we
  882. * TODO: can to wed down the list alot, so the overhead will not be too much.
  883. *
  884. * @param categoryId The Category to search on
  885. * @param attributeName The attribute of the Category relationship
  886. * @param infoGluePrincipal The user making the request
  887. * @param siteNodeId The SiteNode that the request is coming from
  888. * @param languageId The Language of the request
  889. * @param useLanguageFallback True is the search is to use the fallback (default) language for the Repository
  890. * @return A List of ContentVersionVOs matching the Category search, that are considered valid
  891. * @throws SystemException
  892. */
  893. public List findContentVersionVOsForCategory(Database db, Integer categoryId, String attributeName, InfoGluePrincipal infoGluePrincipal, Integer siteNodeId, Integer languageId, boolean useLanguageFallback, DeliveryContext deliveryContext) throws SystemException, Exception
  894. {
  895. deliveryContext.addUsedContent("selectiveCacheUpdateNonApplicable");
  896. List results = findContentCategories(db, categoryId, attributeName);
  897. List versions = findContentVersionsForCategories(results, db);
  898. // Weed out irrelevant versions
  899. for (Iterator iter = versions.iterator(); iter.hasNext();)
  900. {
  901. ContentVersion version = (ContentVersion) iter.next();
  902. if(!isValidContentVersion(version, infoGluePrincipal, siteNodeId, languageId, useLanguageFallback, db, deliveryContext))
  903. iter.remove();
  904. }
  905. return toVOList(versions);
  906. }
  907. public List getAssignedCategoryVOsForContentVersionId(Database db, Integer contentId, Integer languageId, String categoryKey, Integer siteNodeId, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws Exception
  908. {
  909. List assignedCategoryVOList = new ArrayList();
  910. ContentVersion contentVersion = getContentVersion(siteNodeId, contentId, languageId, db, useLanguageFallback, deliveryContext, infoGluePrincipal);
  911. List assignedContentCategories = ContentCategoryController.getController().findByContentVersionAttribute(categoryKey, contentVersion, db);
  912. //List assignedContentCategories = findContentCategoriesForContentVersionId(db, contentVersionVO.getId(), categoryKey, deliveryContext);
  913. if((assignedCategoryVOList == null || assignedCategoryVOList.size() == 0) && useLanguageFallback)
  914. {
  915. LanguageVO masterLanguageVO = LanguageDeliveryController.getLanguageDeliveryController().getMasterLanguageForSiteNode(db, siteNodeId);
  916. contentVersion = getContentVersion(siteNodeId, contentId, masterLanguageVO.getLanguageId(), db, useLanguageFallback, deliveryContext, infoGluePrincipal);
  917. //assignedContentCategories = findContentCategoriesForContentVersionId(db, contentVersionVO.getId(), categoryKey, deliveryContext);
  918. assignedContentCategories = ContentCategoryController.getController().findByContentVersionAttribute(categoryKey, contentVersion, db);
  919. }
  920. Iterator assignedContentCategoriesIterator = assignedContentCategories.iterator();
  921. while(assignedContentCategoriesIterator.hasNext())
  922. {
  923. ContentCategory contentCategory = (ContentCategory)assignedContentCategoriesIterator.next();
  924. assignedCategoryVOList.add(contentCategory.getCategory().getValueObject());
  925. }
  926. return assignedCategoryVOList;
  927. }
  928. /**
  929. * Find all CategoryVOs that are related to the provided content version on a specific category key.
  930. *
  931. * @param contentVersionId The content version id to search on
  932. * @param categoryKey The attribute of the Category relationship
  933. * @param infoGluePrincipal The user making the request
  934. * @param siteNodeId The SiteNode that the request is coming from
  935. * @param languageId The Language of the request
  936. * @param useLanguageFallback True is the search is to use the fallback (default) language for the Repository
  937. * @return A List of ContentVersionVOs matching the Category search, that are considered valid
  938. * @throws SystemException
  939. */
  940. public List findContentCategoryVOsForContentVersionId(Database db, Integer contentVersionId, String categoryKey, DeliveryContext deliveryContext) throws SystemException, Exception
  941. {
  942. List contentCategories = findContentVersionCategories(db, contentVersionId, categoryKey);
  943. return toVOList(contentCategories);
  944. }
  945. /**
  946. * Find all CategoryVOs that are related to the provided content version on a specific category key.
  947. *
  948. * @param contentVersionId The content version id to search on
  949. * @param categoryKey The attribute of the Category relationship
  950. * @param infoGluePrincipal The user making the request
  951. * @param siteNodeId The SiteNode that the request is coming from
  952. * @param languageId The Language of the request
  953. * @param useLanguageFallback True is the search is to use the fallback (default) language for the Repository
  954. * @return A List of ContentVersionVOs matching the Category search, that are considered valid
  955. * @throws SystemException
  956. */
  957. public List findContentCategoriesForContentVersionId(Database db, Integer contentVersionId, String categoryKey, DeliveryContext deliveryContext) throws SystemException, Exception
  958. {
  959. List contentCategories = findContentVersionCategories(db, contentVersionId, categoryKey);
  960. return contentCategories;
  961. }
  962. /**
  963. * Find all ContentCategories for the given Category id and attributeName.
  964. * @param categoryId The Category to find ContentCategories
  965. * @param attributeName The ContentTYpeDefintion attribute name of a ContentCategory relationship.
  966. * @return A List of ContentCategoryVOs for the supplied Category id.
  967. * @throws SystemException If an error happens
  968. */
  969. private List findContentCategories(Database db, Integer categoryId, String attributeName) throws SystemException, Exception
  970. {
  971. StringBuffer oql = new StringBuffer();
  972. oql.append("SELECT c FROM org.infoglue.cms.entities.content.impl.simple.ContentCategoryImpl c ");
  973. oql.append("WHERE c.category.categoryId = $1 AND c.attributeName = $2");
  974. ArrayList params = new ArrayList();
  975. params.add(categoryId);
  976. params.add(attributeName);
  977. return toVOList(executeQuery(db, oql.toString(), params));
  978. }
  979. /**
  980. * Find all ContentCategories for the given Contentversion id and categoryKey.
  981. * @param contentVersionId The contentVersionId to find ContentCategories on
  982. * @param categoryKey The ContentTYpeDefintion attribute name of a ContentCategory relationship.
  983. * @return A List of ContentCategoryVOs for the supplied content version id.
  984. * @throws SystemException If an error happens
  985. */
  986. private List findContentVersionCategories(Database db, Integer contentVersionId, String categoryKey) throws SystemException, Exception
  987. {
  988. StringBuffer oql = new StringBuffer();
  989. oql.append("SELECT c FROM org.infoglue.cms.entities.content.impl.simple.ContentCategoryImpl c ");
  990. oql.append("WHERE c.contentVersion.contentVersionId = $1 AND c.attributeName = $2");
  991. ArrayList params = new ArrayList();
  992. params.add(contentVersionId);
  993. params.add(categoryKey);
  994. return executeQuery(db, oql.toString(), params);
  995. }
  996. /**
  997. * Find content versions that are in the provided list of version ids. However over time this
  998. * could get to be a large list, so lets weed it out initially at the database restricted
  999. * on the time parameters. That should keep the lists manageable
  1000. *
  1001. * @param contentCategories A ContentCategoryVO list used to find related ContentVersions
  1002. * @param db A Database to execute the query against
  1003. * @return A List of ContentVersions that were related to the provided ContentCategories and
  1004. * fell withing the publishing time frame
  1005. * @throws Exception if an error happens
  1006. */
  1007. private List findContentVersionsForCategories(List contentCategories, Database db) throws Exception
  1008. {
  1009. if(contentCategories.isEmpty())
  1010. return Collections.EMPTY_LIST;
  1011. /*
  1012. StringBuffer oql = new StringBuffer();
  1013. oql.append("SELECT c FROM org.infoglue.cms.entities.content.impl.simple.ContentVersionImpl c ")
  1014. .append("WHERE c.owningContent.publishDateTime <= $1 AND c.owningContent.expireDateTime >= $2 ")
  1015. .append("AND c.contentVersionId IN LIST ").append(toVersionIdList(contentCategories));
  1016. */
  1017. StringBuffer oql = new StringBuffer();
  1018. oql.append("SELECT c FROM org.infoglue.cms.entities.content.impl.simple.ContentVersionImpl c ")
  1019. .append("WHERE c.contentVersionId IN LIST ").append(toVersionIdList(contentCategories));
  1020. ArrayList params = new ArrayList();
  1021. //params.add(new Date());
  1022. //params.add(new Date());
  1023. return executeQuery(db, oql.toString(), params);
  1024. }
  1025. /**
  1026. * Is this a valid Content item based on defined rules for publican/expiration etc.,
  1027. * and is it the most recent ContentVersion for this deployment. If not then we retrieved
  1028. * based on categories attached to an old version.
  1029. */
  1030. private boolean isValidContentVersion(ContentVersion version, InfoGluePrincipal infoGluePrincipal, Integer siteNodeId, Integer languageId, boolean useLanguageFallback, Database db, DeliveryContext deliveryContext) throws Exception
  1031. {
  1032. //Content content = version.getOwningContent();
  1033. Integer contentId = version.getValueObject().getContentId();
  1034. logger.info("contentId:" + contentId);
  1035. //Content content = (MediumContentImpl)getObjectWithId(MediumContentImpl.class, contentId, db);
  1036. //Content content = ContentController.getContentController().getContentWithId(contentId, db);
  1037. ContentVO content = ContentController.getContentController().getSmallContentVOWithId(contentId, db, deliveryContext);
  1038. SmallestContentVersionVO mostRecentVersion = getSmallestContentVersionVO(db, siteNodeId, content.getContentId(), languageId, useLanguageFallback, deliveryContext, infoGluePrincipal);
  1039. boolean isProperVersion = (mostRecentVersion != null) && (mostRecentVersion.getId().equals(version.getId()));
  1040. boolean isValidContent = isValidContent(infoGluePrincipal, content, languageId, useLanguageFallback, false, db, deliveryContext);
  1041. return isProperVersion && isValidContent;
  1042. }
  1043. /**
  1044. * Builds and IN list for the query to find all potentially relevant content versions.
  1045. */
  1046. private String toVersionIdList(List results)
  1047. {
  1048. StringBuffer ids = new StringBuffer("(");
  1049. for(Iterator iter = results.iterator(); iter.hasNext();)
  1050. ids.append(((ContentCategoryVO) iter.next()).getContentVersionId() + (iter.hasNext()? ", " : ""));
  1051. ids.append(")");
  1052. return ids.toString();
  1053. }
  1054. /**
  1055. * This method returns all the assetsKeys available in a contentVersion.
  1056. */
  1057. public Collection getAssetKeys(Database db, Integer contentId, Integer languageId, Integer siteNodeId, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception
  1058. {
  1059. Collection assetKeys = new ArrayList();
  1060. SmallestContentVersionVO contentVersion = getSmallestContentVersionVO(siteNodeId, contentId, languageId, db, useLanguageFallback, deliveryContext, infoGluePrincipal);
  1061. if (contentVersion != null)
  1062. {
  1063. Collection assets = getDigitalAssetVOList(contentVersion.getId(), db);
  1064. Iterator keysIterator = assets.iterator();
  1065. while(keysIterator.hasNext())
  1066. {
  1067. DigitalAssetVO asset = (DigitalAssetVO)keysIterator.next();
  1068. String assetKey = asset.getAssetKey();
  1069. assetKeys.add(assetKey);
  1070. }
  1071. }
  1072. return assetKeys;
  1073. }
  1074. /**
  1075. * This method returns all the assetsKeys available in a contentVersion.
  1076. */
  1077. public Collection getAssetIds(Database db, Integer contentId, Integer languageId, Integer siteNodeId, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception
  1078. {
  1079. Collection assetIds = new ArrayList();
  1080. SmallestContentVersionVO contentVersion = getSmallestContentVersionVO(siteNodeId, contentId, languageId, db, useLanguageFallback, deliveryContext, infoGluePrincipal);
  1081. if (contentVersion != null)
  1082. {
  1083. Collection assets = getDigitalAssetVOList(contentVersion.getId(), db);
  1084. Iterator keysIterator = assets.iterator();
  1085. while(keysIterator.hasNext())
  1086. {
  1087. DigitalAssetVO asset = (DigitalAssetVO)keysIterator.next();
  1088. assetIds.add(asset.getId());
  1089. }
  1090. }
  1091. return assetIds;
  1092. }
  1093. /**
  1094. * This method returns all the assets available in a contentVersion.
  1095. */
  1096. public List getAssets(Database db, Integer contentId, Integer languageId, Integer siteNodeId, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception
  1097. {
  1098. List digitalAssetVOList = new ArrayList();
  1099. SmallestContentVersionVO contentVersion = getSmallestContentVersionVO(siteNodeId, contentId, languageId, db, useLanguageFallback, deliveryContext, infoGluePrincipal);
  1100. if (contentVersion != null)
  1101. {
  1102. digitalAssetVOList = getDigitalAssetVOList(contentVersion.getId(), db);
  1103. }
  1104. return digitalAssetVOList;
  1105. }
  1106. /**
  1107. * This method returns all the assets available in a contentVersion.
  1108. */
  1109. public DigitalAssetVO getAsset(Database db, Integer contentId, Integer languageId, String assetKey, Integer siteNodeId, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception
  1110. {
  1111. DigitalAssetVO digitalAssetVO = null;
  1112. SmallestContentVersionVO contentVersion = getSmallestContentVersionVO(siteNodeId, contentId, languageId, db, useLanguageFallback, deliveryContext, infoGluePrincipal);
  1113. if (contentVersion != null)
  1114. {
  1115. Collection assets = getDigitalAssetVOList(contentVersion.getId(), db);
  1116. Iterator keysIterator = assets.iterator();
  1117. while(keysIterator.hasNext())
  1118. {
  1119. DigitalAssetVO asset = (DigitalAssetVO)keysIterator.next();
  1120. if(asset.getAssetKey().equalsIgnoreCase(assetKey))
  1121. {
  1122. digitalAssetVO = asset;
  1123. break;
  1124. }
  1125. }
  1126. }
  1127. if(digitalAssetVO == null && useLanguageFallback)
  1128. {
  1129. digitalAssetVO = getLanguageIndependentAssetVO(contentId, languageId, siteNodeId, db, assetKey, deliveryContext, infoGluePrincipal);
  1130. }
  1131. return digitalAssetVO;
  1132. }
  1133. /**
  1134. * This method should return a list of those digital assets the contentVersion has.
  1135. */
  1136. public List getDigitalAssetVOList(Integer contentVersionId, Database db) throws Exception
  1137. {
  1138. String key = "all_" + contentVersionId;
  1139. String cacheName = "digitalAssetCache";
  1140. List digitalAssetVOList = (List)CacheController.getCachedObject(cacheName, key);
  1141. if(digitalAssetVOList != null)
  1142. {
  1143. if(logger.isInfoEnabled())
  1144. logger.info("There was an cached digitalAssetVOList:" + digitalAssetVOList);
  1145. return digitalAssetVOList;
  1146. }
  1147. digitalAssetVOList = new ArrayList();
  1148. if(logger.isInfoEnabled())
  1149. logger.info("Making a sql call for assets on " + contentVersionId);
  1150. OQLQuery oql = db.getOQLQuery("CALL SQL SELECT c.digitalAssetId, c.assetFileName, c.assetKey, c.assetFilePath, c.assetContentType, c.assetFileSize FROM cmDigitalAsset c, cmContentVersionDigitalAsset cvda where cvda.digitalAssetId = c.digitalAssetId AND cvda.contentVersionId = $1 ORDER BY c.digitalAssetId AS org.infoglue.cms.entities.content.impl.simple.SmallDigitalAssetImpl");
  1151. if(CmsPropertyHandler.getUseShortTableNames() != null && CmsPropertyHandler.getUseShortTableNames().equalsIgnoreCase("true"))
  1152. oql = db.getOQLQuery("CALL SQL SELECT c.DigAssetId, c.assetFileName, c.assetKey, c.assetFilePath, c.assetContentType, c.assetFileSize FROM cmDigAsset c, cmContVerDigAsset cvda where cvda.DigAssetId = c.DigAssetId AND cvda.ContVerId = $1 ORDER BY c.DigAssetId AS org.infoglue.cms.entities.content.impl.simple.SmallDigitalAssetImpl");
  1153. oql.bind(contentVersionId);
  1154. QueryResults results = oql.execute(Database.ReadOnly);
  1155. while(results.hasMore())
  1156. {
  1157. SmallDigitalAssetImpl digitalAsset = (SmallDigitalAssetImpl)results.next();
  1158. digitalAssetVOList.add(digitalAsset.getValueObject());
  1159. }
  1160. results.close();
  1161. oql.close();
  1162. if(digitalAssetVOList != null)
  1163. CacheController.cacheObject(cacheName, key, digitalAssetVOList);
  1164. return digitalAssetVOList;
  1165. }
  1166. /**
  1167. * This method is used by the getAssetUrl methods, to locate a digital asset in another
  1168. * languageversion. It is called in the case where no asset where found in the supplied language.
  1169. *
  1170. * This way an image is only required to exist in one of the language versions, reducing the need for
  1171. * many duplicates.
  1172. *
  1173. */
  1174. /*
  1175. private DigitalAsset getLanguageIndependentAsset(Integer contentId, Integer languageId, Integer siteNodeId, Database db, String assetKey, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception
  1176. {
  1177. DigitalAsset asset = null;
  1178. // TODO: This method should only return a asset url depending on settings on the actual content in the future
  1179. // or possibly a systemwide setting.
  1180. // TODO: experimental
  1181. // addition ss - 030422
  1182. // Search digital asset among language versions.
  1183. List langs = LanguageDeliveryController.getLanguageDeliveryController().getAvailableLanguages(db, siteNodeId);
  1184. Iterator lit = langs.iterator();
  1185. while (lit.hasNext())
  1186. {
  1187. LanguageVO langVO = (LanguageVO) lit.next();
  1188. if (langVO.getLanguageId().compareTo(languageId)!=0)
  1189. {
  1190. ContentVersion contentVersion = getContentVersion(siteNodeId, contentId, langVO.getLanguageId(), db, false, deliveryContext, infoGluePrincipal);
  1191. if (contentVersion != null)
  1192. {
  1193. DigitalAsset digitalAsset = (assetKey == null) ? getLatestDigitalAsset(contentVersion) :getDigitalAssetWithKey(contentVersion, assetKey);
  1194. if(digitalAsset != null)
  1195. {
  1196. asset = digitalAsset;
  1197. break;
  1198. }
  1199. }
  1200. }
  1201. }
  1202. return asset;
  1203. }
  1204. */
  1205. /**
  1206. * This method is used by the getAssetUrl methods, to locate a digital asset in another
  1207. * languageversion. It is called in the case where no asset where found in the supplied language.
  1208. *
  1209. * This way an image is only required to exist in one of the language versions, reducing the need for
  1210. * many duplicates.
  1211. *
  1212. */
  1213. private DigitalAssetVO getLanguageIndependentAssetVO(Integer contentId, Integer languageId, Integer siteNodeId, Database db, String assetKey, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception
  1214. {
  1215. DigitalAssetVO asset = null;
  1216. // TODO: This method should only return a asset url depending on settings on the actual content in the future
  1217. // or possibly a systemwide setting.
  1218. // TODO: experimental
  1219. // addition ss - 030422
  1220. // Search digital asset among language versions.
  1221. List langs = LanguageDeliveryController.getLanguageDeliveryController().getAvailableLanguages(db, siteNodeId);
  1222. List<Integer> checkedLanguages = new ArrayList<Integer>();
  1223. Iterator lit = langs.iterator();
  1224. while (lit.hasNext())
  1225. {
  1226. LanguageVO langVO = (LanguageVO) lit.next();
  1227. if (langVO.getLanguageId().compareTo(languageId)!=0)
  1228. {
  1229. SmallestContentVersionVO contentVersion = getSmallestContentVersionVO(siteNodeId, contentId, langVO.getLanguageId(), db, false, deliveryContext, infoGluePrincipal);
  1230. if (contentVersion != null)
  1231. {
  1232. DigitalAssetVO digitalAsset = (assetKey == null) ? DigitalAssetController.getLatestDigitalAssetVO(contentVersion.getId(), db) : DigitalAssetController.getLatestDigitalAssetVO(contentVersion.getId(), assetKey, db);
  1233. if(digitalAsset != null)
  1234. {
  1235. asset = digitalAsset;
  1236. break;
  1237. }
  1238. }
  1239. checkedLanguages.add(langVO.getLanguageId());
  1240. }
  1241. }
  1242. if(asset == null)
  1243. {
  1244. ContentVO contentVO = getContentVO(db, contentId, deliveryContext);
  1245. SiteNodeVO siteNodeVO = SiteNodeController.getController().getSiteNodeVOWithId(siteNodeId, db);
  1246. if(!contentVO.getRepositoryId().equals(siteNodeVO.getRepositoryId()))
  1247. {
  1248. List contentRepositoryLangs = LanguageDeliveryController.getLanguageDeliveryController().getAvailableLanguagesForRepository(db, contentVO.getRepositoryId());
  1249. Iterator contentRepositoryLangsIterator = contentRepositoryLangs.iterator();
  1250. while (contentRepositoryLangsIterator.hasNext())
  1251. {
  1252. LanguageVO langVO = (LanguageVO) contentRepositoryLangsIterator.next();
  1253. if (langVO.getLanguageId().compareTo(languageId)!=0)
  1254. {
  1255. if(checkedLanguages.contains(langVO.getLanguageId()))
  1256. {
  1257. continue;
  1258. }
  1259. SmallestContentVersionVO contentVersion = getSmallestContentVersionVO(siteNodeId, contentId, langVO.getLanguageId(), db, false, deliveryContext, infoGluePrincipal);
  1260. if (contentVersion != null)
  1261. {
  1262. DigitalAssetVO digitalAsset = (assetKey == null) ? DigitalAssetController.getLatestDigitalAssetVO(contentVersion.getId(), db) : DigitalAssetController.getLatestDigitalAssetVO(contentVersion.getId(), assetKey, db);
  1263. if(digitalAsset != null)
  1264. {
  1265. asset = digitalAsset;
  1266. break;
  1267. }
  1268. }
  1269. }
  1270. }
  1271. }
  1272. }
  1273. return asset;
  1274. }
  1275. private String getLanguageIndependentAssetUrl(Integer contentId, Integer languageId, Integer siteNodeId, Database db, String assetKey, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception
  1276. {
  1277. String assetUrl = "";
  1278. assetUrl = urlComposer.composeDigitalAssetUrl("", null, "", deliveryContext);
  1279. DigitalAssetVO digitalAssetVO = getLanguageIndependentAssetVO(contentId, languageId, siteNodeId, db, assetKey, deliveryContext, infoGluePrincipal);
  1280. if(digitalAssetVO != null)
  1281. {
  1282. //String fileName = digitalAssetVO.getDigitalAssetId() + "_" + digitalAssetVO.getAssetFileName();
  1283. String fileName = DigitalAssetDeliveryController.getAssetFileName(digitalAssetVO, contentId, languageId, db);
  1284. //String folderName = "" + (digitalAssetVO.getDigitalAssetId().intValue() / 1000);
  1285. String folderName = DigitalAssetDeliveryController.getAssetFolderName(digitalAssetVO, contentId, languageId, db);
  1286. logger.info("folderName:" + folderName);
  1287. String filePath = CmsPropertyHandler.getDigitalAssetPath0() + File.separator + folderName;
  1288. int i = 0;
  1289. File masterFile = null;
  1290. while(filePath != null)
  1291. {
  1292. try
  1293. {
  1294. if(masterFile == null)
  1295. masterFile = DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(digitalAssetVO, fileName, filePath, db);
  1296. else
  1297. DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(masterFile, fileName, filePath);
  1298. }
  1299. catch(Exception e)
  1300. {
  1301. logger.warn("An file could not be written:" + e.getMessage(), e);
  1302. }
  1303. i++;
  1304. filePath = CmsPropertyHandler.getProperty("digitalAssetPath." + i);
  1305. if(filePath != null)
  1306. filePath += File.separator + folderName;
  1307. }
  1308. //String filePath = CmsPropertyHandler.getDigitalAssetPath();
  1309. //DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(digitalAsset, fileName, filePath);
  1310. SiteNodeVO siteNodeVO = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, contentId, deliveryContext).getSiteNodeVO(db, siteNodeId);
  1311. String dnsName = CmsPropertyHandler.getWebServerAddress();
  1312. if(siteNodeVO != null)
  1313. {
  1314. RepositoryVO repositoryVO = RepositoryController.getController().getRepositoryVOWithId(siteNodeVO.getRepositoryId(), db);
  1315. if(repositoryVO.getDnsName() != null && !repositoryVO.getDnsName().equals(""))
  1316. dnsName = repositoryVO.getDnsName();
  1317. }
  1318. /*
  1319. SiteNode siteNode = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, contentId).getSiteNode(db, siteNodeId);
  1320. String dnsName = CmsPropertyHandler.getWebServerAddress();
  1321. if(siteNode != null && siteNode.getRepository().getDnsName() != null && !siteNode.getRepository().getDnsName().equals(""))
  1322. dnsName = siteNode.getRepository().getDnsName();
  1323. */
  1324. //assetUrl = dnsName + "/" + CmsPropertyHandler.getDigitalAssetBaseUrl() + "/" + fileName;
  1325. if(deliveryContext.getUseDownloadAction())
  1326. assetUrl = urlComposer.composeDigitalAssetUrl(dnsName, siteNodeId, contentId, languageId, assetKey, deliveryContext, db);
  1327. else
  1328. assetUrl = urlComposer.composeDigitalAssetUrl(dnsName, folderName, fileName, deliveryContext);
  1329. }
  1330. return assetUrl;
  1331. }
  1332. private String getLanguageIndependentAssetThumbnailUrl(Integer contentId, Integer languageId, Integer siteNodeId, Database db, String assetKey, int width, int height, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception
  1333. {
  1334. String assetUrl = "";
  1335. assetUrl = urlComposer.composeDigitalAssetUrl("", null, "", deliveryContext);
  1336. DigitalAssetVO digitalAsset = getLanguageIndependentAssetVO(contentId, languageId, siteNodeId, db, assetKey, deliveryContext, infoGluePrincipal);
  1337. if(digitalAsset != null)
  1338. {
  1339. //String fileName = digitalAsset.getDigitalAssetId() + "_" + digitalAsset.getAssetFileName();
  1340. String fileName = DigitalAssetDeliveryController.getAssetFileName(digitalAsset, contentId, languageId, db);
  1341. //String folderName = "" + (digitalAssetVO.getDigitalAssetId().intValue() / 1000);
  1342. String folderName = DigitalAssetDeliveryController.getAssetFolderName(digitalAsset, contentId, languageId, db);
  1343. String thumbnailFileName = "thumbnail_" + width + "_" + height + "_" + fileName;
  1344. int i = 0;
  1345. File masterFile = null;
  1346. File masterThumbFile = null;
  1347. String filePath = CmsPropertyHandler.getDigitalAssetPath0() + File.separator + folderName;
  1348. while(filePath != null)
  1349. {
  1350. if(masterFile == null)
  1351. masterFile = DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(digitalAsset, fileName, filePath, db);
  1352. else
  1353. DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(masterFile, fileName, filePath);
  1354. if(masterThumbFile == null)
  1355. masterThumbFile = DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAssetThumbnail(fileName, thumbnailFileName, filePath, width, height);
  1356. else
  1357. DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAssetThumbnail(fileName, thumbnailFileName, filePath, width, height);
  1358. /*
  1359. if(masterFile == null)
  1360. masterThumbFile = DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAssetThumbnail(fileName, thumbnailFileName, filePath, width, height);
  1361. else
  1362. DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAssetThumbnail(fileName, thumbnailFileName, filePath, width, height);
  1363. */
  1364. i++;
  1365. filePath = CmsPropertyHandler.getProperty("digitalAssetPath." + i);
  1366. if(filePath != null)
  1367. filePath += File.separator + folderName;
  1368. }
  1369. //String filePath = CmsPropertyHandler.getDigitalAssetPath();
  1370. //DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAssetThumbnail(digitalAsset, fileName, thumbnailFileName, filePath, width, height);
  1371. SiteNodeVO siteNodeVO = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, contentId, deliveryContext).getSiteNodeVO(db, siteNodeId);
  1372. String dnsName = CmsPropertyHandler.getWebServerAddress();
  1373. if(siteNodeVO != null)
  1374. {
  1375. RepositoryVO repositoryVO = RepositoryController.getController().getRepositoryVOWithId(siteNodeVO.getRepositoryId(), db);
  1376. if(repositoryVO.getDnsName() != null && !repositoryVO.getDnsName().equals(""))
  1377. dnsName = repositoryVO.getDnsName();
  1378. }
  1379. //assetUrl = dnsName + "/" + CmsPropertyHandler.getDigitalAssetBaseUrl() + "/" + thumbnailFileName;
  1380. assetUrl = urlComposer.composeDigitalAssetUrl(dnsName, folderName, thumbnailFileName, deliveryContext);
  1381. }
  1382. return assetUrl;
  1383. }
  1384. /**
  1385. * This method returns the id of the digital asset.
  1386. * It selects the correct contentVersion depending on the language and then gets the digitalAsset associated.
  1387. */
  1388. public Integer getDigitalAssetId(Database db, Integer contentId, Integer languageId, String assetKey, Integer siteNodeId, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception
  1389. {
  1390. Integer digitalAssetId = null;
  1391. SmallestContentVersionVO contentVersion = getSmallestContentVersionVO(siteNodeId, contentId, languageId, db, useLanguageFallback, deliveryContext, infoGluePrincipal);
  1392. if (contentVersion != null)
  1393. {
  1394. DigitalAssetVO digitalAsset = DigitalAssetController.getLatestDigitalAssetVO(contentVersion.getContentVersionId(), assetKey, db);
  1395. if(digitalAsset != null)
  1396. {
  1397. digitalAssetId = digitalAsset.getId();
  1398. }
  1399. }
  1400. return digitalAssetId;
  1401. }
  1402. /**
  1403. * This is the basic way of getting an asset-url for a content.
  1404. * It selects the correct contentVersion depending on the language and then gets the digitalAsset associated.
  1405. * If the asset is cached on disk it returns that path imediately it's ok - otherwise it dumps it fresh.
  1406. */
  1407. public String getAssetUrl(Database db, Integer contentId, Integer languageId, Integer siteNodeId, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception
  1408. {
  1409. String assetCacheKey = "" + languageId + "_" + contentId + "_" + siteNodeId + "_" + useLanguageFallback;
  1410. logger.info("assetCacheKey:" + assetCacheKey);
  1411. String cacheName = "assetUrlCache";
  1412. String cachedAssetUrl = (String)CacheController.getCachedObject(cacheName, assetCacheKey);
  1413. if(cachedAssetUrl != null)
  1414. {
  1415. logger.info("There was an cached cachedAssetUrl:" + cachedAssetUrl);
  1416. return cachedAssetUrl;
  1417. }
  1418. String assetUrl = "";
  1419. SmallestContentVersionVO contentVersion = getSmallestContentVersionVO(siteNodeId, contentId, languageId, db, useLanguageFallback, deliveryContext, infoGluePrincipal);
  1420. if (contentVersion != null)
  1421. {
  1422. DigitalAssetVO digitalAsset = DigitalAssetController.getLatestDigitalAssetVO(contentVersion.getId(), db);
  1423. if(digitalAsset != null)
  1424. {
  1425. //String fileName = digitalAsset.getDigitalAssetId() + "_" + digitalAsset.getAssetFileName();
  1426. String fileName = DigitalAssetDeliveryController.getAssetFileName(digitalAsset, contentId, languageId, db);
  1427. //String folderName = "" + (digitalAsset.getDigitalAssetId().intValue() / 1000);
  1428. String folderName = DigitalAssetDeliveryController.getAssetFolderName(digitalAsset, contentId, languageId, db);
  1429. int i = 0;
  1430. File masterFile = null;
  1431. String filePath = CmsPropertyHandler.getDigitalAssetPath0() + File.separator + folderName;
  1432. while(filePath != null)
  1433. {
  1434. try
  1435. {
  1436. if(masterFile == null)
  1437. masterFile = DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(digitalAsset, fileName, filePath, db);
  1438. else
  1439. DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(masterFile, fileName, filePath);
  1440. }
  1441. catch(Exception e)
  1442. {
  1443. logger.warn("An file could not be written:" + e.getMessage(), e);
  1444. }
  1445. i++;
  1446. filePath = CmsPropertyHandler.getProperty("digitalAssetPath." + i);
  1447. if(filePath != null)
  1448. filePath += File.separator + folderName;
  1449. }
  1450. //String filePath = CmsPropertyHandler.getDigitalAssetPath();
  1451. //DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(digitalAsset, fileName, filePath);
  1452. SiteNodeVO siteNodeVO = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, contentId, deliveryContext).getSiteNodeVO(db, siteNodeId);
  1453. String dnsName = CmsPropertyHandler.getWebServerAddress();
  1454. if(siteNodeVO != null)
  1455. {
  1456. RepositoryVO repositoryVO = RepositoryController.getController().getRepositoryVOWithId(siteNodeVO.getRepositoryId(), db);
  1457. if(repositoryVO.getDnsName() != null && !repositoryVO.getDnsName().equals(""))
  1458. dnsName = repositoryVO.getDnsName();
  1459. }
  1460. /*
  1461. SiteNode siteNode = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, contentId).getSiteNode(db, siteNodeId);
  1462. String dnsName = CmsPropertyHandler.getWebServerAddress();
  1463. if(siteNode != null && siteNode.getRepository().getDnsName() != null && !siteNode.getRepository().getDnsName().equals(""))
  1464. dnsName = siteNode.getRepository().getDnsName();
  1465. */
  1466. //assetUrl = dnsName + "/" + CmsPropertyHandler.getDigitalAssetBaseUrl() + "/" + fileName;
  1467. assetUrl = urlComposer.composeDigitalAssetUrl(dnsName, folderName, fileName, deliveryContext);
  1468. }
  1469. else
  1470. {
  1471. assetUrl = getLanguageIndependentAssetUrl(contentId, languageId, siteNodeId, db, null, deliveryContext, infoGluePrincipal);
  1472. }
  1473. }
  1474. CacheController.cacheObject(cacheName, assetCacheKey, assetUrl);
  1475. //System.out.println("Group:" + "content_" + contentId);
  1476. //CacheController.cacheObjectInAdvancedCache(cacheName, assetCacheKey, assetUrl, new String[]{"content_" + contentId}, true);
  1477. return assetUrl;
  1478. }
  1479. /**
  1480. * This is the basic way of getting an asset-url for a content.
  1481. * It selects the correct contentVersion depending on the language and then gets the digitalAsset associated.
  1482. * If the asset is cached on disk it returns that path imediately it's ok - otherwise it dumps it fresh.
  1483. */
  1484. public String getAssetUrl(Database db, Integer digitalAssetId, Integer siteNodeId, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception
  1485. {
  1486. String assetCacheKey = "" + digitalAssetId + "_" + siteNodeId ;
  1487. logger.info("assetCacheKey:" + assetCacheKey);
  1488. String cacheName = "assetUrlCache";
  1489. String cachedAssetUrl = (String)CacheController.getCachedObject(cacheName, assetCacheKey);
  1490. if(cachedAssetUrl != null)
  1491. {
  1492. logger.info("There was an cached cachedAssetUrl:" + cachedAssetUrl);
  1493. return cachedAssetUrl;
  1494. }
  1495. String assetUrl = "";
  1496. DigitalAssetVO digitalAsset = DigitalAssetController.getSmallDigitalAssetVOWithId(digitalAssetId, db);
  1497. if(digitalAsset != null)
  1498. {
  1499. //String fileName = digitalAsset.getDigitalAssetId() + "_" + digitalAsset.getAssetFileName();
  1500. String fileName = DigitalAssetDeliveryController.getAssetFileName(digitalAsset, null, null, db);
  1501. //String folderName = "" + (digitalAsset.getDigitalAssetId().intValue() / 1000);
  1502. String folderName = DigitalAssetDeliveryController.getAssetFolderName(digitalAsset, null, null, db);
  1503. int i = 0;
  1504. File masterFile = null;
  1505. String filePath = CmsPropertyHandler.getDigitalAssetPath0() + File.separator + folderName;
  1506. while(filePath != null)
  1507. {
  1508. try
  1509. {
  1510. if(masterFile == null)
  1511. masterFile = DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(digitalAsset, fileName, filePath, db);
  1512. else
  1513. DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(masterFile, fileName, filePath);
  1514. }
  1515. catch(Exception e)
  1516. {
  1517. logger.warn("An file could not be written:" + e.getMessage(), e);
  1518. }
  1519. i++;
  1520. filePath = CmsPropertyHandler.getProperty("digitalAssetPath." + i);
  1521. if(filePath != null)
  1522. filePath += File.separator + folderName;
  1523. }
  1524. SiteNodeVO siteNodeVO = NodeDeliveryController.getNodeDeliveryController(null, deliveryContext.getLanguageId(), null, deliveryContext).getSiteNodeVO(db, siteNodeId);
  1525. String dnsName = CmsPropertyHandler.getWebServerAddress();
  1526. if(siteNodeVO != null)
  1527. {
  1528. RepositoryVO repositoryVO = RepositoryController.getController().getRepositoryVOWithId(siteNodeVO.getRepositoryId(), db);
  1529. if(repositoryVO.getDnsName() != null && !repositoryVO.getDnsName().equals(""))
  1530. dnsName = repositoryVO.getDnsName();
  1531. }
  1532. /*
  1533. SiteNode siteNode = NodeDeliveryController.getNodeDeliveryController(null, deliveryContext.getLanguageId(), null, deliveryContext).getSiteNode(db, siteNodeId);
  1534. String dnsName = CmsPropertyHandler.getWebServerAddress();
  1535. if(siteNode != null && siteNode.getRepository().getDnsName() != null && !siteNode.getRepository().getDnsName().equals(""))
  1536. dnsName = siteNode.getRepository().getDnsName();
  1537. */
  1538. assetUrl = urlComposer.composeDigitalAssetUrl(dnsName, folderName, fileName, deliveryContext);
  1539. }
  1540. CacheController.cacheObject(cacheName, assetCacheKey, assetUrl);
  1541. return assetUrl;
  1542. }
  1543. /**
  1544. * This is the basic way of getting an asset-url for a content.
  1545. * It selects the correct contentVersion depending on the language and then gets the digitalAsset associated with the key.
  1546. * If the asset is cached on disk it returns that path imediately it's ok - otherwise it dumps it fresh.
  1547. */
  1548. public String getAssetUrl(Database db, Integer contentId, Integer languageId, String assetKey, Integer siteNodeId, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception
  1549. {
  1550. if(contentId == null || contentId.intValue() < 1)
  1551. return "";
  1552. Timer t = new Timer();
  1553. //System.out.println("Adding:" + "content_" + contentId);
  1554. deliveryContext.addUsedContent(CacheController.getPooledString(1, contentId));
  1555. SiteNodeVO siteNodeVO = SiteNodeController.getController().getSiteNodeVOWithId(siteNodeId, db);
  1556. String assetCacheKey = "" + languageId + "_" + contentId + "_" + siteNodeVO.getRepositoryId() + "_" + assetKey + "_" + useLanguageFallback + "_" + deliveryContext.getUseFullUrl() + "_" + deliveryContext.getUseDownloadAction();
  1557. if(logger.isInfoEnabled())
  1558. logger.info("assetCacheKey:" + assetCacheKey);
  1559. assetKey = URLDecoder.decode(assetKey, "utf-8");
  1560. String cacheName = "assetUrlCacheWithGroups";
  1561. //String cachedAssetUrl = (String)CacheController.getCachedObject(cacheName, assetCacheKey);
  1562. String cachedAssetUrl = (String)CacheController.getCachedObjectFromAdvancedCache(cacheName, assetCacheKey);
  1563. if(cachedAssetUrl != null)
  1564. {
  1565. if(logger.isInfoEnabled())
  1566. logger.info("There was an cached cachedAssetUrl:" + cachedAssetUrl);
  1567. return cachedAssetUrl;
  1568. }
  1569. String assetUrl = "";
  1570. assetUrl = urlComposer.composeDigitalAssetUrl("", null, "", deliveryContext);
  1571. SmallestContentVersionVO contentVersion = getSmallestContentVersionVO(siteNodeId, contentId, languageId, db, useLanguageFallback, deliveryContext, infoGluePrincipal);
  1572. ContentVO contentVO = this.getContentVO(db, contentId, deliveryContext);
  1573. LanguageVO masterLanguageVO = LanguageDeliveryController.getLanguageDeliveryController().getMasterLanguageForRepository(contentVO.getRepositoryId(), db);
  1574. if(logger.isInfoEnabled())
  1575. {
  1576. logger.info("languageId:" + languageId);
  1577. logger.info("masterLanguageVO:" + masterLanguageVO);
  1578. }
  1579. /*
  1580. if(deliveryContext.getUseDownloadAction())
  1581. {
  1582. SiteNode siteNode = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, contentId).getSiteNode(db, siteNodeId);
  1583. String dnsName = CmsPropertyHandler.getWebServerAddress();
  1584. if(siteNode != null && siteNode.getRepository().getDnsName() != null && !siteNode.getRepository().getDnsName().equals(""))
  1585. dnsName = siteNode.getRepository().getDnsName();
  1586. return urlComposer.composeDigitalAssetUrl(dnsName, siteNodeId, contentId, languageId, assetKey, deliveryContext);
  1587. }
  1588. */
  1589. boolean isUnprotectedAsset = getHasUserContentAccess(db, UserControllerProxy.getController().getUser(CmsPropertyHandler.getAnonymousUser()), contentId);
  1590. if(!isUnprotectedAsset)
  1591. {
  1592. DigitalAssetVO digitalAsset = DigitalAssetController.getLatestDigitalAssetVO(contentVersion.getId(), assetKey, db);
  1593. if(digitalAsset == null)
  1594. return "";
  1595. //SiteNodeVO siteNodeVO = getSiteNodeVO(db, siteNodeId);
  1596. String dnsName = CmsPropertyHandler.getWebServerAddress();
  1597. if(siteNodeVO != null)
  1598. {
  1599. RepositoryVO repositoryVO = RepositoryController.getController().getRepositoryVOWithId(siteNodeVO.getRepositoryId(), db);
  1600. if(repositoryVO.getDnsName() != null && !repositoryVO.getDnsName().equals(""))
  1601. dnsName = repositoryVO.getDnsName();
  1602. }
  1603. /*
  1604. SiteNode siteNode = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, contentId).getSiteNodeVO(db, siteNodeId);
  1605. String dnsName = CmsPropertyHandler.getWebServerAddress();
  1606. if(siteNode != null && siteNode.getRepository().getDnsName() != null && !siteNode.getRepository().getDnsName().equals(""))
  1607. dnsName = siteNode.getRepository().getDnsName();
  1608. */
  1609. return urlComposer.composeDigitalAssetUrl(dnsName, siteNodeId, contentId, languageId, assetKey, deliveryContext, db);
  1610. }
  1611. else if(contentVersion != null)
  1612. {
  1613. DigitalAssetVO digitalAsset = DigitalAssetController.getLatestDigitalAssetVO(contentVersion.getId(), assetKey, db);
  1614. if(digitalAsset != null)
  1615. {
  1616. //String fileName = digitalAsset.getDigitalAssetId() + "_" + digitalAsset.getAssetFileName();
  1617. String fileName = DigitalAssetDeliveryController.getAssetFileName(digitalAsset, contentId, languageId, db);
  1618. //String folderName = "" + (digitalAsset.getDigitalAssetId().intValue() / 1000);
  1619. String folderName = DigitalAssetDeliveryController.getAssetFolderName(digitalAsset, contentId, languageId, db);
  1620. int i = 0;
  1621. File masterFile = null;
  1622. String filePath = CmsPropertyHandler.getDigitalAssetPath0() + File.separator + folderName;
  1623. while(filePath != null)
  1624. {
  1625. try
  1626. {
  1627. if(masterFile == null)
  1628. masterFile = DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(digitalAsset, fileName, filePath, db);
  1629. else
  1630. DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(masterFile, fileName, filePath);
  1631. }
  1632. catch(Exception e)
  1633. {
  1634. logger.warn("An file could not be written:" + e.getMessage(), e);
  1635. }
  1636. i++;
  1637. filePath = CmsPropertyHandler.getProperty("digitalAssetPath." + i);
  1638. if(filePath != null)
  1639. filePath += File.separator + folderName;
  1640. }
  1641. //SiteNodeVO siteNodeVO = getSiteNodeVO(db, siteNodeId);
  1642. String dnsName = CmsPropertyHandler.getWebServerAddress();
  1643. if(siteNodeVO != null)
  1644. {
  1645. RepositoryVO repositoryVO = RepositoryController.getController().getRepositoryVOWithId(siteNodeVO.getRepositoryId(), db);
  1646. if(repositoryVO.getDnsName() != null && !repositoryVO.getDnsName().equals(""))
  1647. dnsName = repositoryVO.getDnsName();
  1648. }
  1649. /*
  1650. SiteNode siteNode = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, contentId).getSiteNode(db, siteNodeId);
  1651. String dnsName = CmsPropertyHandler.getWebServerAddress();
  1652. if(siteNode != null && siteNode.getRepository().getDnsName() != null && !siteNode.getRepository().getDnsName().equals(""))
  1653. dnsName = siteNode.getRepository().getDnsName();
  1654. */
  1655. if(deliveryContext.getUseDownloadAction())
  1656. assetUrl = urlComposer.composeDigitalAssetUrl(dnsName, siteNodeId, contentId, languageId, assetKey, deliveryContext, db);
  1657. else
  1658. assetUrl = urlComposer.composeDigitalAssetUrl(dnsName, folderName, fileName, deliveryContext);
  1659. }
  1660. else if(useLanguageFallback)
  1661. {
  1662. assetUrl = getLanguageIndependentAssetUrl(contentId, languageId, siteNodeId, db, assetKey, deliveryContext, infoGluePrincipal);
  1663. }
  1664. }
  1665. else if(useLanguageFallback && languageId != null && masterLanguageVO != null && languageId.intValue() != masterLanguageVO.getId().intValue())
  1666. {
  1667. contentVersion = getSmallestContentVersionVO(siteNodeId, contentId, languageId, db, useLanguageFallback, deliveryContext, infoGluePrincipal);
  1668. logger.info("contentVersion:" + contentVersion);
  1669. if(contentVersion != null)
  1670. {
  1671. DigitalAssetVO digitalAsset = DigitalAssetController.getLatestDigitalAssetVO(contentVersion.getId(), assetKey, db);
  1672. if(digitalAsset != null)
  1673. {
  1674. //String fileName = digitalAsset.getDigitalAssetId() + "_" + digitalAsset.getAssetFileName();
  1675. String fileName = DigitalAssetDeliveryController.getAssetFileName(digitalAsset, contentId, languageId, db);
  1676. //String folderName = "" + (digitalAsset.getDigitalAssetId().intValue() / 1000);
  1677. String folderName = DigitalAssetDeliveryController.getAssetFolderName(digitalAsset, contentId, languageId, db);
  1678. int i = 0;
  1679. File masterFile = null;
  1680. String filePath = CmsPropertyHandler.getDigitalAssetPath0() + File.separator + folderName;
  1681. while(filePath != null)
  1682. {
  1683. try
  1684. {
  1685. if(masterFile == null)
  1686. masterFile = DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(digitalAsset, fileName, filePath, db);
  1687. else
  1688. DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(masterFile, fileName, filePath);
  1689. }
  1690. catch(Exception e)
  1691. {
  1692. logger.warn("An file could not be written:" + e.getMessage(), e);
  1693. }
  1694. i++;
  1695. filePath = CmsPropertyHandler.getProperty("digitalAssetPath." + i);
  1696. if(filePath != null)
  1697. filePath += File.separator + folderName;
  1698. }
  1699. //SiteNodeVO siteNodeVO = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, contentId).getSiteNodeVO(db, siteNodeId);
  1700. String dnsName = CmsPropertyHandler.getWebServerAddress();
  1701. if(siteNodeVO != null)
  1702. {
  1703. RepositoryVO repositoryVO = RepositoryController.getController().getRepositoryVOWithId(siteNodeVO.getRepositoryId(), db);
  1704. if(repositoryVO.getDnsName() != null && !repositoryVO.getDnsName().equals(""))
  1705. dnsName = repositoryVO.getDnsName();
  1706. }
  1707. /*
  1708. SiteNode siteNode = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, contentId).getSiteNode(db, siteNodeId);
  1709. String dnsName = CmsPropertyHandler.getWebServerAddress();
  1710. if(siteNode != null && siteNode.getRepository().getDnsName() != null && !siteNode.getRepository().getDnsName().equals(""))
  1711. dnsName = siteNode.getRepository().getDnsName();
  1712. */
  1713. if(deliveryContext.getUseDownloadAction())
  1714. assetUrl = urlComposer.composeDigitalAssetUrl(dnsName, siteNodeId, contentId, languageId, assetKey, deliveryContext, db);
  1715. else
  1716. assetUrl = urlComposer.composeDigitalAssetUrl(dnsName, folderName, fileName, deliveryContext);
  1717. }
  1718. else if(useLanguageFallback)
  1719. {
  1720. assetUrl = getLanguageIndependentAssetUrl(contentId, languageId, siteNodeId, db, assetKey, deliveryContext, infoGluePrincipal);
  1721. }
  1722. }
  1723. }
  1724. if(assetUrl == null || assetUrl.equals(""))
  1725. {
  1726. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("Missed as assetURL was empty", t.getElapsedTime());
  1727. logger.info("Missed as assetURL was empty:" + assetKey);
  1728. }
  1729. return assetUrl;
  1730. }
  1731. /**
  1732. * This is the basic way of getting an asset-url for a content.
  1733. * It selects the correct contentVersion depending on the language and then gets the digitalAsset associated.
  1734. * If the asset is cached on disk it returns that path imediately it's ok - otherwise it dumps it fresh.
  1735. */
  1736. public String getAssetFilePath(Database db, Integer digitalAssetId, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception
  1737. {
  1738. String assetFilePath = "";
  1739. Integer contentId = DigitalAssetController.getController().getContentId(digitalAssetId, db);
  1740. boolean hasAccess = getHasUserContentAccess(db, infoGluePrincipal, contentId);
  1741. if(hasAccess)
  1742. {
  1743. DigitalAssetVO digitalAsset = DigitalAssetController.getSmallDigitalAssetVOWithId(digitalAssetId, db);
  1744. if(digitalAsset != null)
  1745. {
  1746. //String fileName = digitalAsset.getDigitalAssetId() + "_" + digitalAsset.getAssetFileName();
  1747. String fileName = DigitalAssetDeliveryController.getAssetFileName(digitalAsset, null, null, db);
  1748. //String folderName = "" + (digitalAsset.getDigitalAssetId().intValue() / 1000);
  1749. String folderName = DigitalAssetDeliveryController.getAssetFolderName(digitalAsset, null, null, db);
  1750. int i = 0;
  1751. File masterFile = null;
  1752. String filePath = CmsPropertyHandler.getDigitalAssetPath0() + File.separator + folderName;
  1753. while(filePath != null)
  1754. {
  1755. try
  1756. {
  1757. if(masterFile == null)
  1758. masterFile = DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(digitalAsset, fileName, filePath, db);
  1759. else
  1760. DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(masterFile, fileName, filePath);
  1761. }
  1762. catch(Exception e)
  1763. {
  1764. logger.warn("An file could not be written:" + e.getMessage(), e);
  1765. }
  1766. i++;
  1767. filePath = CmsPropertyHandler.getProperty("digitalAssetPath." + i);
  1768. if(filePath != null)
  1769. filePath += File.separator + folderName;
  1770. }
  1771. assetFilePath = CmsPropertyHandler.getDigitalAssetPath() + File.separator + folderName + File.separator + fileName;
  1772. }
  1773. }
  1774. return assetFilePath;
  1775. }
  1776. /**
  1777. * This is the basic way of getting an asset-url for a content.
  1778. * It selects the correct contentVersion depending on the language and then gets the digitalAsset associated.
  1779. * If the asset is cached on disk it returns that path imediately it's ok - otherwise it dumps it fresh.
  1780. */
  1781. public String getAssetThumbnailUrl(Database db, Integer contentId, Integer languageId, Integer siteNodeId, boolean useLanguageFallback, int width, int height, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception
  1782. {
  1783. String assetCacheKey = "" + languageId + "_" + contentId + "_" + siteNodeId + "_" + useLanguageFallback + "_" + width + "_" + height;
  1784. logger.info("assetCacheKey:" + assetCacheKey);
  1785. String cacheName = "assetThumbnailUrlCache";
  1786. String cachedAssetUrl = (String)CacheController.getCachedObject(cacheName, assetCacheKey);
  1787. if(cachedAssetUrl != null)
  1788. {
  1789. logger.info("There was an cached cachedAssetUrl:" + cachedAssetUrl);
  1790. return cachedAssetUrl;
  1791. }
  1792. String assetUrl = "";
  1793. SmallestContentVersionVO contentVersion = getSmallestContentVersionVO(siteNodeId, contentId, languageId, db, useLanguageFallback, deliveryContext, infoGluePrincipal);
  1794. if (contentVersion != null)
  1795. {
  1796. //DigitalAsset digitalAsset = getLatestDigitalAsset(contentVersion);
  1797. DigitalAssetVO digitalAsset = DigitalAssetController.getLatestDigitalAssetVO(contentVersion.getId(), db);
  1798. if(digitalAsset != null)
  1799. {
  1800. //String fileName = digitalAsset.getDigitalAssetId() + "_" + digitalAsset.getAssetFileName();
  1801. String fileName = DigitalAssetDeliveryController.getAssetFileName(digitalAsset, contentId, languageId, db);
  1802. //String folderName = "" + (digitalAsset.getDigitalAssetId().intValue() / 1000);
  1803. String folderName = DigitalAssetDeliveryController.getAssetFolderName(digitalAsset, contentId, languageId, db);
  1804. String thumbnailFileName = "thumbnail_" + width + "_" + height + "_" + fileName;
  1805. int i = 0;
  1806. File masterFile = null;
  1807. File masterThumbFile = null;
  1808. String filePath = CmsPropertyHandler.getDigitalAssetPath0() + File.separator + folderName;
  1809. while(filePath != null)
  1810. {
  1811. try
  1812. {
  1813. if(masterFile == null)
  1814. masterFile = DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(digitalAsset, fileName, filePath, db);
  1815. else
  1816. DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(masterFile, fileName, filePath);
  1817. if(masterThumbFile == null)
  1818. masterThumbFile = DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAssetThumbnail(fileName, thumbnailFileName, filePath, width, height);
  1819. else
  1820. DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAssetThumbnail(fileName, thumbnailFileName, filePath, width, height);
  1821. }
  1822. catch(Exception e)
  1823. {
  1824. logger.warn("An file could not be written:" + e.getMessage(), e);
  1825. }
  1826. i++;
  1827. filePath = CmsPropertyHandler.getProperty("digitalAssetPath." + i);
  1828. if(filePath != null)
  1829. filePath += File.separator + folderName;
  1830. }
  1831. SiteNodeVO siteNodeVO = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, contentId, deliveryContext).getSiteNodeVO(db, siteNodeId);
  1832. String dnsName = CmsPropertyHandler.getWebServerAddress();
  1833. if(siteNodeVO != null)
  1834. {
  1835. RepositoryVO repositoryVO = RepositoryController.getController().getRepositoryVOWithId(siteNodeVO.getRepositoryId(), db);
  1836. if(repositoryVO.getDnsName() != null && !repositoryVO.getDnsName().equals(""))
  1837. dnsName = repositoryVO.getDnsName();
  1838. }
  1839. /*
  1840. SiteNode siteNode = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, contentId).getSiteNode(db, siteNodeId);
  1841. String dnsName = CmsPropertyHandler.getWebServerAddress();
  1842. if(siteNode != null && siteNode.getRepository().getDnsName() != null && !siteNode.getRepository().getDnsName().equals(""))
  1843. dnsName = siteNode.getRepository().getDnsName();
  1844. */
  1845. assetUrl = urlComposer.composeDigitalAssetUrl(dnsName, folderName, thumbnailFileName, deliveryContext);
  1846. }
  1847. else
  1848. {
  1849. assetUrl = getLanguageIndependentAssetThumbnailUrl(contentId, languageId, siteNodeId, db, null, width, height, deliveryContext, infoGluePrincipal);
  1850. }
  1851. }
  1852. CacheController.cacheObject(cacheName, assetCacheKey, assetUrl);
  1853. return assetUrl;
  1854. }
  1855. /**
  1856. * This is the basic way of getting an asset-url for a content.
  1857. * It selects the correct contentVersion depending on the language and then gets the digitalAsset associated.
  1858. * If the asset is cached on disk it returns that path imediately it's ok - otherwise it dumps it fresh.
  1859. */
  1860. public String getAssetThumbnailUrl(Database db, Integer digitalAssetId, Integer siteNodeId, int width, int height, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception
  1861. {
  1862. String assetCacheKey = "" + digitalAssetId + "_" + siteNodeId + "_" + width + "_" + height;
  1863. logger.info("assetCacheKey:" + assetCacheKey);
  1864. String cacheName = "assetThumbnailUrlCache";
  1865. String cachedAssetUrl = (String)CacheController.getCachedObject(cacheName, assetCacheKey);
  1866. if(cachedAssetUrl != null)
  1867. {
  1868. logger.info("There was an cached cachedAssetUrl:" + cachedAssetUrl);
  1869. return cachedAssetUrl;
  1870. }
  1871. String assetUrl = "";
  1872. DigitalAssetVO digitalAsset = DigitalAssetController.getSmallDigitalAssetVOWithId(digitalAssetId, db);
  1873. if(digitalAsset != null)
  1874. {
  1875. //String fileName = digitalAsset.getDigitalAssetId() + "_" + digitalAsset.getAssetFileName();
  1876. String fileName = DigitalAssetDeliveryController.getAssetFileName(digitalAsset, null, null, db);
  1877. //String folderName = "" + (digitalAsset.getDigitalAssetId().intValue() / 1000);
  1878. String folderName = DigitalAssetDeliveryController.getAssetFolderName(digitalAsset, null, null, db);
  1879. String thumbnailFileName = "thumbnail_" + width + "_" + height + "_" + fileName;
  1880. int i = 0;
  1881. File masterFile = null;
  1882. File masterThumbFile = null;
  1883. String filePath = CmsPropertyHandler.getDigitalAssetPath0() + File.separator + folderName;
  1884. while(filePath != null)
  1885. {
  1886. try
  1887. {
  1888. if(masterFile == null)
  1889. masterFile = DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(digitalAsset, fileName, filePath, db);
  1890. else
  1891. DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(masterFile, fileName, filePath);
  1892. if(masterThumbFile == null)
  1893. masterThumbFile = DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAssetThumbnail(fileName, thumbnailFileName, filePath, width, height);
  1894. else
  1895. DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAssetThumbnail(fileName, thumbnailFileName, filePath, width, height);
  1896. }
  1897. catch(Exception e)
  1898. {
  1899. logger.warn("An file could not be written:" + e.getMessage(), e);
  1900. }
  1901. i++;
  1902. filePath = CmsPropertyHandler.getProperty("digitalAssetPath." + i);
  1903. if(filePath != null)
  1904. filePath += File.separator + folderName;
  1905. }
  1906. SiteNodeVO siteNodeVO = NodeDeliveryController.getNodeDeliveryController(null, deliveryContext.getLanguageId(), null, deliveryContext).getSiteNodeVO(db, siteNodeId);
  1907. String dnsName = CmsPropertyHandler.getWebServerAddress();
  1908. if(siteNodeVO != null)
  1909. {
  1910. RepositoryVO repositoryVO = RepositoryController.getController().getRepositoryVOWithId(siteNodeVO.getRepositoryId(), db);
  1911. if(repositoryVO.getDnsName() != null && !repositoryVO.getDnsName().equals(""))
  1912. dnsName = repositoryVO.getDnsName();
  1913. }
  1914. /*
  1915. SiteNode siteNode = NodeDeliveryController.getNodeDeliveryController(null, deliveryContext.getLanguageId(), null).getSiteNode(db, siteNodeId);
  1916. String dnsName = CmsPropertyHandler.getWebServerAddress();
  1917. if(siteNode != null && siteNode.getRepository().getDnsName() != null && !siteNode.getRepository().getDnsName().equals(""))
  1918. dnsName = siteNode.getRepository().getDnsName();
  1919. */
  1920. assetUrl = urlComposer.composeDigitalAssetUrl(dnsName, folderName, thumbnailFileName, deliveryContext);
  1921. }
  1922. CacheController.cacheObject(cacheName, assetCacheKey, assetUrl);
  1923. return assetUrl;
  1924. }
  1925. /**
  1926. * This is the basic way of getting an asset-url for a content.
  1927. * It selects the correct contentVersion depending on the language and then gets the digitalAsset associated with the key.
  1928. * If the asset is cached on disk it returns that path imediately it's ok - otherwise it dumps it fresh.
  1929. */
  1930. 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
  1931. {
  1932. String assetCacheKey = "" + languageId + "_" + contentId + "_" + siteNodeId + "_" + assetKey + "_" + useLanguageFallback + "_" + width + "_" + height;
  1933. logger.info("assetCacheKey:" + assetCacheKey);
  1934. String cacheName = "assetThumbnailUrlCache";
  1935. String cachedAssetUrl = (String)CacheController.getCachedObject(cacheName, assetCacheKey);
  1936. if(cachedAssetUrl != null)
  1937. {
  1938. logger.info("There was an cached cachedAssetUrl:" + cachedAssetUrl);
  1939. return cachedAssetUrl;
  1940. }
  1941. String assetUrl = "";
  1942. SmallestContentVersionVO contentVersion = getSmallestContentVersionVO(siteNodeId, contentId, languageId, db, useLanguageFallback, deliveryContext, infoGluePrincipal);
  1943. if (contentVersion != null)
  1944. {
  1945. //DigitalAsset digitalAsset = getDigitalAssetWithKey(contentVersion, assetKey);
  1946. DigitalAssetVO digitalAsset = DigitalAssetController.getLatestDigitalAssetVO(contentVersion.getId(), assetKey, db);
  1947. if(digitalAsset != null)
  1948. {
  1949. //String fileName = digitalAsset.getDigitalAssetId() + "_" + digitalAsset.getAssetFileName();
  1950. String fileName = DigitalAssetDeliveryController.getAssetFileName(digitalAsset, contentId, languageId, null);
  1951. //String folderName = "" + (digitalAsset.getDigitalAssetId().intValue() / 1000);
  1952. String folderName = DigitalAssetDeliveryController.getAssetFolderName(digitalAsset, contentId, languageId, null);
  1953. String thumbnailFileName = "thumbnail_" + width + "_" + height + "_" + fileName;
  1954. int i = 0;
  1955. File masterFile = null;
  1956. File masterThumbFile = null;
  1957. String filePath = CmsPropertyHandler.getDigitalAssetPath0() + File.separator + folderName;
  1958. while(filePath != null)
  1959. {
  1960. try
  1961. {
  1962. if(masterFile == null)
  1963. masterFile = DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(digitalAsset, fileName, filePath, db);
  1964. else
  1965. DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(digitalAsset, fileName, filePath, db);
  1966. if(masterThumbFile == null)
  1967. masterThumbFile = DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAssetThumbnail(fileName, thumbnailFileName, filePath, width, height);
  1968. else
  1969. DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAssetThumbnail(fileName, thumbnailFileName, filePath, width, height);
  1970. }
  1971. catch(Exception e)
  1972. {
  1973. logger.warn("An file could not be written:" + e.getMessage(), e);
  1974. }
  1975. i++;
  1976. filePath = CmsPropertyHandler.getProperty("digitalAssetPath." + i);
  1977. if(filePath != null)
  1978. filePath += File.separator + folderName;
  1979. }
  1980. //String filePath = CmsPropertyHandler.getDigitalAssetPath();
  1981. //DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAsset(digitalAsset, fileName, filePath);
  1982. //DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpDigitalAssetThumbnail(digitalAsset, fileName, thumbnailFileName, filePath, width, height);
  1983. SiteNodeVO siteNodeVO = NodeDeliveryController.getNodeDeliveryController(null, deliveryContext.getLanguageId(), null, deliveryContext).getSiteNodeVO(db, siteNodeId);
  1984. String dnsName = CmsPropertyHandler.getWebServerAddress();
  1985. if(siteNodeVO != null)
  1986. {
  1987. RepositoryVO repositoryVO = RepositoryController.getController().getRepositoryVOWithId(siteNodeVO.getRepositoryId(), db);
  1988. if(repositoryVO.getDnsName() != null && !repositoryVO.getDnsName().equals(""))
  1989. dnsName = repositoryVO.getDnsName();
  1990. }
  1991. /*
  1992. SiteNode siteNode = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, contentId).getSiteNode(db, siteNodeId);
  1993. String dnsName = CmsPropertyHandler.getWebServerAddress();
  1994. if(siteNode != null && siteNode.getRepository().getDnsName() != null && !siteNode.getRepository().getDnsName().equals(""))
  1995. dnsName = siteNode.getRepository().getDnsName();
  1996. */
  1997. //assetUrl = dnsName + "/" + CmsPropertyHandler.getDigitalAssetBaseUrl() + "/" + thumbnailFileName;
  1998. assetUrl = urlComposer.composeDigitalAssetUrl(dnsName, folderName, thumbnailFileName, deliveryContext);
  1999. }
  2000. else
  2001. {
  2002. assetUrl = getLanguageIndependentAssetThumbnailUrl(contentId, languageId, siteNodeId, db, assetKey, width, height, deliveryContext, infoGluePrincipal);
  2003. }
  2004. }
  2005. CacheController.cacheObject(cacheName, assetCacheKey, assetUrl);
  2006. return assetUrl;
  2007. }
  2008. /*
  2009. * getAssetFileSize. Prelimenary, we should rather supply a assetvo to the template.
  2010. */
  2011. public Integer getAssetFileSize(Database db, Integer contentId, Integer languageId, Integer siteNodeId, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception
  2012. {
  2013. return getAssetFileSize(db, contentId, languageId, null, siteNodeId, useLanguageFallback, deliveryContext, infoGluePrincipal);
  2014. }
  2015. public Integer getAssetFileSize(Database db, Integer contentId, Integer languageId, String assetKey, Integer siteNodeId, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception
  2016. {
  2017. Integer fileSize = null;
  2018. SmallestContentVersionVO contentVersion = getSmallestContentVersionVO(siteNodeId, contentId, languageId, db, useLanguageFallback, deliveryContext, infoGluePrincipal);
  2019. if (contentVersion != null)
  2020. {
  2021. //DigitalAsset digitalAsset = (assetKey == null) ? getLatestDigitalAsset(contentVersion) : getDigitalAssetWithKey(contentVersion, assetKey);
  2022. DigitalAssetVO digitalAsset = (assetKey == null) ? DigitalAssetController.getLatestDigitalAssetVO(contentVersion.getId(), db) : DigitalAssetController.getLatestDigitalAssetVO(contentVersion.getId(), assetKey, db);
  2023. if(digitalAsset == null)
  2024. digitalAsset = getLanguageIndependentAssetVO(contentId, languageId, siteNodeId, db, assetKey, deliveryContext, infoGluePrincipal);
  2025. if(digitalAsset != null)
  2026. {
  2027. fileSize = digitalAsset.getAssetFileSize();
  2028. }
  2029. }
  2030. return fileSize;
  2031. }
  2032. /**
  2033. * This method deliveres a String containing the URL to the directory resulting from unpacking of a uploaded zip-digitalAsset.
  2034. * This method is meant to be used for javascript plugins and similar bundles - and the target directory is therefore the infoglueDeliverXXXX/script/extensions
  2035. */
  2036. public String getScriptExtensionUrls(Database db, Integer contentId, Integer languageId, String assetKey, String fileNames, Boolean autoCreateMarkup, Boolean addToHeader, Boolean addToBodyEnd, Boolean addToBundledIncludes, String bundleName, boolean prepend, Integer siteNodeId, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception
  2037. {
  2038. Timer t = new Timer();
  2039. String scriptExtensionUrls = "";
  2040. SmallestContentVersionVO contentVersion = getSmallestContentVersionVO(siteNodeId, contentId, languageId, db, useLanguageFallback, deliveryContext, infoGluePrincipal);
  2041. if (contentVersion != null)
  2042. {
  2043. DigitalAssetVO digitalAsset = null;
  2044. if(assetKey == null)
  2045. digitalAsset = DigitalAssetController.getLatestDigitalAssetVO(contentVersion.getContentVersionId(), db);
  2046. else
  2047. digitalAsset = DigitalAssetController.getLatestDigitalAssetVO(contentVersion.getContentVersionId(), assetKey, db);
  2048. if(digitalAsset != null)
  2049. {
  2050. String fileName = digitalAsset.getAssetFileName();
  2051. int i = 0;
  2052. File masterFile = null;
  2053. String filePath = CmsPropertyHandler.getDigitalAssetPath0();
  2054. while(filePath != null)
  2055. {
  2056. File unzipDirectory = new File(filePath + File.separator + "extensions" + File.separator + fileName.substring(0, fileName.lastIndexOf(".")));
  2057. unzipDirectory.mkdirs();
  2058. if(masterFile == null)
  2059. masterFile = DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpAndUnzipDigitalAsset(digitalAsset, fileName, filePath, unzipDirectory, db);
  2060. else
  2061. DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpAndUnzipDigitalAsset(masterFile, fileName, filePath, unzipDirectory);
  2062. i++;
  2063. filePath = CmsPropertyHandler.getProperty("digitalAssetPath." + i);
  2064. }
  2065. //logger.info("filePath (Should be base url):" + filePath);
  2066. SiteNodeVO siteNodeVO = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, contentId, deliveryContext).getSiteNodeVO(db, siteNodeId);
  2067. String dnsName = CmsPropertyHandler.getWebServerAddress();
  2068. if(siteNodeVO != null)
  2069. {
  2070. RepositoryVO repositoryVO = RepositoryController.getController().getRepositoryVOWithId(siteNodeVO.getRepositoryId(), db);
  2071. if(repositoryVO.getDnsName() != null && !repositoryVO.getDnsName().equals(""))
  2072. dnsName = repositoryVO.getDnsName();
  2073. }
  2074. String archiveBaseUrl = urlComposer.composeDigitalAssetUrl(dnsName, "extensions" + File.separator + fileName.substring(0, fileName.lastIndexOf(".")), deliveryContext);
  2075. if(logger.isInfoEnabled())
  2076. logger.info("archiveBaseUrl:" + archiveBaseUrl);
  2077. if(logger.isInfoEnabled())
  2078. logger.info("fileNames:" + fileNames);
  2079. if(fileNames == null || fileNames.equals(""))
  2080. {
  2081. scriptExtensionUrls = archiveBaseUrl;
  2082. }
  2083. else
  2084. {
  2085. String[] fileNamesArray = fileNames.split(",");
  2086. for(int j=0; j<fileNamesArray.length; j++)
  2087. {
  2088. String scriptExtensionFileUrl = archiveBaseUrl + "/" + fileNamesArray[j].trim();
  2089. if(autoCreateMarkup || addToHeader)
  2090. {
  2091. if(scriptExtensionFileUrl.toLowerCase().endsWith(".css"))
  2092. scriptExtensionFileUrl = "<link href=\"" + scriptExtensionFileUrl + "\" rel=\"stylesheet\" type=\"text/css\" />";
  2093. else
  2094. scriptExtensionFileUrl = "<script type=\"text/javascript\" src=\"" + scriptExtensionFileUrl + "\"></script>";
  2095. }
  2096. if(!addToHeader && !addToBodyEnd && !addToBundledIncludes)
  2097. {
  2098. scriptExtensionUrls = scriptExtensionUrls + scriptExtensionFileUrl + "";
  2099. }
  2100. else
  2101. {
  2102. if(addToBundledIncludes)
  2103. {
  2104. ////// TODO - clean all bundles and extensions when assets are updated or similar.. figure out how.
  2105. String extensionSuffix = "extensions" + File.separator + fileName.substring(0, fileName.lastIndexOf(".")) + File.separator + fileNamesArray[j];
  2106. if(logger.isInfoEnabled())
  2107. logger.info("extensionSuffix:" + extensionSuffix);
  2108. if(extensionSuffix.toLowerCase().endsWith(".css"))
  2109. deliveryContext.addCSSExtensionBundleFile(bundleName, extensionSuffix);
  2110. else
  2111. {
  2112. if(addToBodyEnd)
  2113. deliveryContext.addScriptExtensionBodyBundleFile(bundleName, extensionSuffix);
  2114. else if(addToHeader)
  2115. deliveryContext.addScriptExtensionHeadBundleFile(bundleName, extensionSuffix);
  2116. }
  2117. }
  2118. else if(addToHeader)
  2119. deliveryContext.addHtmlHeadItem(scriptExtensionFileUrl, prepend);
  2120. else if(addToBodyEnd)
  2121. deliveryContext.addHtmlBodyEndItem(scriptExtensionFileUrl, prepend);
  2122. }
  2123. }
  2124. }
  2125. }
  2126. }
  2127. if(logger.isInfoEnabled())
  2128. t.printElapsedTime("Getting scriptExtensionUrls took");
  2129. return scriptExtensionUrls;
  2130. }
  2131. /**
  2132. * This method deliveres a String with the URL to the base path of the directory resulting from
  2133. * an unpacking of a uploaded zip-digitalAsset.
  2134. */
  2135. public String getArchiveBaseUrl(Database db, Integer contentId, Integer languageId, String assetKey, Integer siteNodeId, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception
  2136. {
  2137. String archiveBaseUrl = null;
  2138. SmallestContentVersionVO contentVersion = getSmallestContentVersionVO(siteNodeId, contentId, languageId, db, useLanguageFallback, deliveryContext, infoGluePrincipal);
  2139. if (contentVersion != null)
  2140. {
  2141. DigitalAssetVO digitalAsset = DigitalAssetController.getLatestDigitalAssetVO(contentVersion.getContentVersionId(), assetKey, db);
  2142. //DigitalAsset digitalAsset = getDigitalAssetWithKey(contentVersion, assetKey);
  2143. if(digitalAsset != null)
  2144. {
  2145. String fileName = digitalAsset.getAssetFileName();
  2146. int i = 0;
  2147. File masterFile = null;
  2148. String filePath = CmsPropertyHandler.getDigitalAssetPath0();
  2149. String folderName = "" + (digitalAsset.getDigitalAssetId().intValue() / 1000);
  2150. logger.info("folderName:" + folderName);
  2151. while(filePath != null)
  2152. {
  2153. File unzipDirectory = new File(filePath + File.separator + fileName.substring(0, fileName.lastIndexOf(".")));
  2154. unzipDirectory.mkdirs();
  2155. if(masterFile == null)
  2156. masterFile = DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpAndUnzipDigitalAsset(digitalAsset, fileName, filePath, unzipDirectory, db);
  2157. else
  2158. DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpAndUnzipDigitalAsset(masterFile, fileName, filePath, unzipDirectory);
  2159. i++;
  2160. filePath = CmsPropertyHandler.getProperty("digitalAssetPath." + i);
  2161. if(filePath != null)
  2162. filePath += File.separator + folderName;
  2163. }
  2164. //String filePath = CmsPropertyHandler.getDigitalAssetPath();
  2165. //File unzipDirectory = new File(filePath + File.separator + fileName.substring(0, fileName.lastIndexOf(".")));
  2166. //unzipDirectory.mkdirs();
  2167. //DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpAndUnzipDigitalAsset(digitalAsset, fileName, filePath, unzipDirectory);
  2168. SiteNodeVO siteNodeVO = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, contentId, deliveryContext).getSiteNodeVO(db, siteNodeId);
  2169. String dnsName = CmsPropertyHandler.getWebServerAddress();
  2170. if(siteNodeVO != null)
  2171. {
  2172. RepositoryVO repositoryVO = RepositoryController.getController().getRepositoryVOWithId(siteNodeVO.getRepositoryId(), db);
  2173. if(repositoryVO.getDnsName() != null && !repositoryVO.getDnsName().equals(""))
  2174. dnsName = repositoryVO.getDnsName();
  2175. }
  2176. /*
  2177. SiteNode siteNode = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, contentId).getSiteNode(db, siteNodeId);
  2178. String dnsName = CmsPropertyHandler.getWebServerAddress();
  2179. if(siteNode != null && siteNode.getRepository().getDnsName() != null && !siteNode.getRepository().getDnsName().equals(""))
  2180. dnsName = siteNode.getRepository().getDnsName();
  2181. */
  2182. //archiveBaseUrl = dnsName + "/" + CmsPropertyHandler.getDigitalAssetBaseUrl() + "/" + fileName.substring(0, fileName.lastIndexOf("."));
  2183. archiveBaseUrl = urlComposer.composeDigitalAssetUrl(dnsName, folderName, fileName.substring(0, fileName.lastIndexOf(".")), deliveryContext);
  2184. }
  2185. }
  2186. return archiveBaseUrl;
  2187. }
  2188. /**
  2189. * This method deliveres a String with the URL to the base path of the directory resulting from
  2190. * an unpacking of a uploaded zip-digitalAsset.
  2191. */
  2192. public String getArchiveBaseUrl(Database db, Integer digitalAssetId, Integer siteNodeId, DeliveryContext deliveryContext) throws SystemException, Exception
  2193. {
  2194. String archiveBaseUrl = null;
  2195. DigitalAssetVO digitalAsset = DigitalAssetController.getLatestDigitalAssetVO(digitalAssetId, db);
  2196. if(digitalAsset != null)
  2197. {
  2198. String fileName = digitalAsset.getAssetFileName();
  2199. int i = 0;
  2200. File masterFile = null;
  2201. String filePath = CmsPropertyHandler.getDigitalAssetPath0();
  2202. while(filePath != null)
  2203. {
  2204. File unzipDirectory = new File(filePath + File.separator + fileName.substring(0, fileName.lastIndexOf(".")));
  2205. unzipDirectory.mkdirs();
  2206. if(masterFile == null)
  2207. masterFile = DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpAndUnzipDigitalAsset(digitalAsset, fileName, filePath, unzipDirectory, db);
  2208. else
  2209. DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpAndUnzipDigitalAsset(masterFile, fileName, filePath, unzipDirectory);
  2210. i++;
  2211. filePath = CmsPropertyHandler.getProperty("digitalAssetPath." + i);
  2212. }
  2213. SiteNodeVO siteNodeVO = NodeDeliveryController.getNodeDeliveryController(null, deliveryContext.getLanguageId(), null, deliveryContext).getSiteNodeVO(db, siteNodeId);
  2214. String dnsName = CmsPropertyHandler.getWebServerAddress();
  2215. if(siteNodeVO != null)
  2216. {
  2217. RepositoryVO repositoryVO = RepositoryController.getController().getRepositoryVOWithId(siteNodeVO.getRepositoryId(), db);
  2218. if(repositoryVO.getDnsName() != null && !repositoryVO.getDnsName().equals(""))
  2219. dnsName = repositoryVO.getDnsName();
  2220. }
  2221. /*
  2222. SiteNode siteNode = NodeDeliveryController.getNodeDeliveryController(null, deliveryContext.getLanguageId(), null, deliveryContext).getSiteNode(db, siteNodeId);
  2223. String dnsName = CmsPropertyHandler.getWebServerAddress();
  2224. if(siteNode != null && siteNode.getRepository().getDnsName() != null && !siteNode.getRepository().getDnsName().equals(""))
  2225. dnsName = siteNode.getRepository().getDnsName();
  2226. */
  2227. archiveBaseUrl = urlComposer.composeDigitalAssetUrl(dnsName, null, fileName.substring(0, fileName.lastIndexOf(".")), deliveryContext);
  2228. }
  2229. return archiveBaseUrl;
  2230. }
  2231. public Vector getArchiveEntries(Database db, Integer contentId, Integer languageId, String assetKey, Integer siteNodeId, boolean useLanguageFallback, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception
  2232. {
  2233. Vector entries = null;
  2234. SmallestContentVersionVO contentVersion = getSmallestContentVersionVO(siteNodeId, contentId, languageId, db, useLanguageFallback, deliveryContext, infoGluePrincipal);
  2235. if (contentVersion != null)
  2236. {
  2237. DigitalAssetVO digitalAsset = DigitalAssetController.getLatestDigitalAssetVO(contentVersion.getContentVersionId(), assetKey, db);
  2238. //DigitalAsset digitalAsset = getDigitalAssetWithKey(contentVersion, assetKey);
  2239. if(digitalAsset != null)
  2240. {
  2241. String fileName = digitalAsset.getAssetFileName();
  2242. int i = 0;
  2243. File masterFile = null;
  2244. String filePath = CmsPropertyHandler.getDigitalAssetPath0();
  2245. while(filePath != null)
  2246. {
  2247. File unzipDirectory = new File(filePath + File.separator + fileName.substring(0, fileName.lastIndexOf(".")));
  2248. unzipDirectory.mkdirs();
  2249. if(masterFile == null)
  2250. {
  2251. entries = DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpAndGetZipEntries(digitalAsset, fileName, filePath, unzipDirectory, db);
  2252. masterFile = new File(filePath + File.separator + fileName);
  2253. }
  2254. else
  2255. {
  2256. entries = DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpAndGetZipEntries(masterFile, fileName, filePath, unzipDirectory);
  2257. }
  2258. i++;
  2259. filePath = CmsPropertyHandler.getProperty("digitalAssetPath." + i);
  2260. }
  2261. //String filePath = CmsPropertyHandler.getDigitalAssetPath();
  2262. //File unzipDirectory = new File(filePath + File.separator + fileName.substring(0, fileName.lastIndexOf(".")));
  2263. //unzipDirectory.mkdirs();
  2264. //entries = DigitalAssetDeliveryController.getDigitalAssetDeliveryController().dumpAndGetZipEntries(digitalAsset, fileName, filePath, unzipDirectory);
  2265. }
  2266. }
  2267. return entries;
  2268. }
  2269. /**
  2270. * Returns the digital asset for a contentversion that has a certain key.
  2271. */
  2272. /*
  2273. private DigitalAsset getDigitalAssetWithKey(ContentVersion contentVersion, String assetKey)
  2274. {
  2275. Collection digitalAssets = contentVersion.getDigitalAssets();
  2276. Iterator iterator = digitalAssets.iterator();
  2277. while(iterator.hasNext())
  2278. {
  2279. DigitalAsset currentDigitalAsset = (DigitalAsset)iterator.next();
  2280. if(currentDigitalAsset != null && currentDigitalAsset.getAssetKey().equalsIgnoreCase(assetKey))
  2281. {
  2282. return currentDigitalAsset;
  2283. }
  2284. }
  2285. return null;
  2286. }
  2287. */
  2288. /**
  2289. * Returns the latest digital asset for a contentversion.
  2290. */
  2291. /*
  2292. private DigitalAsset getLatestDigitalAsset(ContentVersion contentVersion)
  2293. {
  2294. Collection digitalAssets = contentVersion.getDigitalAssets();
  2295. Iterator iterator = digitalAssets.iterator();
  2296. DigitalAsset digitalAsset = null;
  2297. while(iterator.hasNext())
  2298. {
  2299. DigitalAsset currentDigitalAsset = (DigitalAsset)iterator.next();
  2300. if(digitalAsset == null || currentDigitalAsset.getDigitalAssetId().intValue() > digitalAsset.getDigitalAssetId().intValue())
  2301. digitalAsset = currentDigitalAsset;
  2302. }
  2303. return digitalAsset;
  2304. }
  2305. */
  2306. /**
  2307. * This method fetches a value from the xml that is the contentVersions Value. If the
  2308. * contentVersioVO is null the contentVersion has not been created yet and no values are present.
  2309. */
  2310. public String getAttributeValue(Database db, ContentVersionVO contentVersionVO, String key, boolean escapeHTML)
  2311. {
  2312. String value = "";
  2313. if(contentVersionVO != null)
  2314. {
  2315. try
  2316. {
  2317. String xml = contentVersionVO.getVersionValue();
  2318. int startTagIndex = xml.indexOf("<" + key + ">");
  2319. int endTagIndex = xml.indexOf("]]></" + key + ">");
  2320. if(startTagIndex > 0 && startTagIndex < xml.length() && endTagIndex > startTagIndex && endTagIndex < xml.length())
  2321. value = xml.substring(startTagIndex + key.length() + 11, endTagIndex);
  2322. if(escapeHTML)
  2323. value = formatter.escapeHTML(value);
  2324. }
  2325. catch(Exception e)
  2326. {
  2327. logger.error("An error occurred so we should not return the attribute value:" + e, e);
  2328. }
  2329. }
  2330. return value;
  2331. }
  2332. /**
  2333. * This method fetches a value from the xml that is the contentVersions Value. If the
  2334. * contentVersioVO is null the contentVersion has not been created yet and no values are present.
  2335. */
  2336. public String getAttributeValue(String versionValue, String key, boolean escapeHTML)
  2337. {
  2338. String value = "";
  2339. try
  2340. {
  2341. String xml = versionValue;
  2342. int startTagIndex = xml.indexOf("<" + key + ">");
  2343. int endTagIndex = xml.indexOf("]]></" + key + ">");
  2344. if(startTagIndex > 0 && startTagIndex < xml.length() && endTagIndex > startTagIndex && endTagIndex < xml.length())
  2345. value = xml.substring(startTagIndex + key.length() + 11, endTagIndex);
  2346. if(escapeHTML)
  2347. value = formatter.escapeHTML(value);
  2348. }
  2349. catch(Exception e)
  2350. {
  2351. logger.error("An error occurred so we should not return the attribute value:" + e, e);
  2352. }
  2353. return value;
  2354. }
  2355. /**
  2356. * This method returns a sorted list of childContents to a content ordered by the given attribute in the direction given.
  2357. */
  2358. public List getChildContents(Database db, InfoGluePrincipal infoGluePrincipal, Integer contentId, Integer languageId, boolean useLanguageFallback, boolean includeFolders, DeliveryContext deliveryContext) throws SystemException, Exception
  2359. {
  2360. List childContents = new ArrayList();
  2361. getChildContents(infoGluePrincipal, childContents, contentId, languageId, useLanguageFallback, 0, false, includeFolders, 1, db, deliveryContext);
  2362. return childContents;
  2363. }
  2364. /**
  2365. * This method returns a sorted list of childContents to a content ordered by the given attribute in the direction given.
  2366. */
  2367. 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
  2368. {
  2369. String sortedChildContentsKey = "" + infoGluePrincipal.getName() + "_" + languageId + "_" + contentId + "_" + siteNodeId + "_" + searchRecursive + "_" + maximumNumberOfLevels + "_" + sortAttribute + "_" + sortOrder + "_" + useLanguageFallback + "_" + includeFolders;
  2370. logger.info("sortedChildContentsKey:" + sortedChildContentsKey);
  2371. String cacheName = "sortedChildContentsCache";
  2372. List cachedSortedContentVOList = (List)CacheController.getCachedObject(cacheName, sortedChildContentsKey);
  2373. if(cachedSortedContentVOList != null)
  2374. {
  2375. logger.info("There was an cached content cachedSortedContentVOList:" + cachedSortedContentVOList.size());
  2376. return cachedSortedContentVOList;
  2377. }
  2378. List sortedContentVOList = new ArrayList();
  2379. List unsortedChildren = getChildContents(infoGluePrincipal, languageId, useLanguageFallback, contentId, siteNodeId, searchRecursive, maximumNumberOfLevels, db, includeFolders, deliveryContext);
  2380. List sortedContents = sortContents(db, unsortedChildren, languageId, siteNodeId, sortAttribute, sortOrder, useLanguageFallback, includeFolders, deliveryContext, infoGluePrincipal);
  2381. Iterator boundContentsIterator = sortedContents.iterator();
  2382. while(boundContentsIterator.hasNext())
  2383. {
  2384. Content content = (Content)boundContentsIterator.next();
  2385. sortedContentVOList.add(content.getValueObject());
  2386. }
  2387. CacheController.cacheObject(cacheName, sortedChildContentsKey, sortedContentVOList);
  2388. return sortedContentVOList;
  2389. }
  2390. /**
  2391. * This method returns the contentTypeDefinitionVO of the content sent in.
  2392. */
  2393. public ContentTypeDefinitionVO getContentTypeDefinitionVO(Database db, Integer contentId) throws SystemException, Exception
  2394. {
  2395. //Timer t = new Timer();
  2396. ContentTypeDefinitionVO contentTypeDefinitionVO = null;
  2397. if(contentId != null && contentId.intValue() > 0)
  2398. {
  2399. ContentVO contentVO = getContentVO(db, contentId, null);
  2400. contentTypeDefinitionVO = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithId(contentVO.getContentTypeDefinitionId(), db);
  2401. //SmallContentImpl smallContent = (SmallContentImpl)getObjectWithId(SmallContentImpl.class, contentId, db);
  2402. //contentTypeDefinitionVO = (ContentTypeDefinitionVO) getVOWithId(ContentTypeDefinitionImpl.class, smallContent.getContentTypeDefinitionId(), db);
  2403. //RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getContentTypeDefinitionVO 1", t.getElapsedTimeNanos() / 1000);
  2404. /*
  2405. Content content = (Content)getObjectWithId(ContentImpl.class, contentId, db);
  2406. contentTypeDefinitionVO = content.getContentTypeDefinition().getValueObject();
  2407. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getContentTypeDefinitionVO 2", t.getElapsedTimeNanos() / 1000);
  2408. */
  2409. }
  2410. return contentTypeDefinitionVO;
  2411. }
  2412. /**
  2413. * This method returns a list of children to the content given. It is mostly used to get all
  2414. * children a folder has.
  2415. */
  2416. 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
  2417. {
  2418. List contents = new ArrayList();
  2419. getChildContents(infoGluePrincipal, contents, contentId, languageId, useLanguageFallback, 0, searchRecursive, maximumNumberOfLevels.intValue(), db, includeFolders, deliveryContext);
  2420. return contents;
  2421. }
  2422. /**
  2423. * This method recurses into the dept of the content-children and fills the list of contents.
  2424. */
  2425. 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
  2426. {
  2427. /*
  2428. OQLQuery oql = db.getOQLQuery("SELECT contentVersion FROM org.infoglue.cms.entities.content.impl.simple.ContentVersionImpl contentVersion WHERE contentVersion.stateId = $1 AND contentVersion.isActive = $2 AND contentVersion.owningContent.parentContent.contentId = $3");
  2429. oql.bind(getOperatingMode());
  2430. oql.bind(new Boolean(true));
  2431. oql.bind(contentId);
  2432. QueryResults results = oql.execute(Database.ReadOnly);
  2433. while (results.hasMore())
  2434. {
  2435. ContentVersion contentVersion = (ContentVersion)results.next();
  2436. Content content = contentVersion.getOwningContent();
  2437. if(searchRecursive && currentLevel < maximumNumberOfLevels)
  2438. getChildContents(contents, content.getContentId(), currentLevel + 1, searchRecursive, maximumNumberOfLevels, db);
  2439. if(isValidContent(content, db))
  2440. {
  2441. if(!contents.contains(content))
  2442. contents.add(content);
  2443. }
  2444. }
  2445. */
  2446. if(searchRecursive)
  2447. deliveryContext.addUsedContent("selectiveCacheUpdateNonApplicable");
  2448. OQLQuery oql = db.getOQLQuery("SELECT content FROM org.infoglue.cms.entities.content.impl.simple.SmallContentImpl content WHERE content.parentContentId = $1 ORDER BY content.contentId");
  2449. //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");
  2450. oql.bind(contentId);
  2451. QueryResults results = oql.execute(Database.ReadOnly);
  2452. while (results.hasMore())
  2453. {
  2454. Content content = (Content)results.next();
  2455. if(searchRecursive && currentLevel < maximumNumberOfLevels)
  2456. getChildContents(infoGluePrincipal, contents, content.getContentId(), languageId, useLanguageFallback, currentLevel + 1, searchRecursive, maximumNumberOfLevels, db, includeFolders, deliveryContext);
  2457. if(isValidContent(infoGluePrincipal, content.getValueObject(), languageId, useLanguageFallback, includeFolders, db, deliveryContext))
  2458. {
  2459. contents.add(content);
  2460. }
  2461. }
  2462. results.close();
  2463. oql.close();
  2464. //t.printElapsedTime("getChildContents took");
  2465. }
  2466. /**
  2467. * This method recurses into the dept of the content-children and fills the list of contents.
  2468. */
  2469. 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
  2470. {
  2471. if(searchRecursive)
  2472. deliveryContext.addUsedContent("selectiveCacheUpdateNonApplicable");
  2473. 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");
  2474. oql.bind(contentId);
  2475. QueryResults results = oql.execute(Database.ReadOnly);
  2476. while (results.hasMore())
  2477. {
  2478. Content content = (Content)results.next();
  2479. if(searchRecursive && currentLevel < maximumNumberOfLevels)
  2480. getChildContents(infoGluePrincipal, contents, content.getContentId(), languageId, useLanguageFallback, currentLevel + 1, searchRecursive, includeFolders, maximumNumberOfLevels, db, deliveryContext);
  2481. if(content.getIsBranch().booleanValue() && includeFolders && isValidContent(infoGluePrincipal, content.getValueObject(), languageId, useLanguageFallback, includeFolders, db, deliveryContext))
  2482. {
  2483. contents.add(content);
  2484. }
  2485. else if(isValidContent(infoGluePrincipal, content.getValueObject(), languageId, useLanguageFallback, includeFolders, db, deliveryContext))
  2486. {
  2487. contents.add(content);
  2488. }
  2489. }
  2490. results.close();
  2491. oql.close();
  2492. }
  2493. /**
  2494. * This method validates that right now is between publishdate and expiredate.
  2495. */
  2496. private boolean isValidOnDates(Date publishDate, Date expireDate, boolean validateOnDates)
  2497. {
  2498. if(!validateOnDates)
  2499. return true;
  2500. return isValidOnDates(publishDate, expireDate);
  2501. }
  2502. /**
  2503. * This method validates that right now is between publishdate and expiredate.
  2504. */
  2505. private boolean isValidOnDates(Date publishDate, Date expireDate)
  2506. {
  2507. boolean isValid = true;
  2508. Date now = new Date();
  2509. if(publishDate.after(now) || expireDate.before(now))
  2510. isValid = false;
  2511. return isValid;
  2512. }
  2513. /**
  2514. * Returns if a content is between dates and has a content version suitable for this delivery mode.
  2515. * @throws Exception
  2516. */
  2517. /*
  2518. public boolean isValidContent(Integer contentId, InfoGluePrincipal infoGluePrincipal, Database db) throws Exception
  2519. {
  2520. boolean isValidContent = false;
  2521. Content content = (Content)getObjectWithId(ContentImpl.class, contentId, db);
  2522. isValidContent = isValidContent(content, db);
  2523. return isValidContent;
  2524. }
  2525. */
  2526. /**
  2527. * Returns if a content is between dates and has a content version suitable for this delivery mode.
  2528. * @throws Exception
  2529. */
  2530. public boolean isValidContent(Database db, Integer contentId, Integer languageId, boolean useLanguageFallback, boolean includeFolders, InfoGluePrincipal infoGluePrincipal, DeliveryContext deliveryContext) throws Exception
  2531. {
  2532. boolean isValidContent = false;
  2533. Timer t = new Timer();
  2534. //Content content = (Content)getObjectWithId(ContentImpl.class, contentId, db);
  2535. ContentVO content = getContentVO(db, contentId, deliveryContext);
  2536. isValidContent = isValidContent(infoGluePrincipal, content, languageId, useLanguageFallback, includeFolders, db, deliveryContext, true, true);
  2537. return isValidContent;
  2538. }
  2539. /**
  2540. * Returns if a content is between dates and has a content version suitable for this delivery mode.
  2541. * @throws Exception
  2542. */
  2543. public boolean isValidContent(Database db, Content content, Integer languageId, boolean useLanguageFallback, boolean includeFolders, InfoGluePrincipal infoGluePrincipal, DeliveryContext deliveryContext, boolean checkIfVersionExists, boolean checkAuthorization) throws Exception
  2544. {
  2545. return isValidContent(db, content.getValueObject(), languageId, useLanguageFallback, includeFolders, infoGluePrincipal, deliveryContext, checkIfVersionExists, checkAuthorization);
  2546. }
  2547. /**
  2548. * Returns if a content is between dates and has a content version suitable for this delivery mode.
  2549. * @throws Exception
  2550. */
  2551. public boolean isValidContent(Database db, ContentVO content, Integer languageId, boolean useLanguageFallback, boolean includeFolders, InfoGluePrincipal infoGluePrincipal, DeliveryContext deliveryContext, boolean checkIfVersionExists, boolean checkAuthorization) throws Exception
  2552. {
  2553. boolean isValidContent = false;
  2554. Timer t = new Timer();
  2555. //Content content = (Content)getObjectWithId(ContentImpl.class, contentId, db);
  2556. //RequestAnalyser.getRequestAnalyser().registerComponentStatistics("isValidContent2 content", t.getElapsedTimeNanos() / 1000);
  2557. isValidContent = isValidContent(infoGluePrincipal, content, languageId, useLanguageFallback, includeFolders, db, deliveryContext, checkIfVersionExists, checkAuthorization);
  2558. //RequestAnalyser.getRequestAnalyser().registerComponentStatistics("isValidContent2", t.getElapsedTimeNanos() / 1000);
  2559. /*
  2560. Timer t = new Timer();
  2561. Content content = (Content)getObjectWithId(ContentImpl.class, contentId, db);
  2562. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("isValidContent2 content", t.getElapsedTimeNanos() / 1000);
  2563. isValidContent = isValidContent(infoGluePrincipal, content, languageId, useLanguageFallback, includeFolders, db, deliveryContext);
  2564. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("isValidContent2", t.getElapsedTimeNanos() / 1000);
  2565. */
  2566. return isValidContent;
  2567. }
  2568. /**
  2569. * Returns if a content is between dates and has a content version suitable for this delivery mode.
  2570. * @throws Exception
  2571. */
  2572. public boolean isValidContent(InfoGluePrincipal infoGluePrincipal, ContentVO content, Integer languageId, boolean useLanguageFallBack, boolean includeFolders, Database db, DeliveryContext deliveryContext) throws Exception
  2573. {
  2574. Timer t = new Timer();
  2575. boolean isValidContent = false;
  2576. if(infoGluePrincipal == null)
  2577. throw new SystemException("There was no anonymous user found in the system. There must be - add the user anonymous/anonymous and try again.");
  2578. if(metaInfoContentTypeId == null)
  2579. {
  2580. ContentTypeDefinitionVO ctdVO = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithName("Meta info", db);
  2581. if(ctdVO != null)
  2582. metaInfoContentTypeId = ctdVO.getId();
  2583. }
  2584. if(HTMLTemplateContentTypeId == null)
  2585. {
  2586. ContentTypeDefinitionVO ctdVO = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithName("HTMLTemplate", db);
  2587. if(ctdVO != null)
  2588. HTMLTemplateContentTypeId = ctdVO.getId();
  2589. }
  2590. if(PagePartTemplateContentTypeId == null)
  2591. {
  2592. ContentTypeDefinitionVO ctdVO = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithName("PagePartTemplate", db);
  2593. if(ctdVO != null)
  2594. PagePartTemplateContentTypeId = ctdVO.getId();
  2595. }
  2596. if(PageTemplateContentTypeId == null)
  2597. {
  2598. ContentTypeDefinitionVO ctdVO = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithName("PageTemplate", db);
  2599. if(ctdVO != null)
  2600. PageTemplateContentTypeId = ctdVO.getId();
  2601. }
  2602. if(content.getContentTypeDefinitionId() != null && (content.getContentTypeDefinitionId().equals(metaInfoContentTypeId) ||
  2603. content.getContentTypeDefinitionId().equals(HTMLTemplateContentTypeId) ||
  2604. content.getContentTypeDefinitionId().equals(PagePartTemplateContentTypeId) ||
  2605. content.getContentTypeDefinitionId().equals(PageTemplateContentTypeId)))
  2606. {
  2607. return true;
  2608. }
  2609. /*
  2610. if(content.getContentTypeDefinitionId() != null)
  2611. {
  2612. ContentTypeDefinitionVO ctdVO = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithId(content.getContentTypeDefinitionId(), db);
  2613. if(ctdVO.getName().equalsIgnoreCase("Meta info") ||
  2614. ctdVO.getName().equalsIgnoreCase("HTMLTemplate") ||
  2615. ctdVO.getName().equalsIgnoreCase("PagePartTemplate") ||
  2616. ctdVO.getName().equalsIgnoreCase("PageTemplate"))
  2617. return true;
  2618. }
  2619. */
  2620. if(content.getIsDeleted().booleanValue())
  2621. return false;
  2622. boolean validateOnDates = true;
  2623. String operatingMode = CmsPropertyHandler.getOperatingMode();
  2624. if(!deliveryContext.getOperatingMode().equals(operatingMode))
  2625. operatingMode = deliveryContext.getOperatingMode();
  2626. if(operatingMode.equals("0"))
  2627. {
  2628. validateOnDates = deliveryContext.getValidateOnDates();
  2629. }
  2630. //RequestAnalyser.getRequestAnalyser().registerComponentStatistics("isValidContentPart1", t.getElapsedTimeNanos() / 1000);
  2631. try
  2632. {
  2633. Integer protectedContentId = getProtectedContentId(db, content);
  2634. deliveryContext.addDebugInformation("content:" + content.getName() + ":" + protectedContentId);
  2635. if(logger.isInfoEnabled())
  2636. logger.info("content:" + content.getName() + ":" + protectedContentId);
  2637. if(protectedContentId != null && !AccessRightController.getController().getIsPrincipalAuthorized(db, infoGluePrincipal, "Content.Read", protectedContentId.toString()))
  2638. {
  2639. deliveryContext.addDebugInformation("No access to Content.READ for " + infoGluePrincipal);
  2640. return false;
  2641. }
  2642. }
  2643. catch (Exception e)
  2644. {
  2645. logger.error("An error occurred trying to validate access to a content. Resetting datalayer and disabling page cache but allowing for now. Reson: " + e.getMessage());
  2646. logger.warn("An error occurred trying to validate access to a content. Resetting datalayer and disabling page cache but allowing for now. Reson: " + e.getMessage(), e);
  2647. }
  2648. //RequestAnalyser.getRequestAnalyser().registerComponentStatistics("isValidContentPart protectedContentId", t.getElapsedTimeNanos() / 1000);
  2649. if(includeFolders && content.getIsBranch().booleanValue() && isValidOnDates(content.getPublishDateTime(), content.getExpireDateTime(), validateOnDates))
  2650. {
  2651. isValidContent = true;
  2652. }
  2653. else if(isValidOnDates(content.getPublishDateTime(), content.getExpireDateTime(), validateOnDates))
  2654. {
  2655. //RequestAnalyser.getRequestAnalyser().registerComponentStatistics("isValidContentPart3", t.getElapsedTimeNanos() / 1000000);
  2656. //ContentVersion contentVersion = getContentVersion(content, languageId, getOperatingMode(), deliveryContext, db);
  2657. //TODO
  2658. ContentVersionVO contentVersion = getContentVersionVO(content.getId(), languageId, getOperatingMode(deliveryContext), deliveryContext, db);
  2659. //SmallestContentVersionVO contentVersion = getSmallestContentVersionVO(content.getId(), languageId, getOperatingMode(deliveryContext), deliveryContext, db);
  2660. //RequestAnalyser.getRequestAnalyser().registerComponentStatistics("isValidContentPart4", t.getElapsedTimeNanos() / 1000);
  2661. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getContentVersionVO in isValid(micro)", t.getElapsedTimeNanos() / 1000);
  2662. //RequestAnalyser.getRequestAnalyser().registerComponentStatistics("isValidContentPart4.1", t.getElapsedTimeNanos() / 1000000);
  2663. Integer repositoryId = content.getRepositoryId();
  2664. if(contentVersion == null && useLanguageFallBack && repositoryId != null)
  2665. {
  2666. RequestAnalyser.getRequestAnalyser().registerComponentStatistics("Before LanguageFallBack", t.getElapsedTimeNanos() / 1000);
  2667. LanguageVO masterLanguage = LanguageDeliveryController.getLanguageDeliveryController().getMasterLanguageForRepository(repositoryId, db);
  2668. //TODO
  2669. if(masterLanguage != null && !masterLanguage.getId().equals(languageId))
  2670. {
  2671. contentVersion = getContentVersionVO(content.getId(), masterLanguage.getId(), getOperatingMode(deliveryContext), deliveryContext, db);
  2672. //contentVersion = getSmallestContentVersionVO(content.getId(), masterLanguage.getId(), getOperatingMode(deliveryContext), deliveryContext, db);
  2673. }
  2674. }
  2675. //RequestAnalyser.getRequestAnalyser().registerComponentStatistics("isValidContentPart5", t.getElapsedTimeNanos() / 1000);
  2676. if(contentVersion != null)
  2677. isValidContent = true;
  2678. }
  2679. if(isValidContent && !content.getExpireDateTime().before(new Date()))
  2680. {
  2681. Date expireDateTimeCandidate = content.getExpireDateTime();
  2682. if(CacheController.expireDateTime == null || expireDateTimeCandidate.before(CacheController.expireDateTime))
  2683. {
  2684. CacheController.expireDateTime = expireDateTimeCandidate;
  2685. }
  2686. }
  2687. else if(content.getPublishDateTime().after(new Date())) //If it's a publish date to come we consider it
  2688. {
  2689. Date publishDateTimeCandidate = content.getPublishDateTime();
  2690. if(CacheController.publishDateTime == null || publishDateTimeCandidate.after(CacheController.publishDateTime))
  2691. {
  2692. CacheController.publishDateTime = publishDateTimeCandidate;
  2693. }
  2694. }
  2695. //RequestAnalyser.getRequestAnalyser().registerComponentStatistics("isValidContentPart end", t.getElapsedTimeNanos() / 1000);
  2696. return isValidContent;
  2697. }
  2698. private static Integer metaInfoContentTypeId = null;
  2699. private static Integer HTMLTemplateContentTypeId = null;
  2700. private static Integer PagePartTemplateContentTypeId = null;
  2701. private static Integer PageTemplateContentTypeId = null;
  2702. public boolean isValidContent(InfoGluePrincipal infoGluePrincipal, ContentVO content, Integer languageId, boolean useLanguageFallBack, boolean includeFolders, Database db, DeliveryContext deliveryContext, boolean checkVersionExists, boolean checkAccessRights) throws Exception
  2703. {
  2704. //Timer t = new Timer();
  2705. boolean isValidContent = false;
  2706. if(infoGluePrincipal == null)
  2707. throw new SystemException("There was no anonymous user found in the system. There must be - add the user anonymous/anonymous and try again.");
  2708. if(metaInfoContentTypeId == null)
  2709. {
  2710. ContentTypeDefinitionVO ctdVO = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithName("Meta info", db);
  2711. if(ctdVO != null)
  2712. metaInfoContentTypeId = ctdVO.getId();
  2713. }
  2714. if(HTMLTemplateContentTypeId == null)
  2715. {
  2716. ContentTypeDefinitionVO ctdVO = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithName("HTMLTemplate", db);
  2717. if(ctdVO != null)
  2718. HTMLTemplateContentTypeId = ctdVO.getId();
  2719. }
  2720. if(PagePartTemplateContentTypeId == null)
  2721. {
  2722. ContentTypeDefinitionVO ctdVO = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithName("PagePartTemplate", db);
  2723. if(ctdVO != null)
  2724. PagePartTemplateContentTypeId = ctdVO.getId();
  2725. }
  2726. if(PageTemplateContentTypeId == null)
  2727. {
  2728. ContentTypeDefinitionVO ctdVO = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithName("PageTemplate", db);
  2729. if(ctdVO != null)
  2730. PageTemplateContentTypeId = ctdVO.getId();
  2731. }
  2732. if(content.getContentTypeDefinitionId() != null && (content.getContentTypeDefinitionId().equals(metaInfoContentTypeId) ||
  2733. content.getContentTypeDefinitionId().equals(HTMLTemplateContentTypeId) ||
  2734. content.getContentTypeDefinitionId().equals(PagePartTemplateContentTypeId) ||
  2735. content.getContentTypeDefinitionId().equals(PageTemplateContentTypeId)))
  2736. {
  2737. return true;
  2738. }
  2739. if(content.getIsDeleted().booleanValue())
  2740. return false;
  2741. boolean validateOnDates = true;
  2742. String operatingMode = CmsPropertyHandler.getOperatingMode();
  2743. if(!deliveryContext.getOperatingMode().equals(operatingMode))
  2744. operatingMode = deliveryContext.getOperatingMode();
  2745. if(operatingMode.equals("0"))
  2746. {
  2747. validateOnDates = deliveryContext.getValidateOnDates();
  2748. }
  2749. if(checkAccessRights)
  2750. {
  2751. Integer protectedContentId = getProtectedContentId(db, content);
  2752. if(protectedContentId != null && !AccessRightController.getController().getIsPrincipalAuthorized(db, infoGluePrincipal, "Content.Read", protectedContentId.toString()))
  2753. {
  2754. return false;
  2755. }
  2756. }
  2757. if(includeFolders && content.getIsBranch().booleanValue() && isValidOnDates(content.getPublishDateTime(), content.getExpireDateTime(), validateOnDates))
  2758. {
  2759. isValidContent = true;
  2760. }
  2761. else if(isValidOnDates(content.getPublishDateTime(), content.getExpireDateTime(), validateOnDates))
  2762. {
  2763. if(checkVersionExists)
  2764. {
  2765. //ContentVersion contentVersion = getContentVersion(content, languageId, getOperatingMode(), deliveryContext, db);
  2766. //TODO
  2767. ContentVersionVO contentVersion = getContentVersionVO(content.getId(), languageId, getOperatingMode(deliveryContext), deliveryContext, db);
  2768. //SmallestContentVersionVO contentVersion = getSmallestContentVersionVO(content.getId(), languageId, getOperatingMode(deliveryContext), deliveryContext, db);
  2769. //RequestAnalyser.getRequestAnalyser().registerComponentStatistics("isValidContentPart4.2", t.getElapsedTimeNanos() / 1000);
  2770. Integer repositoryId = content.getRepositoryId();
  2771. if(contentVersion == null && useLanguageFallBack && repositoryId != null)
  2772. {
  2773. LanguageVO masterLanguage = LanguageDeliveryController.getLanguageDeliveryController().getMasterLanguageForRepository(repositoryId, db);
  2774. //TODO
  2775. if(masterLanguage != null && !masterLanguage.getId().equals(languageId))
  2776. {
  2777. //contentVersion = getContentVersion(content, masterLanguage.getId(), getOperatingMode(), deliveryContext, db);
  2778. //contentVersion = getSmallestContentVersionVO(content.getId(), masterLanguage.getId(), getOperatingMode(deliveryContext), deliveryContext, db);
  2779. contentVersion = getContentVersionVO(content.getId(), masterLanguage.getId(), getOperatingMode(deliveryContext), deliveryContext, db);
  2780. }
  2781. }
  2782. if(contentVersion != null)
  2783. isValidContent = true;
  2784. }
  2785. else
  2786. {
  2787. isValidContent = true;
  2788. }
  2789. }
  2790. if(isValidContent && !content.getExpireDateTime().before(new Date()))
  2791. {
  2792. Date expireDateTimeCandidate = content.getExpireDateTime();
  2793. if(CacheController.expireDateTime == null || expireDateTimeCandidate.before(CacheController.expireDateTime))
  2794. {
  2795. CacheController.expireDateTime = expireDateTimeCandidate;
  2796. }
  2797. }
  2798. else if(content.getPublishDateTime().after(new Date())) //If it's a publish date to come we consider it
  2799. {
  2800. Date publishDateTimeCandidate = content.getPublishDateTime();
  2801. if(CacheController.publishDateTime == null || publishDateTimeCandidate.after(CacheController.publishDateTime))
  2802. {
  2803. CacheController.publishDateTime = publishDateTimeCandidate;
  2804. }
  2805. }
  2806. //RequestAnalyser.getRequestAnalyser().registerComponentStatistics("isValidContentPart end", t.getElapsedTimeNanos() / 1000);
  2807. return isValidContent;
  2808. }
  2809. /**
  2810. * This method returns the id of the content that is protected if any. Looks recursive upwards.
  2811. */
  2812. //static long totalLoadTime = 0;
  2813. public Integer getProtectedContentId(Database db, Integer contentId) throws SystemException, Exception
  2814. {
  2815. Integer protectedContentId = null;
  2816. //org.infoglue.deliver.util.Timer t = new org.infoglue.deliver.util.Timer();
  2817. Content content = (Content)getObjectWithId(SmallContentImpl.class, contentId, db);
  2818. //Content content = (Content)getObjectWithId(ContentImpl.class, contentId, db);
  2819. protectedContentId = getProtectedContentId(db, content);
  2820. //totalLoadTime = totalLoadTime + t.getElapsedTimeNanos();
  2821. //System.out.println("totalLoadTime:" + totalLoadTime / 1000000);
  2822. return protectedContentId;
  2823. }
  2824. /**
  2825. * This method returns the id of the content that is protected if any. Looks recursive upwards.
  2826. */
  2827. public Integer getProtectedContentId(Database db, Content content)
  2828. {
  2829. Integer protectedContentId = null;
  2830. try
  2831. {
  2832. logger.info("content:" + content.getId() + ":" + content.getIsProtected());
  2833. if(content != null && content.getIsProtected() != null)
  2834. {
  2835. if(content.getIsProtected().intValue() == ContentVO.NO.intValue())
  2836. protectedContentId = null;
  2837. else if(content.getIsProtected().intValue() == ContentVO.YES.intValue())
  2838. protectedContentId = content.getId();
  2839. else if(content.getIsProtected().intValue() == ContentVO.INHERITED.intValue())
  2840. {
  2841. Content parentContent = null; //= content.getParentContent();
  2842. if(content instanceof MediumContentImpl)
  2843. {
  2844. Integer parentContentId = ((MediumContentImpl)content).getParentContentId();
  2845. if(parentContentId != null)
  2846. parentContent = (MediumContentImpl)getObjectWithId(MediumContentImpl.class, parentContentId, db);
  2847. }
  2848. else if(content instanceof SmallContentImpl)
  2849. {
  2850. Integer parentContentId = ((SmallContentImpl)content).getParentContentId();
  2851. if(parentContentId != null)
  2852. parentContent = (SmallContentImpl)getObjectWithId(SmallContentImpl.class, parentContentId, db);
  2853. }
  2854. else if(content instanceof ContentImpl)
  2855. {
  2856. parentContent = content.getParentContent();
  2857. }
  2858. if(parentContent != null)
  2859. {
  2860. protectedContentId = getProtectedContentId(db, parentContent);
  2861. }
  2862. }
  2863. }
  2864. }
  2865. catch(Exception e)
  2866. {
  2867. logger.warn("An error occurred trying to get if the siteNodeVersion has disabled pageCache:" + e.getMessage(), e);
  2868. }
  2869. return protectedContentId;
  2870. }
  2871. /**
  2872. * This method returns the id of the content that is protected if any. Looks recursive upwards.
  2873. */
  2874. public Integer getProtectedContentId(Database db, ContentVO content)
  2875. {
  2876. Integer protectedContentId = null;
  2877. try
  2878. {
  2879. logger.info("content:" + content.getId() + ":" + content.getIsProtected());
  2880. if(content != null && content.getIsProtected() != null)
  2881. {
  2882. if(content.getIsProtected().intValue() == ContentVO.NO.intValue())
  2883. protectedContentId = null;
  2884. else if(content.getIsProtected().intValue() == ContentVO.YES.intValue())
  2885. protectedContentId = content.getId();
  2886. else if(content.getIsProtected().intValue() == ContentVO.INHERITED.intValue())
  2887. {
  2888. Integer parentContentId = content.getParentContentId();
  2889. if(parentContentId != null)
  2890. {
  2891. //TODO - optimera
  2892. ContentVO parentContentVO = ContentController.getContentController().getSmallContentVOWithId(parentContentId, db, null);
  2893. protectedContentId = getProtectedContentId(db, parentContentVO);
  2894. }
  2895. }
  2896. }
  2897. }
  2898. catch(Exception e)
  2899. {
  2900. logger.warn("An error occurred trying to get if the siteNodeVersion has disabled pageCache:" + e.getMessage(), e);
  2901. }
  2902. return protectedContentId;
  2903. }
  2904. /**
  2905. * This method just sorts the list of qualifyers on sortOrder.
  2906. */
  2907. public List sortContents(Database db, Collection contents, Integer languageId, Integer siteNodeId, String sortAttributeName, String sortOrder, boolean useLanguageFallback, boolean includeFolders, DeliveryContext deliveryContext, InfoGluePrincipal infoGluePrincipal)
  2908. {
  2909. List sortedContents = new ArrayList();
  2910. long attributesTimes = 0;
  2911. try
  2912. {
  2913. Iterator iterator = contents.iterator();
  2914. while(iterator.hasNext())
  2915. {
  2916. Content content = (Content)iterator.next();
  2917. if(includeFolders || content.getIsBranch().booleanValue() == false)
  2918. {
  2919. int index = 0;
  2920. Iterator sortedListIterator = sortedContents.iterator();
  2921. while(sortedListIterator.hasNext())
  2922. {
  2923. Content sortedContent = (Content)sortedListIterator.next();
  2924. //Here we sort on name if the name on a container is wanted
  2925. if(sortAttributeName.equalsIgnoreCase("contentId"))
  2926. {
  2927. Integer id = content.getContentId();
  2928. Integer sortedId = sortedContent.getContentId();
  2929. if(id != null && sortedId != null && sortOrder.equalsIgnoreCase("asc") && id.compareTo(sortedId) < 0)
  2930. {
  2931. break;
  2932. }
  2933. else if(id != null && sortedId != null && sortOrder.equalsIgnoreCase("desc") && id.compareTo(sortedId) > 0)
  2934. {
  2935. break;
  2936. }
  2937. }
  2938. else if(sortAttributeName.equalsIgnoreCase("name"))
  2939. {
  2940. String name = content.getName();
  2941. String sortedName = sortedContent.getName();
  2942. if(name != null && sortedName != null && sortOrder.equalsIgnoreCase("asc") && name.compareTo(sortedName) < 0)
  2943. {
  2944. break;
  2945. }
  2946. else if(name != null && sortedName != null && sortOrder.equalsIgnoreCase("desc") && name.compareTo(sortedName) > 0)
  2947. {
  2948. break;
  2949. }
  2950. }
  2951. //Here we sort on date if the dates on a container is wanted
  2952. else if(sortAttributeName.equalsIgnoreCase("publishDateTime"))
  2953. {
  2954. Date date = content.getPublishDateTime();
  2955. Date sortedDate = sortedContent.getPublishDateTime();
  2956. if(date != null && sortedDate != null && sortOrder.equalsIgnoreCase("asc") && date.before(sortedDate))
  2957. {
  2958. break;
  2959. }
  2960. else if(date != null && sortedDate != null && sortOrder.equalsIgnoreCase("desc") && date.after(sortedDate))
  2961. {
  2962. break;
  2963. }
  2964. }
  2965. else if(sortAttributeName.equalsIgnoreCase("expireDateTime"))
  2966. {
  2967. Date date = content.getExpireDateTime();
  2968. Date sortedDate = sortedContent.getExpireDateTime();
  2969. if(date != null && sortedDate != null && sortOrder.equalsIgnoreCase("asc") && date.before(sortedDate))
  2970. {
  2971. break;
  2972. }
  2973. else if(date != null && sortedDate != null && sortOrder.equalsIgnoreCase("desc") && date.after(sortedDate))
  2974. {
  2975. break;
  2976. }
  2977. }
  2978. else
  2979. {
  2980. long current = System.currentTimeMillis();
  2981. String contentAttribute = this.getContentAttribute(db, content.getId(), languageId, sortAttributeName, siteNodeId, useLanguageFallback, deliveryContext, infoGluePrincipal, false);
  2982. String sortedContentAttribute = this.getContentAttribute(db, sortedContent.getId(), languageId, sortAttributeName, siteNodeId, useLanguageFallback, deliveryContext, infoGluePrincipal, false);
  2983. attributesTimes = attributesTimes + (System.currentTimeMillis() - current);
  2984. if(contentAttribute != null && sortedContentAttribute != null && sortOrder.equalsIgnoreCase("asc") && contentAttribute.compareTo(sortedContentAttribute) < 0)
  2985. {
  2986. break;
  2987. }
  2988. else if(contentAttribute != null && sortedContentAttribute != null && sortOrder.equalsIgnoreCase("desc") && contentAttribute.compareTo(sortedContentAttribute) > 0)
  2989. {
  2990. break;
  2991. }
  2992. }
  2993. index++;
  2994. }
  2995. sortedContents.add(index, content);
  2996. }
  2997. }
  2998. }
  2999. catch(Exception e)
  3000. {
  3001. logger.warn("The sorting of contents failed:" + e.getMessage(), e);
  3002. }
  3003. return sortedContents;
  3004. }
  3005. }