[opencms-dev] Accessing File Contents

Jonathan Woods jonathan.woods at scintillance.com
Fri Dec 8 06:43:57 CET 2006


Dwayne -

There's lots of API in this area - just browse the Javadoc.  Generally, you
can start off by getting hold of a CmsResource, from which you can get a
CmsFile and thence an OpenCms-flavoured XML document object:

final CmsResource cmsResource =
this.cmsObject.readResource(relativeResourcePath, CmsResourceFilter.ALL);
final CmsFile resourceFile = CmsFile.upgrade(cmsResource, this.cmsObject);
final CmsXmlContent xmlDocument =
CmsXmlContentFactory.unmarshal(this.cmsObject, resourceFile, true);

I've attached a utility class I use to do XML stuff.  It's not polished, but
it shows most of what you're talking about.

Bear in mind that there's another approach: indexing XML contents
element-by-element, then pulling element content out from fields in the
Lucene index at resource display time.  This'll almost certainly be faster
than reading XML content on the fly.  To do this, though, you'll have to
develop quite a bit of Lucene-related code.  Alternatively, OpenCms 7 (not
due for a while) will provide out of the box more fine-grained control over
XML element indexing.

Jon

-----Original Message-----
From: sfdbfoui at host2.scintillance.com
[mailto:sfdbfoui at host2.scintillance.com] On Behalf Of Dwayne Kristjanson
Sent: 07 December 2006 21:58
To: opencms-dev at opencms.org
Subject: [opencms-dev] Accessing File Contents

I'm trying to figure out how to access the XML nodes created when a file is
edited. I want to create a dynamic list of new articles that shows the first
heading and paragraph from each article. But I don't know how to get at that
data. Is there a class that can load in a resource as XML and walk through
the element nodes?

--
Dwayne Kristjanson

_______________________________________________
This mail is sent to you from the opencms-dev mailing list To change your
list options, or to unsubscribe from the list, please visit
http://lists.opencms.org/mailman/listinfo/opencms-dev

-------------- next part --------------
A non-text attachment was scrubbed...
Name: XmlContentHandler.java
Type: application/octet-stream
Size: 12558 bytes
Desc: not available
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20061208/2bd4ce2c/attachment.obj>


More information about the opencms-dev mailing list