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


001:        /**********************************************************************************
002:         * $URL:https://source.sakaiproject.org/svn/osp/trunk/presentation/tool/src/java/org/theospi/portfolio/presentation/control/TemplateBuilderController.java $
003:         * $Id:TemplateBuilderController.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.presentation.control;
021:
022:        import java.io.IOException;
023:        import java.util.ArrayList;
024:        import java.util.Collection;
025:        import java.util.HashMap;
026:        import java.util.Iterator;
027:        import java.util.Map;
028:
029:        import org.sakaiproject.metaobj.shared.mgt.HomeFactory;
030:        import org.sakaiproject.metaobj.shared.mgt.ReadableObjectHome;
031:        import org.sakaiproject.metaobj.shared.mgt.WritableObjectHome;
032:        import org.sakaiproject.metaobj.shared.mgt.home.StructuredArtifactHomeInterface;
033:        import org.sakaiproject.metaobj.shared.model.Id;
034:        import org.sakaiproject.metaobj.shared.model.PersistenceException;
035:        import org.sakaiproject.metaobj.utils.mvc.intf.LoadObjectController;
036:        import org.sakaiproject.metaobj.utils.xml.SchemaNode;
037:        import org.springframework.validation.Errors;
038:        import org.springframework.web.servlet.ModelAndView;
039:        import org.theospi.portfolio.presentation.model.PresentationItemDefinition;
040:        import org.theospi.portfolio.presentation.model.PresentationTemplate;
041:        import org.theospi.portfolio.presentation.model.TemplateFileRef;
042:
043:        public class TemplateBuilderController extends
044:                AbstractPresentationController implements  LoadObjectController {
045:            private WritableObjectHome fileArtifactHome;
046:            private HomeFactory homeFactory;
047:
048:            public ModelAndView handleRequest(Object requestModel, Map request,
049:                    Map session, Map application, Errors errors) {
050:                PresentationTemplate template = (PresentationTemplate) requestModel;
051:                try {
052:                    //    	TODO: 20050810 ContentHosting
053:                    //FileArtifact artifact = (FileArtifact) getFileArtifactHome().load(template.getRenderer());
054:                    //artifact.setSize(template.getMarkup().getBytes().length);
055:                    //artifact.setFile(new ByteArrayInputStream(prepareBody(template.getMarkup()).getBytes()));
056:                    //getFileArtifactHome().store(artifact);
057:                    getPresentationManager().storeTemplate(template);
058:                    Map params = new HashMap();
059:                    params.put("id", template.getId().getValue());
060:                    params.put("_target1", "1");
061:                    params.put("formSubmission", "true");
062:                    return new ModelAndView("success", params);
063:                } catch (PersistenceException e) {
064:                    //TODO is this right ?
065:                    errors.reject("markup", e.getMessage());
066:                    return new ModelAndView("failure");
067:                }
068:            }
069:
070:            public ModelAndView processCancel(Map request, Map session,
071:                    Map application, Object command, Errors errors)
072:                    throws Exception {
073:                PresentationTemplate template = (PresentationTemplate) command;
074:                Map params = new HashMap();
075:                params.put("id", template.getId().getValue());
076:                params.put("_target1", "1");
077:                params.put("formSubmission", "true");
078:                return new ModelAndView("success", params);
079:            }
080:
081:            protected String prepareBody(String body) {
082:                StringBuffer buffer = new StringBuffer();
083:                buffer
084:                        .append("<?xml version=\"1.0\" ?>\n"
085:                                + "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n"
086:                                + "\t\n\t<xsl:template match=\"ospiPresentation\">");
087:                buffer.append(body.replaceAll("\\$\\{(.*?)\\}",
088:                        "<xsl:copy-of select=\"$1\"/>"));
089:                buffer.append("\t</xsl:template>\n\n</xsl:stylesheet>");
090:                return buffer.toString();
091:            }
092:
093:            public Object fillBackingObject(Object incomingModel, Map request,
094:                    Map session, Map application) throws Exception {
095:                PresentationTemplate template = (PresentationTemplate) incomingModel;
096:                template = getPresentationManager().getPresentationTemplate(
097:                        template.getId());
098:
099:                Map elements = new HashMap();
100:
101:                for (Iterator i = template.getSortedItems().iterator(); i
102:                        .hasNext();) {
103:                    PresentationItemDefinition itemDef = (PresentationItemDefinition) i
104:                            .next();
105:                    elements.put(itemDef.getName(), findPaths(itemDef));
106:                }
107:
108:                request.put("elements", elements);
109:
110:                Map images = new HashMap();
111:
112:                for (Iterator i = template.getFiles().iterator(); i.hasNext();) {
113:                    TemplateFileRef fileRef = (TemplateFileRef) i.next();
114:                    //       TODO: 20050810 ContentHosting
115:                    //if (fileRef.getFileArtifact() instanceof FileArtifact){
116:                    //   FileArtifact fileArtifact = (FileArtifact)fileRef.getFileArtifact();
117:                    //   if (fileArtifact.getMimeType().getPrimaryType().equals("image")){
118:                    //      images.put(fileArtifact.getDisplayName(),fileArtifact.getExternalUri());
119:                    //   }
120:                    //}
121:                }
122:
123:                session.put("images", images);
124:
125:                return template;
126:            }
127:
128:            /**
129:             * places ${ } around each path
130:             * @param paths
131:             * @return
132:             */
133:            protected Collection tagPaths(Collection paths) {
134:                Collection taggedPaths = new ArrayList();
135:                for (Iterator i = paths.iterator(); i.hasNext();) {
136:                    taggedPaths.add("${" + i.next() + "}");
137:                }
138:                return taggedPaths;
139:            }
140:
141:            /**
142:             * creates collection of possible xpaths associated with the rendered xml for this item definition
143:             * @param itemDef
144:             * @return
145:             */
146:            protected Collection findPaths(PresentationItemDefinition itemDef) {
147:                ReadableObjectHome home = getHomeFactory().getHome(
148:                        itemDef.getType());
149:                Collection paths = new ArrayList();
150:
151:                paths.add(itemDef.getName() + "/artifact/metaData/id");
152:                paths.add(itemDef.getName() + "/artifact/metaData/displayName");
153:                paths.add(itemDef.getName() + "/artifact/metaData/type/id");
154:                paths.add(itemDef.getName()
155:                        + "/artifact/metaData/type/description");
156:
157:                if (home instanceof  StructuredArtifactHomeInterface) {
158:                    StructuredArtifactHomeInterface structuredArtifactHome = (StructuredArtifactHomeInterface) home;
159:                    addPath(paths, structuredArtifactHome.getRootSchema(),
160:                            itemDef.getName() + "/artifact/structuredData");
161:                } else if (home != null
162:                        && home.getType().getId().equals(
163:                                getFileArtifactHome().getType().getId())) {
164:                    //TODO deal with technical metadata
165:                    paths.add(itemDef.getName() + "/artifact/fileArtifact/uri");
166:                }
167:                return tagPaths(paths);
168:            }
169:
170:            /**
171:             * recursively finds all possible xpaths for given schema
172:             * @param paths
173:             * @param node
174:             * @param parent
175:             */
176:            protected void addPath(Collection paths, SchemaNode node,
177:                    String parent) {
178:                String path = parent + "/" + node.getName();
179:                paths.add(path);
180:                if (node.getChildren() != null && node.getChildren().size() > 0) {
181:                    for (Iterator i = node.getChildren().iterator(); i
182:                            .hasNext();) {
183:                        addPath(paths, (SchemaNode) i.next(), path);
184:                    }
185:                }
186:            }
187:
188:            /**
189:             * loads contents of a file into a string
190:             * @param fileId
191:             * @return
192:             */
193:            protected String loadContents(Id fileId) throws IOException,
194:                    PersistenceException {
195:                //	 TODO: 20050810 ContentHosting
196:                //FileArtifact artifact = (FileArtifact)getFileArtifactHome().load(fileId);
197:                //BufferedReader reader = new BufferedReader(new InputStreamReader(artifact.getFile()));
198:                StringBuffer buffer = new StringBuffer();
199:                //String line;
200:                //while ((line = reader.readLine()) != null){
201:                //   if (line == null) break;
202:                //   buffer.append(line + "\n");
203:                //}
204:                return buffer.toString();
205:            }
206:
207:            public WritableObjectHome getFileArtifactHome() {
208:                return fileArtifactHome;
209:            }
210:
211:            public void setFileArtifactHome(WritableObjectHome fileArtifactHome) {
212:                this .fileArtifactHome = fileArtifactHome;
213:            }
214:
215:            public HomeFactory getHomeFactory() {
216:                return homeFactory;
217:            }
218:
219:            public void setHomeFactory(HomeFactory homeFactory) {
220:                this.homeFactory = homeFactory;
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.