Liferay DocumentAndMedia hook with CMIS



我从DocumentAndMedia制作了一个挂钩。在portal.properties中,我写了com.liferay.portlet.dococumentlibrary.action.EditFileEntryAction=commycompany.acciones.Test,所以当我看到文件条目视图时,我可以获得文件条目。我想从FileEntry.getModel()将FileEntry强制转换为org.apache.chemistry.opencmis.client.runtime.DocumentImpl文档以获得一些额外的属性,但抛出了一个异常。

测试行动类别

package com.mycompany.acciones;
import javax.portlet.*;
import org.apache.chemistry.opencmis.client.runtime.*;
import com.liferay.portal.kernel.repository.model.*;
import com.liferay.portal.kernel.struts.*;
import com.liferay.portal.kernel.util.*;
public class Test extends BaseStrutsPortletAction{
    public void processAction(StrutsPortletAction originalStrutsPortletAction, PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
        originalStrutsPortletAction.processAction(originalStrutsPortletAction, portletConfig, actionRequest, actionResponse);
    }
    @Override
    public String render(StrutsPortletAction originalStrutsPortletAction,PortletConfig portletConfig,RenderRequest renderRequest, RenderResponse renderResponse) throws Exception {
        String ret = originalStrutsPortletAction.render(null, portletConfig, renderRequest, renderResponse);
        renderRequest.setAttribute(WebKeys.PORTLET_DECORATE, Boolean.TRUE);
        FileEntry fileEntry = (FileEntry)renderRequest.getAttribute("DOCUMENT_LIBRARY_FILE_ENTRY"); 
        // Exception is throws here
        DocumentImpl doc = (DocumentImpl)fileEntry.getModel();      
        String propertyName = doc.getProperties().get(0).getDisplayName();
        String propertyvalue = doc.getProperties().get(0).getValue();
        String propertyName2 = doc.getProperties().get(1).getDisplayName();
        String propertyvalue2 = doc.getProperties().get(1).getValue();
        return ret;
    }
}

Stacktrace

17:33:52,796 ERROR [http-bio-8080-exec-398][render_portlet_jsp:154] java.lang.ClassCastException: org.apache.chemistry.opencmis.client.runtime.DocumentImpl cannot be cast to org.apache.chemistry.opencmis.client.runtime.DocumentImpl
    at com.mycompany.acciones.Test.render(Test.java:31)
    at com.liferay.portal.kernel.bean.ClassLoaderBeanHandler.invoke(ClassLoaderBeanHandler.java:67)
    at com.liferay.portal.struts.PortletActionAdapter.render(PortletActionAdapter.java:74)
    at com.liferay.portal.struts.PortletAction.execute(PortletAction.java:111)
    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
    at com.liferay.portal.struts.PortletRequestProcessor.processActionPerform(PortletRequestProcessor.java:441)
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
    at com.liferay.portal.struts.PortletRequestProcessor.process(PortletRequestProcessor.java:224)
    at com.liferay.portlet.StrutsPortlet.include(StrutsPortlet.java:274)
    at com.liferay.portlet.StrutsPortlet.doView(StrutsPortlet.java:153)
    at com.liferay.portal.kernel.portlet.LiferayPortlet.doDispatch(LiferayPortlet.java:218)
    at javax.portlet.GenericPortlet.render(GenericPortlet.java:233)
    at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:100)
    at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:64)
    at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:548)
    at com.liferay.portlet.InvokerPortletImpl.invokeRender(InvokerPortletImpl.java:607)
    at com.liferay.portlet.InvokerPortletImpl.render(InvokerPortletImpl.java:359)
    at org.apache.jsp.html.portal.render_005fportlet_jsp._jspService(render_005fportlet_jsp.java:1207)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

如果一个类不能被类型化为它合法应该被类型化的另一个类(甚至是它自己),那么类路径上肯定有两个inccristing类或它的超类。检查你的类路径是否重复,解决它。它可能是tomcat的全局类路径(tomcat/lib,或者对于Liferay也是tomcat/lib/ext)或你的Web应用程序(在其WEB-INF/libWEB-INF/classes中)中的库。或者它们的组合(因为它是一个同名类的多个实现。

去掉多余的,重新启动,再试一次。

包测试;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import com.liferay.portal.kernel.repository.model.FileEntry;
import com.liferay.portal.kernel.struts.BaseStrutsPortletAction;
import com.liferay.portal.kernel.struts.StrutsPortletAction;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portlet.documentlibrary.model.DLFileEntry;
public class EditFileEntryAction extends BaseStrutsPortletAction {
     public void processAction(StrutsPortletAction originalStrutsPortletAction, PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
            originalStrutsPortletAction.processAction(originalStrutsPortletAction, portletConfig, actionRequest, actionResponse);
        }
        @Override
        public String render(StrutsPortletAction originalStrutsPortletAction,PortletConfig portletConfig,RenderRequest renderRequest, RenderResponse renderResponse) throws Exception {
            String ret = originalStrutsPortletAction.render(null, portletConfig, renderRequest, renderResponse);
            renderRequest.setAttribute(WebKeys.PORTLET_DECORATE, Boolean.TRUE);
            FileEntry fileEntry = (FileEntry)renderRequest.getAttribute("DOCUMENT_LIBRARY_FILE_ENTRY"); 
            // Exception is throws here
            DLFileEntry doc = (DLFileEntry)fileEntry.getModel();      

            return ret;
        }
}

这对我很有效,但演员阵容是DLFileEntry,而不是DocumentImpl。

你为什么需要org.apache.chemistry.openmis.client.runtime.DocumentImpl?你怎么知道getModel()会返回这种类型的对象?

相关内容

  • 没有找到相关文章