I never tried, thanks!

Jacques

From: "Adrian Crum" <adri...@hlmksw.com>
Use a file: URL.

-Adrian

Jacques Le Roux wrote:
I'm not sure it's the reason but with the Freemarker include directive you can't get a file out of the webapp root (there is no real absolute path option)

Jacques

From: "Adrian Crum" <adri...@hlmksw.com>
Why is this necessary? Freemarker already has an include directive.

-Adrian

lekt...@apache.org wrote:
Author: lektran
Date: Mon Jun 15 10:18:55 2009
New Revision: 784712

URL: http://svn.apache.org/viewvc?rev=784712&view=rev
Log:
Add a new template transform for including templates in freemarker templates 
using component notation:
<@includeTemplate location="component://common/webcommon/includes/cctypes.ftl"/>

Added:
    
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/ftl/IncludeTemplateTransform.java
   (with props)
Modified:
    ofbiz/trunk/framework/webapp/config/freemarkerTransforms.properties

Modified: ofbiz/trunk/framework/webapp/config/freemarkerTransforms.properties
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/config/freemarkerTransforms.properties?rev=784712&r1=784711&r2=784712&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/config/freemarkerTransforms.properties (original)
+++ ofbiz/trunk/framework/webapp/config/freemarkerTransforms.properties Mon Jun 
15 10:18:55 2009
@@ -27,3 +27,4 @@
 ofbizAmount=org.ofbiz.webapp.ftl.OfbizAmountTransform
 setRequestAttribute=org.ofbiz.webapp.ftl.SetRequestAttributeMethod
 renderWrappedText=org.ofbiz.webapp.ftl.RenderWrappedTextTransform
+includeTemplate=org.ofbiz.webapp.ftl.IncludeTemplateTransform

Added: 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/ftl/IncludeTemplateTransform.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/ftl/IncludeTemplateTransform.java?rev=784712&view=auto
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/ftl/IncludeTemplateTransform.java (added)
+++ 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/ftl/IncludeTemplateTransform.java
 Mon Jun 15 10:18:55 2009
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ 
*******************************************************************************/
+package org.ofbiz.webapp.ftl;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Map;
+
+import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.base.util.template.FreeMarkerWorker;
+
+import freemarker.core.Environment;
+import freemarker.template.SimpleScalar;
+import freemarker.template.Template;
+import freemarker.template.TemplateException;
+import freemarker.template.TemplateModelException;
+import freemarker.template.TemplateTransformModel;
+
+public class IncludeTemplateTransform implements TemplateTransformModel {
+
+    public final static String module = 
IncludeTemplateTransform.class.getName();
+
+    public Writer getWriter(final Writer out, Map args) {
+        final StringBuilder buf = new StringBuilder();
+        final String templateLocation = this.getTemplateLocation(args);
+        +        return new Writer(out) {
+            public void write(char cbuf[], int off, int len) {
+                buf.append(cbuf, off, len);
+            }
+
+            public void flush() throws IOException {
+                out.flush();
+            }
+
+            public void close() throws IOException {
+                try {
+                    Environment env = Environment.getCurrentEnvironment();
+                    Template template = 
FreeMarkerWorker.getTemplate(templateLocation);
+                    env.include(template);
+                } catch (TemplateModelException e) {
+                    throw new IOException(e.getMessage());
+                } catch (TemplateException e) {
+                    throw new IOException(e.getMessage());
+                }
+            }
+        };
+    }
+    +    private String getTemplateLocation(Map args) {
+        Object templateLocationObj = args.get("location");
+        if (templateLocationObj != null && templateLocationObj instanceof 
SimpleScalar) {
+            return ((SimpleScalar) templateLocationObj).getAsString();
+        }
+        return null;
+    }
+}

Propchange: 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/ftl/IncludeTemplateTransform.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/ftl/IncludeTemplateTransform.java
------------------------------------------------------------------------------
    svn:keywords = "Date Rev Author URL Id"

Propchange: 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/ftl/IncludeTemplateTransform.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain










Reply via email to