Source Code Cross Referenced for GenericViewRenderer.java in  » ERP-CRM-Financial » ofbiz » org » ofbiz » webapp » view » 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 » ERP CRM Financial » ofbiz » org.ofbiz.webapp.view 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements.  See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership.  The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License.  You may obtain a copy of the License at
009:         * 
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         * 
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied.  See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         *******************************************************************************/package org.ofbiz.webapp.view;
019:
020:        import java.io.FileInputStream;
021:        import java.io.IOException;
022:        import java.io.InputStream;
023:        import java.io.InputStreamReader;
024:        import java.io.OutputStream;
025:        import java.io.OutputStreamWriter;
026:        import java.io.Reader;
027:        import java.io.Writer;
028:        import java.util.HashMap;
029:        import java.util.Iterator;
030:        import java.util.Map;
031:        import javax.servlet.http.HttpServletRequest;
032:        import javax.servlet.http.HttpSession;
033:
034:        import com.anthonyeden.lib.config.Configuration;
035:        import com.anthonyeden.lib.config.ConfigurationException;
036:        import com.anthonyeden.lib.config.XMLConfiguration;
037:
038:        import org.ofbiz.base.util.Debug;
039:        import org.ofbiz.entity.GenericValue;
040:        import org.ofbiz.security.Security;
041:
042:        import org.jpublish.JPublishContext;
043:        import org.jpublish.Page;
044:        import org.jpublish.SiteContext;
045:        import org.jpublish.Template;
046:        import org.jpublish.page.PageInstance;
047:        import org.jpublish.view.ViewRenderException;
048:        import org.jpublish.view.ViewRenderer;
049:
050:        /**
051:         * Generic JPublish View Renderer - This is in testing; for use in wrapping other renderers
052:         */
053:        public class GenericViewRenderer implements  ViewRenderer {
054:
055:            public static final String module = GenericViewRenderer.class
056:                    .getName();
057:            public static final String DEFAULT_RENDERER = "freemarker";
058:            public Map renderers = null;
059:
060:            protected SiteContext siteContext = null;
061:
062:            /**
063:             * @see org.jpublish.view.ViewRenderer#setSiteContext(org.jpublish.SiteContext)
064:             */
065:            public void setSiteContext(SiteContext siteContext) {
066:                this .siteContext = siteContext;
067:                this .renderers = new HashMap();
068:                try {
069:                    loadCustom();
070:                } catch (Exception e) {
071:                    Debug.logError(e, "Problems loading custom settings",
072:                            module);
073:                    throw new RuntimeException(e.toString());
074:                }
075:            }
076:
077:            /* (non-Javadoc)
078:             * @see org.jpublish.view.ViewRenderer#init()
079:             */
080:            public void init() throws Exception {
081:            }
082:
083:            /**
084:             * @see org.jpublish.view.ViewRenderer#render(org.jpublish.JPublishContext, java.io.Reader, java.io.Writer)
085:             */
086:            public void render(JPublishContext context, String path, Reader in,
087:                    Writer out) throws IOException, ViewRenderException {
088:                HttpServletRequest request = context.getRequest();
089:                HttpSession session = context.getSession();
090:                Security security = (Security) request.getAttribute("security");
091:                GenericValue userLogin = (GenericValue) session
092:                        .getAttribute("userLogin");
093:
094:                Page parent = (Page) context.get("page");
095:                Page page = getPage(path);
096:
097:                // decorate the content w/ edit images if we have permission              
098:                if (userLogin != null
099:                        && security.hasEntityPermission("CONTENTMGR",
100:                                "_UPDATE", userLogin)) {
101:                    out.write("<a href='/content/control/editContent?filePath="
102:                            + path + "'>*</a>");
103:                }
104:
105:                /* this loops -- not good
106:                // if this page has a template, lets render the template                
107:                if (page != null && parent != null && page.getPath() != parent.getPath()) {
108:                    Debug.logInfo("Parent: " + parent.getPath(), module);
109:                    Debug.logInfo("Page: " + page.getPath(), module);
110:                    Debug.logInfo("Template: " + page.getFullTemplateName(), module);
111:                    if (!page.getTemplateName().equals("basic")) {                
112:                        renderTemplate(cloneContext(context), page, out);
113:                        return;
114:                    }
115:                } 
116:                 */
117:
118:                // get the view renderer for this page
119:                if (Debug.verboseOn())
120:                    Debug.logVerbose("Getting renderer for: " + path, module);
121:                String rendererName = DEFAULT_RENDERER;
122:                if (page != null) {
123:                    rendererName = page.getProperty("page-renderer");
124:                    if (rendererName == null)
125:                        rendererName = DEFAULT_RENDERER;
126:                }
127:
128:                ViewRenderer renderer = (ViewRenderer) renderers
129:                        .get(rendererName);
130:                if (renderer == null)
131:                    renderer = (ViewRenderer) renderers.get(DEFAULT_RENDERER);
132:
133:                // call the renderer to render the rest of the page.
134:                Debug.logVerbose("Calling render", module);
135:                renderer.render(context, path, in, out);
136:            }
137:
138:            private void renderTemplate(JPublishContext context, Page page,
139:                    Writer out) throws IOException, ViewRenderException {
140:                context.disableCheckReservedNames(this );
141:                context.put("page", page);
142:                if (siteContext.isProtectReservedNames()) {
143:                    context.enableCheckReservedNames(this );
144:                }
145:                try {
146:                    Debug.logInfo("Merging template", module);
147:                    Template template = siteContext.getTemplateManager()
148:                            .getTemplate(page.getFullTemplateName());
149:                    template.merge(context, page, out);
150:                } catch (Exception e) {
151:                    throw new ViewRenderException(e);
152:                }
153:            }
154:
155:            private JPublishContext cloneContext(JPublishContext context) {
156:                JPublishContext newContext = new JPublishContext(this );
157:                context.disableCheckReservedNames(this );
158:                Object keys[] = context.getKeys();
159:                for (int i = 0; i < keys.length; i++)
160:                    newContext.put((String) keys[i], context
161:                            .get((String) keys[i]));
162:                if (siteContext.isProtectReservedNames()) {
163:                    context.enableCheckReservedNames(this );
164:                }
165:                return newContext;
166:            }
167:
168:            /**
169:             * @see org.jpublish.view.ViewRenderer#render(org.jpublish.JPublishContext, java.io.InputStream, java.io.OutputStream)
170:             */
171:            public void render(JPublishContext context, String path,
172:                    InputStream in, OutputStream out) throws IOException,
173:                    ViewRenderException {
174:                render(context, path, new InputStreamReader(in),
175:                        new OutputStreamWriter(out));
176:            }
177:
178:            /**
179:             * @see org.jpublish.view.ViewRenderer#loadConfiguration(com.anthonyeden.lib.config.Configuration)
180:             */
181:            public void loadConfiguration(Configuration config)
182:                    throws ConfigurationException {
183:            }
184:
185:            private Page getPage(String path) {
186:                Page page = null;
187:                try {
188:                    PageInstance pi = siteContext.getPageManager().getPage(
189:                            path.substring(path.lastIndexOf(":") + 1));
190:                    if (pi != null)
191:                        page = new Page(pi);
192:                } catch (Exception e) {
193:                }
194:                return page;
195:            }
196:
197:            private void loadCustom() throws Exception {
198:                ClassLoader cl = Thread.currentThread().getContextClassLoader();
199:                InputStream in = new FileInputStream(siteContext
200:                        .getConfigurationFile());
201:                Configuration configuration = new XMLConfiguration(in);
202:
203:                Iterator renderElements = configuration.getChildren(
204:                        "page-renderer").iterator();
205:                while (renderElements.hasNext()) {
206:                    Configuration viewRendererConfiguration = (Configuration) renderElements
207:                            .next();
208:                    String renderName = viewRendererConfiguration
209:                            .getAttribute("name");
210:                    String className = viewRendererConfiguration
211:                            .getAttribute("classname");
212:                    ViewRenderer renderer = (ViewRenderer) cl.loadClass(
213:                            className).newInstance();
214:                    renderer.setSiteContext(siteContext);
215:                    renderer.loadConfiguration(viewRendererConfiguration);
216:                    renderer.init();
217:                    Debug.logInfo("Added renderer [" + renderName + "] - ["
218:                            + className + "]", module);
219:                    renderers.put(renderName, renderer);
220:                }
221:            }
222:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.