[opencms-dev] Writing HTML directly into a vfs file

Matthias Schmidt matthias.schmidt at gmx.de
Tue Jul 1 11:26:00 CEST 2003


That looks like it's just the thing I was looking for! Thanks a lot!

David Currie wrote:
> Ok.  If you're going to use a file of type "Page" then I suppose the
> html you want to write is in one of the fields within the XML file in
> bodies.  In that case, you need code like:
> 
> CmsObject cms = <insert mojo for getting the correct instance>;
> CmsFile f = <get your file here>;
> // Now the interesting bit...
> // Get the control file for your page.  This defines the templates,
> // body location, etc.
> CmsXmlControlFile cf = new CmsXmlControlFile(f);
> // This line gets the name of the file in /system/bodies/...
> String contentFileName = cf.getElementTemplate("body");
> // And open it
> CmsFile contentFile = cms.readFile(contentFileName);
> 
> Ok, now you can read and write the raw XML in the content file using the
> getContents() and setContents() methods in CmsFile to read and write
> data to it.
> 
> When you're finished don't forget to call cms.writeFile(contentFile), or
> else the changes will not be saved.
> 
> I've left out the import paths for each class, but they're in the
> javadocs.
> 
> I hope this is of more help to you. :)
> 
> Dave
> 
> On Mon, 2003-06-30 at 21:46, Matthias Schmidt wrote:
> 
>>Well, there's this file with type "page", say "/myFile.html".
>>
>>The HTML content is in an XML file in /system/bodies/ with the same 
>>name, so in this case "/system/bodies/myFile.html".
>>
>>And I guess there must be some way to find the file in system/bodies/ 
>>and then to insert the new HTML content.
>>
>>It would look something like this (in my 'dream' ;)):
>>
>>CmsFile xmlFile = CmsFile.getMeTheSystemBodiesFile();
>>xmlFile.insertTheNewHtmlContent("<html>...</html>");
>>
>>I looked all my way through the CmsObject and CmsFile and CmsResource.
>>
>>Got any hints?
>>
>>David Currie wrote:
>>
>>>Hi Matthias.
>>>
>>>Can you be a little more specific about what you are trying to do?  I
>>>have various fragments of code I've written that might help you, but I
>>>need to know more about the context.  Are you going to do this from a
>>>Content Definition?  A JSP?  A class called from a JSP?  etc.
>>>
>>>Basically, you should look at the CmsResource.createResource() calls. 
>>>You need to have a CmsResource object available, which is why I asked
>>>those questions above.
>>>
>>>By the way, /system/bodies/* is only used for files of type PAGE.  If
>>>you just want to create a PLAIN file in the VFS, all you have to do is
>>>include the file path and body in the arguments to createResource() and
>>>you're done.
>>>
>>>Hope this helps.
>>>
>>>Dave
>>>
>>>On Fri, 2003-06-27 at 12:13, Matthias Schmidt wrote:
>>>
>>>
>>>>Hi list,
>>>>
>>>>I have to write a Class that can directly write HTML code into a file in the
>>>>vfs. I know that the file content of a file
>>>>
>>>>/myfile.html
>>>>
>>>>really is stored in a file
>>>>
>>>>/system/bodies/myfile.html
>>>>
>>>>inside an XML tag. I guess, there MUST be an OpenCms method that does
>>>>exactly that for me, but I cannot find it. Has anybody got a hint for 
>>>>me? The Code
>>>>and HTML editors must be using it, but I still cannot find it.
>>>>
>>>>Thanks in advance!
>>
>>_______________________________________________
>>This mail is send to you from the opencms-dev mailing list
>>To change your list options, or to unsubscribe from the list, please visit
>>http://mail.opencms.org/mailman/listinfo/opencms-dev





More information about the opencms-dev mailing list