[opencms-dev] Two elements on schema to mapping

Michael Emmerich m.emmerich at alkacon.com
Thu Jun 16 12:10:12 CEST 2011


Juan,


> Can I map two element of schema on a property?
>
> I have this schema:
>
> <xsd:sequence>
>
> <xsd:elementname=/"Name"/ type=/"OpenCmsString"/ />
>
> <xsd:elementname=/"Surname"/ type=/"OpenCmsString"/ />
>
>
> I would like to do something like this,
>
> <mappings>
>
> <mappingelement=/"*Name,Surname*"/ mapto=/"property:fullname"/ />
>
> How I can it?
>
> Thanks.

Its not possible to do that in the XSD.

You could implement your own CmsXmlContentHandler by implementing the 
I_CmsXmlContentHandler. There, you can perform an operation on XML 
content creation or save operation:

You can do that by writing your own XML content handler that performs 
actions in the prepareForWrite() method.
This method is triggered every time an xml content is saved, so you have 
to avoid the database update when the temporary file is written 
automatically by the OpenCms xml content editor.

Here is a short example how to implement such a content handler:

public class CmsActionXmlContentHandler extends 
CmsDefaultXmlContentHandler {
     public CmsFile prepareForWrite(CmsObject cms, CmsXmlContent 
content, CmsFile file)
         throws CmsException {

         // first call super implementation
         super.prepareForWrite(cms, content, file);

         if (file.getName().indexOf(CmsWorkplace.TEMP_FILE_PREFIX) != 0) {
             String folderPath = cms.getRequestContext().removeSiteRoot(
               &#160CmsResource.getFolderPath(file.getRootPath()));

             if (cms.existsResource(folderPath + 
CmsWorkplace.TEMP_FILE_PREFIX +
                         file.getName(), CmsResourceFilter.ALL)) {

                 // do your stuff here
                 ...
             }
         }
     return file;
     }
}


In the XSD of your XML content, you have to add the following node to 
the appinfo section:

<xsd:annotation>
     <xsd:appinfo>
         <handler class="my.package.CmsActionXmlContentHandler"/>
                 ...
     </xsd:appinfo>
</xsd:annotation>


As you can see, you have access to the CmsObject, the XmlContent and the 
Resource in the OpenCms VFS.


Kind regards,
Michael

-- 

Alkacon Software GmbH - The OpenCms Experts
Michael Emmerich
An der Wachsfabrik 13
50996 Koeln, DE

Tel: +49 (0)2236 3826-14
Fax: +49 (0)2236 3826-20
Email: m.emmerich at alkacon.com

http://www.alkacon.com
http://www.opencms.org


Geschäftsführer: Alexander Kandzior, Amtsgericht Köln, HRB 54613



More information about the opencms-dev mailing list