public class CmsXmlContent extends A_CmsXmlDocument
Use the CmsXmlContentFactory
to generate an
instance of this class.
Modifier and Type | Field and Description |
---|---|
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.
|
m_conversion, m_document, m_elementLocales, m_elementNames, m_encoding, m_file, m_locales
Modifier | Constructor and Description |
---|---|
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.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addBookmarkForElement(org.dom4j.Element element,
java.util.Locale locale,
org.dom4j.Element parent,
java.lang.String parentPath,
CmsXmlContentDefinition parentDef)
Creates a new bookmark for the given element.
|
protected void |
addBookmarkForValue(I_CmsXmlContentValue value,
java.lang.String path,
java.util.Locale locale,
boolean enabled)
Adds a bookmark for the given value.
|
void |
addLocale(CmsObject cms,
java.util.Locale locale)
Adds the given locale to this XML document.
|
protected I_CmsXmlContentValue |
addValue(CmsObject cms,
org.dom4j.Element parent,
I_CmsXmlSchemaType type,
java.util.Locale locale,
int insertIndex)
Adds a new XML schema type with the default value to the given parent node.
|
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.
|
CmsXmlContent |
clone() |
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.
|
java.util.List<I_CmsXmlContentValue> |
getAllSimpleSubValues(I_CmsXmlContentValue value)
Returns all simple type sub values.
|
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.
|
java.util.List<I_CmsXmlSchemaType> |
getChoiceOptions(java.lang.String xpath,
java.util.Locale locale)
Returns the list of choice options for the given xpath in the selected locale.
|
CmsXmlContentDefinition |
getContentDefinition()
Returns the content definition object used for this XML document.
|
protected CmsXmlContentDefinition |
getContentDefinition(org.xml.sax.EntityResolver resolver)
Returns the content definition object for this xml content object.
|
I_CmsXmlContentHandler |
getHandler()
Returns the content handler associated with the content definition of this XML document.
|
CmsLinkProcessor |
getLinkProcessor(CmsObject cms,
CmsLinkTable linkTable)
Returns a link processor for the values of this XML document.
|
org.dom4j.Element |
getLocaleNode(java.util.Locale locale)
Returns the XML root element node for the given locale.
|
java.util.List<I_CmsXmlContentValue> |
getSimpleValuesBelowPath(java.lang.String elementPath,
java.util.Locale locale)
Returns all simple type values below a given path.
|
java.util.List<I_CmsXmlContentValue> |
getSubValues(java.lang.String path,
java.util.Locale locale)
Returns the list of sub-value for the given xpath in the selected locale.
|
java.util.List<I_CmsXmlContentValue> |
getValuesByPath(java.lang.String elementPath,
java.util.Locale locale)
Returns all values of the given element path.
|
CmsXmlContentValueSequence |
getValueSequence(java.lang.String xpath,
java.util.Locale locale)
Returns the value sequence for the selected element xpath in this XML content.
|
boolean |
hasChoiceOptions(java.lang.String xpath,
java.util.Locale locale)
Returns
true if choice options exist for the given xpath in the selected locale. |
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. |
boolean |
isLocaleIndependent()
Checks if the content is locale independent.
|
protected void |
processSchemaNode(org.dom4j.Element root,
java.lang.String rootPath,
java.util.Locale locale,
CmsXmlContentDefinition definition)
Processes a document node and extracts the values of the node according to the provided XML
content definition.
|
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.
|
void |
synchronizeLocaleIndependentValues(CmsObject cms,
java.util.Collection<java.lang.String> skipPaths,
java.util.Locale sourceLocale)
Synchronizes the locale independent fields for the given locale.
|
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.
|
addBookmark, addLocale, clearBookmarks, copyLocale, copyLocale, correctXmlStructure, createDeepElementCopy, getBestMatchingLocale, getBookmark, getBookmarkName, getConversion, getEncoding, getFile, getIndexCount, getLocales, getLocales, getNames, getStringValue, getStringValue, getValue, getValue, getValueInternal, getValues, getValues, hasLocale, hasValue, hasValue, initDocument, isEnabled, isEnabled, marshal, marshal, moveLocale, removeBookmark, removeLocale, setConversion, toString, updateLocaleNodeSorting, validateXmlStructure
public static final java.lang.String AUTO_CORRECTION_ATTRIBUTE
public static final java.lang.String XERCES_SCHEMA_PROPERTY
protected boolean m_autoCorrectionEnabled
protected CmsXmlContentDefinition m_contentDefinition
protected CmsXmlContent()
protected CmsXmlContent(CmsObject cms, org.dom4j.Document document, java.lang.String encoding, org.xml.sax.EntityResolver resolver)
The given encoding is used when marshalling the XML again later.
cms
- the cms context, if null
no link validation is performeddocument
- the document to create the xml content fromencoding
- the encoding of the xml contentresolver
- the XML entitiy resolver to useprotected CmsXmlContent(CmsObject cms, java.util.Locale locale, java.lang.String modelUri) throws CmsException
The given encoding is used when marshalling the XML again later.
cms
- the current users OpenCms contentlocale
- the locale to generate the default content formodelUri
- the absolute path to the XML content file acting as modelCmsException
- in case the model file is not found or not validprotected CmsXmlContent(CmsObject cms, java.util.Locale locale, java.lang.String encoding, CmsXmlContentDefinition contentDefinition)
The given encoding is used when marshalling the XML again later.
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 forpublic void addLocale(CmsObject cms, java.util.Locale locale) throws CmsXmlException
I_CmsXmlDocument
cms
- the current users OpenCms contextlocale
- the locale to addCmsXmlException
- in case the locale already existed, or if something else goes wrongI_CmsXmlDocument.addLocale(org.opencms.file.CmsObject, java.util.Locale)
public I_CmsXmlContentValue addValue(CmsObject cms, java.lang.String path, java.util.Locale locale, int index) throws CmsIllegalArgumentException, CmsRuntimeException
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)CmsIllegalArgumentException
- if the given path is invalidCmsRuntimeException
- if the element identified by the path already occurred I_CmsXmlSchemaType.getMaxOccurs()
or the given index
is invalid (too high).public CmsXmlContent clone()
clone
in class java.lang.Object
Object.clone()
public void copyLocale(java.util.Locale source, java.util.Locale destination, java.util.Set<java.lang.String> elements) throws CmsXmlException
source
- the source localedestination
- the destination loacleelements
- the set of elements to copyCmsXmlException
- if something goes wrongpublic java.util.List<I_CmsXmlContentValue> getAllSimpleSubValues(I_CmsXmlContentValue value)
value
- the valuepublic java.util.List<I_CmsXmlSchemaType> getChoiceOptions(java.lang.String xpath, java.util.Locale 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.
xpath
- the xpath to check the choice options forlocale
- the locale to checkpublic CmsXmlContentDefinition getContentDefinition()
I_CmsXmlDocument
I_CmsXmlDocument.getContentDefinition()
public I_CmsXmlContentHandler getHandler()
I_CmsXmlDocument
This is a shortcut for getContentDefinition().getContentHandler()
.
I_CmsXmlDocument.getHandler()
public CmsLinkProcessor getLinkProcessor(CmsObject cms, CmsLinkTable linkTable)
I_CmsXmlDocument
cms
- the current OpenCms user context that provides access to the link processorlinkTable
- the table with the links to processI_CmsXmlDocument.getLinkProcessor(org.opencms.file.CmsObject, org.opencms.staticexport.CmsLinkTable)
public org.dom4j.Element getLocaleNode(java.util.Locale locale) throws CmsRuntimeException
locale
- the locale to get the root element forCmsRuntimeException
- if no language element is found in the documentpublic java.util.List<I_CmsXmlContentValue> getSimpleValuesBelowPath(java.lang.String elementPath, java.util.Locale locale)
elementPath
- the element pathlocale
- the content localepublic java.util.List<I_CmsXmlContentValue> getSubValues(java.lang.String path, java.util.Locale locale)
getSubValues
in interface I_CmsXmlDocument
getSubValues
in class A_CmsXmlDocument
path
- the xpath to look up the sub-value forlocale
- the locale to useI_CmsXmlDocument.getSubValues(java.lang.String, java.util.Locale)
public java.util.List<I_CmsXmlContentValue> getValuesByPath(java.lang.String elementPath, java.util.Locale locale)
elementPath
- the element pathlocale
- the content localepublic CmsXmlContentValueSequence getValueSequence(java.lang.String xpath, java.util.Locale locale)
If the given element xpath is not valid according to the schema of this XML content,
null
is returned.
xpath
- the element xpath to get the value sequence forlocale
- the locale to get the value sequence forpublic boolean hasChoiceOptions(java.lang.String xpath, java.util.Locale locale)
true
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.
xpath
- the xpath to check the choice options forlocale
- the locale to checktrue
if choice options exist for the given xpath in the selected localepublic boolean isAutoCorrectionEnabled()
A_CmsXmlDocument
true
if the auto correction feature is enabled for saving this XML content.isAutoCorrectionEnabled
in class A_CmsXmlDocument
true
if the auto correction feature is enabled for saving this XML contentA_CmsXmlDocument.isAutoCorrectionEnabled()
public boolean isLocaleIndependent()
public void removeValue(java.lang.String name, java.util.Locale locale, int index)
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)public void resolveMappings(CmsObject cms)
cms
- the current users OpenCms contextpublic void setAutoCorrectionEnabled(boolean value)
value
- the flag to control if auto correction is enabled when saving this XML contentpublic void synchronizeLocaleIndependentValues(CmsObject cms, java.util.Collection<java.lang.String> skipPaths, java.util.Locale sourceLocale)
cms
- the cms contextskipPaths
- the paths to skipsourceLocale
- the source localepublic CmsXmlContentErrorHandler validate(CmsObject cms)
I_CmsXmlDocument
To check for errors in a single document locale only, use
CmsXmlContentErrorHandler.hasErrors(Locale)
in the result object.
cms
- the current OpenCms user contextI_CmsXmlDocument.validate(org.opencms.file.CmsObject)
public void visitAllValuesWith(I_CmsXmlContentValueVisitor 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.
visitor
- the value visitor implementation to visit the values withprotected void addBookmarkForElement(org.dom4j.Element element, java.util.Locale locale, org.dom4j.Element parent, java.lang.String parentPath, CmsXmlContentDefinition parentDef)
element
- the element to create the bookmark forlocale
- the localeparent
- the parent node of the elementparentPath
- the parent's pathparentDef
- the parent's content definitionprotected void addBookmarkForValue(I_CmsXmlContentValue value, java.lang.String path, java.util.Locale locale, boolean enabled)
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 disabledprotected I_CmsXmlContentValue addValue(CmsObject cms, org.dom4j.Element parent, I_CmsXmlSchemaType type, java.util.Locale locale, int insertIndex)
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 nodeprotected I_CmsXmlContentValue getBookmark(java.lang.String bookmark)
A_CmsXmlDocument
A_CmsXmlDocument.getBookmarks()
to get the list of all valid bookmark names.getBookmark
in class A_CmsXmlDocument
bookmark
- the bookmark name to look upA_CmsXmlDocument.getBookmark(java.lang.String)
protected java.util.Set<java.lang.String> getBookmarks()
A_CmsXmlDocument
getBookmarks
in class A_CmsXmlDocument
A_CmsXmlDocument.getBookmarks()
protected CmsXmlContentDefinition getContentDefinition(org.xml.sax.EntityResolver resolver) throws CmsRuntimeException
resolver
- the XML entity resolver to use, required for VFS accessCmsRuntimeException
- if the schema location attribute (systemId
)cannot be found,
parsing of the schema fails, an underlying IOException occurs or unmarshalling failsprotected void initDocument(CmsObject cms, org.dom4j.Document document, java.lang.String encoding, CmsXmlContentDefinition definition)
Checks the links and removes invalid ones in the initialized document.
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 useprotected void initDocument(org.dom4j.Document document, java.lang.String encoding, CmsXmlContentDefinition definition)
A_CmsXmlDocument
initDocument
in class A_CmsXmlDocument
document
- the base XML document to use for initializingencoding
- the encoding to use when marshalling the document laterdefinition
- the content definition to useA_CmsXmlDocument.initDocument(org.dom4j.Document, java.lang.String, org.opencms.xml.CmsXmlContentDefinition)
protected void processSchemaNode(org.dom4j.Element root, java.lang.String rootPath, java.util.Locale locale, CmsXmlContentDefinition definition)
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