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

M Butcher mbutcher at grcomputing.net
Mon Jun 30 23:00:01 CEST 2003


Well, maybe it would help to look at the code that drives the editor.
It's in com.opencms.workplace.CmsEditor. There is a lot there, but it
may answer your questions. It looks like there may be two CDATA sections
-- one for each editor (text versus WYSIWIG), but I'm not sure. I
haven't looked too carefully. com.opencms.templates.A_CmsXmlContent has
a bunch of methods for dealing with the XML itself. You may want to look
at the javadoc for that.

Matt

On Mon, 2003-06-30 at 14:15, Matthias Schmidt wrote:
> Sure, I thought the same thing, BUT:
> 
> Funny thing about this XML file is that it stores the HTML twice. One 
> version stores my tags with lower case letters and one with upper case. 
> It looks like this:
> ================
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <XMLTEMPLATE>
>      <TEMPLATE><![CDATA[<strong>dfhjdfhdfhfh</strong>]]></TEMPLATE>
>      <edittemplate><![CDATA[<STRONG>dfhjdfhdfhfh</STRONG>]]></edittemplate>
> </XMLTEMPLATE>
> ================
> 
> 1) I don't want to parse to whole file to convert every tag to upper case.
> 2) I'd rather not touch the xml myself, because I don't understand what 
> this saving things twice thing is used to.
> 
> And there MUST be a method for me. The editor hast to store it's stuff, 
> too. That's what I'm looking for.
> 
> M Butcher wrote:
> 
> > 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
> 
> 
> _______________________________________________
> 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