PageRenderTime 59ms CodeModel.GetById 21ms RepoModel.GetById 1ms 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

Large files files are truncated, but you can click here to view the full file

  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 u…

Large files files are truncated, but you can click here to view the full file