1 23 24 package org.infoglue.deliver.invokers; 25 26 import java.io.PrintWriter ; 27 import java.io.StringWriter ; 28 import java.util.Map ; 29 30 import org.apache.log4j.Logger; 31 import org.infoglue.cms.entities.content.ContentVO; 32 import org.infoglue.cms.exception.SystemException; 33 import org.infoglue.deliver.controllers.kernel.impl.simple.NodeDeliveryController; 34 import org.infoglue.deliver.util.VelocityTemplateProcessor; 35 36 42 43 public class HTMLPageInvoker extends PageInvoker 44 { 45 private final static Logger logger = Logger.getLogger(HTMLPageInvoker.class.getName()); 46 47 51 52 public PageInvoker getDecoratedPageInvoker() throws SystemException 53 { 54 return this; 55 } 56 57 60 61 public void invokePage() throws SystemException, Exception 62 { 63 try 64 { 65 String templateString = getPageTemplateString(); 66 67 Map context = getDefaultContext(); 68 69 StringWriter cacheString = new StringWriter (); 70 PrintWriter cachedStream = new PrintWriter (cacheString); 71 new VelocityTemplateProcessor().renderTemplate(context, cachedStream, templateString); 72 String pageString = cacheString.toString(); 73 74 pageString = this.getTemplateController().decoratePage(pageString); 75 76 this.setPageString(pageString); 77 } 78 catch(Exception e) 79 { 80 logger.error(e.getMessage(), e); 81 throw e; 82 } 83 84 } 85 86 87 90 91 private String getPageTemplateString() throws SystemException, Exception 92 { 93 String template = null; 94 95 try 96 { 97 logger.info("DeliveryContext:" + this.getDeliveryContext().toString()); 98 ContentVO contentVO = NodeDeliveryController.getNodeDeliveryController(this.getDeliveryContext().getSiteNodeId(), this.getDeliveryContext().getLanguageId(), this.getDeliveryContext().getContentId()).getBoundContent(this.getTemplateController().getDatabase(), this.getTemplateController().getPrincipal(), this.getDeliveryContext().getSiteNodeId(), this.getDeliveryContext().getLanguageId(), true, "Template", this.getDeliveryContext()); 99 100 logger.info("contentVO:" + contentVO); 101 102 if(contentVO == null) 103 throw new SystemException("There was no template bound to this page which makes it impossible to render."); 104 105 logger.info("contentVO:" + contentVO.getName()); 106 107 template = this.getTemplateController().getContentAttribute(contentVO.getContentId(), this.getTemplateController().getTemplateAttributeName()); 108 109 if(template == null) 110 throw new SystemException("There was no template bound to this page which makes it impossible to render."); 111 } 112 catch(Exception e) 113 { 114 logger.error(e.getMessage(), e); 115 throw e; 116 } 117 118 return template; 119 } 120 121 } 122 | Popular Tags |