[opencms-dev] Access to CmsObject from Spring controller
Florian Hopf
hopf at synyx.de
Wed Jun 30 11:05:29 CEST 2010
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