myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jl...@apache.org
Subject svn commit: r551685 - in /myfaces/tomahawk/trunk/sandbox/core: ./ src/main/java/org/apache/myfaces/renderkit/freemarker/ src/main/java/org/apache/myfaces/renderkit/html/ext/ src/main/resources-facesconfig/META-INF/ src/main/resources/org/apache/myfaces...
Date Thu, 28 Jun 2007 19:57:14 GMT
Author: jlust
Date: Thu Jun 28 12:57:13 2007
New Revision: 551685

URL: http://svn.apache.org/viewvc?view=rev&rev=551685
Log:
added Freemarker-based renderer

Added:
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/renderkit/freemarker/
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/renderkit/freemarker/FreemarkerRenderer.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/renderkit/html/ext/HtmlOutputTextRenderer.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/renderkit/
    myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/renderkit/html/
    myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/renderkit/html/ext/
    myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/renderkit/html/ext/template/
    myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/renderkit/html/ext/template/outputText_begin.ftl
    myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/renderkit/html/ext/template/outputText_children.ftl
    myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/renderkit/html/ext/template/outputText_end.ftl
Modified:
    myfaces/tomahawk/trunk/sandbox/core/pom.xml
    myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml

Modified: myfaces/tomahawk/trunk/sandbox/core/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/pom.xml?view=diff&rev=551685&r1=551684&r2=551685
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/pom.xml (original)
+++ myfaces/tomahawk/trunk/sandbox/core/pom.xml Thu Jun 28 12:57:13 2007
@@ -108,6 +108,12 @@
             <version>2.3</version>
             <scope>provided</scope>
         </dependency>
+        
+        <dependency>
+        	<groupId>org.freemarker</groupId>
+        	<artifactId>freemarker</artifactId>
+        	<version>2.3.10</version>
+        </dependency>
 
         <!-- test dependencies -->
 

Added: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/renderkit/freemarker/FreemarkerRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/renderkit/freemarker/FreemarkerRenderer.java?view=auto&rev=551685
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/renderkit/freemarker/FreemarkerRenderer.java
(added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/renderkit/freemarker/FreemarkerRenderer.java
Thu Jun 28 12:57:13 2007
@@ -0,0 +1,72 @@
+package org.apache.myfaces.renderkit.freemarker;
+
+import java.io.IOException;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.render.Renderer;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import freemarker.cache.ClassTemplateLoader;
+import freemarker.cache.TemplateLoader;
+import freemarker.template.Configuration;
+import freemarker.template.DefaultObjectWrapper;
+import freemarker.template.Template;
+import freemarker.template.TemplateException;
+
+public abstract class FreemarkerRenderer extends Renderer
+{
+    private static final Log log = LogFactory.getLog(FreemarkerRenderer.class);
+
+    /**
+     * @see javax.faces.render.Renderer#encodeBegin(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
+     */
+    public void encodeBegin(FacesContext context, UIComponent component) throws IOException
+    {
+        if (!component.isRendered()) return;
+        encodeTemplate(context, component, getTemplateName(context, component) + "_begin.ftl");
+    }
+
+    /**
+     * @see javax.faces.render.Renderer#encodeChildren(javax.faces.context.FacesContext,
javax.faces.component.UIComponent)
+     */
+    public void encodeChildren(FacesContext context, UIComponent component) throws IOException
+    {
+        if (!component.isRendered()) return;
+        if (!getRendersChildren()) return;
+        encodeTemplate(context, component, getTemplateName(context, component) + "_children.ftl");
+    }
+
+    /**
+     * @see javax.faces.render.Renderer#encodeEnd(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
+     */
+    public void encodeEnd(FacesContext context, UIComponent component) throws IOException
+    {
+        if (!component.isRendered()) return;
+        encodeTemplate(context, component, getTemplateName(context, component) + "_end.ftl");
+    }
+
+    protected void encodeTemplate(FacesContext context, UIComponent component, String template)
throws IOException {
+        Configuration cfg = new Configuration();
+        log.info(getClass().getResource("templates/outputText_begin.ftl"));
+        TemplateLoader templateLoader = new ClassTemplateLoader(getClass(), "template");
+        cfg.setTemplateLoader(templateLoader);
+        cfg.setObjectWrapper(new DefaultObjectWrapper());
+        Template temp = cfg.getTemplate(template);
+        try
+        {
+            temp.process(getDatamodel(context, component), context.getResponseWriter());
+        }
+        catch (TemplateException e)
+        {
+            throw new IOException(e.getMessage());
+        }
+    }
+    
+    protected abstract Object getDatamodel(FacesContext context, UIComponent component);
+    protected abstract String getTemplateName(FacesContext context, UIComponent component);
+    
+    
+}

Added: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/renderkit/html/ext/HtmlOutputTextRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/renderkit/html/ext/HtmlOutputTextRenderer.java?view=auto&rev=551685
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/renderkit/html/ext/HtmlOutputTextRenderer.java
(added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/renderkit/html/ext/HtmlOutputTextRenderer.java
Thu Jun 28 12:57:13 2007
@@ -0,0 +1,37 @@
+package org.apache.myfaces.renderkit.html.ext;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIOutput;
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.renderkit.freemarker.FreemarkerRenderer;
+
+public class HtmlOutputTextRenderer extends FreemarkerRenderer
+{
+
+    protected Object getDatamodel(FacesContext context, UIComponent component)
+    {
+        UIOutput outputText = (UIOutput)component;
+        Map datamodel = new HashMap();
+        datamodel.put("text", outputText.getValue());
+        return datamodel;
+    }
+
+    protected String getTemplateName(FacesContext context,
+            UIComponent component)
+    {
+        return "outputText";
+    }
+
+    /**
+     * @see javax.faces.render.Renderer#getRendersChildren()
+     */
+    public boolean getRendersChildren()
+    {
+        return true;
+    }
+
+}

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml?view=diff&rev=551685&r1=551684&r2=551685
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml
(original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml
Thu Jun 28 12:57:13 2007
@@ -328,6 +328,12 @@
 
     <!-- extended standard renderers -->
      <renderer>
+     	<component-family>javax.faces.Output</component-family>
+     	<renderer-type>javax.faces.Text</renderer-type>
+     	<renderer-class>org.apache.myfaces.renderkit.html.ext.HtmlOutputTextRenderer</renderer-class>
+     </renderer>
+    
+     <renderer>
          <component-family>javax.faces.Form</component-family>
          <renderer-type>javax.faces.Form</renderer-type>
          <renderer-class>org.apache.myfaces.renderkit.html.ext.HtmlFormRenderer</renderer-class>

Added: myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/renderkit/html/ext/template/outputText_begin.ftl
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/renderkit/html/ext/template/outputText_begin.ftl?view=auto&rev=551685
==============================================================================
    (empty)

Added: myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/renderkit/html/ext/template/outputText_children.ftl
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/renderkit/html/ext/template/outputText_children.ftl?view=auto&rev=551685
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/renderkit/html/ext/template/outputText_children.ftl
(added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/renderkit/html/ext/template/outputText_children.ftl
Thu Jun 28 12:57:13 2007
@@ -0,0 +1 @@
+${text}
\ No newline at end of file

Added: myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/renderkit/html/ext/template/outputText_end.ftl
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/renderkit/html/ext/template/outputText_end.ftl?view=auto&rev=551685
==============================================================================
    (empty)



Mime
View raw message