org.opencms.xml.types
Interface I_CmsXmlSchemaType

All Superinterfaces:
java.lang.Comparable<I_CmsXmlSchemaType>
All Known Subinterfaces:
I_CmsXmlContentValue
All Known Implementing Classes:
A_CmsXmlContentValue, A_CmsXmlValueCdataBase, A_CmsXmlValueTextBase, CmsXmlBooleanValue, CmsXmlColorValue, CmsXmlDateTimeValue, CmsXmlHtmlValue, CmsXmlLocaleValue, CmsXmlNestedContentDefinition, CmsXmlPlainTextStringValue, CmsXmlStringValue, CmsXmlVarLinkValue, CmsXmlVfsFileValue, CmsXmlVfsImageValue

public interface I_CmsXmlSchemaType
extends java.lang.Comparable<I_CmsXmlSchemaType>

Describes a type in an OpenCms XML schema based content definition.

A XML content definition in OpenCms basically consists of a sequence of nodes in the following format:

<xsd:element name="title" type="cmsStringType" minOccurs="0" maxOccurs="unbounded" default="Some text" />.

Internally, each configured element in a XML schema is represented by an instance of this interface. This allows for constructing or changing the XML schema through the provided API.

Note that this class only describes the definition of a value in the XML schema. It is not the representation of an actual value from a XML file, for this you need an instance of a I_CmsXmlContentValue.

Since:
6.0.0
Version:
$Revision: 1.30 $
Author:
Alexander Kandzior
See Also:
I_CmsXmlContentValue

Field Summary
static org.dom4j.Namespace XSI_NAMESPACE
          The schema instance namespace.
static org.dom4j.QName XSI_NAMESPACE_ATTRIBUTE_NO_SCHEMA_LOCATION
          Constant for the XML schema attribute "noNamespaceSchemaLocation" in the XML schema instance namespace.
 
Method Summary
 void appendXmlSchema(org.dom4j.Element root)
          Appends an XML representation of this schema type to the given XML element.
 I_CmsXmlContentValue createValue(I_CmsXmlDocument document, org.dom4j.Element element, java.util.Locale locale)
          Creates a XML content value object for this type.
 org.dom4j.Element generateXml(CmsObject cms, I_CmsXmlDocument document, org.dom4j.Element root, java.util.Locale locale)
          Appends an XML for a new, empty node of this schema type to the given root element.
 CmsXmlContentDefinition getContentDefinition()
          Returns the content definition this schema type belongs to.
 java.lang.String getDefault(java.util.Locale locale)
          Returns the default value for a node of this type in the current schema.
 int getMaxOccurs()
          Returns the maximum occurrences of this type in the current schema.
 int getMinOccurs()
          Returns the minimum occurrences of this type in the current schema.
 java.lang.String getName()
          Returns the XML element node name of this type in the current schema.
 java.lang.String getSchemaDefinition()
          Returns a String representation of the XML definition for this schema type.
 java.lang.String getTypeName()
          Returns the schema type name.
 boolean isSimpleType()
          Returns true if this is a simple type, or false if this type is a nested schema.
 I_CmsXmlSchemaType newInstance(java.lang.String name, java.lang.String minOccurs, java.lang.String maxOccurs)
          Creates a new instance of this XML schema type initialized with the given values.
 void setContentDefinition(CmsXmlContentDefinition contentDefinition)
          Sets the content definition this schema type belongs to.
 void setDefault(java.lang.String defaultValue)
          Sets the default value for a node of this type in the current schema.
 boolean validateValue(java.lang.String value)
          Checks if a given value is valid according to the validation rule (regular expression) used for validation of this schema type in the XML schema.
 
Methods inherited from interface java.lang.Comparable
compareTo
 

Field Detail

XSI_NAMESPACE

static final org.dom4j.Namespace XSI_NAMESPACE
The schema instance namespace.


XSI_NAMESPACE_ATTRIBUTE_NO_SCHEMA_LOCATION

static final org.dom4j.QName XSI_NAMESPACE_ATTRIBUTE_NO_SCHEMA_LOCATION
Constant for the XML schema attribute "noNamespaceSchemaLocation" in the XML schema instance namespace.

Method Detail

appendXmlSchema

void appendXmlSchema(org.dom4j.Element root)
Appends an XML representation of this schema type to the given XML element.

This is used to dynamically build a XML schema from an instance of a CmsXmlContentDefinition class.

Parameters:
root - the element to append the XML to

createValue

I_CmsXmlContentValue createValue(I_CmsXmlDocument document,
                                 org.dom4j.Element element,
                                 java.util.Locale locale)
