[opencms-dev] Schema Default - advanced logic
Michael Emmerich
m.emmerich at alkacon.com
Mon Feb 15 14:16:42 CET 2021
Thomas,
you cannot use anything except %(value:XPATH) for this kind of macro,
and its usage is limited to certain use cases like setting the value of
the GalleryTitle in the Mercury template.
Of course, you can use all the macros that are defined in the default
macro resolver, see the source for it.
For anything that goes beyond this, you have to implement your own
content handler class.
Storing and loading content is performed by a content handler. The
default content handler used in OpenCms is
org.opencms.xml.content.CmsDefaultXmlContentHandler
The default content handler makes the following:
* sets the default values for elements
* writes the defined mappings
* validates elements
To extend the content handler, extend the default content handler class
and overwrite some methods.
In most cases, additional actions should be performed when saving an XML
content, e.g., validation, pretty printing, resource modification
To adjust actions performed on saving, override the method
CmsXmlContent prepareForWrite(CmsObject cms, CmsXmlContent content,
CmsFile file)
that is always called before the XML content is written to the OpenCms VFS.
Important! Always call the method of the super class from your
implementation first!
Another possible extension is to perform specific actions before the XML
content is used (in the editor or in the frontend)
In this case, the method
CmsXmlContent prepareForUse(CmsObject cms, CmsXmlContent content)
should be overwritten.
This method is always called after the XML content is unmarshaled, so
modifications can be made to the XML content element values. You could
add your default value logic in here.
If you need special validation of content fields (e.g. depending on
other fields, access to external sources) validation can be extended. In
this case, the method
CmsXmlContentErrorHandler resolveValidation( CmsObject cms,
I_CmsXmlContentValue value, CmsXmlContentErrorHandler errorHandler)
should be overwritten
This method is called for each content field (value) and allows to
access the complete content.
The XML content handler to use must be specified in the appinfo section
of the XSD defining the XML content:
<xsd:annotation>
<xsd:appinfo>
<handler class= "myContentHandlerClass" /> …
If no handler class is specified, OpenCms uses automatically the default
XML content handler.
Hope this helps.
Kind regards,
Michael
Am 15.02.21 um 13:12 schrieb Thomas Schmidt:
> Hello,
> I tried a lot of combinations like:
>
> %(value:substring(currentuser.firstname,1)), %(value:substring(currentuser.firstname,0,1)),
> and many more (also with other bracket type) - but this has no effect - so I wonder what of XPath is actually supported (and where is the code for that) …
>
> Thanks
> BR
> ThomasS
>
>
>
>
>
>
>> Am 15.02.2021 um 12:28 schrieb Thomas Schmidt <t.schmidt at md-network.de>:
>>
>> Hello Anne,
>> thanks a lot for your reply and for the good pointer.
>>
>> In the org.opencms.util.*MacroResolver code see a number of literals.
>> I wonder how
>> %(value:{XPath})
>>
>> Could be used. I was in hope that some of the basic XPath expressions might be possible. But I currently I don't find any hint for this in the code.
>>
>> Thanks
>> Kind Regards
>> ThomasS
>>
>>
>>
>>> Am 15.02.2021 um 09:56 schrieb Gebert, Anne <a.gebert at comundus.com>:
>>>
>>> Hi Thomas,
>>>
>>> perhaps a look at org.opencms.util.CmsMacroResolver.java may help you.
>>>
>>> Regards
>>> Anne
>>>
>> _______________________________________________
>> 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
>> https://lists.opencms.org/mailman/listinfo/opencms-dev
>>
>>
>>
> _______________________________________________
> 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
> https://lists.opencms.org/mailman/listinfo/opencms-dev
>
>
>
--
Michael Emmerich
-------------------
Alkacon Software GmbH & Co. KG - The OpenCms Experts
Michael Emmerich
Email: m.emmerich at alkacon.com
http://www.alkacon.com
http://www.opencms.org
Amtsgericht Köln, HRA 32185, USt-IdNr.: DE259882372
Vertreten durch: Alkacon Verwaltungs GmbH
Geschäftsführer: Alexander Kandzior, Amtsgericht Köln, HRB 88218
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.opencms.org/pipermail/opencms-dev/attachments/20210215/d142f9be/attachment.htm>
More information about the opencms-dev
mailing list