Source Code Cross Referenced for XmlElementView.java in  » ERP-CRM-Financial » sakai » org » theospi » portfolio » shared » control » 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 » sakai » org.theospi.portfolio.shared.control 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**********************************************************************************
002:         * $URL:https://source.sakaiproject.org/svn/osp/trunk/common/tool-lib/src/java/org/theospi/portfolio/shared/control/XmlElementView.java $
003:         * $Id:XmlElementView.java 9134 2006-05-08 20:28:42Z chmaurer@iupui.edu $
004:         ***********************************************************************************
005:         *
006:         * Copyright (c) 2005, 2006 The Sakai Foundation.
007:         *
008:         * Licensed under the Educational Community License, Version 1.0 (the "License");
009:         * you may not use this file except in compliance with the License.
010:         * You may obtain a copy of the License at
011:         *
012:         *      http://www.opensource.org/licenses/ecl1.php
013:         *
014:         * Unless required by applicable law or agreed to in writing, software
015:         * distributed under the License is distributed on an "AS IS" BASIS,
016:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017:         * See the License for the specific language governing permissions and
018:         * limitations under the License.
019:         *
020:         **********************************************************************************/package org.theospi.portfolio.shared.control;
021:
022:        import java.io.File;
023:        import java.io.FileWriter;
024:        import java.util.Map;
025:
026:        import javax.servlet.http.HttpServletRequest;
027:        import javax.servlet.http.HttpServletResponse;
028:
029:        import org.apache.velocity.Template;
030:        import org.apache.velocity.VelocityContext;
031:        import org.apache.velocity.app.VelocityEngine;
032:        import org.apache.velocity.exception.ResourceNotFoundException;
033:        import org.sakaiproject.metaobj.shared.control.EditedArtifactStorage;
034:        import org.sakaiproject.metaobj.shared.control.SchemaBean;
035:        import org.sakaiproject.metaobj.shared.mgt.HomeFactory;
036:        import org.sakaiproject.metaobj.shared.mgt.home.StructuredArtifactHomeInterface;
037:        import org.sakaiproject.metaobj.shared.model.StructuredArtifact;
038:        import org.sakaiproject.metaobj.utils.mvc.impl.TemplateJstlView;
039:        import org.sakaiproject.metaobj.utils.mvc.intf.VelocityEngineFactory;
040:        import org.sakaiproject.metaobj.utils.xml.SchemaNode;
041:        import org.springframework.beans.BeansException;
042:        import org.springframework.beans.factory.BeanFactoryUtils;
043:        import org.springframework.beans.factory.NoSuchBeanDefinitionException;
044:        import org.springframework.context.ApplicationContextException;
045:
046:        /**
047:         * Created by IntelliJ IDEA.
048:         * User: John Ellis
049:         * Date: Apr 20, 2004
050:         * Time: 3:32:34 PM
051:         * To change this template use File | Settings | File Templates.
052:         */
053:        public class XmlElementView extends TemplateJstlView {
054:
055:            private String templateName = "";
056:            private VelocityEngine velocityEngine;
057:            private Template template;
058:            private String baseUrl = null;
059:
060:            public void render(Map model, HttpServletRequest request,
061:                    HttpServletResponse response) throws Exception {
062:                setBody(prepareTemplateForRendering(model, request, response));
063:                super .render(model, request, response);
064:            }
065:
066:            /**
067:             * Prepare for rendering, and determine the request dispatcher path
068:             * to forward to respectively to include.
069:             * <p>This implementation simply returns the configured URL.
070:             * Subclasses can override this to determine a resource to render,
071:             * typically interpreting the URL in a different manner.
072:             *
073:             * @param request  current HTTP request
074:             * @param response current HTTP response
075:             * @return the request dispatcher path to use
076:             * @throws Exception if preparations failed
077:             * @see #getUrl
078:             * @see org.springframework.web.servlet.view.tiles.TilesView#prepareForRendering
079:             */
080:            protected String prepareTemplateForRendering(Map model,
081:                    HttpServletRequest request, HttpServletResponse response)
082:                    throws Exception {
083:                HomeFactory factory = (HomeFactory) getWebApplicationContext()
084:                        .getBean("homeFactory");
085:
086:                SchemaNode schema = null;
087:                StructuredArtifactHomeInterface home = null;
088:                String schemaName = null;
089:                schemaName = request.getParameter("schema");
090:                if (schemaName == null) {
091:
092:                    schemaName = (String) request.getAttribute("schema");
093:
094:                    if (schemaName == null) {
095:                        schemaName = request.getParameter("artifactType");
096:                    }
097:                }
098:
099:                home = (StructuredArtifactHomeInterface) factory
100:                        .getHome(schemaName);
101:
102:                if (request
103:                        .getAttribute(EditedArtifactStorage.STORED_ARTIFACT_FLAG) != null) {
104:                    EditedArtifactStorage sessionBean = (EditedArtifactStorage) request
105:                            .getSession()
106:                            .getAttribute(
107:                                    EditedArtifactStorage.EDITED_ARTIFACT_STORAGE_SESSION_KEY);
108:
109:                    if (!(sessionBean.getCurrentElement() instanceof  StructuredArtifact)) {
110:                        home = (StructuredArtifactHomeInterface) sessionBean
111:                                .getHome();
112:                        schema = sessionBean.getCurrentSchemaNode();
113:                        schemaName += "." + sessionBean.getCurrentPath();
114:                    }
115:                }
116:
117:                String baseFile = getBaseUrl() + "_" + schemaName;
118:
119:                File genFile = new File(getWebApplicationContext()
120:                        .getServletContext().getRealPath(""), baseFile + ".jsp");
121:                File customFile = new File(getWebApplicationContext()
122:                        .getServletContext().getRealPath(""), baseFile
123:                        + "_custom.jsp");
124:
125:                if (customFile.exists()) {
126:                    return baseFile + "_custom.jsp";
127:                }
128:
129:                if (genFile.exists()) {
130:                    if (genFile.lastModified() > home.getModified().getTime()
131:                            && genFile.lastModified() > getVelocityTemplate()
132:                                    .getLastModified()) {
133:                        return baseFile + ".jsp";
134:                    }
135:                }
136:
137:                return createJspFromTemplate(home, baseFile + ".jsp", genFile,
138:                        schemaName, schema);
139:            }
140:
141:            protected String createJspFromTemplate(
142:                    StructuredArtifactHomeInterface home, String resultFile,
143:                    File jspFile, String schemaName, SchemaNode schema)
144:                    throws Exception {
145:                VelocityContext context = new VelocityContext();
146:
147:                if (schema != null) {
148:                    context.put("schema", new SchemaBean(schema, home
149:                            .getRootNode(), null, home.getType()
150:                            .getDescription()));
151:                } else {
152:                    context.put("schema", new SchemaBean(home.getRootNode(),
153:                            home.getSchema(), schemaName, home.getType()
154:                                    .getDescription()));
155:                }
156:
157:                context.put("instruction", home.getInstruction());
158:
159:                FileWriter output = new FileWriter(jspFile);
160:
161:                getVelocityTemplate().merge(context, output);
162:
163:                output.close();
164:
165:                return resultFile;
166:            }
167:
168:            /**
169:             * Invoked on startup. Looks for a single VelocityConfig bean to
170:             * find the relevant VelocityEngine for this factory.
171:             */
172:            protected void initApplicationContext() throws BeansException {
173:                super .initApplicationContext();
174:
175:                if (this .velocityEngine == null) {
176:                    try {
177:                        VelocityEngineFactory velocityConfig = (VelocityEngineFactory) BeanFactoryUtils
178:                                .beanOfTypeIncludingAncestors(
179:                                        getApplicationContext(),
180:                                        VelocityEngineFactory.class, true, true);
181:                        this .velocityEngine = velocityConfig
182:                                .getVelocityEngine();
183:                    } catch (NoSuchBeanDefinitionException ex) {
184:                        throw new ApplicationContextException(
185:                                "Must define a single VelocityConfig bean in this web application "
186:                                        + "context (may be inherited): VelocityConfigurer is the usual implementation. "
187:                                        + "This bean may be given any name.",
188:                                ex);
189:                    }
190:                }
191:
192:                try {
193:                    // check that we can get the template, even if we might subsequently get it again
194:                    this .template = getVelocityTemplate();
195:                } catch (ResourceNotFoundException ex) {
196:                    throw new ApplicationContextException(
197:                            "Cannot find Velocity template for URL ["
198:                                    + getBaseUrl()
199:                                    + "]: Did you specify the correct resource loader path?",
200:                            ex);
201:                } catch (Exception ex) {
202:                    throw new ApplicationContextException(
203:                            "Cannot load Velocity template for URL ["
204:                                    + getBaseUrl() + "]", ex);
205:                }
206:            }
207:
208:            /**
209:             * Retrieve the Velocity template.
210:             *
211:             * @return the Velocity template to process
212:             * @throws Exception if thrown by Velocity
213:             */
214:            protected Template getVelocityTemplate() throws Exception {
215:                return this .velocityEngine.getTemplate(templateName);
216:            }
217:
218:            public String getTemplateName() {
219:                return templateName;
220:            }
221:
222:            public void setTemplateName(String templateName) {
223:                this .templateName = templateName;
224:            }
225:
226:            public String getBaseUrl() {
227:                return baseUrl;
228:            }
229:
230:            public void setBaseUrl(String baseUrl) {
231:                this.baseUrl = baseUrl;
232:            }
233:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.