[opencms-dev] creating a file

Roman Uhlig roman.uhlig at knve.de
Wed Aug 27 15:24:16 CEST 2008


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);
	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

-- 
View this message in context: http://www.nabble.com/creating-a-file-tp19178157p19180880.html
Sent from the OpenCMS - Dev mailing list archive at Nabble.com.




More information about the opencms-dev mailing list