You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2014/07/08 23:06:03 UTC
[1/2] git commit: Added support for using freemarker templates for
resource requests
Repository: struts
Updated Branches:
refs/heads/develop 01e338098 -> cc89601b6
Added support for using freemarker templates for resource requests
Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/2786455a
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/2786455a
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/2786455a
Branch: refs/heads/develop
Commit: 2786455a255ce40b83b2a2c809a6dc8c734337cd
Parents: 63de773
Author: Kristoffer Michael <kr...@eduix.fi>
Authored: Tue Jun 24 09:21:12 2014 +0300
Committer: Kristoffer Michael <kr...@eduix.fi>
Committed: Tue Jun 24 09:21:12 2014 +0300
----------------------------------------------------------------------
.../portlet/context/PortletActionContext.java | 14 ++++++++
.../freemarker/PortletFreemarkerResult.java | 37 ++++++++++++++++++--
2 files changed, 49 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/struts/blob/2786455a/plugins/portlet/src/main/java/org/apache/struts2/portlet/context/PortletActionContext.java
----------------------------------------------------------------------
diff --git a/plugins/portlet/src/main/java/org/apache/struts2/portlet/context/PortletActionContext.java b/plugins/portlet/src/main/java/org/apache/struts2/portlet/context/PortletActionContext.java
index 92e0d74..a51a3ca 100644
--- a/plugins/portlet/src/main/java/org/apache/struts2/portlet/context/PortletActionContext.java
+++ b/plugins/portlet/src/main/java/org/apache/struts2/portlet/context/PortletActionContext.java
@@ -35,6 +35,7 @@ import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
+import javax.portlet.ResourceResponse;
import java.util.Map;
import static org.apache.struts2.portlet.PortletConstants.DEFAULT_ACTION_FOR_MODE;
@@ -113,6 +114,19 @@ public class PortletActionContext {
}
return (ActionResponse) getContext().get(RESPONSE);
}
+
+ /**
+ * Get the ResourceResponse. Can only be invoked in the resource phase.
+ *
+ * @return The current ResourceResponse.
+ * @throws IllegalStateException If the method is invoked in the wrong phase.
+ */
+ public static ResourceResponse getResourceResponse() {
+ if (!getPhase().isResource()) {
+ throw new IllegalStateException("ResourceResponse cannot be obtained in event phase");
+ }
+ return (ResourceResponse) getContext().get(RESPONSE);
+ }
/**
* Get the action namespace of the portlet. Used to organize actions for multiple portlets in
http://git-wip-us.apache.org/repos/asf/struts/blob/2786455a/plugins/portlet/src/main/java/org/apache/struts2/views/freemarker/PortletFreemarkerResult.java
----------------------------------------------------------------------
diff --git a/plugins/portlet/src/main/java/org/apache/struts2/views/freemarker/PortletFreemarkerResult.java b/plugins/portlet/src/main/java/org/apache/struts2/views/freemarker/PortletFreemarkerResult.java
index 3112fb9..71d0cee 100644
--- a/plugins/portlet/src/main/java/org/apache/struts2/views/freemarker/PortletFreemarkerResult.java
+++ b/plugins/portlet/src/main/java/org/apache/struts2/views/freemarker/PortletFreemarkerResult.java
@@ -38,6 +38,7 @@ import org.apache.struts2.views.util.ResourceUtil;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;
+import javax.portlet.ResourceResponse;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -103,9 +104,11 @@ public class PortletFreemarkerResult extends StrutsResultSupport {
throws IOException, TemplateException, PortletException {
PortletPhase phase = PortletActionContext.getPhase();
if (phase.isAction()) {
- executeActionResult(location, invocation);
+ executeActionResult(location, invocation);
} else if (phase.isRender()) {
- executeRenderResult(location, invocation);
+ executeRenderResult(location, invocation);
+ } else if (phase.isResource()){
+ executeResourceResult(location, invocation);
}
}
@@ -147,6 +150,36 @@ public class PortletFreemarkerResult extends StrutsResultSupport {
}
}
}
+
+ private void executeResourceResult(String location, ActionInvocation invocation)
+ throws TemplateException, IOException, PortletException {
+ this.location = location;
+ this.invocation = invocation;
+ this.configuration = getConfiguration();
+ this.wrapper = getObjectWrapper();
+
+ HttpServletRequest req = ServletActionContext.getRequest();
+
+ if (!location.startsWith("/")) {
+ String base = ResourceUtil.getResourceBase(req);
+ location = base + "/" + location;
+ }
+
+ Template template = configuration.getTemplate(location, deduceLocale());
+ TemplateModel model = createModel();
+ // Give subclasses a chance to hook into preprocessing
+ if (preTemplateProcess(template, model)) {
+ try {
+ // Process the template
+ ResourceResponse response = PortletActionContext.getResourceResponse();
+ response.setContentType(pContentType);
+ template.process(model, response.getWriter());
+ } finally {
+ // Give subclasses a chance to hook into postprocessing
+ postTemplateProcess(template, model);
+ }
+ }
+ }
/**
* This method is called from {@link #doExecute(String, ActionInvocation)}
[2/2] git commit: WW-4363 Adds support for freemarker views in
portlet resource phase Closes #17
Posted by lu...@apache.org.
WW-4363 Adds support for freemarker views in portlet resource phase
Closes #17
Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/cc89601b
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/cc89601b
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/cc89601b
Branch: refs/heads/develop
Commit: cc89601b6d4d29959030fab2dcd44637d1ece9fe
Parents: 01e3380 2786455
Author: Lukasz Lenart <lu...@apache.org>
Authored: Tue Jul 8 23:05:01 2014 +0200
Committer: Lukasz Lenart <lu...@apache.org>
Committed: Tue Jul 8 23:05:01 2014 +0200
----------------------------------------------------------------------
.../portlet/context/PortletActionContext.java | 14 ++++++++
.../freemarker/PortletFreemarkerResult.java | 37 ++++++++++++++++++--
2 files changed, 49 insertions(+), 2 deletions(-)
----------------------------------------------------------------------