Forums de discussion

Accessing JackRabbit from a portlet

Viðar Svansson, modifié il y a 15 années.

Accessing JackRabbit from a portlet

New Member Publications: 5 Date d'inscription: 17/09/08 Publications récentes
Hi.

I am curious on how I can access the JCR repository in Liferay. As far as I can understand, Liferay uses JackRabbit internally. However, I can't find any examples/documentation on how I can access this from client code.

I have found examples how to use access Alfresco repository, but not JR. What I need to do is to get a JCR session so I can add and manipulate Liferay nodes.

Thanks.
Viðar
thumbnail
Tobias Amon, modifié il y a 15 années.

RE: Accessing JackRabbit from a portlet

Liferay Master Publications: 546 Date d'inscription: 08/08/07 Publications récentes
Hi,

Liferay provides several services for this.

You can try some of them:
  • DLFileVersionLocalServiceUtil
  • DLFolderLocalServiceUtil
  • ...


You can have a look at the portal-service.jar -> com.liferay.portlet.documentlibrary.service

kind regards
Tobias
Viðar Svansson, modifié il y a 15 années.

RE: Accessing JackRabbit from a portlet

New Member Publications: 5 Date d'inscription: 17/09/08 Publications récentes
Thanks for the quick reply.

I had a look at the document library and it seems that it deals with actual files. What I want is to insert arbitrary nodes into the workspace. Is that not possible?

Cheers
Viðar
Viðar Svansson, modifié il y a 15 années.

RE: Accessing JackRabbit from a portlet

New Member Publications: 5 Date d'inscription: 17/09/08 Publications récentes
After more search I found some javadoc http://content.liferay.com/4.3/api/portal-impl/com/liferay/portal/jcr/package-summary.html
There are no comments on how to use it though. But I guess I can use JCRFactoryUtil.createSession() to get started.
Viðar Svansson, modifié il y a 15 années.

RE: Accessing JackRabbit from a portlet

New Member Publications: 5 Date d'inscription: 17/09/08 Publications récentes
Now I have the problem of JCRFactoryUtil not being in portlal-services.jsr

I see two possible solutions. Move liferay jars to the shared lib in Tomcat, or manually connect to the JCR directly. I really don't want to move the jars around since I want to stay away from possible library version conflicts.

Is there any documentation on how to access the JCR directly? From the admin guide I see the following property: jcr.initialize.on.startup=false

Does that mean JCR is not loaded. I cant see anything in the jackrabbit folder except for repository.xml

Does Liferay not store the Journal content in the JCR? What I am trying to accomplish is to operate directly on the Journal content using the JCR API. I know there is a Liferay specific API for Journal manipulation, but we like to work directly with the standard.

Thanks.
thumbnail
Tobias Amon, modifié il y a 15 années.

RE: Accessing JackRabbit from a portlet

Liferay Master Publications: 546 Date d'inscription: 08/08/07 Publications récentes
Hi,

moving jars into common libs folder will cause several problems. I already tried that!

You can start developing your portlets in the ext environment. These portlets will be deployed in the liferay web applications and thus have full access everywhere.

kind regards
Tobias
Viðar Svansson, modifié il y a 15 années.

RE: Accessing JackRabbit from a portlet

New Member Publications: 5 Date d'inscription: 17/09/08 Publications récentes
Hi

That is true, but I prefer to keep my portlets as standalone as possible.

However, it looks like Liferay is not really using JCR for anything else than documents. So I will have to use the Liferay API to manipulate Journal content, which is not acceptable.

Will I need to install Alfresco just to get some JCR backed content that comes with portlets to display/edit content? I must say that I am a little disappointed because I was certain that Liferay used JCR for content management.
thumbnail
Sean Condon, modifié il y a 15 années.

RE: Accessing JackRabbit from a portlet

New Member Publications: 7 Date d'inscription: 09/09/08 Publications récentes
Hi Viðar

I'm in the same boat as you on this - I'd like to stick as close to the standards on this as possible.

I have a problem with the PortalBeanLocatorUtil which leaves me with a ClassCastException

I use the line
JCRFactory factory = JCRFactoryUtil.getJCRFactory();
in the doView() method of a Portlet and I get the error

12:10:39,201 ERROR [jsp:52] java.lang.ClassCastException: com.liferay.portal.jcr.jackrabbit.JCRFactoryImpl cannot be cast to com.liferay.portal.jcr.JCRFactory
at com.liferay.portal.jcr.JCRFactoryUtil.getJCRFactory(JCRFactoryUtil.java:40)
at com.xyz.portal.processes.ProcessDisplay.doPrint(ProcessDisplay.java:121)
at javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:319)
at com.xyz.portal.processes.ProcessDisplay.doDispatch(ProcessDisplay.java:54)
at javax.portlet.GenericPortlet.render(GenericPortlet.java:233)
at com.sun.portal.portletcontainer.appengine.filter.FilterChainImpl.doFilter(FilterChainImpl.java:121)
at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:69)
at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:96)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:630)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:535)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:472)
at com.liferay.portlet.InvokerPortlet.invoke(InvokerPortlet.java:534)
at com.liferay.portlet.InvokerPortlet.invokeRender(InvokerPortlet.java:605)
at com.liferay.portlet.InvokerPortlet.render(InvokerPortlet.java:373)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)


To get the JCRFactoryUtil, I had to include the file portal-impl.jar from /opt/liferay-portal-tomcat-6.0-5.1.1/webapps/ROOT/WEB-INF/lib in to my own project. Did you come across this?

Sean
thumbnail
Tobias Amon, modifié il y a 15 années.

RE: Accessing JackRabbit from a portlet

Liferay Master Publications: 546 Date d'inscription: 08/08/07 Publications récentes
Hi,

you cannot include the portal-impl.jar into your application as this results in your classcast exceptions. Even if it's the same class, it's loaded by a different classloader.

There is one way I didn't try completely: You can tell your app to use the liferay classloader.

kind regards
Tobias
thumbnail
Sean Condon, modifié il y a 15 années.

RE: Accessing JackRabbit from a portlet

New Member Publications: 7 Date d'inscription: 09/09/08 Publications récentes
Hi Tobias

Thanks for the response. I gave up on the JackRabbit thing because of the Class Cast Exception and I thought I'd try the DL classes to get access to the Document Library. Again this is code inside the doView() method of the GenericPortlet derived class:

//Connecting to the document library
DLService docLibrary = new DLServiceImpl();
try {
String[] fileNames = docLibrary.getFileNames(1, 1, "/Processes");
} catch (PortalException pe) {
_log.error("Portal exception while trying to get access to Document Library Foler /Processes", pe);
} catch (SystemException se) {
_log.error("Portal exception while trying to get access to Document Library Foler /Processes", se);
}

I get the ClassCastException problem all over again, presumably because (as you pointed out) the Document Library is loaded by the Portal's own classloader, and I guess my app is using its own class loader. Do you have any code examples on how to get the class loader for the Portal? Would it be through the PortalContext object (available inside the GenericPortlet)?

Thanks again for your help

Sean
thumbnail
Tobias Amon, modifié il y a 15 années.

RE: Accessing JackRabbit from a portlet

Liferay Master Publications: 546 Date d'inscription: 08/08/07 Publications récentes
Hi,

you need to use the DL*LocalServiceUtil classes.

In your code you access it via
DLService docLibrary = new DLServiceImpl();
. This won't work.

Unfortunately you don't have the "full" access to all methods there. Have a look at the classes in "portal-service.jar/com/liferay/portlet/documentlibrary/service".

kind regards
Tobias