[opencms-dev] OpenCMS Not Read Manual Updates To File

Brett Sheeran brett.sheeran at gmail.com
Tue Jul 1 03:55:09 CEST 2008


Hi,

I recently wrote some code to programmatically write to and publish a
text file. The code *seems* to work. However, I am concerned that
OpenCMS now seems to ignore any updates I make to the text file
manually. Can anyone tell me if there is something wrong with my code
or how I can stop this from happening? Details as follows.

This is the write code:
----------
CmsRequestContext cmsContext = cmsObj.getRequestContext();
CmsProject curProject = cmsContext.currentProject();

if(curProject.isOnlineProject()){
CmsProject offlineProject = cmsObj.readProject("Offline");
cmsContext.setCurrentProject(offlineProject);
}

String newResname =
cmsObj.getRequestContext().getFileTranslator().translateResource(mFileName);
CmsFile file = cmsObj.readFile(newResname);
file.setContents(contentBuffer.toString().getBytes());

//lock the file
cmsObj.lockResource(newResname);

//write the file
cmsObj.writeFile(file);

//unlock the file
cmsObj.unlockResource(newResname);
----------

This is the publish code
----------
String newResname =
cmsObj.getRequestContext().getFileTranslator().translateResource(mFileName);
OpenCms.getPublishManager().publishResource(cmsObj, newResname);
----------

and this is the read code:
----------
String newResname =
cmsObj.getRequestContext().getFileTranslator().translateResource(mFileName);
CmsFile file = cmsObj.readFile(newResname);
----------

If I write to and publish the text file using the code above,
everything seems fine. I can see the changes when I manually open the
file and also when I read the file programmatically.

However if I manually edit then publish the file and read the file
using the code above, I cannot see the manual changes.
This is strange because I *can* see the changes if I reopen the file
in the editor.
You might think that I forgot to publish, but I have manually
doublechecked the text file in both on-line and off-line mode.
Furthermore, I have restarted OpenCMS and still do not see the manual
updates to the text file when reading the file using the above code.

Any ideas?

Thank you.

Regards Brett S



More information about the opencms-dev mailing list