[opencms-dev] Access to CmsObject from Spring controller
Steve Bryan
steve at bright-interactive.com
Wed Jun 30 13:18:01 CEST 2010
Thanks Florian, that's much nicer. The required OpenCmsCore methods
getInstance and initCmsObjectFromSession are protected, so can be accessed
from the custom class in the same package!
Perhaps Jonathan's code needed to be in OpenCmsCore because he also accessed
a private method.
Steve
-----Original Message-----
Date: Wed, 30 Jun 2010 11:05:29 +0200
From: Florian Hopf <hopf at synyx.de>
Subject: Re: [opencms-dev] Access to CmsObject from Spring controller
To: The OpenCms mailing list <opencms-dev at opencms.org>
Message-ID: <4C2B08D9.7010801 at synyx.de>
Content-Type: text/plain; charset=ISO-8859-1
Hi,
Steve Bryan schrieb:
> We have an OpenCms and Spring integration. We can access the Spring
context
> from JSPs running in OpenCms fine, and would now like to access the Cms
> context from Spring controllers (ie CmsObject).
>
> I found this article from Jonathan Woods Aug 2009
> http://lists.opencms.org/pipermail/opencms-dev/2009q3/032699.html.
>
I think you don't need to patch for many cases. It should be enough to
create a class in your project that is inside the package
org.opencms.main. This is what I am using:
package org.opencms.main;
import javax.servlet.http.HttpServletRequest;
import org.opencms.file.CmsObject;
/**
* Provides methods from the OpenCms core that can't be accessed outside
of the package.
*
* @author Florian Hopf, Synyx GmbH & Co. KG, hopf at synyx.de
*/
public class OpenCmsCoreAccessImpl implements OpenCmsCoreAccess {
public CmsObject initCmsObject(HttpServletRequest request) throws
CmsException {
return OpenCmsCore.getInstance().initCmsObjectFromSession(request);
}
}
Not sure if this will work for all cases, but it should if you
additionally use the OpenCms login mechanism which makes sure that the
session is initialized correctly.
Regards
Florian
More information about the opencms-dev
mailing list