001
014
015 package com.liferay.portal.struts;
016
017 import com.liferay.portal.kernel.struts.StrutsPortletAction;
018 import com.liferay.portal.kernel.util.Validator;
019
020 import javax.portlet.ActionRequest;
021 import javax.portlet.ActionResponse;
022 import javax.portlet.PortletConfig;
023 import javax.portlet.RenderRequest;
024 import javax.portlet.RenderResponse;
025 import javax.portlet.ResourceRequest;
026 import javax.portlet.ResourceResponse;
027
028 import org.apache.struts.action.ActionForm;
029 import org.apache.struts.action.ActionForward;
030 import org.apache.struts.action.ActionMapping;
031
032
035 public class PortletActionAdapter extends PortletAction {
036
037 public PortletActionAdapter(StrutsPortletAction strutsPortletAction) {
038 _strutsPortletAction = strutsPortletAction;
039 }
040
041 @Override
042 public void processAction(
043 ActionMapping actionMapping, ActionForm actionForm,
044 PortletConfig portletConfig, ActionRequest actionRequest,
045 ActionResponse actionResponse)
046 throws Exception {
047
048 StrutsPortletAction originalStrutsPortletAction = null;
049
050 if (_originalPortletAction != null) {
051 originalStrutsPortletAction = new StrutsPortletActionAdapter(
052 _originalPortletAction, actionMapping, actionForm);
053 }
054
055 _strutsPortletAction.processAction(
056 originalStrutsPortletAction, portletConfig, actionRequest,
057 actionResponse);
058 }
059
060 @Override
061 public ActionForward render(
062 ActionMapping actionMapping, ActionForm actionForm,
063 PortletConfig portletConfig, RenderRequest renderRequest,
064 RenderResponse renderResponse)
065 throws Exception {
066
067 StrutsPortletAction originalStrutsPortletAction = null;
068
069 if (_originalPortletAction != null) {
070 originalStrutsPortletAction = new StrutsPortletActionAdapter(
071 _originalPortletAction, actionMapping, actionForm);
072 }
073
074 String forward = _strutsPortletAction.render(
075 originalStrutsPortletAction, portletConfig, renderRequest,
076 renderResponse);
077
078 if (Validator.isNull(forward)) {
079 return null;
080 }
081
082 ActionForward actionForward = actionMapping.findForward(forward);
083
084 if (actionForward == null) {
085 actionForward = new ActionForward(forward);
086 }
087
088 return actionForward;
089 }
090
091 @Override
092 public void serveResource(
093 ActionMapping actionMapping, ActionForm actionForm,
094 PortletConfig portletConfig, ResourceRequest resourceRequest,
095 ResourceResponse resourceResponse)
096 throws Exception {
097
098 StrutsPortletAction originalStrutsPortletAction = null;
099
100 if (_originalPortletAction != null) {
101 originalStrutsPortletAction = new StrutsPortletActionAdapter(
102 _originalPortletAction, actionMapping, actionForm);
103 }
104
105 _strutsPortletAction.serveResource(
106 originalStrutsPortletAction, portletConfig, resourceRequest,
107 resourceResponse);
108 }
109
110 public void setOriginalPortletAction(PortletAction portletAction) {
111 _originalPortletAction = portletAction;
112 }
113
114 @Override
115 protected boolean isCheckMethodOnProcessAction() {
116 if (_originalPortletAction != null) {
117 return _originalPortletAction.isCheckMethodOnProcessAction();
118 }
119 else {
120 return super.isCheckMethodOnProcessAction();
121 }
122 }
123
124 private PortletAction _originalPortletAction;
125 private StrutsPortletAction _strutsPortletAction;
126
127 }