[opencms-dev] Two elements on schema to mapping
Juan Antonio Ruiz
jaruiz at sopde.es
Thu Jun 16 12:19:36 CEST 2011
Hi Michael,
Ok, thank you for everything. I will try it.
-----Mensaje original-----
De: opencms-dev-bounces at opencms.org [mailto:opencms-dev-bounces at opencms.org]
En nombre de Michael Emmerich
Enviado el: jueves, 16 de junio de 2011 12:10
Para: The OpenCms mailing list
Asunto: Re: [opencms-dev] Two elements on schema to mapping
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(
 CmsResource.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
_______________________________________________
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
More information about the opencms-dev
mailing list