Advanced XSD configuration

With OpenCms XML contents, advanced configuration options can be defined in the <appinfo> node of the XSD.

In the <appinfo> node, the following configuration options are possible:

  • Define a localized resource bundle name for usage in the XML content editor. This allows you to define localized Strings for the names and/or help texts to display for the input form fields.
  • Map values of the XML content to OpenCms resource properties like "Title" or file attributes like modification date.
  • Define regular expressions to validate the submitted input field values before saving the XML content file.
  • Define default values for each element of the XML content.
  • Apply different layout widgets to the input fields if you don't want to use the default widgets for a data type. For some widgets like the SelectorWidget or the ComboWidget, additional configuration data is necessary to build the available options.

The following code is taken from the article example article.xsd  in the folder /xmlcontentdemo/:

1  <xsd:annotation>
2		<xsd:appinfo>
3			<resourcebundle name="org.opencms.frontend.templateone.xmlcontentdemo.workplace"/>
4			<mappings>
5				<mapping element="Title" mapto="property:Title" />
6				<mapping element="Release" mapto="attribute:datereleased" />
7			</mappings>
8			<validationrules>
9				<rule element="Title" regex="!.*[Ee]rror.*" 
                          message="${key.editor.errormessage.Article.mustnotcontainerror|${validation.path}}" />
10				<rule element="Title" regex="!.*[Ww]arn.*" type="warning" 
11				<rule element="Teaser" regex="!.*[Ww]arn.*" type="warning" 
12				<rule element="Text" regex="!.*[Ww]arn.*" type="warning" 
13			</validationrules>
14			<defaults>
15				<default element="Title" value="${key.editor.defaults.Article.Title}"/>
16				<default element="Teaser" value="${key.editor.defaults.Article.Teaser}"/>
17				<default element="Release" value="${currenttime}"/>
18				<default element="Author" value="${currentuser.fullname}"/>
19			</defaults>
20		</xsd:appinfo>
21 </xsd:annotation>

The next example is taken from the widget demo widgetdemo.xsd in the folder /xmlcontentdemo/widgetdemo/.  It shows how to assign and configure other widgets for XML content types: 

1  <xsd:annotation>
2   <xsd:appinfo>
3	...
4	<layouts>
5		<layout element="Image" widget="ImageGalleryWidget" />
6		<layout element="StringPlaintext" widget="StringWidgetPlaintext"/>
7		<layout element="Download" widget="DownloadGalleryWidget" />
8		<layout element="Link" widget="LinkGalleryWidget" />
9		<layout element="HtmlSnippet" widget="HtmlGalleryWidget" />
10		<layout element="TableSnippet" widget="TableGalleryWidget" /> 
11		<layout element="Selector" widget="SelectorWidget" 
                 configuration="Option 1|Option 2|Option 3|Option4" />
12		<layout element="MultiSelector" widget="MultiSelectWidget" 
                 configuration="Option 1|Option 2|Option 3|Option 4" />
13		<layout element="Textarea" widget="TextareaWidget" />
14		<layout element="TextareaPlaintext" widget="TextareaWidgetPlaintext"/>
15		<layout element="Combobox" widget="ComboWidget" 
                        configuration="value='Value 1' help='A help text for value 1'|
			value='Value 2' help='Another help text for the second value.'|
			value='Value 3' default='true' help='The help text vor value three.'|
			value='Value 4 which has a very long value text' 
			help='The is the help for value 4'" />
16		<layout element="DisplayWidget" widget="DisplayWidget"/>
17	</layouts>
18  </xsd:appinfo>
18 </xsd:annotation>

The definition of the options to show in a select box or combo box is written in the configuration attribute value of a layout node. For a select box, it is possible to define the options and the shown values. The options are separated by a pipe symbol  "|". An example to define 2 options with different shown values is: configuration="value='value1' option='option1'|value='value2' option='option2' default='true'". This defines two selectable options with the second option as default value.

The combo box does not support values to show, but help texts can be displayed for each item if the widget is configured as shown at line 12 of the second example.

Learn more about localizing XML contents on the next page .