Author: tmjee
Date: Thu Jun 8 08:29:36 2006
New Revision: 412774
URL: http://svn.apache.org/viewvc?rev=412774&view=rev
Log:
- added a simple example into showcase demonstrating the usage of a
custom freemarker manager instantiated using Spring.
- the custom freemarker manager have a custom util class injected into
it through Spring's constructor injection
- a simple ftl page just uses freemarker interpolation to display some
date and time put into freemarker's model by the custom freemarker
manager
Added:
struts/action2/trunk/apps/showcase/src/main/java/org/apache/struts/action2/showcase/freemarker/
struts/action2/trunk/apps/showcase/src/main/java/org/apache/struts/action2/showcase/freemarker/CustomFreemarkerManager.java
(with props)
struts/action2/trunk/apps/showcase/src/main/java/org/apache/struts/action2/showcase/freemarker/CustomFreemarkerManagerUtil.java
(with props)
struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/classes/xwork-freemarker.xml
(with props)
Modified:
struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/applicationContext.xml
struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/classes/struts.properties
struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/classes/xwork.xml
struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/decorators/main.jsp
struts/action2/trunk/apps/showcase/src/main/webapp/showcase.jsp
Added:
struts/action2/trunk/apps/showcase/src/main/java/org/apache/struts/action2/showcase/freemarker/CustomFreemarkerManager.java
URL:
http://svn.apache.org/viewvc/struts/action2/trunk/apps/showcase/src/main/java/org/apache/struts/action2/showcase/freemarker/CustomFreemarkerManager.java?rev=412774&view=auto
==============================================================================
---
struts/action2/trunk/apps/showcase/src/main/java/org/apache/struts/action2/showcase/freemarker/CustomFreemarkerManager.java
(added)
+++
struts/action2/trunk/apps/showcase/src/main/java/org/apache/struts/action2/showcase/freemarker/CustomFreemarkerManager.java
Thu Jun 8 08:29:36 2006
@@ -0,0 +1,54 @@
+/*
+ * $Id: FileUploadAction.java 394498 2006-04-16 15:28:06Z tmjee $
+ *
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.apache.struts.action2.showcase.freemarker;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.struts.action2.views.freemarker.FreemarkerManager;
+import org.apache.struts.action2.views.freemarker.ScopesHashModel;
+
+import com.opensymphony.xwork.util.OgnlValueStack;
+
+/**
+ * This is an example of a custom FreemarkerManager, mean to be
+ * instantiated through Spring.
+ * <p/>
+ *
+ * It will add into Freemarker's model
+ * an utility class called [EMAIL PROTECTED] CustomFreemarkerManagerUtil} as a
simple
+ * example demonstrating how to extends FreemarkerManager.
+ * <p/>
+ *
+ * The [EMAIL PROTECTED] CustomFreemarkerManagerUtil} will be created by
Spring and
+ * injected through constructor injection.
+ * <p/>
+ */
+public class CustomFreemarkerManager extends FreemarkerManager {
+
+ private CustomFreemarkerManagerUtil util;
+
+ public CustomFreemarkerManager(CustomFreemarkerManagerUtil util) {
+ this.util = util;
+ }
+
+ public void populateContext(ScopesHashModel model, OgnlValueStack
stack, Object action, HttpServletRequest request, HttpServletResponse response)
{
+ super.populateContext(model, stack, action, request, response);
+ model.put("customFreemarkerManagerUtil", util);
+ }
+}
Propchange:
struts/action2/trunk/apps/showcase/src/main/java/org/apache/struts/action2/showcase/freemarker/CustomFreemarkerManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
struts/action2/trunk/apps/showcase/src/main/java/org/apache/struts/action2/showcase/freemarker/CustomFreemarkerManagerUtil.java
URL:
http://svn.apache.org/viewvc/struts/action2/trunk/apps/showcase/src/main/java/org/apache/struts/action2/showcase/freemarker/CustomFreemarkerManagerUtil.java?rev=412774&view=auto
==============================================================================
---
struts/action2/trunk/apps/showcase/src/main/java/org/apache/struts/action2/showcase/freemarker/CustomFreemarkerManagerUtil.java
(added)
+++
struts/action2/trunk/apps/showcase/src/main/java/org/apache/struts/action2/showcase/freemarker/CustomFreemarkerManagerUtil.java
Thu Jun 8 08:29:36 2006
@@ -0,0 +1,39 @@
+/*
+ * $Id: FileUploadAction.java 394498 2006-04-16 15:28:06Z tmjee $
+ *
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.apache.struts.action2.showcase.freemarker;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * This class is just a simple util that gets injected into
+ * [EMAIL PROTECTED] CustomFreemarkerManager} through Spring's constructor
+ * injection, serving as a simple example in SAF2's Showcase.
+ */
+public class CustomFreemarkerManagerUtil {
+
+ public String getTodayDate() {
+ SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
+ return sdf.format(new Date());
+ }
+
+ public String getTimeNow() {
+ SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss");
+ return sdf.format(new Date());
+ }
+}
Propchange:
struts/action2/trunk/apps/showcase/src/main/java/org/apache/struts/action2/showcase/freemarker/CustomFreemarkerManagerUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/applicationContext.xml
URL:
http://svn.apache.org/viewvc/struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/applicationContext.xml?rev=412774&r1=412773&r2=412774&view=diff
==============================================================================
---
struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/applicationContext.xml
(original)
+++
struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/applicationContext.xml
Thu Jun 8 08:29:36 2006
@@ -11,4 +11,14 @@
<bean id="personManager"
class="org.apache.struts.action2.showcase.person.PersonManager"
singleton="true"/>
+ <!-- Showcase's CustomFreemarkerManager example -->
+ <bean id="customFreemarkerManager"
class="org.apache.struts.action2.showcase.freemarker.CustomFreemarkerManager">
+ <constructor-arg index="0">
+ <ref bean="customFreemarkerManagerUtil" />
+ </constructor-arg>
+ </bean>
+ <bean id="customFreemarkerManagerUtil"
class="org.apache.struts.action2.showcase.freemarker.CustomFreemarkerManagerUtil"
/>
+
+
</beans>
+
Modified:
struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/classes/struts.properties
URL:
http://svn.apache.org/viewvc/struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/classes/struts.properties?rev=412774&r1=412773&r2=412774&view=diff
==============================================================================
---
struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/classes/struts.properties
(original)
+++
struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/classes/struts.properties
Thu Jun 8 08:29:36 2006
@@ -6,3 +6,4 @@
struts.custom.i18n.resources=globalMessages
#struts.action.extension=jspa
struts.url.http.port = 8080
+struts.freemarker.manager.classname=customFreemarkerManager
Added:
struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/classes/xwork-freemarker.xml
URL:
http://svn.apache.org/viewvc/struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/classes/xwork-freemarker.xml?rev=412774&view=auto
==============================================================================
---
struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/classes/xwork-freemarker.xml
(added)
+++
struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/classes/xwork-freemarker.xml
Thu Jun 8 08:29:36 2006
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!DOCTYPE xwork PUBLIC
+ "-//OpenSymphony Group//XWork 1.1.1//EN"
+ "http://www.opensymphony.com/xwork/xwork-1.1.1.dtd">
+
+
+<xwork>
+ <include file="struts-default.xml" />
+
+ <package name="freemarker" namespace="/freemarker"
extends="struts-default">
+ <action name="customFreemarkerManagerDemo">
+ <result
type="freemarker">/freemarker/customFreemarkerManagerUsage.ftl</result>
+ </action>
+ </package>
+</xwork>
Propchange:
struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/classes/xwork-freemarker.xml
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/classes/xwork.xml
URL:
http://svn.apache.org/viewvc/struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/classes/xwork.xml?rev=412774&r1=412773&r2=412774&view=diff
==============================================================================
---
struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/classes/xwork.xml
(original)
+++
struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/classes/xwork.xml
Thu Jun 8 08:29:36 2006
@@ -37,6 +37,8 @@
<include file="xwork-filedownload.xml" />
<include file="xwork-conversion.xml" />
+
+ <include file="xwork-freemarker.xml" />
<package name="default" extends="struts-default">
<interceptors>
Modified:
struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/decorators/main.jsp
URL:
http://svn.apache.org/viewvc/struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/decorators/main.jsp?rev=412774&r1=412773&r2=412774&view=diff
==============================================================================
---
struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/decorators/main.jsp
(original)
+++
struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/decorators/main.jsp
Thu Jun 8 08:29:36 2006
@@ -77,6 +77,7 @@
<li><a href="<saf:url
value="/filedownload/index.jsp"/>">File Download</a></li>
<li><a href="<saf:url
value="/conversion/index.jsp"/>"/>Conversion</a></li>
<li><a href="<saf:url action="index"
namespace="/jsf"/>">JSF</a></li>
+ <li><a href="<saf:url
value="/freemarker/index.jsp"/>">Freemarker</a>
<li class="last"><a href="<saf:url
value="/help.jsp"/>">Help</a></li>
</ul>
</div>
Modified: struts/action2/trunk/apps/showcase/src/main/webapp/showcase.jsp
URL:
http://svn.apache.org/viewvc/struts/action2/trunk/apps/showcase/src/main/webapp/showcase.jsp?rev=412774&r1=412773&r2=412774&view=diff
==============================================================================
--- struts/action2/trunk/apps/showcase/src/main/webapp/showcase.jsp (original)
+++ struts/action2/trunk/apps/showcase/src/main/webapp/showcase.jsp Thu Jun 8
08:29:36 2006
@@ -56,6 +56,9 @@
<!-- model-driven -->
<li><saf:url id="url" action="modelDriven" namespace="/modelDriven"
method="input"/><saf:a href="%{url}">Model Driven Example</saf:a>
+
+ <!-- freemarker -->
+ <li><saf:url id="url" value="/freemarker" /><saf:a
href="%{#url}">Freemarker Example</saf:a></li>
</ul>
</p>