org.opencms.xml.content
Class CmsXmlContent

java.lang.Object
  extended by org.opencms.xml.A_CmsXmlDocument
      extended by org.opencms.xml.content.CmsXmlContent
All Implemented Interfaces:
I_CmsXmlDocument

public class CmsXmlContent
extends A_CmsXmlDocument

Implementation of a XML content object, used to access and manage structured content.

Use the CmsXmlContentFactory to generate an instance of this class.

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

Field Summary
static java.lang.String AUTO_CORRECTION_ATTRIBUTE
          The name of the XML content auto correction runtime attribute, this must always be a Boolean.
protected  boolean m_autoCorrectionEnabled
          Flag to control if auto correction is enabled when saving this XML content.
protected  CmsXmlContentDefinition m_contentDefinition
          The XML content definition object (i.e.
static java.lang.String XERCES_SCHEMA_PROPERTY
          The property to set to enable xerces schema validation.
 
Fields inherited from class org.opencms.xml.A_CmsXmlDocument
m_conversion, m_document, m_elementLocales, m_elementNames, m_encoding, m_file, m_locales
 
Constructor Summary
protected CmsXmlContent()
          Hides the public constructor.
protected CmsXmlContent(CmsObject cms, org.dom4j.Document document, java.lang.String encoding, org.xml.sax.EntityResolver resolver)
          Creates a new XML content based on the provided XML document.
protected CmsXmlContent(CmsObject cms, java.util.Locale locale, java.lang.String modelUri)
          Create a new XML content based on the given default content, that will have all language nodes of the default content and ensures the presence of the given locale.
protected CmsXmlContent(CmsObject cms, java.util.Locale locale, java.lang.String encoding, CmsXmlContentDefinition contentDefinition)
          Create a new XML content based on the given content definiton, that will have one language node for the given locale all initialized with default values.
 
Method Summary
 void addLocale(CmsObject cms, java.util.Locale locale)
          Adds the given locale to this XML document.
 I_CmsXmlContentValue addValue(CmsObject cms, java.lang.String path, java.util.Locale locale, int index)
          Adds a new XML content value for the given element name and locale at the given index position to this XML content document.
 void copyLocale(java.util.Locale source, java.util.Locale destination, java.util.Set<java.lang.String> elements)
          Copies the content of the given source locale to the given destination locale in this XML document.
protected  I_CmsXmlContentValue getBookmark(java.lang.String bookmark)
          Returns the bookmarked value for the given bookmark, which must be a valid bookmark name.
protected  java.util.Set<java.lang.String> getBookmarks()
          Returns the names of all bookmarked elements.
 CmsXmlContentDefinition getContentDefinition()
          Returns the content definition object used for this XML document.
 CmsLinkProcessor getLinkProcessor(CmsObject cms, CmsLinkTable linkTable)
          Returns a link processor for the values of this XML document.
protected  org.dom4j.Element getLocaleNode(java.util.Locale locale)
          Returns the XML root element node for the given locale.
 CmsXmlContentValueSequence getValueSequence(java.lang.String name, java.util.Locale locale)
          Returns the value sequence for the selected element name in this XML content.
protected  void initDocument(CmsObject cms, org.dom4j.Document document, java.lang.String encoding, CmsXmlContentDefinition definition)
          Initializes an XML document based on the provided document, encoding and content definition.
protected  void initDocument(org.dom4j.Document document, java.lang.String encoding, CmsXmlContentDefinition definition)
          Initializes an XML document based on the provided document, encoding and content definition.
 boolean isAutoCorrectionEnabled()
          Returns true if the auto correction feature is enabled for saving this XML content.
 void removeValue(java.lang.String name, java.util.Locale locale, int index)
          Removes an existing XML content value of the given element name and locale at the given index position from this XML content document.
 void resolveMappings(CmsObject cms)
          Resolves the mappings for all values of this XML content.
 void setAutoCorrectionEnabled(boolean value)
          Sets the flag to control if auto correction is enabled when saving this XML content.
protected  void setFile(CmsFile file)
          Sets the file this XML content is written to.
 CmsXmlContentErrorHandler validate(CmsObject cms)
          Validates the content of this XML document.
 void visitAllValuesWith(I_CmsXmlContentValueVisitor visitor)
          Visits all values of this XML content with the given value visitor.
 
Methods inherited from class org.opencms.xml.A_CmsXmlDocument
addBookmark, addLocale, clearBookmarks, copyLocale, copyLocale, correctXmlStructure, createDeepElementCopy, getBookmark, getBookmarkName, getConversion, getEncoding, getFile, getIndexCount, getLocales, getLocales, getNames, getStringValue, getStringValue, getValue, getValue, getValues, getValues, hasLocale, hasValue, hasValue, initDocument, isEnabled, isEnabled, marshal, marshal, moveLocale, removeBookmark, removeLocale, setConversion, toString, validateXmlStructure
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

AUTO_CORRECTION_ATTRIBUTE

public static final java.lang.String AUTO_CORRECTION_ATTRIBUTE
The name of the XML content auto correction runtime attribute, this must always be a Boolean.


XERCES_SCHEMA_PROPERTY

public static final java.lang.String XERCES_SCHEMA_PROPERTY
The property to set to enable xerces schema validation.

See Also:
Constant Field Values

m_autoCorrectionEnabled

protected boolean m_autoCorrectionEnabled
Flag to control if auto correction is enabled when saving this XML content.


m_contentDefinition

protected CmsXmlContentDefinition m_contentDefinition
The XML content definition object (i.e. XML schema) used by this content.

Constructor Detail

CmsXmlContent

protected CmsXmlContent()
Hides the public constructor.


CmsXmlContent

protected CmsXmlContent(CmsObject cms,
                        org.dom4j.Document document,
                        java.lang.String encoding,
                        org.xml.sax.EntityResolver resolver)
Creates a new XML content based on the provided XML document.

The given encoding is used when marshalling the XML again later.

Parameters:
cms - the cms context, if null no link validation is performed
document - the document to create the xml content from
encoding - the encoding of the xml content
resolver - the XML entitiy resolver to use

CmsXmlContent

protected CmsXmlContent(CmsObject cms,
                        java.util.Locale locale,
                        java.lang.String modelUri)
                 throws CmsException
Create a new XML content based on the given default content, that will have all language nodes of the default content and ensures the presence of the given locale.

The given encoding is used when marshalling the XML again later.

Parameters:
cms - the current users OpenCms content
locale - the locale to generate the default content for
modelUri - the absolute path to the XML content file acting as model
Throws:
CmsException - in case the model file is not found or not valid

CmsXmlContent

protected CmsXmlContent(CmsObject cms,
                        java.util.Locale locale,
                        java.lang.String encoding,
                        CmsXmlContentDefinition contentDefinition)
Create a new XML content based on the given content definiton, that will have one language node for the given locale all initialized with default values.

The given encoding is used when marshalling the XML again later.

Parameters:
cms - the current users OpenCms content
locale - the locale to generate the default content for
encoding - the encoding to use when marshalling the XML content later
contentDefinition - the content definiton to create the content for
Method Detail

addLocale

public void addLocale(CmsObject cms,
                      java.util.Locale locale)
               throws CmsXmlException
Description copied from interface: I_CmsXmlDocument
Adds the given locale to this XML document.

Parameters:
cms - the current users OpenCms context
locale - the locale to add
Throws:
CmsXmlException - in case the locale already existed, or if something else goes wrong
See Also:
I_CmsXmlDocument.addLocale(org.opencms.file.CmsObject, java.util.Locale)

addValue

public I_CmsXmlContentValue addValue(CmsObject cms,
                                     java.lang.String path,
                                     java.util.Locale locale,
                                     int index)
                              throws CmsIllegalArgumentException,
                                     CmsRuntimeException
Adds a new XML content value for the given element name and locale at the given index position to this XML content document.

Parameters:
cms - the current users OpenCms context
path - the path to the XML content value element
locale - the locale where to add the new value
index - the index where to add the value (relative to all other values of this type)
Returns:
the created XML content value
Throws:
CmsIllegalArgumentException - if the given path is invalid
CmsRuntimeException - if the element identified by the path already occurred I_CmsXmlSchemaType.getMaxOccurs() or the given index is invalid (too high).

copyLocale

public void copyLocale(java.util.Locale source,
                       java.util.Locale destination,
                       java.util.Set<java.lang.String> elements)
                throws CmsXmlException
Copies the content of the given source locale to the given destination locale in this XML document.

Parameters:
source - the source locale
destination - the destination loacle
elements - the set of elements to copy
Throws:
CmsXmlException - if something goes wrong

getContentDefinition

public CmsXmlContentDefinition getContentDefinition()
Description copied from interface: I_CmsXmlDocument
Returns the content definition object used for this XML document.

Returns:
the content definition object used for this XML document
See Also:
I_CmsXmlDocument.getContentDefinition()

getLinkProcessor

public CmsLinkProcessor getLinkProcessor(CmsObject cms,
                                         CmsLinkTable linkTable)
Description copied from interface: I_CmsXmlDocument
Returns a link processor for the values of this XML document.

Parameters:
cms - the current OpenCms user context that provides access to the link processor
linkTable - the table with the links to process
Returns:
a link processor for the values of this XML document
See Also:
I_CmsXmlDocument.getLinkProcessor(org.opencms.file.CmsObject, org.opencms.staticexport.CmsLinkTable)

getValueSequence

public CmsXmlContentValueSequence getValueSequence(java.lang.String name,
                                                   java.util.Locale locale)
Returns the value sequence for the selected element name in this XML content.

If the given element name is not valid according to the schema of this XML content, null is returned.

Parameters:
name - the element name (XML node name) to the the value sequence for
locale - the locale to get the value sequence for
Returns:
the value sequence for the selected element name in this XML content

isAutoCorrectionEnabled

public boolean isAutoCorrectionEnabled()
Description copied from class: A_CmsXmlDocument
Returns true if the auto correction feature is enabled for saving this XML content.

Overrides:
isAutoCorrectionEnabled in class A_CmsXmlDocument
Returns:
true if the auto correction feature is enabled for saving this XML content
See Also:
A_CmsXmlDocument.isAutoCorrectionEnabled()

removeValue

public void removeValue(java.lang.String name,
                        java.util.Locale locale,
                        int index)
Removes an existing XML content value of the given element name and locale at the given index position from this XML content document.

Parameters:
name - the name of the XML content value element
locale - the locale where to remove the value
index - the index where to remove the value (relative to all other values of this type)

resolveMappings

public void resolveMappings(CmsObject cms)
Resolves the mappings for all values of this XML content.

Parameters:
cms - the current users OpenCms context

setAutoCorrectionEnabled

public void setAutoCorrectionEnabled(boolean value)
Sets the flag to control if auto correction is enabled when saving this XML content.

Parameters:
value - the flag to control if auto correction is enabled when saving this XML content

validate

public CmsXmlContentErrorHandler validate(CmsObject cms)
Description copied from interface: I_CmsXmlDocument
Validates the content of this XML document.

To check for errors in a single document locale only, use CmsXmlContentErrorHandler.hasErrors(Locale) in the result object.

Parameters:
cms - the current OpenCms user context
Returns:
an error handler instance that provides information about the errors or warnings that have been found
See Also:
I_CmsXmlDocument.validate(org.opencms.file.CmsObject)

visitAllValuesWith

public void visitAllValuesWith(I_CmsXmlContentValueVisitor visitor)
Visits all values of this XML content with the given value visitor.

Please note that the order in which the values are visited may NOT be the order they appear in the XML document. It is ensured that the the parent of a nested value is visited before the element it contains.

Parameters:
visitor - the value visitor implementation to visit the values with

getBookmark

protected I_CmsXmlContentValue getBookmark(java.lang.String bookmark)
Description copied from class: A_CmsXmlDocument
Returns the bookmarked value for the given bookmark, which must be a valid bookmark name. Use A_CmsXmlDocument.getBookmarks() to get the list of all valid bookmark names.

Overrides:
getBookmark in class A_CmsXmlDocument
Parameters:
bookmark - the bookmark name to look up
Returns:
the bookmarked value for the given bookmark
See Also:
A_CmsXmlDocument.getBookmark(java.lang.String)

getBookmarks

protected java.util.Set<java.lang.String> getBookmarks()
Description copied from class: A_CmsXmlDocument
Returns the names of all bookmarked elements.

Overrides:
getBookmarks in class A_CmsXmlDocument
Returns:
the names of all bookmarked elements
See Also:
A_CmsXmlDocument.getBookmarks()

getLocaleNode

protected org.dom4j.Element getLocaleNode(java.util.Locale locale)
                                   throws CmsRuntimeException
Returns the XML root element node for the given locale.

Parameters:
locale - the locale to get the root element for
Returns:
the XML root element node for the given locale
Throws:
CmsRuntimeException - if no language element is found in the document

initDocument

protected void initDocument(CmsObject cms,
                            org.dom4j.Document document,
                            java.lang.String encoding,
                            CmsXmlContentDefinition definition)
Initializes an XML document based on the provided document, encoding and content definition.

Checks the links and removes invalid ones in the initialized document.

Parameters:
cms - the current users OpenCms content
document - the base XML document to use for initializing
encoding - the encoding to use when marshalling the document later
definition - the content definition to use

initDocument

protected void initDocument(org.dom4j.Document document,
                            java.lang.String encoding,
                            CmsXmlContentDefinition definition)
Description copied from class: A_CmsXmlDocument
Initializes an XML document based on the provided document, encoding and content definition.

Specified by:
initDocument in class A_CmsXmlDocument
Parameters:
document - the base XML document to use for initializing
encoding - the encoding to use when marshalling the document later
definition - the content definition to use
See Also:
A_CmsXmlDocument.initDocument(org.dom4j.Document, java.lang.String, org.opencms.xml.CmsXmlContentDefinition)

setFile

protected void setFile(CmsFile file)
Sets the file this XML content is written to.

Parameters:
file - the file this XML content content is written to