{
logger.info("PageKey:" + this.getDeliveryContext().getPageKey());
logger.info("PageCache:" + this.getDeliveryContext().getDisablePageCache());
}
LanguageVO languageVO = LanguageDeliveryController.getLanguageDeliveryController().getLanguageVO(getDatabase(), this.getTemplateController().getLanguageId());
if(logger.isInfoEnabled())
logger.info("languageVO:" + languageVO);
if(languageVO == null)
throw new SystemException("There was no such active language for the page with languageId:" + this.getTemplateController().getLanguageId());
String isPageCacheOn = CmsPropertyHandler.getIsPageCacheOn();
String refresh = this.getRequest().getParameter("refresh");
String pageCacheName = "pageCache"; // + this.getTemplateController().getRepositoryId();
String pageCacheExtraName = "pageCacheExtra"; // + this.getTemplateController().getRepositoryId();
if(logger.isInfoEnabled())
logger.info("isPageCacheOn:" + isPageCacheOn);
if(isPageCacheOn.equalsIgnoreCase("true") && (refresh == null || !refresh.equalsIgnoreCase("true")) && getRequest().getMethod().equals("GET"))
{
Map cachedExtraData = null;
Integer pageCacheTimeout = (Integer)CacheController.getCachedObjectFromAdvancedCache("pageCacheExtra", this.getDeliveryContext().getPageKey() + "_pageCacheTimeout");
if(pageCacheTimeout == null)
pageCacheTimeout = this.getTemplateController().getPageCacheTimeout();
if(pageCacheTimeout == null)
{
//cachedCompressedData = (byte[])CacheController.getCachedObjectFromAdvancedCache(pageCacheName, this.getDeliveryContext().getPageKey());
Class[] argsClasses = new Class[2];
argsClasses[0] = String.class;
argsClasses[1] = String.class;
Object[] args = new Object[]{pageCacheName, pageCacheExtraName};
this.pageString = (String)CacheController.getCachedObjectFromAdvancedCache(pageCacheName, this.getDeliveryContext().getPageKey(), true, "utf-8", true, this, this.getClass().getMethod("invokeAndDecoratePage", argsClasses), args, this);
cachedExtraData = (Map)CacheController.getCachedObjectFromAdvancedCache(pageCacheExtraName, this.getDeliveryContext().getPageKey());
if(this.pageString != null)
this.getDeliveryContext().setIsCachedResponse(true);
}
else
{
//cachedCompressedData = (byte[])CacheController.getCachedObjectFromAdvancedCache(pageCacheName, this.getDeliveryContext().getPageKey(), pageCacheTimeout.intValue());
//this.pageString = (String)CacheController.getCachedObjectFromAdvancedCache(pageCacheName, this.getDeliveryContext().getPageKey(), pageCacheTimeout.intValue(), true, "utf-8", false);
Object pageCacheFileName = CacheController.getCachedObjectFromAdvancedCache(pageCacheName, this.getDeliveryContext().getPageKey(), pageCacheTimeout.intValue(), true, "utf-8", false);
if(pageCacheFileName != null && !pageCacheFileName.equals(""))
this.pageString = PageCacheHelper.getInstance().getCachedPageString(this.getDeliveryContext().getPageKey(), new File(pageCacheFileName.toString()));
else
logger.info("No page file name in memory cache:" + this.getDeliveryContext().getPageKey());
cachedExtraData = (Map)CacheController.getCachedObjectFromAdvancedCache(pageCacheExtraName, this.getDeliveryContext().getPageKey(), pageCacheTimeout.intValue());
this.getDeliveryContext().setPageCacheTimeout(pageCacheTimeout.intValue());
if(this.pageString == null)
{
invokePage();
this.pageString = getPageString();
getLastModifiedDateTime(false);
pageString = decorateHeadAndPageWithVarsFromComponents(pageString);
this.getDeliveryContext().setPagePath(this.templateController.getCurrentPagePath());
}
else
this.getDeliveryContext().setIsCachedResponse(true);
}
logger.info("this.getDeliveryContext().getIsCachedResponse():" + this.getDeliveryContext().getIsCachedResponse());
if(this.getDeliveryContext().getIsCachedResponse())
{
String usedEntitiesString = null;
if(CmsPropertyHandler.getOperatingMode().equals("0"))
{
usedEntitiesString = (String)CacheController.getCachedObjectFromAdvancedCache("pageCacheExtra", this.getDeliveryContext().getPageKey() + "_entitiesAsByte");
}
else
{
byte[] usedEntitiesByteArray = (byte[])CacheController.getCachedObjectFromAdvancedCache("pageCacheExtra", this.getDeliveryContext().getPageKey() + "_entitiesAsByte");
if(usedEntitiesByteArray != null)
usedEntitiesString = compressionHelper.decompress(usedEntitiesByteArray);
}
if(logger.isInfoEnabled())
logger.info("usedEntitiesString:" + usedEntitiesString);
if(usedEntitiesString != null)
{
String[] usedEntities = StringUtils.split(usedEntitiesString, "|");
for(String usedEntity : usedEntities)
{
if(usedEntity.startsWith("content_"))
this.getDeliveryContext().addUsedContent(usedEntity);
else if(usedEntity.startsWith("contentVersion_"))
this.getDeliveryContext().addUsedContentVersion(usedEntity);
else if(usedEntity.startsWith("siteNode_"))
this.getDeliveryContext().addUsedSiteNode(usedEntity);
else if(usedEntity.startsWith("siteNodeVersion_"))
this.getDeliveryContext().addUsedSiteNodeVersion(usedEntity);
}
}
}
getLastModifiedDateTime(true);
if(cachedExtraData != null)
this.getDeliveryContext().populateExtraData(cachedExtraData);
//Caching the pagePath
this.getDeliveryContext().setPagePath((String)CacheController.getCachedObject("pagePathCache", this.getDeliveryContext().getPageKey()));
if(this.getDeliveryContext().getPagePath() == null)
{
this.getDeliveryContext().setPagePath(this.getTemplateController().getCurrentPagePath());
if(!this.getTemplateController().getIsPageCacheDisabled() && !this.getDeliveryContext().getDisablePageCache()) //Caching page path if not disabled
CacheController.cacheObject("pagePathCache", this.getDeliveryContext().getPageKey(), this.getDeliveryContext().getPagePath());
}
if(logger.isInfoEnabled())
logger.info("Done caching the pagePath...");
}
else
{
invokePage();
this.pageString = getPageString();
//TEST
getLastModifiedDateTime(false);
//END TEST
pageString = decorateHeadAndPageWithVarsFromComponents(pageString);
this.getDeliveryContext().setPagePath(this.templateController.getCurrentPagePath());
}
if(this.getRequest().getParameter("includeUsedEntities") != null && this.getRequest().getParameter("includeUsedEntities").equals("true") && (!CmsPropertyHandler.getOperatingMode().equals("3") || CmsPropertyHandler.getLivePublicationThreadClass().equalsIgnoreCase("org.infoglue.deliver.util.SelectiveLivePublicationThread")))
{
StringBuilder sb = new StringBuilder("<usedEntities>");
String[] usedEntities = this.getDeliveryContext().getAllUsedEntities();
for(int i=0; i<usedEntities.length; i++)
sb.append(usedEntities[i]).append(",");
sb.append("</usedEntities>");
if(this.getTemplateController().getPageContentType() != null && (this.getTemplateController().getPageContentType().equalsIgnoreCase("text/css") || this.getTemplateController().getPageContentType().equalsIgnoreCase("text/javascript")))
this.pageString = this.pageString + "/*" + sb.toString() + "*/";
else
this.pageString = this.pageString + "<!--" + sb.toString() + "-->";
}
String contentType = this.getTemplateController().getPageContentType();
if(this.deliveryContext.getContentType() != null && !contentType.equalsIgnoreCase(this.deliveryContext.getContentType()))
contentType = this.deliveryContext.getContentType();
if(!CmsPropertyHandler.getOperatingMode().equals("3"))
{
getResponse().setHeader("Cache-Control","no-cache");
getResponse().setHeader("Pragma","no-cache");
getResponse().setDateHeader ("Expires", 0);
}
//logger.info("pageString before:" + pageString);
//pageString = decorateHeadAndPageWithVarsFromComponents(pageString);
//logger.info("pageString after:" + pageString);
try
{
//logger.info("ContentType:" + contentType);
String charSet = languageVO.getCharset();
if(contentType.indexOf("charset=") > -1)
{
try
{
int startIndex = contentType.indexOf("charset=");
int endIndex = contentType.indexOf(";", startIndex + 1);
if(endIndex != -1)
charSet = contentType.substring(startIndex + "charset=".length(), endIndex).trim();
else
charSet = contentType.substring(startIndex + "charset=".length()).trim();
if(logger.isInfoEnabled())
logger.info("Found a user defined charset: " + charSet);
}
catch(Exception e)
{
logger.warn("Error parsing charset:" + e.getMessage());
}
this.getResponse().setContentType(contentType);
}
else
this.getResponse().setContentType(contentType + "; charset=" + languageVO.getCharset());
if(logger.isInfoEnabled())
logger.info("Using charset: " + charSet);
Iterator headersIterator = this.getDeliveryContext().getHttpHeaders().keySet().iterator();
while(headersIterator.hasNext())
{
String key = (String)headersIterator.next();
Object valueObject = this.getDeliveryContext().getHttpHeaders().get(key);
if(valueObject instanceof Date)
{
Date value = (Date)valueObject;
this.getResponse().setDateHeader(key, value.getTime());
}
else
{
String value = (String)valueObject;
this.getResponse().setHeader(key, value);
}
}
if(logger.isInfoEnabled())
logger.info("contentType:" + contentType + "; charset=" + languageVO.getCharset());
String compressPageResponse = CmsPropertyHandler.getCompressPageResponse();
if(logger.isInfoEnabled())
logger.info("compressPageResponse:" + compressPageResponse);