diff --git a/apps/showcase/src/main/java/org/apache/struts/action2/showcase/freemarker/CustomFreemarkerManager.java b/apps/showcase/src/main/java/org/apache/struts/action2/showcase/freemarker/CustomFreemarkerManager.java new file mode 100644 index 000000000..4121d49bb --- /dev/null +++ b/apps/showcase/src/main/java/org/apache/struts/action2/showcase/freemarker/CustomFreemarkerManager.java @@ -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. + *

+ * + * It will add into Freemarker's model + * an utility class called {@link CustomFreemarkerManagerUtil} as a simple + * example demonstrating how to extends FreemarkerManager. + *

+ * + * The {@link CustomFreemarkerManagerUtil} will be created by Spring and + * injected through constructor injection. + *

+ */ +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); + } +} diff --git a/apps/showcase/src/main/java/org/apache/struts/action2/showcase/freemarker/CustomFreemarkerManagerUtil.java b/apps/showcase/src/main/java/org/apache/struts/action2/showcase/freemarker/CustomFreemarkerManagerUtil.java new file mode 100644 index 000000000..7bb6758fc --- /dev/null +++ b/apps/showcase/src/main/java/org/apache/struts/action2/showcase/freemarker/CustomFreemarkerManagerUtil.java @@ -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 + * {@link 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()); + } +} diff --git a/apps/showcase/src/main/webapp/WEB-INF/applicationContext.xml b/apps/showcase/src/main/webapp/WEB-INF/applicationContext.xml index 6629f243e..421205fe6 100644 --- a/apps/showcase/src/main/webapp/WEB-INF/applicationContext.xml +++ b/apps/showcase/src/main/webapp/WEB-INF/applicationContext.xml @@ -11,4 +11,14 @@ + + + + + + + + + + diff --git a/apps/showcase/src/main/webapp/WEB-INF/classes/struts.properties b/apps/showcase/src/main/webapp/WEB-INF/classes/struts.properties index cebe63760..9e59fdbf5 100644 --- a/apps/showcase/src/main/webapp/WEB-INF/classes/struts.properties +++ b/apps/showcase/src/main/webapp/WEB-INF/classes/struts.properties @@ -6,3 +6,4 @@ struts.objectFactory = spring struts.custom.i18n.resources=globalMessages #struts.action.extension=jspa struts.url.http.port = 8080 +struts.freemarker.manager.classname=customFreemarkerManager diff --git a/apps/showcase/src/main/webapp/WEB-INF/classes/xwork-freemarker.xml b/apps/showcase/src/main/webapp/WEB-INF/classes/xwork-freemarker.xml new file mode 100644 index 000000000..c6dbf112b --- /dev/null +++ b/apps/showcase/src/main/webapp/WEB-INF/classes/xwork-freemarker.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + /freemarker/customFreemarkerManagerUsage.ftl + + + diff --git a/apps/showcase/src/main/webapp/WEB-INF/classes/xwork.xml b/apps/showcase/src/main/webapp/WEB-INF/classes/xwork.xml index 9b4387eeb..6cd461d9b 100644 --- a/apps/showcase/src/main/webapp/WEB-INF/classes/xwork.xml +++ b/apps/showcase/src/main/webapp/WEB-INF/classes/xwork.xml @@ -37,6 +37,8 @@ + + diff --git a/apps/showcase/src/main/webapp/WEB-INF/decorators/main.jsp b/apps/showcase/src/main/webapp/WEB-INF/decorators/main.jsp index 04b317ad6..eef093984 100644 --- a/apps/showcase/src/main/webapp/WEB-INF/decorators/main.jsp +++ b/apps/showcase/src/main/webapp/WEB-INF/decorators/main.jsp @@ -77,6 +77,7 @@

  • ">File Download
  • "/>Conversion
  • ">JSF
  • +
  • ">Freemarker
  • ">Help
  • diff --git a/apps/showcase/src/main/webapp/showcase.jsp b/apps/showcase/src/main/webapp/showcase.jsp index dba15cdd4..5471e2aa8 100644 --- a/apps/showcase/src/main/webapp/showcase.jsp +++ b/apps/showcase/src/main/webapp/showcase.jsp @@ -56,6 +56,9 @@
  • Model Driven Example + + +
  • Freemarker Example