Source Code Cross Referenced for VelocityScreenUtil.java in  » Groupware » coefficient » za » org » coefficient » util » ejb » 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 » Groupware » coefficient » za.org.coefficient.util.ejb 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Coefficient - facilitates project based collaboration
003:         * Copyright (C) 2003, Dylan Etkin, CSIR icomtek
004:         * PO Box 395
005:         * Pretoria 0001, RSA
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or (at your option) any later version.
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         * Lesser General Public License for more details.
014:         *
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
018:         */
019:
020:        package za.org.coefficient.util.ejb;
021:
022:        import za.org.coefficient.core.Constants;
023:
024:        import org.apache.commons.lang.StringUtils;
025:
026:        import org.apache.velocity.Template;
027:        import org.apache.velocity.VelocityContext;
028:        import org.apache.velocity.app.Velocity;
029:        import org.apache.velocity.context.Context;
030:
031:        import java.io.StringWriter;
032:
033:        import java.text.SimpleDateFormat;
034:
035:        import java.util.Map;
036:        import java.util.Properties;
037:
038:        /**
039:         * DOCUMENT ME!
040:         *
041:         * @author $author$
042:         * @version $Revision: 1.3 $
043:         */
044:        public class VelocityScreenUtil {
045:            //~ Static fields/initializers =============================================
046:
047:            public static final String TEMPLATES = "/templates/";
048:
049:            static {
050:                initVelocity();
051:            }
052:
053:            //~ Methods ================================================================
054:
055:            /**
056:             * This method will look for the template name on the classpath and if
057:             * found merge it with the data provided in the map. The result is returned
058:             * as a StringBuffer.
059:             *
060:             * @param templateName identifies the template that should
061:             *        be merged. If the template is not found or there is a parsing
062:             *        error in the template or there is a method invocation error
063:             *        while parsing the template then the return value will be null.
064:             *        It is assumed that this template will be found in the classpath
065:             *        in the same package space as the caller plus a level deeper
066:             *        called templates
067:             * @param context is a map containing all the mappings that are to be
068:             *        merged into the template.
069:             *
070:             * @return StringBuffer containing the result of the merge, null if there
071:             *         were any exceptions thrown during the merge.
072:             */
073:            public static StringBuffer getProcessedScreen(String templateName,
074:                    Map context) {
075:                String fullTemplateName = getCallingClassPackage() + TEMPLATES
076:                        + templateName;
077:                StringBuffer retVal = null;
078:                try {
079:                    Template currTemplate = Velocity
080:                            .getTemplate(fullTemplateName);
081:                    StringWriter sw = new StringWriter();
082:                    context.put("dateFormat", new SimpleDateFormat(
083:                            Constants.SYSTEM_DATE_FORMAT));
084:                    Context ctx = new VelocityContext(context);
085:                    currTemplate.merge(ctx, sw);
086:                    retVal = sw.getBuffer();
087:                } catch (Exception e) {
088:                    e.printStackTrace();
089:                }
090:
091:                return retVal;
092:            }
093:
094:            public static StringBuffer getProcessedScreenFullyQualified(
095:                    String fullyQualifiedTemplateName, Map context) {
096:                StringBuffer retVal = null;
097:                try {
098:                    Template currTemplate = Velocity
099:                            .getTemplate(fullyQualifiedTemplateName);
100:                    StringWriter sw = new StringWriter();
101:                    context.put("dateFormat", new SimpleDateFormat(
102:                            Constants.SYSTEM_DATE_FORMAT));
103:                    Context ctx = new VelocityContext(context);
104:                    currTemplate.merge(ctx, sw);
105:                    retVal = sw.getBuffer();
106:                } catch (Exception e) {
107:                    e.printStackTrace();
108:                }
109:
110:                return retVal;
111:            }
112:
113:            /**
114:             * This method will look for the template name on the classpath and if
115:             * found merge it with the data provided in the map. The result is returned
116:             * as a StringBuffer.
117:             *
118:             * @param inString is a string containing velocity code that will be merged
119:             * @param context is a map containing all the mappings that are to be
120:             *        merged into the template.
121:             *
122:             * @return StringBuffer containing the result of the merge, null if there
123:             *         were any exceptions thrown during the merge.
124:             */
125:            public static StringBuffer getProcessedString(String inString,
126:                    Map context) {
127:                StringBuffer retVal = null;
128:                try {
129:                    StringWriter sw = new StringWriter();
130:                    context.put("dateFormat", new SimpleDateFormat(
131:                            Constants.SYSTEM_DATE_FORMAT));
132:                    Context ctx = new VelocityContext(context);
133:                    Velocity.evaluate(ctx, sw, "temp", inString);
134:                    retVal = sw.getBuffer();
135:                } catch (Exception e) {
136:                    e.printStackTrace();
137:                }
138:
139:                return retVal;
140:            }
141:
142:            public static String getCallingClassPackage() {
143:                StackTraceElement[] ste = new Exception().getStackTrace();
144:                if ((ste == null) || (ste.length < 3)) {
145:                    return null;
146:                } else {
147:                    String temp = ste[2].getClassName();
148:
149:                    return StringUtils.replace(temp.substring(0, temp
150:                            .lastIndexOf(".")), ".", "/");
151:                }
152:            }
153:
154:            private static void initVelocity() {
155:                try {
156:                    Properties props = new Properties();
157:                    props.setProperty("resource.loader", "templateLoader");
158:                    props.setProperty("templateLoader.loader.description",
159:                            "Project Engine loader");
160:                    props
161:                            .setProperty(
162:                                    "templateLoader.resource.loader.class",
163:                                    "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
164:                    props.setProperty(
165:                            "velocimacro.permissions.allow.inline.local.scope",
166:                            "true");
167:                    Velocity.init(props);
168:                } catch (Exception ex) {
169:                    ex.printStackTrace();
170:
171:                    // How to indicate the problem ??
172:                }
173:            }
174:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.