Class A_CmsXmlDocument
- All Implemented Interfaces:
I_CmsXmlDocument
- Direct Known Subclasses:
CmsXmlContent
,CmsXmlPage
- Since:
- 6.0.0
-
Field Summary
Modifier and TypeFieldDescriptionprotected String
The content conversion to use for this XML document.protected org.dom4j.Document
The document object of the document.Maps element names to available locales.Maps locales to available element names.protected String
The encoding to use for this XML document.protected CmsFile
The file that contains the document data (note: is not set when creating an empty or document based document).Set of locales contained in this document. -
Constructor Summary
ModifierConstructorDescriptionprotected
Default constructor for a XML document that initializes some internal values. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addBookmark
(String path, Locale locale, boolean enabled, I_CmsXmlContentValue value) Adds a bookmark for the given value.protected void
Adds a locale to the set of locales of the XML document.protected void
Clears the XML document bookmarks.void
copyLocale
(List<Locale> possibleSources, Locale destination) Copies the content from the first matching source locale that exists in this XML document to the given destination locale in this XML document.void
copyLocale
(Locale source, Locale destination) Copies the content of the given source locale to the given destination locale in this XML document.Corrects the structure of this XML document.protected org.dom4j.Element
createDeepElementCopy
(org.dom4j.Element element, Set<String> copyElements) Creates a partial deep element copy according to the set of element paths.getBestMatchingLocale
(Locale locale) Returns the first matching locale (eventually simplified) from the available locales.protected I_CmsXmlContentValue
getBookmark
(String bookmark) Returns the bookmarked value for the given bookmark, which must be a valid bookmark name.protected I_CmsXmlContentValue
getBookmark
(String path, Locale locale) Returns the bookmarked value for the given name.protected static final String
getBookmarkName
(String name, Locale locale) Creates the bookmark name for a localized element to be used in the bookmark lookup table.Returns the names of all bookmarked elements.Returns the content conversion parameter used for this XML document.Returns the encoding used for this XML document.getFile()
Returns the file this document was generated from, may benull
if the file not available.int
getIndexCount
(String path, Locale locale) Returns the index count of existing values for the given path, or-1
if no such path exists.Returns a List of all locales that have at last one value in this XML document.getLocales
(String path) Returns a List of all locales that have the named element set in this document.Returns a List of all available elements paths (Strings) used in this document for the given locale.getStringValue
(CmsObject cms, String path, Locale locale) Returns the first content value for the given path as a String, ornull
if no such value exists.getStringValue
(CmsObject cms, String path, Locale locale, int index) Returns the content value for the given path and the selected index as a String, ornull
if no such value exists.getSubValues
(String path, Locale locale) Returns all content values (of typeI_CmsXmlContentValue
) directly below the given path available in this document for the given locale.Gets the temporary data cache.Returns the content value Object for the given path, ornull
if no such value exists.Returns the content value Object for the given path and the selected index, ornull
if no such value exists.protected I_CmsXmlContentValue
getValueInternal
(String path, Locale locale) Internal method to look up a value, requires that the name already has been "normalized" for the bookmark lookup.Returns all content values (of typeI_CmsXmlContentValue
) with the given path available in this document for the given locale.Returns all available content values (of typeI_CmsXmlContentValue
) in this document for the given locale.boolean
Returnstrue
if the given locale exists in this XML document.boolean
Returnstrue
if a value with the given path exists for the selected locale in this XML document, orfalse
otherwise.boolean
Returnstrue
if a value with the given path and the provided index exists for the selected locale in this XML document, orfalse
otherwise.void
Initializes this XML document, required after structural changes to the internal XML.protected abstract void
initDocument
(org.dom4j.Document document, String encoding, CmsXmlContentDefinition contentDefinition) Initializes an XML document based on the provided document, encoding and content definition.protected boolean
Returnstrue
if the auto correction feature is enabled for saving this XML content.boolean
Returnstrue
if a value with the given path exists for the selected locale in this XML document, and that value is enabled, orfalse
otherwise.boolean
Returnstrue
if a value with the given path and the provided index exists for the selected locale in this XML document, and that value is enabled, orfalse
otherwise.byte[]
marshal()
Marshals (writes) the content of the current XML document into a byte array using the selected encoding.protected OutputStream
marshal
(OutputStream out, String encoding) Marshals (writes) the content of the current XML document into an output stream.void
moveLocale
(Locale source, Locale destination) Moves the content of the given source locale to the given destination locale in this XML document.protected I_CmsXmlContentValue
removeBookmark
(String path, Locale locale) Removes the bookmark for an element with the given name and locale.void
removeLocale
(Locale locale) Removes the given locale from this XML document.void
setConversion
(String conversion) Sets the content conversion mode for this document.toString()
protected void
Updates the order of the locale nodes if required.void
validateXmlStructure
(EntityResolver resolver) Validates the XML structure of the document with the DTD or XML schema used by the document.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.opencms.xml.I_CmsXmlDocument
addLocale, getContentDefinition, getHandler, getLinkProcessor, validate
-
Field Details
-
m_conversion
The content conversion to use for this XML document. -
m_document
The document object of the document. -
m_elementLocales
Maps element names to available locales. -
m_elementNames
Maps locales to available element names. -
m_encoding
The encoding to use for this XML document. -
m_file
The file that contains the document data (note: is not set when creating an empty or document based document). -
m_locales
Set of locales contained in this document.
-
-
Constructor Details
-
A_CmsXmlDocument
protected A_CmsXmlDocument()Default constructor for a XML document that initializes some internal values.
-
-
Method Details
-
getBookmarkName
Creates the bookmark name for a localized element to be used in the bookmark lookup table.- Parameters:
name
- the element namelocale
- the element locale- Returns:
- the bookmark name for a localized element
-
copyLocale
Description copied from interface:I_CmsXmlDocument
Copies the content from the first matching source locale that exists in this XML document to the given destination locale in this XML document.The list of possible sources, has to be sorted in order of preference. The first match that exists in this XML document is used as source for the destination locale. No "locale simplification" ("en_EN" to "en" etc.) is performed for the match.
- Specified by:
copyLocale
in interfaceI_CmsXmlDocument
- Parameters:
possibleSources
- the possible source locales in order of preference, must contain objects of typeLocale
destination
- the destination locale- Throws:
CmsXmlException
- in case non of the source locales did not exist, or the destination locale already exists in the document, or if something else goes wrong- See Also:
-
copyLocale
Description copied from interface:I_CmsXmlDocument
Copies the content of the given source locale to the given destination locale in this XML document.- Specified by:
copyLocale
in interfaceI_CmsXmlDocument
- Parameters:
source
- the source localedestination
- the destination locale- Throws:
CmsXmlException
- in case either the source locale did not exist, or the destination locale already exists in the document, or if something else goes wrong- See Also:
-
correctXmlStructure
Corrects the structure of this XML document.- Parameters:
cms
- the current OpenCms user context- Returns:
- the file that contains the corrected XML structure
- Throws:
CmsXmlException
- if something goes wrong
-
getBestMatchingLocale
Description copied from interface:I_CmsXmlDocument
Returns the first matching locale (eventually simplified) from the available locales.In case no match is found, code
null
is returned.- Specified by:
getBestMatchingLocale
in interfaceI_CmsXmlDocument
- Parameters:
locale
- the requested locale- Returns:
- the matching locale available within the document
- See Also:
-
getConversion
Description copied from interface:I_CmsXmlDocument
Returns the content conversion parameter used for this XML document.- Specified by:
getConversion
in interfaceI_CmsXmlDocument
- Returns:
- the content conversion parameter used for this XML document
- See Also:
-
getEncoding
Description copied from interface:I_CmsXmlDocument
Returns the encoding used for this XML document.- Specified by:
getEncoding
in interfaceI_CmsXmlDocument
- Returns:
- the encoding used for this XML document
- See Also:
-
getFile
Description copied from interface:I_CmsXmlDocument
Returns the file this document was generated from, may benull
if the file not available.The file may not be available if the document was generated from a String or a pure XML document.
- Specified by:
getFile
in interfaceI_CmsXmlDocument
- Returns:
- the file this document was generated from
- See Also:
-
getIndexCount
Description copied from interface:I_CmsXmlDocument
Returns the index count of existing values for the given path, or-1
if no such path exists.- Specified by:
getIndexCount
in interfaceI_CmsXmlDocument
- Parameters:
path
- the path to get the index count forlocale
- the locale to get the index count for- Returns:
- the index count for the given key name
- See Also:
-
getLocales
Description copied from interface:I_CmsXmlDocument
Returns a List of all locales that have at last one value in this XML document.- Specified by:
getLocales
in interfaceI_CmsXmlDocument
- Returns:
- a List of all locales that have at last one value in this XML document
- See Also:
-
getLocales
Returns a List of all locales that have the named element set in this document.If no locale for the given element name is available, an empty list is returned.
- Specified by:
getLocales
in interfaceI_CmsXmlDocument
- Parameters:
path
- the element to look up the locale List for- Returns:
- a List of all Locales that have the named element set in this document
-
getNames
Description copied from interface:I_CmsXmlDocument
Returns a List of all available elements paths (Strings) used in this document for the given locale.If no element for the given locale is available, an empty list is returned.
- Specified by:
getNames
in interfaceI_CmsXmlDocument
- Parameters:
locale
- the locale to look up the elements paths for- Returns:
- a List of all available elements paths (Strings) used in this document for the given locale
- See Also:
-
getStringValue
Description copied from interface:I_CmsXmlDocument
Returns the first content value for the given path as a String, ornull
if no such value exists.- Specified by:
getStringValue
in interfaceI_CmsXmlDocument
- Parameters:
cms
- the current OpenCms user contextpath
- the path to get the content value forlocale
- the locale to get the content value for- Returns:
- the first content value for the given path as a String
- See Also:
-
getStringValue
Description copied from interface:I_CmsXmlDocument
Returns the content value for the given path and the selected index as a String, ornull
if no such value exists.- Specified by:
getStringValue
in interfaceI_CmsXmlDocument
- Parameters:
cms
- the current OpenCms user contextpath
- the path to get the content value forlocale
- the locale to get the content value forindex
- the index position to get the value from- Returns:
- the content value for the given path and the selected index as a String
- See Also:
-
getSubValues
Description copied from interface:I_CmsXmlDocument
Returns all content values (of typeI_CmsXmlContentValue
) directly below the given path available in this document for the given locale.If no content value for the given path is available with this locale, an empty list is returned.
- Specified by:
getSubValues
in interfaceI_CmsXmlDocument
- Parameters:
path
- the path to get the sub content values forlocale
- the locale to get the sub content values for- Returns:
- all content values (of type
I_CmsXmlContentValue
) directly below the given path available in this document for the given locale - See Also:
-
getTempDataCache
Gets the temporary data cache.- Returns:
- the temporary data cache
-
getValue
Description copied from interface:I_CmsXmlDocument
Returns the content value Object for the given path, ornull
if no such value exists.You can provide an index by appending a number in square brackets to the path parameter like this "Title[1]". If no index is provided, 1 is used for the index position.
- Specified by:
getValue
in interfaceI_CmsXmlDocument
- Parameters:
path
- the path to get the content value forlocale
- the locale to get the content value for- Returns:
- the content value Object for the given path
- See Also:
-
getValue
Description copied from interface:I_CmsXmlDocument
Returns the content value Object for the given path and the selected index, ornull
if no such value exists.- Specified by:
getValue
in interfaceI_CmsXmlDocument
- Parameters:
path
- the path to get the content value forlocale
- the locale to get the content value forindex
- the index position to get the value from- Returns:
- the content value Object for the given path and the selected index
- See Also:
-
getValues
Description copied from interface:I_CmsXmlDocument
Returns all available content values (of typeI_CmsXmlContentValue
) in this document for the given locale.If no content value for the given locale is available, an empty list is returned.
- Specified by:
getValues
in interfaceI_CmsXmlDocument
- Parameters:
locale
- the locale to get the content values for- Returns:
- all available content values (of type
I_CmsXmlContentValue
) in this document for the given locale - See Also:
-
getValues
Description copied from interface:I_CmsXmlDocument
Returns all content values (of typeI_CmsXmlContentValue
) with the given path available in this document for the given locale.If no content value for the given path is available with this locale, an empty list is returned.
- Specified by:
getValues
in interfaceI_CmsXmlDocument
- Parameters:
path
- the path to get the content values forlocale
- the locale to get the content values for- Returns:
- all content values (of type
I_CmsXmlContentValue
) with the given path available in this document for the given locale - See Also:
-
hasLocale
Description copied from interface:I_CmsXmlDocument
Returnstrue
if the given locale exists in this XML document.- Specified by:
hasLocale
in interfaceI_CmsXmlDocument
- Parameters:
locale
- the locale to check- Returns:
true
if the given locale exists in this XML document,false
otherwise- See Also:
-
hasValue
Description copied from interface:I_CmsXmlDocument
Returnstrue
if a value with the given path exists for the selected locale in this XML document, orfalse
otherwise.You can provide an index by appending a number in square brackets to the path parameter like this "Title[1]". If no index is provided, 1 is used for the index position.
- Specified by:
hasValue
in interfaceI_CmsXmlDocument
- Parameters:
path
- the path to checklocale
- the locale to check- Returns:
true
if a value with the given path exists for the selected locale in this XML document- See Also:
-
hasValue
Description copied from interface:I_CmsXmlDocument
Returnstrue
if a value with the given path and the provided index exists for the selected locale in this XML document, orfalse
otherwise.- Specified by:
hasValue
in interfaceI_CmsXmlDocument
- Parameters:
path
- the path to checklocale
- the locale to checkindex
- the index position to check- Returns:
true
if a value with the given path and the provided index exists for the selected locale in this XML document- See Also:
-
initDocument
Description copied from interface:I_CmsXmlDocument
Initializes this XML document, required after structural changes to the internal XML.If nodes in the XML are added, removed or moved, the document needs to be initialized in order to update the internal data structures.
- Specified by:
initDocument
in interfaceI_CmsXmlDocument
- See Also:
-
isEnabled
Description copied from interface:I_CmsXmlDocument
Returnstrue
if a value with the given path exists for the selected locale in this XML document, and that value is enabled, orfalse
otherwise.This is only used with implementations that support enabling and disabling individual values, such as
CmsXmlPage
. If enabling / disabling values is not supported, this is identical toI_CmsXmlDocument.hasValue(String, Locale)
.You can provide an index by appending a number in square brackets to the path parameter like this "Title[1]". If no index is provided, 1 is used for the index position.
- Specified by:
isEnabled
in interfaceI_CmsXmlDocument
- Parameters:
path
- the path to checklocale
- the locale to check- Returns:
true
if a value with the given path exists for the selected locale in this XML document, and that value is enabled- See Also:
-
isEnabled
Description copied from interface:I_CmsXmlDocument
Returnstrue
if a value with the given path and the provided index exists for the selected locale in this XML document, and that value is enabled, orfalse
otherwise.This is only used with implementations that support enabling and disabling individual values, such as
CmsXmlPage
. If enabling / disabling values is not supported, this is identical toI_CmsXmlDocument.hasValue(String, Locale, int)
.- Specified by:
isEnabled
in interfaceI_CmsXmlDocument
- Parameters:
path
- the path to checklocale
- the locale to checkindex
- the index position to check- Returns:
true
if a value with the given path and the provided index exists for the selected locale in this XML document, and that value is enabled- See Also:
-
marshal
Marshals (writes) the content of the current XML document into a byte array using the selected encoding.- Returns:
- the content of the current XML document written into a byte array
- Throws:
CmsXmlException
- if something goes wrong
-
moveLocale
Description copied from interface:I_CmsXmlDocument
Moves the content of the given source locale to the given destination locale in this XML document.- Specified by:
moveLocale
in interfaceI_CmsXmlDocument
- Parameters:
source
- the source localedestination
- the destination locale- Throws:
CmsXmlException
- in case either the source locale does not exist, or the destination locale already exists in the document, or if something else goes wrong- See Also:
-
removeLocale
Description copied from interface:I_CmsXmlDocument
Removes the given locale from this XML document.- Specified by:
removeLocale
in interfaceI_CmsXmlDocument
- Parameters:
locale
- the locale to remove- Throws:
CmsXmlException
- in case the locale did not exist in the document, or if something else goes wrong- See Also:
-
setConversion
Sets the content conversion mode for this document.- Parameters:
conversion
- the conversion mode to set for this document
-
toString
-
validateXmlStructure
Validates the XML structure of the document with the DTD or XML schema used by the document.This is required in case someone modifies the XML structure of a document using the "edit control code" option.
- Parameters:
resolver
- the XML entity resolver to use- Throws:
CmsXmlException
- if the validation fails
-
addBookmark
Adds a bookmark for the given value.- Parameters:
path
- 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 disabledvalue
- the value to bookmark
-
addLocale
Adds a locale to the set of locales of the XML document.- Parameters:
locale
- the locale to add
-
clearBookmarks
Clears the XML document bookmarks. -
createDeepElementCopy
protected org.dom4j.Element createDeepElementCopy(org.dom4j.Element element, Set<String> copyElements) Creates a partial deep element copy according to the set of element paths.Only elements contained in that set will be copied.
- Parameters:
element
- the element to copycopyElements
- the set of paths for elements to copy- Returns:
- a partial deep copy of
element
-
getBookmark
Returns the bookmarked value for the given bookmark, which must be a valid bookmark name. UsegetBookmarks()
to get the list of all valid bookmark names.- Parameters:
bookmark
- the bookmark name to look up- Returns:
- the bookmarked value for the given bookmark
-
getBookmark
Returns the bookmarked value for the given name.- Parameters:
path
- the lookup path to use for the bookmarklocale
- the locale to get the bookmark for- Returns:
- the bookmarked value
-
getBookmarks
Returns the names of all bookmarked elements.- Returns:
- the names of all bookmarked elements
-
getValueInternal
Internal method to look up a value, requires that the name already has been "normalized" for the bookmark lookup. This is required to find names like "title/subtitle" which are stored internally as "title[0]/subtitle[0]" in the bookmarks.- Parameters:
path
- the path to look uplocale
- the locale to look up- Returns:
- the value found in the bookmarks
-
initDocument
protected abstract void initDocument(org.dom4j.Document document, String encoding, CmsXmlContentDefinition contentDefinition) Initializes an XML document based on the provided document, encoding and content definition.- Parameters:
document
- the base XML document to use for initializingencoding
- the encoding to use when marshalling the document latercontentDefinition
- the content definition to use
-
isAutoCorrectionEnabled
Returnstrue
if the auto correction feature is enabled for saving this XML content.- Returns:
true
if the auto correction feature is enabled for saving this XML content
-
marshal
Marshals (writes) the content of the current XML document into an output stream.- Parameters:
out
- the output stream to write toencoding
- the encoding to use- Returns:
- the output stream with the XML content
- Throws:
CmsXmlException
- if something goes wrong
-
removeBookmark
Removes the bookmark for an element with the given name and locale.- Parameters:
path
- the lookup path to use for the bookmarklocale
- the locale of the element- Returns:
- the element removed from the bookmarks or null
-
updateLocaleNodeSorting
Updates the order of the locale nodes if required.
-