Class A_CmsXmlDocument
- All Implemented Interfaces:
I_CmsXmlDocument
- Direct Known Subclasses:
CmsXmlContent,CmsXmlPage
- Since:
- 6.0.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StringThe content conversion to use for this XML document.protected org.dom4j.DocumentThe document object of the document.Maps element names to available locales.Maps locales to available element names.protected StringThe encoding to use for this XML document.protected CmsFileThe 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
ConstructorsModifierConstructorDescriptionprotectedDefault constructor for a XML document that initializes some internal values. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddBookmark(String path, Locale locale, boolean enabled, I_CmsXmlContentValue value) Adds a bookmark for the given value.protected voidAdds a locale to the set of locales of the XML document.protected voidClears the XML document bookmarks.voidcopyLocale(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.voidcopyLocale(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.ElementcreateDeepElementCopy(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_CmsXmlContentValuegetBookmark(String bookmark) Returns the bookmarked value for the given bookmark, which must be a valid bookmark name.protected I_CmsXmlContentValuegetBookmark(String path, Locale locale) Returns the bookmarked value for the given name.protected static final StringgetBookmarkName(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 benullif the file not available.intgetIndexCount(String path, Locale locale) Returns the index count of existing values for the given path, or-1if 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, ornullif 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, ornullif 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, ornullif no such value exists.Returns the content value Object for the given path and the selected index, ornullif no such value exists.protected I_CmsXmlContentValuegetValueInternal(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.booleanReturnstrueif the given locale exists in this XML document.booleanReturnstrueif a value with the given path exists for the selected locale in this XML document, orfalseotherwise.booleanReturnstrueif a value with the given path and the provided index exists for the selected locale in this XML document, orfalseotherwise.voidInitializes this XML document, required after structural changes to the internal XML.protected abstract voidinitDocument(org.dom4j.Document document, String encoding, CmsXmlContentDefinition contentDefinition) Initializes an XML document based on the provided document, encoding and content definition.protected booleanReturnstrueif the auto correction feature is enabled for saving this XML content.booleanReturnstrueif a value with the given path exists for the selected locale in this XML document, and that value is enabled, orfalseotherwise.booleanReturnstrueif a value with the given path and the provided index exists for the selected locale in this XML document, and that value is enabled, orfalseotherwise.byte[]marshal()Marshals (writes) the content of the current XML document into a byte array using the selected encoding.protected OutputStreammarshal(OutputStream out, String encoding) Marshals (writes) the content of the current XML document into an output stream.voidmoveLocale(Locale source, Locale destination) Moves the content of the given source locale to the given destination locale in this XML document.protected I_CmsXmlContentValueremoveBookmark(String path, Locale locale) Removes the bookmark for an element with the given name and locale.voidremoveLocale(Locale locale) Removes the given locale from this XML document.voidsetConversion(String conversion) Sets the content conversion mode for this document.toString()protected voidUpdates the order of the locale nodes if required.voidvalidateXmlStructure(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, waitMethods 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_CmsXmlDocumentCopies 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:
copyLocalein interfaceI_CmsXmlDocument- Parameters:
possibleSources- the possible source locales in order of preference, must contain objects of typeLocaledestination- 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_CmsXmlDocumentCopies the content of the given source locale to the given destination locale in this XML document.- Specified by:
copyLocalein 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_CmsXmlDocumentReturns the first matching locale (eventually simplified) from the available locales.In case no match is found, code
nullis returned.- Specified by:
getBestMatchingLocalein interfaceI_CmsXmlDocument- Parameters:
locale- the requested locale- Returns:
- the matching locale available within the document
- See Also:
-
getConversion
Description copied from interface:I_CmsXmlDocumentReturns the content conversion parameter used for this XML document.- Specified by:
getConversionin interfaceI_CmsXmlDocument- Returns:
- the content conversion parameter used for this XML document
- See Also:
-
getEncoding
Description copied from interface:I_CmsXmlDocumentReturns the encoding used for this XML document.- Specified by:
getEncodingin interfaceI_CmsXmlDocument- Returns:
- the encoding used for this XML document
- See Also:
-
getFile
Description copied from interface:I_CmsXmlDocumentReturns the file this document was generated from, may benullif 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:
getFilein interfaceI_CmsXmlDocument- Returns:
- the file this document was generated from
- See Also:
-
getIndexCount
Description copied from interface:I_CmsXmlDocumentReturns the index count of existing values for the given path, or-1if no such path exists.- Specified by:
getIndexCountin 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_CmsXmlDocumentReturns a List of all locales that have at last one value in this XML document.- Specified by:
getLocalesin 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:
getLocalesin 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_CmsXmlDocumentReturns 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:
getNamesin 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_CmsXmlDocumentReturns the first content value for the given path as a String, ornullif no such value exists.- Specified by:
getStringValuein 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_CmsXmlDocumentReturns the content value for the given path and the selected index as a String, ornullif no such value exists.- Specified by:
getStringValuein 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_CmsXmlDocumentReturns 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:
getSubValuesin 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_CmsXmlDocumentReturns the content value Object for the given path, ornullif 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:
getValuein 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_CmsXmlDocumentReturns the content value Object for the given path and the selected index, ornullif no such value exists.- Specified by:
getValuein 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_CmsXmlDocumentReturns 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:
getValuesin 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_CmsXmlDocumentReturns 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:
getValuesin 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_CmsXmlDocumentReturnstrueif the given locale exists in this XML document.- Specified by:
hasLocalein interfaceI_CmsXmlDocument- Parameters:
locale- the locale to check- Returns:
trueif the given locale exists in this XML document,falseotherwise- See Also:
-
hasValue
Description copied from interface:I_CmsXmlDocumentReturnstrueif a value with the given path exists for the selected locale in this XML document, orfalseotherwise.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:
hasValuein interfaceI_CmsXmlDocument- Parameters:
path- the path to checklocale- the locale to check- Returns:
trueif a value with the given path exists for the selected locale in this XML document- See Also:
-
hasValue
Description copied from interface:I_CmsXmlDocumentReturnstrueif a value with the given path and the provided index exists for the selected locale in this XML document, orfalseotherwise.- Specified by:
hasValuein interfaceI_CmsXmlDocument- Parameters:
path- the path to checklocale- the locale to checkindex- the index position to check- Returns:
trueif 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_CmsXmlDocumentInitializes 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:
initDocumentin interfaceI_CmsXmlDocument- See Also:
-
isEnabled
Description copied from interface:I_CmsXmlDocumentReturnstrueif a value with the given path exists for the selected locale in this XML document, and that value is enabled, orfalseotherwise.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:
isEnabledin interfaceI_CmsXmlDocument- Parameters:
path- the path to checklocale- the locale to check- Returns:
trueif 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_CmsXmlDocumentReturnstrueif a value with the given path and the provided index exists for the selected locale in this XML document, and that value is enabled, orfalseotherwise.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:
isEnabledin interfaceI_CmsXmlDocument- Parameters:
path- the path to checklocale- the locale to checkindex- the index position to check- Returns:
trueif 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_CmsXmlDocumentMoves the content of the given source locale to the given destination locale in this XML document.- Specified by:
moveLocalein 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_CmsXmlDocumentRemoves the given locale from this XML document.- Specified by:
removeLocalein 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
Returnstrueif the auto correction feature is enabled for saving this XML content.- Returns:
trueif 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.
-