[opencms-dev] creating a file
Christoph P. Kukulies
kuku at physik.rwth-aachen.de
Thu Aug 28 11:30:47 CEST 2008
On Wed, Aug 27, 2008 at 06:24:16AM -0700, Roman Uhlig wrote:
>
> We use OpenCms.createResource() for that (e.g. automatically creating Google
> Sitemaps every night).
>
> Looks like that:
>
> CmsObject cmso = ....
> String filename = ...
> String s_filecontent = ...
> ...
>
> cmso.getRequestContext().setCurrentProject(cmso.readProject("Offline"));
>
> if (cmso.existsResource(filename)) {
> cmso.lockResourceTemporary(filename);
lockResourceTemporary()
doesn't seem to work in 6.2.3
Can I use lockResource()?
> cmso.deleteResource(filename, CmsResource.DELETE_PRESERVE_SIBLINGS);
> if (cmso.existsResource(filename)) {
> cmso.unlockResource(filename);
> cmso.publishResource(filename);
> }
> }
> cmso.createResource(
> filename,
> OpenCms.getResourceManager().getResourceType("plain").getTypeId(),
> s_filecontent.getBytes(),
> new ArrayList()
> );
> cmso.unlockResource(filename);
> cmso.publishResource(filename);
>
> cmso.getRequestContext().setCurrentProject(cmso.readProject("Online"));
>
>
> This works also in the latest OpenCms 6 versions (publishResource is
> deprecated as of version 7).
>
> HTH,
> Roman
--
Chris Christoph P. U. Kukulies kukulies (at) rwth-aachen.de
More information about the opencms-dev
mailing list