[opencms-dev] How to map field of nested choice xsd to property and solrfield?

Rüdiger Kurz r.kurz at alkacon.com
Wed Oct 2 21:25:07 CEST 2013


Hi Mathias,

thank you very much pointing out this interesting question(s)! I'm not 
sure how the mapping of choice elements in general but:

1. First of all it is possible to overwrite the method:
org.opencms.xml.content.CmsDefaultXmlContentHandler.resolveMapping(CmsObject, 
CmsXmlContent, I_CmsXmlContentValue) and then configure your own class 
in the XSD like:
<handler class="your.handler.fqn" />
as the first node of the appinfo part.

2. The second idea is to use
  <mapping element="ElementName" mapto="propertyList:PropertyName"/>

3. In general one resource can only have one release date, so mapping 
several values to a resource attribute does not make sense at all.

4. Regarding the Solr search field mapping, you always have to place it 
in the ROOT-XSD and what you can do is adding your on field like is 
shown at: 
https://github.com/alkacon/opencms-core/blob/branch_9_0_x/test/data/imports/solrtest/sites/default/xmlcontent/article.xsd#L58

5. Images are not supported yet.

regards
Rüdiger


Am 26.08.2013 10:19, schrieb Mathias Lin:
> How do you configure a field mapping from a nested xsd, which has choices?
>
> Since it's not clear at what position the certain choice element is, I
> am not sure how to configure the mapping.
>
> Furthermore, how do you configure a searchsetting/solrfield for such
> nested choice element? Does it also need to be configured in the parent
> xsd or in the nested xsd?
>
> The OpenCms documentation unfortunately doesn't give that much info
> about those cases.
>
>
> Below is an article.xsd, which embeds a article-choices.xsd.
>
>
>      <xsd:complexType name="OpenCmsMAArticle">
>          <xsd:sequence>
>              <xsd:element name="Title" type="OpenCmsString"
> minOccurs="1" maxOccurs="1"/>
>              <xsd:element name="Subtitle" type="OpenCmsString"
> minOccurs="0" maxOccurs="1"/>
>              <xsd:element name="Teaser" type="OpenCmsString"
> minOccurs="0" maxOccurs="1"/>
>              <xsd:element name="Text" type="OpenCmsHtml" minOccurs="0"
> maxOccurs="1"/>
>              <xsd:element name="DetailViewPage" type="OpenCmsVfsFile"
> minOccurs="0" maxOccurs="1"/>
> *            <xsd:element name="OptionalElements"
> type="OpenCmsMAArticleChoice" minOccurs="0" maxOccurs="unbounded"/>*
>          </xsd:sequence>
>          <xsd:attribute name="language" type="OpenCmsLocale"
> use="required"/>
>      </xsd:complexType>
>
>
>      <xsd:complexType name="OpenCmsMAArticleChoice">
>          <xsd:choice>
>              <xsd:element name="FeaturedImage" type="OpenCmsVfsFile"
> minOccurs="0" maxOccurs="1"/>
>              <xsd:element name="LandingPageImage" type="OpenCmsVfsFile"
> minOccurs="0" maxOccurs="1"/>
>              <xsd:element name="Image" type="OpenCmsVfsFile"
> minOccurs="0" maxOccurs="1"/>
>              <xsd:element name="IFrame" type="OpenCmsString"
> minOccurs="0" maxOccurs="1"/>
>              <xsd:element name="Video" type="OpenCmsMAVideo"
> minOccurs="0" maxOccurs="1"/>
>              <xsd:element name="LeftButton" type="OpenCmsMAButton"
> minOccurs="0" maxOccurs="1"/>
>              <xsd:element name="RightButton" type="OpenCmsMAButton"
> minOccurs="0" maxOccurs="1"/>
>              <xsd:element name="ReleaseDate" type="OpenCmsDateTime"
> minOccurs="0" maxOccurs="1"/>
>          </xsd:choice>
>          <xsd:attribute name="language" type="OpenCmsLocale"
> use="optional"/>
>      </xsd:complexType>
>
>
> My question now is, how can I map the nested
> OptionalElements/ReleaseDate to attribute:datereleased ?
>
> The approach below seems to work for the first mapping of a choice
> element, but it doesn't "feel right". Do I really need to configure a
> mapping for all the 7 position at which the choice item could be?
> Assuming that there can be a maximum of 7 choice elements (number of
> elements in my article-choice.xsd), I mapped all of them to the
> attribute, which seems to work that OpenCms only takes the
>
>              <mappings>
>                  <mapping element="Title" mapto="property:Title"/>
>                  <mapping element="OptionalElements[1]/ReleaseDate"
> mapto="attribute:datereleased"/>
>                  <mapping element="OptionalElements[2]/ReleaseDate"
> mapto="attribute:datereleased"/>
>                  <mapping element="OptionalElements[3]/ReleaseDate"
> mapto="attribute:datereleased"/>
>                  <mapping element="OptionalElements[4]/ReleaseDate"
> mapto="attribute:datereleased"/>
>                  <mapping element="OptionalElements[5]/ReleaseDate"
> mapto="attribute:datereleased"/>
>                  <mapping element="OptionalElements[6]/ReleaseDate"
> mapto="attribute:datereleased"/>
>                  <mapping element="OptionalElements[7]/ReleaseDate"
> mapto="attribute:datereleased"/>
>
> However, when I want to add further mappings for other choice elements,
> this approach doesn't work.
>
>
> Also, how to map such field to a searchsetting / solrfield? Do I add it
> to the parent or the nested xsd? Because using brackets for the [index]
> doesn't seem to be valid syntax.
>
> This doesn't work:
>
> <searchsetting element="OptionalElements[2]/FeaturedImage"
> searchcontent="true">
>      <solrfield targetfield="afeaturedimage" />
> </searchsetting>
>
> Thanks.
>
>

-- 
Rüdiger Kurz

-------------------

Alkacon Software GmbH - The OpenCms Experts
Rüdiger Kurz
An der Wachsfabrik 13
50996 Koeln, DE



More information about the opencms-dev mailing list