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

M Butcher mbutcher at grcomputing.net
Mon Jun 30 22:19:02 CEST 2003


Matthias,

Thinking out loud here, but you should be able to do that by getting the
file as an instance of a CmsFile, using getContents to get a byte array,
and (now you have choices) using Xerces to deal with it as an XML file
(Well, XMLDocumentFragment, more likely) or manipulating it as a text
file. When you are done, you should be able to use CmsFile.setContents
to write back to the file.

So, it might look something like this:

public void writeHelloWorld(CmsFile file) throws CmsException {
  byte[] fileContents = file.getContents();
  /// ... do your thing here
  String helloWorld = "<![CDATA[ Hello World ]]>";
  file.setContents(helloWorld.getBytes());
  return;
}

Again, thinking off the top of my head, so this may be way
oversimplified.

As for finding files, there seem to be lots of ways of doing that. Look
at the javadoc for CmsObject for starters. (getFilesInDirectory is one
way)

Matt

On Mon, 2003-06-30 at 13: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
-- 
M Butcher <mbutcher at grcomputing.net>



More information about the opencms-dev mailing list