1 23 24 package org.infoglue.deliver.util; 25 26 import java.security.Principal ; 27 import java.util.Collection ; 28 import java.util.HashMap ; 29 import java.util.Iterator ; 30 import java.util.Map ; 31 32 import javax.servlet.http.HttpServletRequest ; 33 34 import org.apache.log4j.Logger; 35 import org.infoglue.cms.applications.common.Session; 36 import org.infoglue.cms.controllers.kernel.impl.simple.ContentController; 37 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeController; 38 import org.infoglue.cms.entities.content.Content; 39 import org.infoglue.cms.entities.content.ContentVO; 40 import org.infoglue.cms.entities.management.LanguageVO; 41 import org.infoglue.cms.entities.structure.SiteNode; 42 import org.infoglue.cms.entities.structure.SiteNodeVO; 43 import org.infoglue.cms.exception.SystemException; 44 import org.infoglue.cms.security.InfoGluePrincipal; 45 import org.infoglue.cms.util.CmsPropertyHandler; 46 import org.infoglue.cms.util.FakeHttpServletRequest; 47 import org.infoglue.cms.util.FakeHttpServletResponse; 48 import org.infoglue.cms.util.FakeHttpSession; 49 import org.infoglue.deliver.applications.databeans.DatabaseWrapper; 50 import org.infoglue.deliver.applications.databeans.DeliveryContext; 51 import org.infoglue.deliver.controllers.kernel.impl.simple.BasicTemplateController; 52 import org.infoglue.deliver.controllers.kernel.impl.simple.ExtranetController; 53 import org.infoglue.deliver.controllers.kernel.impl.simple.IntegrationDeliveryController; 54 import org.infoglue.deliver.controllers.kernel.impl.simple.LanguageDeliveryController; 55 import org.infoglue.deliver.controllers.kernel.impl.simple.NodeDeliveryController; 56 import org.infoglue.deliver.controllers.kernel.impl.simple.TemplateController; 57 58 59 public class ContentCentricCachePopulator 60 { 61 public final static Logger logger = Logger.getLogger(ContentCentricCachePopulator.class.getName()); 62 63 64 71 72 public void recache(DatabaseWrapper dbWrapper, Integer siteNodeId) throws SystemException, Exception 73 { 74 logger.info("recache starting.."); 75 76 LanguageVO masterLanguageVO = LanguageDeliveryController.getLanguageDeliveryController().getMasterLanguageForSiteNode(dbWrapper.getDatabase(), siteNodeId); 77 if(masterLanguageVO == null) 78 throw new SystemException("There was no master language for the siteNode " + siteNodeId); 79 80 Integer languageId = masterLanguageVO.getLanguageId(); 81 if(languageId == null) 82 languageId = masterLanguageVO.getLanguageId(); 83 84 Integer contentId = new Integer (-1); 85 86 Principal principal = (Principal )CacheController.getCachedObject("userCache", "anonymous"); 87 if(principal == null) 88 { 89 Map arguments = new HashMap (); 90 arguments.put("j_username", CmsPropertyHandler.getAnonymousUser()); 91 arguments.put("j_password", CmsPropertyHandler.getAnonymousPassword()); 92 93 principal = ExtranetController.getController().getAuthenticatedPrincipal(dbWrapper.getDatabase(), arguments); 94 95 if(principal != null) 96 CacheController.cacheObject("userCache", "anonymous", principal); 97 } 98 99 FakeHttpSession fakeHttpServletSession = new FakeHttpSession(); 100 FakeHttpServletResponse fakeHttpServletResponse = new FakeHttpServletResponse(); 101 FakeHttpServletRequest fakeHttpServletRequest = new FakeHttpServletRequest(); 102 fakeHttpServletRequest.setParameter("siteNodeId", "" + siteNodeId); 103 fakeHttpServletRequest.setParameter("languageId", "" + languageId); 104 fakeHttpServletRequest.setParameter("contentId", "" + contentId); 105 fakeHttpServletRequest.setRequestURI("ViewPage.action"); 106 107 fakeHttpServletRequest.setAttribute("siteNodeId", "" + siteNodeId); 108 fakeHttpServletRequest.setAttribute("languageId", "" + languageId); 109 fakeHttpServletRequest.setAttribute("contentId", "" + contentId); 110 111 fakeHttpServletRequest.setServletContext(DeliverContextListener.getServletContext()); 112 113 BrowserBean browserBean = new BrowserBean(); 114 116 NodeDeliveryController nodeDeliveryController = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, contentId); 117 IntegrationDeliveryController integrationDeliveryController = IntegrationDeliveryController.getIntegrationDeliveryController(siteNodeId, languageId, contentId); 118 TemplateController templateController = getTemplateController(dbWrapper, siteNodeId, languageId, contentId, new FakeHttpServletRequest(), (InfoGluePrincipal)principal, false, browserBean, nodeDeliveryController, integrationDeliveryController); 119 120 DeliveryContext deliveryContext = DeliveryContext.getDeliveryContext(); 121 deliveryContext.setSiteNodeId(siteNodeId); 123 deliveryContext.setContentId(contentId); 124 deliveryContext.setLanguageId(languageId); 125 deliveryContext.setPageKey("" + System.currentTimeMillis()); 126 deliveryContext.setSession(new Session(fakeHttpServletSession)); 127 deliveryContext.setInfoGlueAbstractAction(null); 128 deliveryContext.setHttpServletRequest(fakeHttpServletRequest); 129 deliveryContext.setHttpServletResponse(fakeHttpServletResponse); 130 131 templateController.setDeliveryContext(deliveryContext); 132 133 deliveryContext.setDisablePageCache(true); 135 136 Integer rootMetaInfoContentId = templateController.getMetaInformationContentId(siteNodeId); 137 logger.info("rootMetaInfoContentId:" + rootMetaInfoContentId); 138 139 recurseSiteNodeTree(siteNodeId, languageId, templateController); 140 141 Integer topContentId = null; 142 ContentVO contentVO = templateController.getContent(rootMetaInfoContentId); 143 logger.info("contentVO:" + contentVO.getName()); 144 ContentVO parentContentVO = templateController.getContent(contentVO.getParentContentId()); 145 logger.info("parentContentVO:" + parentContentVO.getName()); 146 while(parentContentVO != null) 147 { 148 topContentId = parentContentVO.getContentId(); 149 150 if(parentContentVO.getParentContentId() != null) 151 parentContentVO = templateController.getContent(parentContentVO.getParentContentId()); 152 else 153 parentContentVO = null; 154 } 155 156 logger.info("topContentId:" + topContentId); 157 158 if(topContentId != null) 159 recurseContentTree(topContentId, languageId, templateController); 160 161 } 162 163 164 private void recurseContentTree(Integer contentId, Integer languageId, TemplateController templateController) throws Exception 165 { 166 Content content = ContentController.getContentController().getReadOnlyContentWithId(contentId, templateController.getDatabase()); 167 ContentVO contentVO = templateController.getContent(contentId); 168 169 Collection childContents = content.getChildren(); 170 171 Iterator childContentsIterator = childContents.iterator(); 172 while(childContentsIterator.hasNext()) 173 { 174 Content childContent = (Content)childContentsIterator.next(); 175 recurseContentTree(childContent.getId(), languageId, templateController); 176 177 logger.info("Before read title of content..."); 178 templateController.getContentAttribute(childContent.getId(), languageId, "Title", true); 179 templateController.getContentAttribute(childContent.getId(), languageId, "NavigationTitle", true); 180 logger.info("Read title of content..."); 183 } 184 } 186 187 private void recurseSiteNodeTree(Integer siteNodeId, Integer languageId, TemplateController templateController) throws Exception 188 { 189 SiteNode siteNode = SiteNodeController.getController().getSiteNodeWithId(siteNodeId, templateController.getDatabase(), true); 190 SiteNodeVO siteNodeVO = templateController.getSiteNode(siteNodeId); 191 Collection childSiteNodes = siteNode.getChildSiteNodes(); 192 193 Iterator childSiteNodesIterator = childSiteNodes.iterator(); 194 while(childSiteNodesIterator.hasNext()) 195 { 196 SiteNode childSiteNode = (SiteNode)childSiteNodesIterator.next(); 197 recurseSiteNodeTree(childSiteNode.getSiteNodeId(), languageId, templateController); 198 199 Integer metaInfoContentId = templateController.getMetaInformationContentId(childSiteNode.getSiteNodeId()); 200 templateController.getContentAttribute(metaInfoContentId, languageId, "ComponentStructure", true); 203 } 204 } 205 206 207 213 214 public TemplateController getTemplateController(DatabaseWrapper dbWrapper, Integer siteNodeId, Integer languageId, Integer contentId, HttpServletRequest request, InfoGluePrincipal infoGluePrincipal, boolean allowEditOnSightAtAll, BrowserBean browserBean, NodeDeliveryController nodeDeliveryController, IntegrationDeliveryController integrationDeliveryController) throws SystemException, Exception 215 { 216 TemplateController templateController = new BasicTemplateController(dbWrapper, infoGluePrincipal); 217 templateController.setStandardRequestParameters(siteNodeId, languageId, contentId); 218 templateController.setHttpRequest(request); 219 templateController.setBrowserBean(browserBean); 220 templateController.setDeliveryControllers(nodeDeliveryController, null, integrationDeliveryController); 221 222 return templateController; 223 } 224 225 } | Popular Tags |