Source Code Cross Referenced for FreemarkerTag.java in  » Template-Engine » freemarker-2.3.10 » freemarker » ext » jsp » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Template Engine » freemarker 2.3.10 » freemarker.ext.jsp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2003 The Visigoth Software Society. All rights
003:         * reserved.
004:         *
005:         * Redistribution and use in source and binary forms, with or without
006:         * modification, are permitted provided that the following conditions
007:         * are met:
008:         *
009:         * 1. Redistributions of source code must retain the above copyright
010:         *    notice, this list of conditions and the following disclaimer.
011:         *
012:         * 2. Redistributions in binary form must reproduce the above copyright
013:         *    notice, this list of conditions and the following disclaimer in
014:         *    the documentation and/or other materials provided with the
015:         *    distribution.
016:         *
017:         * 3. The end-user documentation included with the redistribution, if
018:         *    any, must include the following acknowledgement:
019:         *       "This product includes software developed by the
020:         *        Visigoth Software Society (http://www.visigoths.org/)."
021:         *    Alternately, this acknowledgement may appear in the software itself,
022:         *    if and wherever such third-party acknowledgements normally appear.
023:         *
024:         * 4. Neither the name "FreeMarker", "Visigoth", nor any of the names of the 
025:         *    project contributors may be used to endorse or promote products derived
026:         *    from this software without prior written permission. For written
027:         *    permission, please contact visigoths@visigoths.org.
028:         *
029:         * 5. Products derived from this software may not be called "FreeMarker" or "Visigoth"
030:         *    nor may "FreeMarker" or "Visigoth" appear in their names
031:         *    without prior written permission of the Visigoth Software Society.
032:         *
033:         * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
034:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
035:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
036:         * DISCLAIMED.  IN NO EVENT SHALL THE VISIGOTH SOFTWARE SOCIETY OR
037:         * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
038:         * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
039:         * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
040:         * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
041:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
042:         * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
043:         * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
044:         * SUCH DAMAGE.
045:         * ====================================================================
046:         *
047:         * This software consists of voluntary contributions made by many
048:         * individuals on behalf of the Visigoth Software Society. For more
049:         * information on the Visigoth Software Society, please see
050:         * http://www.visigoths.org/
051:         */
052:
053:        package freemarker.ext.jsp;
054:
055:        import java.io.IOException;
056:
057:        import javax.servlet.ServletException;
058:        import javax.servlet.jsp.JspException;
059:        import javax.servlet.jsp.PageContext;
060:        import javax.servlet.jsp.tagext.BodyContent;
061:        import javax.servlet.jsp.tagext.BodyTag;
062:        import javax.servlet.jsp.tagext.Tag;
063:
064:        import freemarker.template.SimpleHash;
065:        import freemarker.template.Template;
066:
067:        /**
068:         * Simple implementation of JSP tag to allow use of FreeMarker templates in
069:         * JSP. Inspired by similar class in Velocity template engine developed by
070:         * <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
071:         * @author Attila Szegedi
072:         */
073:        public class FreemarkerTag implements  BodyTag {
074:            private Tag parent;
075:            private BodyContent bodyContent;
076:            private PageContext pageContext;
077:            private SimpleHash root;
078:            private Template template;
079:            private boolean caching = true;
080:            private String name = "";
081:
082:            public boolean getCaching() {
083:                return caching;
084:            }
085:
086:            public void setCaching(boolean caching) {
087:                this .caching = caching;
088:            }
089:
090:            public void setName(String name) {
091:                this .name = name == null ? "" : name;
092:            }
093:
094:            public Tag getParent() {
095:                return parent;
096:            }
097:
098:            public void setParent(Tag parent) {
099:                this .parent = parent;
100:            }
101:
102:            public int doStartTag() {
103:                return EVAL_BODY_BUFFERED;
104:            }
105:
106:            public void setBodyContent(BodyContent bodyContent) {
107:                this .bodyContent = bodyContent;
108:            }
109:
110:            public void setPageContext(PageContext pageContext) {
111:                this .pageContext = pageContext;
112:                root = null;
113:            }
114:
115:            public void doInitBody() {
116:            }
117:
118:            public int doAfterBody() {
119:                return SKIP_BODY;
120:            }
121:
122:            public void release() {
123:                root = null;
124:                template = null;
125:                name = "";
126:            }
127:
128:            public int doEndTag() throws JspException {
129:                if (bodyContent == null)
130:                    return EVAL_PAGE;
131:
132:                try {
133:                    if (template == null) {
134:                        template = new Template(name, bodyContent.getReader());
135:                    }
136:
137:                    if (root == null) {
138:                        root = new SimpleHash();
139:                        root.put("page", new JspContextModel(pageContext,
140:                                JspContextModel.PAGE_SCOPE));
141:                        root.put("request", new JspContextModel(pageContext,
142:                                JspContextModel.REQUEST_SCOPE));
143:                        root.put("session", new JspContextModel(pageContext,
144:                                JspContextModel.SESSION_SCOPE));
145:                        root
146:                                .put("application", new JspContextModel(
147:                                        pageContext,
148:                                        JspContextModel.APPLICATION_SCOPE));
149:                        root.put("any", new JspContextModel(pageContext,
150:                                JspContextModel.ANY_SCOPE));
151:                    }
152:                    template.process(root, pageContext.getOut());
153:                } catch (Exception e) {
154:                    try {
155:                        pageContext.handlePageException(e);
156:                    } catch (ServletException e2) {
157:                        throw new JspException(e2.getMessage());
158:                    } catch (IOException e2) {
159:                        throw new JspException(e2.getMessage());
160:                    }
161:                } finally {
162:                    if (!caching) {
163:                        template = null;
164:                    }
165:                }
166:
167:                return EVAL_PAGE;
168:            }
169:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.