|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.opencms.xml.A_CmsXmlDocument
public abstract class A_CmsXmlDocument
Provides basic XML document handling functions useful when dealing with XML documents that are stored in the OpenCms VFS.
Field Summary | |
---|---|
protected java.lang.String |
m_conversion
The content conversion to use for this XML document. |
protected org.dom4j.Document |
m_document
The document object of the document. |
protected java.util.Map<java.lang.String,java.util.Set<java.util.Locale>> |
m_elementLocales
Maps element names to available locales. |
protected java.util.Map<java.util.Locale,java.util.Set<java.lang.String>> |
m_elementNames
Maps locales to available element names. |
protected java.lang.String |
m_encoding
The encoding to use for this XML document. |
protected CmsFile |
m_file
The file that contains the document data (note: is not set when creating an empty or document based document). |
protected java.util.Set<java.util.Locale> |
m_locales
Set of locales contained in this document. |
Constructor Summary | |
---|---|
protected |
A_CmsXmlDocument()
Default constructor for a XML document that initializes some internal values. |
Method Summary | |
---|---|
protected void |
addBookmark(java.lang.String path,
java.util.Locale locale,
boolean enabled,
I_CmsXmlContentValue value)
Adds a bookmark for the given value. |
protected void |
addLocale(java.util.Locale locale)
Adds a locale to the set of locales of the XML document. |
protected void |
clearBookmarks()
Clears the XML document bookmarks. |
void |
copyLocale(java.util.List<java.util.Locale> possibleSources,
java.util.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(java.util.Locale source,
java.util.Locale destination)
Copies the content of the given source locale to the given destination locale in this XML document. |
CmsFile |
correctXmlStructure(CmsObject cms)
Corrects the structure of this XML document. |
protected org.dom4j.Element |
createDeepElementCopy(org.dom4j.Element element,
java.util.Set<java.lang.String> copyElements)
Creates a partial deep element copy according to the set of element paths. |
protected I_CmsXmlContentValue |
getBookmark(java.lang.String bookmark)
Returns the bookmarked value for the given bookmark, which must be a valid bookmark name. |
protected I_CmsXmlContentValue |
getBookmark(java.lang.String path,
java.util.Locale locale)
Returns the bookmarked value for the given name. |
protected static java.lang.String |
getBookmarkName(java.lang.String name,
java.util.Locale locale)
Creates the bookmark name for a localized element to be used in the bookmark lookup table. |
protected java.util.Set<java.lang.String> |
getBookmarks()
Returns the names of all bookmarked elements. |
java.lang.String |
getConversion()
Returns the content conversion parameter used for this XML document. |
java.lang.String |
getEncoding()
Returns the encoding used for this XML document. |
CmsFile |
getFile()
Returns the file this document was generated from, may be null if the file not available. |
int |
getIndexCount(java.lang.String path,
java.util.Locale locale)
Returns the index count of existing values for the given path, or -1 if no such path exists. |
java.util.List<java.util.Locale> |
getLocales()
Returns a List of all locales that have at last one value in this XML document. |
java.util.List<java.util.Locale> |
getLocales(java.lang.String path)
Returns a List of all locales that have the named element set in this document. |
java.util.List<java.lang.String> |
getNames(java.util.Locale locale)
Returns a List of all available elements paths (Strings) used in this document for the given locale. |
java.lang.String |
getStringValue(CmsObject cms,
java.lang.String path,
java.util.Locale locale)
Returns the first content value for the given path as a String, or null if no such value exists. |
java.lang.String |
getStringValue(CmsObject cms,
java.lang.String path,
java.util.Locale locale,
int index)
Returns the content value for the given path and the selected index as a String, or null if no such value exists. |
I_CmsXmlContentValue |
getValue(java.lang.String path,
java.util.Locale locale)
Returns the content value Object for the given path, or null if no such value exists. |
I_CmsXmlContentValue |
getValue(java.lang.String path,
java.util.Locale locale,
int index)
Returns the content value Object for the given path and the selected index, or null if no such value exists. |
java.util.List<I_CmsXmlContentValue> |
getValues(java.util.Locale locale)
Returns all available content values (of type I_CmsXmlContentValue )
in this document for the given locale. |
java.util.List<I_CmsXmlContentValue> |
getValues(java.lang.String path,
java.util.Locale locale)
Returns all content values (of type I_CmsXmlContentValue ) with the given path
available in this document for the given locale. |
boolean |
hasLocale(java.util.Locale locale)
Returns true if the given locale exists in this XML document. |
boolean |
hasValue(java.lang.String path,
java.util.Locale locale)
Returns true if a value with the given path exists for the selected locale in this XML document, or
false otherwise. |
boolean |
hasValue(java.lang.String path,
java.util.Locale locale,
int index)
Returns true if a value with the given path and the provided index exists for the selected locale
in this XML document, or false otherwise. |
void |
initDocument()
Initializes this XML document, required after structural changes to the internal XML. |
protected abstract void |
initDocument(org.dom4j.Document document,
java.lang.String encoding,
CmsXmlContentDefinition contentDefinition)
Initializes an XML document based on the provided document, encoding and content definition. |
protected boolean |
isAutoCorrectionEnabled()
Returns true if the auto correction feature is enabled for saving this XML content. |
boolean |
isEnabled(java.lang.String path,
java.util.Locale locale)
Returns true if a value with the given path exists for the selected locale in this XML document,
and that value is enabled,
or false otherwise. |
boolean |
isEnabled(java.lang.String path,
java.util.Locale locale,
int index)
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, or false otherwise. |
byte[] |
marshal()
Marshals (writes) the content of the current XML document into a byte array using the selected encoding. |
protected java.io.OutputStream |
marshal(java.io.OutputStream out,
java.lang.String encoding)
Marshals (writes) the content of the current XML document into an output stream. |
void |
moveLocale(java.util.Locale source,
java.util.Locale destination)
Moves the content of the given source locale to the given destination locale in this XML document. |
protected I_CmsXmlContentValue |
removeBookmark(java.lang.String path,
java.util.Locale locale)
Removes the bookmark for an element with the given name and locale. |
void |
removeLocale(java.util.Locale locale)
Removes the given locale from this XML document. |
void |
setConversion(java.lang.String conversion)
Sets the content conversion mode for this document. |
java.lang.String |
toString()
|
void |
validateXmlStructure(org.xml.sax.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, getLinkProcessor, validate |
Field Detail |
---|
protected java.lang.String m_conversion
protected org.dom4j.Document m_document
protected java.util.Map<java.lang.String,java.util.Set<java.util.Locale>> m_elementLocales
protected java.util.Map<java.util.Locale,java.util.Set<java.lang.String>> m_elementNames
protected java.lang.String m_encoding
protected CmsFile m_file
protected java.util.Set<java.util.Locale> m_locales
Constructor Detail |
---|
protected A_CmsXmlDocument()
Method Detail |
---|
protected static final java.lang.String getBookmarkName(java.lang.String name, java.util.Locale locale)
name
- the element namelocale
- the element locale
public void copyLocale(java.util.List<java.util.Locale> possibleSources, java.util.Locale destination) throws CmsXmlException
I_CmsXmlDocument
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.
copyLocale
in interface I_CmsXmlDocument
possibleSources
- the possible source locales in order of preference,
must contain objects of type Locale
destination
- the destination locale
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 wrongI_CmsXmlDocument.copyLocale(java.util.List, java.util.Locale)
public void copyLocale(java.util.Locale source, java.util.Locale destination) throws CmsXmlException
I_CmsXmlDocument
copyLocale
in interface I_CmsXmlDocument
source
- the source localedestination
- the destination locale
CmsXmlException
- in case either the source locale did not exist,
or the destination locale already exists in the document, or if something else goes wrongI_CmsXmlDocument.copyLocale(java.util.Locale, java.util.Locale)
public CmsFile correctXmlStructure(CmsObject cms) throws CmsXmlException
cms
- the current OpenCms user context
CmsXmlException
- if something goes wrongpublic java.lang.String getConversion()
I_CmsXmlDocument
getConversion
in interface I_CmsXmlDocument
I_CmsXmlDocument.getConversion()
public java.lang.String getEncoding()
I_CmsXmlDocument
getEncoding
in interface I_CmsXmlDocument
I_CmsXmlDocument.getEncoding()
public CmsFile getFile()
I_CmsXmlDocument
null
if the file not available.The file may not be available if the document was generated from a String or a pure XML document.
getFile
in interface I_CmsXmlDocument
I_CmsXmlDocument.getFile()
public int getIndexCount(java.lang.String path, java.util.Locale locale)
I_CmsXmlDocument
-1
if no such path exists.
getIndexCount
in interface I_CmsXmlDocument
path
- the path to get the index count forlocale
- the locale to get the index count for
I_CmsXmlDocument.getIndexCount(java.lang.String, java.util.Locale)
public java.util.List<java.util.Locale> getLocales()
I_CmsXmlDocument
getLocales
in interface I_CmsXmlDocument
I_CmsXmlDocument.getLocales()
public java.util.List<java.util.Locale> getLocales(java.lang.String path)
If no locale for the given element name is available, an empty list is returned.
getLocales
in interface I_CmsXmlDocument
path
- the element to look up the locale List for
public java.util.List<java.lang.String> getNames(java.util.Locale locale)
I_CmsXmlDocument
If no element for the given locale is available, an empty list is returned.
getNames
in interface I_CmsXmlDocument
locale
- the locale to look up the elements paths for
I_CmsXmlDocument.getNames(java.util.Locale)
public java.lang.String getStringValue(CmsObject cms, java.lang.String path, java.util.Locale locale)
I_CmsXmlDocument
null
if no such value exists.
getStringValue
in interface I_CmsXmlDocument
cms
- the current OpenCms user contextpath
- the path to get the content value forlocale
- the locale to get the content value for
I_CmsXmlDocument.getStringValue(org.opencms.file.CmsObject, java.lang.String, java.util.Locale)
public java.lang.String getStringValue(CmsObject cms, java.lang.String path, java.util.Locale locale, int index)
I_CmsXmlDocument
null
if no such value exists.
getStringValue
in interface I_CmsXmlDocument
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
I_CmsXmlDocument.getStringValue(CmsObject, java.lang.String, Locale, int)
public I_CmsXmlContentValue getValue(java.lang.String path, java.util.Locale locale)
I_CmsXmlDocument
null
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.
getValue
in interface I_CmsXmlDocument
path
- the path to get the content value forlocale
- the locale to get the content value for
I_CmsXmlDocument.getValue(java.lang.String, java.util.Locale)
public I_CmsXmlContentValue getValue(java.lang.String path, java.util.Locale locale, int index)
I_CmsXmlDocument
null
if no such value exists.
getValue
in interface I_CmsXmlDocument
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
I_CmsXmlDocument.getValue(java.lang.String, java.util.Locale, int)
public java.util.List<I_CmsXmlContentValue> getValues(java.util.Locale locale)
I_CmsXmlDocument
I_CmsXmlContentValue
)
in this document for the given locale.If no content value for the given locale is available, an empty list is returned.
getValues
in interface I_CmsXmlDocument
locale
- the locale to get the content values for
I_CmsXmlContentValue
) in this document for the given localeI_CmsXmlDocument.getValues(java.util.Locale)
public java.util.List<I_CmsXmlContentValue> getValues(java.lang.String path, java.util.Locale locale)
I_CmsXmlDocument
I_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.
getValues
in interface I_CmsXmlDocument
path
- the path to get the content values forlocale
- the locale to get the content values for
I_CmsXmlContentValue
) with the given path
available in this document for the given localeI_CmsXmlDocument.getValues(java.lang.String, java.util.Locale)
public boolean hasLocale(java.util.Locale locale)
I_CmsXmlDocument
true
if the given locale exists in this XML document.
hasLocale
in interface I_CmsXmlDocument
locale
- the locale to check
true
if the given locale exists in this XML document, false
otherwiseI_CmsXmlDocument.hasLocale(java.util.Locale)
public boolean hasValue(java.lang.String path, java.util.Locale locale)
I_CmsXmlDocument
true
if a value with the given path exists for the selected locale in this XML document, or
false
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.
hasValue
in interface I_CmsXmlDocument
path
- the path to checklocale
- the locale to check
true
if a value with the given path exists for the selected locale in this XML documentI_CmsXmlDocument.hasValue(java.lang.String, java.util.Locale)
public boolean hasValue(java.lang.String path, java.util.Locale locale, int index)
I_CmsXmlDocument
true
if a value with the given path and the provided index exists for the selected locale
in this XML document, or false
otherwise.
hasValue
in interface I_CmsXmlDocument
path
- the path to checklocale
- the locale to checkindex
- the index position to check
true
if a value with the given path and the provided index exists for the selected locale
in this XML documentI_CmsXmlDocument.hasValue(java.lang.String, java.util.Locale, int)
public void initDocument()
I_CmsXmlDocument
If nodes in the XML are added, removed or moved, the document needs to be initialized in order to update the internal data structures.
initDocument
in interface I_CmsXmlDocument
I_CmsXmlDocument.initDocument()
public boolean isEnabled(java.lang.String path, java.util.Locale locale)
I_CmsXmlDocument
true
if a value with the given path exists for the selected locale in this XML document,
and that value is enabled,
or false
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 to I_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.
isEnabled
in interface I_CmsXmlDocument
path
- the path to checklocale
- the locale to check
true
if a value with the given path exists for the selected locale in this XML document,
and that value is enabledI_CmsXmlDocument.isEnabled(java.lang.String, java.util.Locale)
public boolean isEnabled(java.lang.String path, java.util.Locale locale, int index)
I_CmsXmlDocument
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, or false
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 to I_CmsXmlDocument.hasValue(String, Locale, int)
.
isEnabled
in interface I_CmsXmlDocument
path
- the path to checklocale
- the locale to checkindex
- the index position to check
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 enabledI_CmsXmlDocument.isEnabled(java.lang.String, java.util.Locale, int)
public byte[] marshal() throws CmsXmlException
CmsXmlException
- if something goes wrongpublic void moveLocale(java.util.Locale source, java.util.Locale destination) throws CmsXmlException
I_CmsXmlDocument
moveLocale
in interface I_CmsXmlDocument
source
- the source localedestination
- the destination locale
CmsXmlException
- in case either the source locale does not exist,
or the destination locale already exists in the document, or if something else goes wrongI_CmsXmlDocument.moveLocale(java.util.Locale, java.util.Locale)
public void removeLocale(java.util.Locale locale) throws CmsXmlException
I_CmsXmlDocument
removeLocale
in interface I_CmsXmlDocument
locale
- the locale to remove
CmsXmlException
- in case the locale did not exist in the document, or if something else goes wrongI_CmsXmlDocument.removeLocale(java.util.Locale)
public void setConversion(java.lang.String conversion)
conversion
- the conversion mode to set for this documentpublic java.lang.String toString()
toString
in class java.lang.Object
Object.toString()
public void validateXmlStructure(org.xml.sax.EntityResolver resolver) throws CmsXmlException
This is required in case someone modifies the XML structure of a document using the "edit control code" option.
resolver
- the XML entity resolver to use
CmsXmlException
- if the validation failsprotected void addBookmark(java.lang.String path, java.util.Locale locale, boolean enabled, I_CmsXmlContentValue value)
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 bookmarkprotected void addLocale(java.util.Locale locale)
locale
- the locale to addprotected void clearBookmarks()
protected org.dom4j.Element createDeepElementCopy(org.dom4j.Element element, java.util.Set<java.lang.String> copyElements)
Only elements contained in that set will be copied.
element
- the element to copycopyElements
- the set of paths for elements to copy
element
protected I_CmsXmlContentValue getBookmark(java.lang.String bookmark)
getBookmarks()
to get the list of all valid bookmark names.
bookmark
- the bookmark name to look up
protected I_CmsXmlContentValue getBookmark(java.lang.String path, java.util.Locale locale)
path
- the lookup path to use for the bookmarklocale
- the locale to get the bookmark for
protected java.util.Set<java.lang.String> getBookmarks()
protected abstract void initDocument(org.dom4j.Document document, java.lang.String encoding, CmsXmlContentDefinition contentDefinition)
document
- the base XML document to use for initializingencoding
- the encoding to use when marshalling the document latercontentDefinition
- the content definition to useprotected boolean isAutoCorrectionEnabled()
true
if the auto correction feature is enabled for saving this XML content.
true
if the auto correction feature is enabled for saving this XML contentprotected java.io.OutputStream marshal(java.io.OutputStream out, java.lang.String encoding) throws CmsXmlException
out
- the output stream to write toencoding
- the encoding to use
CmsXmlException
- if something goes wrongprotected I_CmsXmlContentValue removeBookmark(java.lang.String path, java.util.Locale locale)
path
- the lookup path to use for the bookmarklocale
- the locale of the element
|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |