org.opencms.xml.types
Class A_CmsXmlContentValue

java.lang.Object
  extended byorg.opencms.xml.types.A_CmsXmlContentValue
All Implemented Interfaces:
Comparable, I_CmsWidgetParameter, I_CmsXmlContentValue, I_CmsXmlSchemaType
Direct Known Subclasses:
A_CmsXmlValueCdataBase, A_CmsXmlValueTextBase, CmsXmlHtmlValue, CmsXmlNestedContentDefinition, CmsXmlVfsFileValue

public abstract class A_CmsXmlContentValue
extends Object
implements I_CmsXmlContentValue, I_CmsWidgetParameter

Base class for XML content value implementations.

Since:
6.0.0
Version:
$Revision: 1.32 $
Author:
Alexander Kandzior

Field Summary
protected  String m_defaultValue
          The default value for nodes of this value.
protected  I_CmsXmlDocument m_document
          The XML content instance this value belongs to.
protected  Element m_element
          The XML element node that contains this value.
protected  Locale m_locale
          The locale this value was generated for.
protected  int m_maxOccurs
          The maximum occurences of this value according to the parent schema.
protected  int m_minOccurs
          The minimum occurences of this value according to the parent schema.
protected  String m_name
          The configured XML node name of this value.
 
Fields inherited from interface org.opencms.xml.types.I_CmsXmlSchemaType
XSI_NAMESPACE, XSI_NAMESPACE_ATTRIBUTE_NO_SCHEMA_LOCATION
 
Constructor Summary
protected A_CmsXmlContentValue()
          Default constructor for a xml content type that initializes some internal values.
protected A_CmsXmlContentValue(I_CmsXmlDocument document, Element element, Locale locale, I_CmsXmlSchemaType type)
          Initializes the required members for this XML content value.
protected A_CmsXmlContentValue(String name, String minOccurs, String maxOccurs)
          Initializes the schema type descriptor values for this type descriptor.
 
Method Summary
 void appendXmlSchema(Element root)
          Appends an element XML representation of this type to the given root node.
 int compareTo(Object obj)
           
 boolean equals(Object obj)
           
 Element generateXml(CmsObject cms, I_CmsXmlDocument document, Element root, 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.
 String getDefault(CmsObject cms)
          Returns the default value of this parameter.
 String getDefault(Locale locale)
          Returns the default value for a node of this type in the current schema.
 I_CmsXmlDocument getDocument()
          Returns the XML content instance this value belongs to.
 Element getElement()
          Returns the original XML element of this XML content value.
 String getId()
          Returns the form id of this parameter.
 int getIndex()
          Returns the node index of this XML content value in the source XML document, starting with 0.
 String getKey()
          Returns the localized key identificator of this parameter.
 Locale getLocale()
          Returns the locale of this XML content value was generated for.
 int getMaxOccurs()
          Returns the maximum occurences of this type.
 int getMinOccurs()
          Returns the minimum occurences of this type.
 String getName()
          Returns the name.
 String getPath()
          Returns the path of this XML content value in the source document.
 String getPlainText(CmsObject cms)
          Returns the value of this XML content node as a plain text String.
 boolean hasError()
          Returns true if this widgets value contains an error.
 int hashCode()
           
 boolean isSimpleType()
          Returns true if this is a simple type, or false if this type is a nested schema.
protected  String readSchemaDefinition(String schemaUri)
          Convenience method to loads the XML schema definition for this value type from an external file.
 void setContentDefinition(CmsXmlContentDefinition contentDefinition)
          Sets the content definition this schema type belongs to.
 void setDefault(String defaultValue)
          Sets the default value for a node of this type.
 void setKeyPrefix(String prefix)
          Sets an optional localized key prefix identificator of this parameter.
 boolean validateValue(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 class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.opencms.xml.types.I_CmsXmlContentValue
getStringValue, setStringValue
 
Methods inherited from interface org.opencms.xml.types.I_CmsXmlSchemaType
createValue, getSchemaDefinition, getTypeName, newInstance
 
Methods inherited from interface org.opencms.widgets.I_CmsWidgetParameter
getStringValue, setStringValue
 

Field Detail

m_defaultValue

protected String m_defaultValue
The default value for nodes of this value.


m_document

protected I_CmsXmlDocument m_document
The XML content instance this value belongs to.


m_element

protected Element m_element
The XML element node that contains this value.


m_locale

protected Locale m_locale
The locale this value was generated for.


m_maxOccurs

protected int m_maxOccurs
The maximum occurences of this value according to the parent schema.


m_minOccurs

protected int m_minOccurs
The minimum occurences of this value according to the parent schema.


m_name

protected String m_name
The configured XML node name of this value.

Constructor Detail

A_CmsXmlContentValue

protected A_CmsXmlContentValue()
Default constructor for a xml content type that initializes some internal values.


A_CmsXmlContentValue

protected A_CmsXmlContentValue(I_CmsXmlDocument document,
                               Element element,
                               Locale locale,
                               I_CmsXmlSchemaType type)
Initializes the required members for this XML content value.

Parameters:
document - the XML content instance this value belongs to
element - the XML element that contains this value
locale - the locale this value is created for
type - the type instance to create the value for

A_CmsXmlContentValue

protected A_CmsXmlContentValue(String name,
                               String minOccurs,
                               String maxOccurs)
Initializes the schema type descriptor values for this type descriptor.

Parameters:
name - the name of the XML node containing the value according to the XML schema
minOccurs - minimum number of occurences of this type according to the XML schema
maxOccurs - maximum number of occurences of this type according to the XML schema
Method Detail

appendXmlSchema

public void appendXmlSchema(Element root)
Appends an element XML representation of this type to the given root node.

Specified by:
appendXmlSchema in interface I_CmsXmlSchemaType
Parameters:
root - the element to append the XML to

compareTo

public int compareTo(Object obj)
Specified by:
compareTo in interface Comparable
See Also:
Comparable.compareTo(java.lang.Object)

equals

public boolean equals(Object obj)
See Also:
Object.equals(java.lang.Object)

generateXml

public Element generateXml(CmsObject cms,
                           I_CmsXmlDocument document,
                           Element root,
                           Locale locale)
Description copied from interface: I_CmsXmlSchemaType
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).

Specified by:
generateXml in interface I_CmsXmlSchemaType
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
See Also:
I_CmsXmlSchemaType.generateXml(org.opencms.file.CmsObject, org.opencms.xml.I_CmsXmlDocument, org.dom4j.Element, java.util.Locale)

getContentDefinition

public CmsXmlContentDefinition getContentDefinition()
Description copied from interface: I_CmsXmlSchemaType
Returns the content definition this schema type belongs to.

Note that for nested schemas, the content definition of a nested value is not neccessarily equal to the content defintion of the document returned by I_CmsXmlContentValue.getDocument(). If the value belongs to a nested content, then the content definiton of the value also is the nested content defintion.

Specified by:
getContentDefinition in interface I_CmsXmlSchemaType
Returns:
the content definition this schema type belongs to
See Also:
I_CmsXmlSchemaType.getContentDefinition()

getDefault

public String getDefault(CmsObject cms)
Description copied from interface: I_CmsWidgetParameter
Returns the default value of this parameter.

If no default value has been provided, null is returned.

Specified by:
getDefault in interface I_CmsWidgetParameter
Parameters:
cms - an initialized instance of an OpenCms user context
Returns:
the default value of this parameter
See Also:
I_CmsWidgetParameter.getDefault(org.opencms.file.CmsObject)

getDefault

public String getDefault(Locale locale)
Description copied from interface: I_CmsXmlSchemaType
Returns the default value for a node of this type in the current schema.

Specified by:
getDefault in interface I_CmsXmlSchemaType
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_CmsXmlSchemaType.getDefault(java.util.Locale)

getDocument

public I_CmsXmlDocument getDocument()
Description copied from interface: I_CmsXmlContentValue
Returns the XML content instance this value belongs to.

Specified by:
getDocument in interface I_CmsXmlContentValue
Returns:
the XML content instance this value belongs to
See Also:
I_CmsXmlContentValue.getDocument()

getElement

public Element getElement()
Description copied from interface: I_CmsXmlContentValue
Returns the original XML element of this XML content value.

Specified by:
getElement in interface I_CmsXmlContentValue
Returns:
the original XML element of this XML content value
See Also:
I_CmsXmlContentValue.getElement()

getId

public String getId()
Description copied from interface: I_CmsWidgetParameter
Returns the form id of this parameter.

Specified by:
getId in interface I_CmsWidgetParameter
Returns:
the form id of this parameter
See Also:
I_CmsWidgetParameter.getId()

getIndex

public int getIndex()
Description copied from interface: I_CmsXmlContentValue
Returns the node index of this XML content value in the source XML document, starting with 0.

This is usefull in case there are more then one elements with the same XML node name in the source XML document.

Specified by:
getIndex in interface I_CmsXmlContentValue
Returns:
the index of this XML content node in the source document
See Also:
I_CmsXmlContentValue.getIndex()

getKey

public String getKey()
Description copied from interface: I_CmsWidgetParameter
Returns the localized key identificator of this parameter.

Specified by:
getKey in interface I_CmsWidgetParameter
Returns:
the localized key identificator of this parameter
See Also:
I_CmsWidgetParameter.getKey()

getLocale

public Locale getLocale()
Description copied from interface: I_CmsXmlContentValue
Returns the locale of this XML content value was generated for.

Specified by:
getLocale in interface I_CmsXmlContentValue
Returns:
the locale of this XML content value was generated for
See Also:
I_CmsXmlContentValue.getLocale()

getMaxOccurs

public int getMaxOccurs()
Returns the maximum occurences of this type.

Specified by:
getMaxOccurs in interface I_CmsXmlSchemaType
Returns:
the maximum occurences of this type

getMinOccurs

public int getMinOccurs()
Returns the minimum occurences of this type.

Specified by:
getMinOccurs in interface I_CmsXmlSchemaType
Returns:
the minimum occurences of this type

getName

public String getName()
Returns the name.

Specified by:
getName in interface I_CmsXmlSchemaType
Returns:
the name

getPath

public String getPath()
Description copied from interface: I_CmsXmlContentValue
Returns the path of this XML content value in the source document.

Specified by:
getPath in interface I_CmsXmlContentValue
Returns:
the path of this XML content value in the source document
See Also:
I_CmsXmlContentValue.getPath()

getPlainText

public String getPlainText(CmsObject cms)
Description copied from interface: I_CmsXmlContentValue
Returns the value of this XML content node as a plain text String.

Plain text in this context means a pure textual representation of the content (i.e. without html tags). The plain text may be null, too, if there is no sound or useful textual representation (i.e. color values).

Specified by:
getPlainText in interface I_CmsXmlContentValue
Parameters:
cms - an initialized instance of a CmsObject
Returns:
the value of this XML content node as a plain text String
See Also:
I_CmsXmlContentValue.getPlainText(org.opencms.file.CmsObject)

hasError

public boolean hasError()
Description copied from interface: I_CmsWidgetParameter
Returns true if this widgets value contains an error.

Specified by:
hasError in interface I_CmsWidgetParameter
Returns:
true if this widgets value contains an error
See Also:
I_CmsWidgetParameter.hasError()

hashCode

public int hashCode()
See Also:
Object.hashCode()

isSimpleType

public boolean isSimpleType()
Description copied from interface: I_CmsXmlSchemaType
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.

Specified by:
isSimpleType in interface I_CmsXmlSchemaType
Returns:
true if this is a simple type, or false if this type is a nested schema
See Also:
I_CmsXmlSchemaType.isSimpleType()

setContentDefinition

public void setContentDefinition(CmsXmlContentDefinition contentDefinition)
Description copied from interface: I_CmsXmlSchemaType
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.

Specified by:
setContentDefinition in interface I_CmsXmlSchemaType
Parameters:
contentDefinition - the content definition to set
See Also:
I_CmsXmlSchemaType.setContentDefinition(org.opencms.xml.CmsXmlContentDefinition)

setDefault

public void setDefault(String defaultValue)
Sets the default value for a node of this type.

Specified by:
setDefault in interface I_CmsXmlSchemaType
Parameters:
defaultValue - the default value to set

setKeyPrefix

public void setKeyPrefix(String prefix)
Description copied from interface: I_CmsWidgetParameter
Sets an optional localized key prefix identificator of this parameter.

Specified by:
setKeyPrefix in interface I_CmsWidgetParameter
Parameters:
prefix - the optional localized key prefix identificator of this parameter
See Also:
I_CmsWidgetParameter.setKeyPrefix(java.lang.String)

validateValue

public boolean validateValue(String value)
Description copied from interface: I_CmsXmlSchemaType
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).

Specified by:
validateValue in interface I_CmsXmlSchemaType
Parameters:
value - the value to validate
Returns:
the validation rule (regular expression) used for this schema type in the XML schema
See Also:
I_CmsXmlSchemaType.validateValue(java.lang.String)

readSchemaDefinition

protected String readSchemaDefinition(String schemaUri)
                               throws CmsRuntimeException
Convenience method to loads the XML schema definition for this value type from an external file.

Parameters:
schemaUri - the schema uri to load the XML schema file from
Returns:
the loaded XML schema
Throws:
CmsRuntimeException - if something goes wrong