如何使用Ext插件自定义com.liferay.portlet.wiki.action.GetPageAttachmentAction

时间:2015-05-20 07:18:17

标签: liferay liferay-6

我正在使用Liferay 6.2,我想修改GetPageAttachmentAction

我想在strutsExecute中添加以下代码,以便在文件名中包含标题:

public ActionForward strutsExecute(
        ActionMapping actionMapping, ActionForm actionForm,
        HttpServletRequest request, HttpServletResponse response)
    throws Exception {
    long nodeId = ParamUtil.getLong(request, "nodeId");
    String title = ParamUtil.getString(request, "title");
    String fileName = ParamUtil.getString(request, "fileName");
    // Here my change:
    int pos = fileName.indexOf(CharPool.SLASH); 
    if (pos >= 0) { 
        title = fileName.substring(0, pos); 
        fileName = fileName.substring(pos + 1);
    }
    ...

如果我通过使用自定义类扩展BaseStrutsPortletAction来为此更改创建一个钩子插件,那么它不会提供strutsExecute()来覆盖。

我应该使用Ext插件吗?如果是,那么建议我配置Ext插件来修改GetPageAttachmentAction。

1 个答案:

答案 0 :(得分:0)

您可以执行以下任一操作:Hook插件或Ext插件。

但是钩子似乎在这里更有意义:

public class MyGetPageAttachmentAction extends BaseStrutsPortletAction {

  public void processAction(
      StrutsPortletAction originalStrutsPortletAction,
      PortletConfig portletConfig, ActionRequest actionRequest,
      ActionResponse actionResponse)
      throws Exception {

    String title = ParamUtil.getString(actionRequest, "title");
    String fileName = ParamUtil.getString(actionRequest, "fileName");

    // Your code:
    int pos = fileName.indexOf(CharPool.SLASH); 
    if (pos >= 0) { 
      title = fileName.substring(0, pos); 
      fileName = fileName.substring(pos + 1);
    }

    // Wrap request to add your new parameters (the original request parameters are immutable)
    DynamicActionRequest dynamicActionRequest = new DynamicActionRequest(actionRequest, true);
    dynamicActionRequest.setParameter("fileName", fileName);
    dynamicActionRequest.setParameter("title", title);

    // And delegate to original action
    originalStrutsPortletAction.processAction(portletConfig, dynamicActionRequest, actionResponse);
  }
}

(根据你的问题,我猜你在liferay-hook.xml中已经有了正确的设置)