[opencms-dev] How to make CmsObject use offline project instead ofonline (createSibling problem)?

Andras Balogh andras at reea.net
Tue May 23 15:26:54 CEST 2006


Hello Jon,

Jonathan Woods wrote:

>Jani -
>
>The notion of the 'current project' is part of the CMS session state, just
>as is the 'current site root'.  The session state is modelled in
>CmsRequestContext, which itself is accessible from an instance of CmsObject,
>so you can set the current project thus:
>
>CmsProject project = _cms.readProject(<name of the offline project>);
>
>/*
>or use the method variation which takes an int project id; is either 3 or 4
>for
>Offline; I forget which, and I forget how to obtain this safely for any
>default installation...
>CmsProject = _cms.readProject(3);
>*/
>
>_cms.getRequestContext().setCurrentProject(project);
>
>....
>
>// Get instances of CmsObject from static method on class OpenCms.
>// Means shown is standard way of initialising without needing to know
>credentials.
>CmsObject cmsObject =
>OpenCms.initCmsObject(OpenCms.getDefaultUsers().getUserGuest());
>
>// Then log in the CmsObject instance as the Admin user.
>
>cmsObject.loginUser("Admin", "admin password here");
>  
>

The problem with this approach that you need to hardcode the password of 
the Admin user.
If You develop for a client he may have the requirement or wish to have 
the password in his
hands so he can change it let's say every month or so.

It would be very good if the OpenCMS experts could say if is SAFE to use 
the CmsObject

received from I_CmsModuleAction.initialize or not.



>/* Other stuff necessary - including setting current project and current
>site root; then you can use cmsObject freely.
>*/
>
>Jon
>  
>
Best regards,
Andras.



More information about the opencms-dev mailing list