KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > deliver > invokers > HTMLPageInvoker


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
24 package org.infoglue.deliver.invokers;
25
26 import java.io.PrintWriter JavaDoc;
27 import java.io.StringWriter JavaDoc;
28 import java.util.Map JavaDoc;
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 /**
37  * @author Mattias Bogeblad
38  *
39  * This class delivers a normal html page by using the normal template mechanism introduced in infoglue 1.0
40  * Used mostly for simple pages when the new component-based page type is ready.
41  */

42
43 public class HTMLPageInvoker extends PageInvoker
44 {
45     private final static Logger logger = Logger.getLogger(HTMLPageInvoker.class.getName());
46
47     /**
48      * This method should return an instance of the class that should be used for page editing inside the tools or in working.
49      * Makes it possible to have an alternative to the ordinary delivery optimized class.
50      */

51     
52     public PageInvoker getDecoratedPageInvoker() throws SystemException
53     {
54         return this;
55     }
56
57     /**
58      * This is the method that will render the page. It uses the original template style logic.
59      */

60
61     public void invokePage() throws SystemException, Exception JavaDoc
62     {
63         try
64         {
65             String JavaDoc templateString = getPageTemplateString();
66             
67             Map JavaDoc context = getDefaultContext();
68
69             StringWriter JavaDoc cacheString = new StringWriter JavaDoc();
70             PrintWriter JavaDoc cachedStream = new PrintWriter JavaDoc(cacheString);
71             new VelocityTemplateProcessor().renderTemplate(context, cachedStream, templateString);
72             String JavaDoc pageString = cacheString.toString();
73             
74             pageString = this.getTemplateController().decoratePage(pageString);
75             
76             this.setPageString(pageString);
77         }
78         catch(Exception JavaDoc e)
79         {
80             logger.error(e.getMessage(), e);
81             throw e;
82         }
83
84     }
85     
86     
87     /**
88      * This method fetches the template-string.
89      */

90   
91     private String JavaDoc getPageTemplateString() throws SystemException, Exception JavaDoc
92     {
93         String JavaDoc 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 JavaDoc e)
113         {
114             logger.error(e.getMessage(), e);
115             throw e;
116         }
117
118         return template;
119     }
120
121 }
122
Popular Tags