[opencms-dev] Reading structured content into an object tree

Robert Spielmann spielmann at codecentric.de
Sat Aug 1 13:57:42 CEST 2009


Hi all,

Using OpenCms 6.5, I've been using transfer classes for the XML <-> JSP interaction for some time now. I design the classes as a 1:1 representation of the nested XML content structure. This works quite fine, but I'd like to optimize the logic that maps XML content values to the objects. I'm thinking about using the OpenCms XML API and after I did some experiments, I came across I_CmsXmlContentValueVisitor. The idea is to write a visitor that constructs an object tree for me, which I can then use in the application logic. Using a visitor, I would probably be able to dig into nested content recursively, right? (That's part one of the question)

So if above approach works, if I use value.getTypeName() and if I cut out "OpenCms" (e.g. OpenCmsGreatestTeaser -> GreatestTeaser) I need some way to resolve the appropriate fully qualified class name (e.g. de.whatever.model.GreatestTeaser) in order to construct an object that can hold GreatestTeaser's values. Is there any elegant way to achieve this? (That's part two of the question) The hard and ugly way would be to abuse Spring for XML type <-> Java class mappings, maybe combined with some sort of factory mechanism. Any hints on how to do this in a nice way would be appreciated ;) If there are other ways to achieve XML content -> object tree parsing, let me know - maybe the OpenCms API offers ways to do this?

Have a nice weekend,

Mit freundlichen Grüßen / Best regards

Robert Spielmann
IT Consultant

--

codecentric GmbH
Merscheider Str. 1
42699 Solingen

Büro:  +49 (212) 233628-42
Mobil: +49 (151) 14705709
Fax:   +49 (212) 233628-79

Mail:  spielmann at codecentric.de
Web:   http://www.codecentric.de
Blog:  http://blog.codecentric.de

Geschäftsführer: Peter Gierse, Mirko Novakovic und Rainer Vehns
Sitz der Gesellschaft: Solingen
Registergericht: Amtsgericht Wuppertal, HRB 19214

Diese E-Mail einschließlich evtl. angehängter Dateien enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und löschen Sie diese E-Mail und evtl. anhängende Dateien umgehend. Das unerlaubte Kopieren, Nutzen oder Öffnen evtl. anhängender Dateien sowie die unbefugte Weitergabe dieser E-Mail ist nicht gestattet.




More information about the opencms-dev mailing list