Creates a XML content value object for this type.

Parameters:
document - the XML content instance this value belongs to
element - the XML element to create the value from
locale - the locale to create the value for
Returns:
the created XML content value object

generateXml

org.dom4j.Element generateXml(CmsObject cms,
                              I_CmsXmlDocument document,
                              org.dom4j.Element root,
                              java.util.Locale locale)
Appends an XML for a new, empty node of this schema type to the given root element.

This is used to dynamically build a vaild XML content object from an initialized CmsXmlContentDefinition class.

Important: This method can only be used during initialization of a XML content object, not to add values to an already initialized XML content. To add values after initialization, use CmsXmlContent.addValue(CmsObject, String, Locale, int).

Parameters:
cms - the current users OpenCms context
document - the document the XML is generated for
root - the element to append the XML to
locale - the locale to generate the element default content for
Returns:
the generated XML element

getContentDefinition

CmsXmlContentDefinition getContentDefinition()
Returns the content definition this schema type belongs to.

If the value belongs to a nested content, then the nested content definition is returned. This means that for documents with nested schemas, the content definition of a value is not necessarily equal to the content definition of the document itself, which can be obtained using I_CmsXmlContentValue.getDocument().

Returns:
the content definition this schema type belongs to

getDefault

java.lang.String getDefault(java.util.Locale locale)
Returns the default value for a node of this type in the current schema.

Parameters:
locale - the locale to generate the default value for
Returns:
the default value for a node of this type in the current schema
See Also:
I_CmsXmlContentHandler.getDefault(CmsObject, I_CmsXmlContentValue, Locale)

getMaxOccurs

int getMaxOccurs()
Returns the maximum occurrences of this type in the current schema.

Returns:
the maximum occurrences of this type in the current schema

getMinOccurs

int getMinOccurs()
Returns the minimum occurrences of this type in the current schema.

Returns:
the minimum occurrences of this type in the current schema

getName

java.lang.String getName()
Returns the XML element node name of this type in the current schema.

The XML element node name can be configured in the schema. For example, the node name could be "Title", "Teaser" or "Text". The XML schema controls what node names are allowed.

Returns:
the XML node name of this type in the current schema

getSchemaDefinition

java.lang.String getSchemaDefinition()
Returns a String representation of the XML definition for this schema type.

Returns:
a String representation of the XML definition for this schema type

getTypeName

java.lang.String getTypeName()
Returns the schema type name.

By convention, a XML schema type name has the form "OpenCms + ${name}". Examples are "OpenCmsString" or "OpenCmsBoolean".

The schema type name is fixed by the implementation.

Returns:
the schema type name

isSimpleType

boolean isSimpleType()
Returns true if this is a simple type, or false if this type is a nested schema.

If a value is a nested schema, it must be an instance of CmsXmlNestedContentDefinition.

Returns:
true if this is a simple type, or false if this type is a nested schema
See Also:
CmsXmlNestedContentDefinition

newInstance

I_CmsXmlSchemaType newInstance(java.lang.String name,
                               java.lang.String minOccurs,
                               java.lang.String maxOccurs)
Creates a new instance of this XML schema type initialized with the given values.

Parameters:
name - the name to use in the xml document
minOccurs - minimum number of occurrences
maxOccurs - maximum number of occurrences
Returns:
a new instance of this XML content type initialized with the given values

setContentDefinition

void setContentDefinition(CmsXmlContentDefinition contentDefinition)
Sets the content definition this schema type belongs to.

This is done automatically when the scheme type is added to a content definition. Usually there is no need to call this method from the application.

Parameters:
contentDefinition - the content definition to set

setDefault

void setDefault(java.lang.String defaultValue)
Sets the default value for a node of this type in the current schema.

Parameters:
defaultValue - the default value to set

validateValue

boolean validateValue(java.lang.String value)
Checks if a given value is valid according to the validation rule (regular expression) used for validation of this schema type in the XML schema.

To have a more refined validation according to the special requirements of the content type, use custom validation rules in the appinfo which are processed with I_CmsXmlContentHandler.resolveValidation(CmsObject, I_CmsXmlContentValue, org.opencms.xml.content.CmsXmlContentErrorHandler).

Parameters:
value - the value to validate
Returns:
the validation rule (regular expression) used for this schema type in the XML schema
See Also:
I_CmsXmlContentHandler.resolveValidation(CmsObject, I_CmsXmlContentValue, org.opencms.xml.content.CmsXmlContentErrorHandler)