Class CmsXmlContent
- All Implemented Interfaces:
I_CmsXmlDocument
- Direct Known Subclasses:
CmsXmlContainerPage
,CmsXmlGroupContainer
Use the CmsXmlContentFactory
to generate an
instance of this class.
- Since:
- 6.0.0
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The name of the version attribute.static final String
The name of the XML content auto correction runtime attribute, this must always be a Boolean.protected boolean
Flag to control if auto correction is enabled when saving this XML content.protected CmsXmlContentDefinition
The XML content definition object (i.e.protected boolean
Indicates whether any broken links have been invalidated in the content.static final String
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
ModifierConstructorDescriptionprotected
Hides the public constructor.protected
CmsXmlContent
(CmsObject cms, Locale locale, 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, Locale locale, 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.protected
CmsXmlContent
(CmsObject cms, org.dom4j.Document document, String encoding, EntityResolver resolver) Creates a new XML content based on the provided XML document. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addBookmarkForElement
(org.dom4j.Element element, Locale locale, org.dom4j.Element parent, String parentPath, CmsXmlContentDefinition parentDef) Creates a new bookmark for the given element.protected void
addBookmarkForValue
(I_CmsXmlContentValue value, String path, Locale locale, boolean enabled) Adds a bookmark for the given value.void
Adds the given locale to this XML document.Adds a new XML content value for the given element name and locale at the given index position to this XML content document.protected I_CmsXmlContentValue
addValue
(CmsObject cms, org.dom4j.Element parent, I_CmsXmlSchemaType type, Locale locale, int insertIndex) Adds a new XML schema type with the default value to the given parent node.clone()
void
copyLocale
(Locale source, Locale destination, Set<String> elements) Copies the content of the given source locale to the given destination locale in this XML document.Returns all simple type sub values.protected I_CmsXmlContentValue
getBookmark
(String bookmark) Returns the bookmarked value for the given bookmark, which must be a valid bookmark name.Returns the names of all bookmarked elements.getChoiceOptions
(String xpath, Locale locale) Returns the list of choice options for the given xpath in the selected locale.Returns the content definition object used for this XML document.protected CmsXmlContentDefinition
getContentDefinition
(EntityResolver resolver) Returns the content definition object for this xml content object.Returns the content handler associated with the content definition of this XML document.getLinkProcessor
(CmsObject cms, CmsLinkTable linkTable) Returns a link processor for the values of this XML document.org.dom4j.Element
getLocaleNode
(Locale locale) Returns the XML root element node for the given locale.int
Gets the schema version (or 0 if no schema version is set).getSimpleValuesBelowPath
(String elementPath, Locale locale) Returns all simple type values below a given path.getSubValues
(String path, Locale locale) Returns the list of sub-value for the given xpath in the selected locale.getValuesByPath
(String elementPath, Locale locale) Returns all values of the given element path.getValueSequence
(String xpath, Locale locale) Returns the value sequence for the selected element xpath in this XML content.boolean
hasChoiceOptions
(String xpath, Locale locale) Returnstrue
if choice options exist for the given xpath in the selected locale.boolean
Checks if any broken links have been invalidated in this content.protected void
initDocument
(org.dom4j.Document document, String encoding, CmsXmlContentDefinition definition) Initializes an XML document based on the provided document, encoding and content definition.protected void
initDocument
(CmsObject cms, org.dom4j.Document document, String encoding, CmsXmlContentDefinition definition) Initializes an XML document based on the provided document, encoding and content definition.boolean
Returnstrue
if the auto correction feature is enabled for saving this XML content.boolean
Checks if the content is locale independent.boolean
Checks if a version transformation was used when creating this content object.protected void
processSchemaNode
(org.dom4j.Element root, String rootPath, Locale locale, CmsXmlContentDefinition definition) Processes a document node and extracts the values of the node according to the provided XML content definition.void
removeValue
(String name, 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
Sets the file this XML content is written to.void
synchronizeLocaleIndependentValues
(CmsObject cms, Collection<String> skipPaths, Locale sourceLocale) Synchronizes the locale independent fields for the given locale.Validates the content of this XML document.void
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, getBestMatchingLocale, getBookmark, getBookmarkName, getConversion, getEncoding, getFile, getIndexCount, getLocales, getLocales, getNames, getStringValue, getStringValue, getTempDataCache, getValue, getValue, getValueInternal, getValues, getValues, hasLocale, hasValue, hasValue, initDocument, isEnabled, isEnabled, marshal, marshal, moveLocale, removeBookmark, removeLocale, setConversion, toString, updateLocaleNodeSorting, validateXmlStructure
-
Field Details
-
AUTO_CORRECTION_ATTRIBUTE
The name of the XML content auto correction runtime attribute, this must always be a Boolean. -
A_VERSION
The name of the version attribute.- See Also:
-
XERCES_SCHEMA_PROPERTY
The property to set to enable xerces schema validation.- See Also:
-
m_autoCorrectionEnabled
Flag to control if auto correction is enabled when saving this XML content. -
m_contentDefinition
The XML content definition object (i.e. XML schema) used by this content. -
m_hasInvalidatedBrokenLinks
Indicates whether any broken links have been invalidated in the content.
-
-
Constructor Details
-
CmsXmlContent
protected CmsXmlContent()Hides the public constructor. -
CmsXmlContent
protected CmsXmlContent(CmsObject cms, org.dom4j.Document document, String encoding, 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, ifnull
no link validation is performeddocument
- the document to create the xml content fromencoding
- the encoding of the xml contentresolver
- the XML entitiy resolver to use
-
CmsXmlContent
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 contentlocale
- the locale to generate the default content formodelUri
- 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, Locale locale, 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 contentlocale
- the locale to generate the default content forencoding
- the encoding to use when marshalling the XML content latercontentDefinition
- the content definiton to create the content for
-
-
Method Details
-
addLocale
Description copied from interface:I_CmsXmlDocument
Adds the given locale to this XML document.- Parameters:
cms
- the current users OpenCms contextlocale
- the locale to add- Throws:
CmsXmlException
- in case the locale already existed, or if something else goes wrong- See Also:
-
addValue
public I_CmsXmlContentValue addValue(CmsObject cms, String path, 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 contextpath
- the path to the XML content value elementlocale
- the locale where to add the new valueindex
- 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 invalidCmsRuntimeException
- if the element identified by the path already occurredI_CmsXmlSchemaType.getMaxOccurs()
or the givenindex
is invalid (too high).
-
clone
-
copyLocale
public void copyLocale(Locale source, Locale destination, Set<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 localedestination
- the destination loacleelements
- the set of elements to copy- Throws:
CmsXmlException
- if something goes wrong
-
getAllSimpleSubValues
Returns all simple type sub values.- Parameters:
value
- the value- Returns:
- the simple type sub values
-
getChoiceOptions
Returns the list of choice options for the given xpath in the selected locale.In case the xpath does not select a nested choice content definition, or in case the xpath does not exist at all,
null
is returned.- Parameters:
xpath
- the xpath to check the choice options forlocale
- the locale to check- Returns:
- the list of choice options for the given xpath
-
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:
-
getHandler
Description copied from interface:I_CmsXmlDocument
Returns the content handler associated with the content definition of this XML document.This is a shortcut for
getContentDefinition().getContentHandler()
.- Returns:
- the content handler associated with the content definition of this XML document
- See Also:
-
getLinkProcessor
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 processorlinkTable
- the table with the links to process- Returns:
- a link processor for the values of this XML document
- See Also:
-
getLocaleNode
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
-
getSchemaVersion
Gets the schema version (or 0 if no schema version is set).- Returns:
- the schema version
-
getSimpleValuesBelowPath
Returns all simple type values below a given path.- Parameters:
elementPath
- the element pathlocale
- the content locale- Returns:
- the simple type values
-
getSubValues
Returns the list of sub-value for the given xpath in the selected locale.- Specified by:
getSubValues
in interfaceI_CmsXmlDocument
- Overrides:
getSubValues
in classA_CmsXmlDocument
- Parameters:
path
- the xpath to look up the sub-value forlocale
- the locale to use- Returns:
- the list of sub-value for the given xpath in the selected locale
- See Also:
-
getValuesByPath
Returns all values of the given element path.- Parameters:
elementPath
- the element pathlocale
- the content locale- Returns:
- the values
-
getValueSequence
Returns the value sequence for the selected element xpath in this XML content.If the given element xpath is not valid according to the schema of this XML content,
null
is returned.- Parameters:
xpath
- the element xpath to get the value sequence forlocale
- the locale to get the value sequence for- Returns:
- the value sequence for the selected element name in this XML content
-
hasChoiceOptions
Returnstrue
if choice options exist for the given xpath in the selected locale.In case the xpath does not select a nested choice content definition, or in case the xpath does not exist at all,
false
is returned.- Parameters:
xpath
- the xpath to check the choice options forlocale
- the locale to check- Returns:
true
if choice options exist for the given xpath in the selected locale
-
hasInvalidatedBrokenLinks
Checks if any broken links have been invalidated in this content.- Returns:
- true if broken links have been invalidated
-
isAutoCorrectionEnabled
Description copied from class:A_CmsXmlDocument
Returnstrue
if the auto correction feature is enabled for saving this XML content.- Overrides:
isAutoCorrectionEnabled
in classA_CmsXmlDocument
- Returns:
true
if the auto correction feature is enabled for saving this XML content- See Also:
-
isLocaleIndependent
Checks if the content is locale independent.- Returns:
- true if the content is locale independent
-
isTransformedVersion
Checks if a version transformation was used when creating this content object.- Returns:
- true if a version transformation was used when creating this content object
-
removeValue
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 elementlocale
- the locale where to remove the valueindex
- the index where to remove the value (relative to all other values of this type)
-
resolveMappings
Resolves the mappings for all values of this XML content.- Parameters:
cms
- the current users OpenCms context
-
setAutoCorrectionEnabled
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
-
synchronizeLocaleIndependentValues
public void synchronizeLocaleIndependentValues(CmsObject cms, Collection<String> skipPaths, Locale sourceLocale) Synchronizes the locale independent fields for the given locale.- Parameters:
cms
- the cms contextskipPaths
- the paths to skipsourceLocale
- the source locale
-
validate
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:
-
visitAllValuesWith
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 parent of a nested value is visited before the element it contains.
- Parameters:
visitor
- the value visitor implementation to visit the values with
-
addBookmarkForElement
protected void addBookmarkForElement(org.dom4j.Element element, Locale locale, org.dom4j.Element parent, String parentPath, CmsXmlContentDefinition parentDef) Creates a new bookmark for the given element.- Parameters:
element
- the element to create the bookmark forlocale
- the localeparent
- the parent node of the elementparentPath
- the parent's pathparentDef
- the parent's content definition
-
addBookmarkForValue
protected void addBookmarkForValue(I_CmsXmlContentValue value, String path, Locale locale, boolean enabled) Adds a bookmark for the given value.- Parameters:
value
- the value to bookmarkpath
- the lookup path to use for the bookmarklocale
- the locale to use for the bookmarkenabled
- if true, the value is enabled, if false it is disabled
-
addValue
protected I_CmsXmlContentValue addValue(CmsObject cms, org.dom4j.Element parent, I_CmsXmlSchemaType type, Locale locale, int insertIndex) Adds a new XML schema type with the default value to the given parent node.- Parameters:
cms
- the cms contextparent
- the XML parent element to add the new value totype
- the type of the value to addlocale
- the locale to add the new value forinsertIndex
- the index in the XML document where to add the XML node- Returns:
- the created XML content value
-
getBookmark
Description copied from class:A_CmsXmlDocument
Returns the bookmarked value for the given bookmark, which must be a valid bookmark name. UseA_CmsXmlDocument.getBookmarks()
to get the list of all valid bookmark names.- Overrides:
getBookmark
in classA_CmsXmlDocument
- Parameters:
bookmark
- the bookmark name to look up- Returns:
- the bookmarked value for the given bookmark
- See Also:
-
getBookmarks
Description copied from class:A_CmsXmlDocument
Returns the names of all bookmarked elements.- Overrides:
getBookmarks
in classA_CmsXmlDocument
- Returns:
- the names of all bookmarked elements
- See Also:
-
getContentDefinition
protected CmsXmlContentDefinition getContentDefinition(EntityResolver resolver) throws CmsRuntimeException Returns the content definition object for this xml content object.- Parameters:
resolver
- the XML entity resolver to use, required for VFS access- Returns:
- the content definition object for this xml content object
- Throws:
CmsRuntimeException
- if the schema location attribute (systemId
)cannot be found, parsing of the schema fails, an underlying IOException occurs or unmarshalling fails
-
initDocument
protected void initDocument(CmsObject cms, org.dom4j.Document document, 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 contentdocument
- the base XML document to use for initializingencoding
- the encoding to use when marshalling the document laterdefinition
- the content definition to use
-
initDocument
protected void initDocument(org.dom4j.Document document, 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 classA_CmsXmlDocument
- Parameters:
document
- the base XML document to use for initializingencoding
- the encoding to use when marshalling the document laterdefinition
- the content definition to use- See Also:
-
processSchemaNode
protected void processSchemaNode(org.dom4j.Element root, String rootPath, Locale locale, CmsXmlContentDefinition definition) Processes a document node and extracts the values of the node according to the provided XML content definition.- Parameters:
root
- the root node element to processrootPath
- the Xpath of the root node in the documentlocale
- the localedefinition
- the XML content definition to use for processing the values
-
setFile
Sets the file this XML content is written to.- Parameters:
file
- the file this XML content content is written to
-