Source Code Cross Referenced for EditRenderSubContentTransform.java in  » ERP-CRM-Financial » ofbiz » org » ofbiz » content » webapp » ftl » 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.content.webapp.ftl 
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.content.webapp.ftl;
019:
020:        import java.io.IOException;
021:        import java.io.Writer;
022:        import java.sql.Timestamp;
023:        import java.util.List;
024:        import java.util.Locale;
025:        import java.util.Map;
026:
027:        import org.ofbiz.base.util.Debug;
028:        import org.ofbiz.base.util.GeneralException;
029:        import org.ofbiz.base.util.UtilDateTime;
030:        import org.ofbiz.base.util.UtilMisc;
031:        import org.ofbiz.base.util.UtilValidate;
032:        import org.ofbiz.base.util.template.FreeMarkerWorker;
033:        import org.ofbiz.content.content.ContentWorker;
034:        import org.ofbiz.entity.GenericDelegator;
035:        import org.ofbiz.entity.GenericEntityException;
036:        import org.ofbiz.entity.GenericValue;
037:        import org.ofbiz.service.LocalDispatcher;
038:
039:        import freemarker.core.Environment;
040:        import freemarker.template.TemplateTransformModel;
041:
042:        /**
043:         * EditRenderSubContentTransform - Freemarker Transform for URLs (links)
044:         * 
045:         * This is an interactive FreeMarker tranform that allows the user to modify the contents that are placed within it.
046:         */
047:        public class EditRenderSubContentTransform implements 
048:                TemplateTransformModel {
049:
050:            public static final String module = EditRenderSubContentTransform.class
051:                    .getName();
052:
053:            /**
054:             * A wrapper for the FreeMarkerWorker version.
055:             */
056:            public static Object getWrappedObject(String varName,
057:                    Environment env) {
058:                return FreeMarkerWorker.getWrappedObject(varName, env);
059:            }
060:
061:            public static String getArg(Map args, String key, Environment env) {
062:                return FreeMarkerWorker.getArg(args, key, env);
063:            }
064:
065:            public static String getArg(Map args, String key, Map ctx) {
066:                return FreeMarkerWorker.getArg(args, key, ctx);
067:            }
068:
069:            public Writer getWriter(final Writer out, Map args) {
070:                final StringBuffer buf = new StringBuffer();
071:                final Environment env = Environment.getCurrentEnvironment();
072:                Map ctx = (Map) FreeMarkerWorker.getWrappedObject("context",
073:                        env);
074:                final String editTemplate = getArg(args, "editTemplate", ctx);
075:                final String wrapTemplateId = getArg(args, "wrapTemplateId",
076:                        ctx);
077:                final String mapKey = getArg(args, "mapKey", ctx);
078:                final String templateContentId = getArg(args,
079:                        "templateContentId", ctx);
080:                final String subContentId = getArg(args, "subContentId", ctx);
081:                String subDataResourceTypeIdTemp = getArg(args,
082:                        "subDataResourceTypeId", ctx);
083:                final String contentId = getArg(args, "contentId", ctx);
084:
085:                final Locale locale = (Locale) FreeMarkerWorker
086:                        .getWrappedObject("locale", env);
087:                String mimeTypeIdTemp = getArg(args, "mimeTypeId", ctx);
088:                final String rootDir = getArg(args, "rootDir", ctx);
089:                final String webSiteId = getArg(args, "webSiteId", ctx);
090:                final String https = getArg(args, "https", ctx);
091:                final LocalDispatcher dispatcher = (LocalDispatcher) FreeMarkerWorker
092:                        .getWrappedObject("dispatcher", env);
093:                final GenericDelegator delegator = (GenericDelegator) FreeMarkerWorker
094:                        .getWrappedObject("delegator", env);
095:                final GenericValue userLogin = (GenericValue) FreeMarkerWorker
096:                        .getWrappedObject("userLogin", env);
097:                GenericValue subContentDataResourceViewTemp = (GenericValue) FreeMarkerWorker
098:                        .getWrappedObject("subContentDataResourceView", env);
099:                //final HttpServletRequest request = (HttpServletRequest)FreeMarkerWorker.getWrappedObject("request", env);
100:
101:                ctx.put("mapKey", mapKey);
102:                ctx.put("subDataResourceTypeIdTemp", subDataResourceTypeIdTemp);
103:                ctx.put("contentId", contentId);
104:                ctx.put("templateContentId", templateContentId);
105:                ctx.put("locale", locale);
106:
107:                // This transform does not need information about the subContent until the
108:                // close action, but any embedded RenderDataResourceTransformation will need it
109:                // and since it cannot be passed back up from that transform, the subContent view
110:                // is gotten here and made available to underlying transforms to save overall
111:                // processing time.
112:                GenericValue parentContent = null;
113:                //ctx.put("userLogin", userLogin);
114:                List assocTypes = UtilMisc.toList("SUB_CONTENT");
115:                Timestamp fromDate = UtilDateTime.nowTimestamp();
116:                if (subContentDataResourceViewTemp == null) {
117:                    try {
118:                        subContentDataResourceViewTemp = ContentWorker
119:                                .getSubContent(delegator, contentId, mapKey,
120:                                        subContentId, userLogin, assocTypes,
121:                                        fromDate);
122:                    } catch (IOException e) {
123:                        Debug.logError(e, "Error getting sub-content", module);
124:                        throw new RuntimeException(e.getMessage());
125:                    }
126:                }
127:
128:                final GenericValue subContentDataResourceView = subContentDataResourceViewTemp;
129:
130:                String dataResourceIdTemp = null;
131:                String subContentIdSubTemp = null;
132:                if (subContentDataResourceView != null
133:                        && subContentDataResourceView.get("contentId") != null) {
134:
135:                    dataResourceIdTemp = (String) subContentDataResourceView
136:                            .get("drDataResourceId");
137:                    subContentIdSubTemp = (String) subContentDataResourceView
138:                            .get("contentId");
139:                    if (UtilValidate.isEmpty(subDataResourceTypeIdTemp)) {
140:                        subDataResourceTypeIdTemp = (String) subContentDataResourceView
141:                                .get("drDataResourceTypeId");
142:                    }
143:                    if (UtilValidate.isEmpty(mimeTypeIdTemp)) {
144:                        mimeTypeIdTemp = (String) subContentDataResourceView
145:                                .get("mimeTypeId");
146:                        if (UtilValidate.isEmpty(mimeTypeIdTemp)
147:                                && UtilValidate.isNotEmpty(contentId)) { // will need these below
148:                            try {
149:                                parentContent = delegator.findByPrimaryKey(
150:                                        "Content", UtilMisc.toMap("contentId",
151:                                                contentId));
152:                                if (parentContent != null) {
153:                                    mimeTypeIdTemp = (String) parentContent
154:                                            .get("mimeTypeId");
155:                                }
156:                            } catch (GenericEntityException e) {
157:                                throw new RuntimeException(e.getMessage());
158:                            }
159:                        }
160:
161:                    }
162:                    ctx.put("subContentId", subContentIdSubTemp);
163:                    ctx.put("drDataResourceId", dataResourceIdTemp);
164:                    ctx.put("subContentDataResourceView",
165:                            subContentDataResourceView);
166:                    ctx.put("mimeTypeId", mimeTypeIdTemp);
167:                    //request.setAttribute("drDataResourceId", subContentDataResourceView.get("drDataResourceId"));
168:                } else {
169:                    ctx.put("subContentId", null);
170:                    ctx.put("drDataResourceId", null);
171:                    ctx.put("subContentDataResourceView", null);
172:                    ctx.put("mimeTypeId", null);
173:                    //request.setAttribute("drDataResourceId", null);
174:                }
175:
176:                final String dataResourceId = dataResourceIdTemp;
177:                final String subContentIdSub = subContentIdSubTemp;
178:                //final GenericValue finalSubContentView = subContentDataResourceView;
179:                //final GenericValue content = parentContent;
180:                final Map templateContext = ctx;
181:                final String mimeTypeId = mimeTypeIdTemp;
182:                final String subDataResourceTypeId = subDataResourceTypeIdTemp;
183:
184:                return new Writer(out) {
185:
186:                    public void write(char cbuf[], int off, int len) {
187:                        buf.append(cbuf, off, len);
188:                    }
189:
190:                    public void flush() throws IOException {
191:                        out.flush();
192:                    }
193:
194:                    public void close() throws IOException {
195:                        String wrappedFTL = buf.toString();
196:                        if (editTemplate != null
197:                                && editTemplate.equalsIgnoreCase("true")) {
198:                            if (UtilValidate.isNotEmpty(wrapTemplateId)) {
199:                                templateContext.put("wrappedFTL", wrappedFTL);
200:                                //ServletContext servletContext = (ServletContext)request.getSession().getServletContext();
201:                                //String rootDir = servletContext.getRealPath("/");
202:                                templateContext.put("webSiteId", webSiteId);
203:                                templateContext.put("https", https);
204:                                templateContext.put("rootDir", rootDir);
205:
206:                                Map templateRoot = FreeMarkerWorker
207:                                        .createEnvironmentMap(env);
208:
209:                                templateRoot.put("wrapDataResourceId",
210:                                        dataResourceId);
211:                                templateRoot.put("wrapDataResourceTypeId",
212:                                        subDataResourceTypeId);
213:                                templateRoot.put("wrapContentIdTo", contentId);
214:                                templateRoot.put("wrapSubContentId",
215:                                        subContentIdSub);
216:                                templateRoot.put("wrapMimeTypeId", mimeTypeId);
217:                                templateRoot.put("wrapMapKey", mapKey);
218:                                templateRoot.put("context", templateContext);
219:
220:                                try {
221:                                    ContentWorker.renderContentAsText(
222:                                            dispatcher, delegator,
223:                                            wrapTemplateId, out, templateRoot,
224:                                            locale, mimeTypeId, false);
225:                                } catch (IOException e) {
226:                                    Debug.logError(e, "Error rendering content"
227:                                            + e.getMessage(), module);
228:                                    throw new IOException(
229:                                            "Error rendering content"
230:                                                    + e.toString());
231:                                } catch (GeneralException e2) {
232:                                    Debug.logError(e2,
233:                                            "Error rendering content"
234:                                                    + e2.getMessage(), module);
235:                                    throw new IOException(
236:                                            "Error rendering content"
237:                                                    + e2.toString());
238:                                }
239:
240:                                Map ctx = (Map) FreeMarkerWorker
241:                                        .getWrappedObject("context", env);
242:                                templateContext.put("contentId", contentId);
243:                                templateContext.put("locale", locale);
244:                                templateContext.put("mapKey", null);
245:                                templateContext.put("subContentId", null);
246:                                templateContext.put("templateContentId", null);
247:                                templateContext.put("subDataResourceTypeId",
248:                                        null);
249:                                templateContext.put("mimeTypeId", null);
250:                                templateContext.put("wrappedFTL", null);
251:                            }
252:                        } else {
253:                            out.write(wrappedFTL);
254:                        }
255:                    }
256:                };
257:            }
258:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.