|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.opencms.xml.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 |
m_elementLocales
Maps element names to available locales. |
protected java.util.Map |
m_elementNames
Maps locales to avaliable 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 |
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 name,
java.util.Locale locale,
boolean enabled,
java.lang.Object 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.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 content. |
protected java.lang.Object |
getBookmark(java.lang.String bookmark)
Returns the bookmarked value for the given bookmark, which must be a valid bookmark name. |
protected java.lang.Object |
getBookmark(java.lang.String name,
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 |
getBookmarks()
Returns the names of all bookmarked elements. |
java.lang.String |
getConversion()
Returns the content converison used for the page content. |
java.lang.String |
getEncoding()
Returns the encoding used for this XML document. |
CmsFile |
getFile()
Returns the file with the xml page content or null if not set. |
int |
getIndexCount(java.lang.String name,
java.util.Locale locale)
Returns the index count of existing values for the given key name, or -1 if no such value exists. |
java.util.List |
getLocales()
Returns a List of all locales that have at last one element in this XML document. |
java.util.List |
getLocales(java.lang.String name)
Returns a List of all locales that have the named element set in this document. |
java.util.List |
getNames(java.util.Locale locale)
Returns all available elements names used in this document for the given locale. |
java.lang.String |
getStringValue(CmsObject cms,
java.lang.String name,
java.util.Locale locale)
Returns the first content value for the given key name as a String, or null if no such value exists. |
java.lang.String |
getStringValue(CmsObject cms,
java.lang.String name,
java.util.Locale locale,
int index)
Returns the content value for the given key name from the selected index as a String, or null if no such value exists. |
I_CmsXmlContentValue |
getValue(java.lang.String name,
java.util.Locale locale)
Returns the content value Object for the given key name, or null if no such value exists. |
I_CmsXmlContentValue |
getValue(java.lang.String name,
java.util.Locale locale,
int index)
Returns the content value Object for the given key name from the selected index, or null if no such value exists. |
java.util.List |
getValues(java.util.Locale locale)
Returns all available elements values used in this document for the given locale. |
java.util.List |
getValues(java.lang.String name,
java.util.Locale locale)
Returns all content value Objects for the given key name in a List, or null if no such value exists. |
boolean |
hasLocale(java.util.Locale locale)
Checks if the given locale exists in this XML document. |
boolean |
hasValue(java.lang.String name,
java.util.Locale locale)
Returns true if a value exists with the given key name,
false otherwise. |
boolean |
hasValue(java.lang.String name,
java.util.Locale locale,
int index)
Returns true if a value exists with the given key name at the selected index,
false otherwise. |
void |
initDocument()
Initializes this XML document, required after structural changes to the 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. |
boolean |
isEnabled(java.lang.String name,
java.util.Locale locale)
Returns true if a value exists with the given key name,
and that value is enabled,
false otherwise. |
boolean |
isEnabled(java.lang.String name,
java.util.Locale locale,
int index)
Returns true if a value exists with the given key name at the selected index,
and that value is enabled,
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 name,
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 ot 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 m_elementLocales
protected java.util.Map m_elementNames
protected java.lang.String m_encoding
protected CmsFile m_file
protected java.util.Set 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.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 cms object
CmsXmlException
- if something goes wrongpublic java.lang.String getConversion()
getConversion
in interface I_CmsXmlDocument
public java.lang.String getEncoding()
I_CmsXmlDocument
getEncoding
in interface I_CmsXmlDocument
I_CmsXmlDocument.getEncoding()
public CmsFile getFile()
null
if not set.
getFile
in interface I_CmsXmlDocument
public int getIndexCount(java.lang.String name, java.util.Locale locale)
I_CmsXmlDocument
-1
if no such value exists.
getIndexCount
in interface I_CmsXmlDocument
name
- the key 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 getLocales()
I_CmsXmlDocument
getLocales
in interface I_CmsXmlDocument
I_CmsXmlDocument.getLocales()
public java.util.List getLocales(java.lang.String name)
If no locale for the given element name is available, an empty list is returned.
getLocales
in interface I_CmsXmlDocument
name
- the element to look up the locale List for
public java.util.List 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
I_CmsXmlDocument.getNames(java.util.Locale)
public java.lang.String getStringValue(CmsObject cms, java.lang.String name, java.util.Locale locale)
I_CmsXmlDocument
null
if no such value exists..
getStringValue
in interface I_CmsXmlDocument
cms
- the current OpenCms user contextname
- the key 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 name, java.util.Locale locale, int index)
I_CmsXmlDocument
null
if no such value exists.
getStringValue
in interface I_CmsXmlDocument
cms
- the current OpenCms user contextname
- the key 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 name, java.util.Locale locale)
I_CmsXmlDocument
null
if no such value exists..
You can provide an index for the value by appending a numer in aquare brackets to the name parameter like this "Title[1]". If no index is provided, 0 is used for the index position.
getValue
in interface I_CmsXmlDocument
name
- the key 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 name, java.util.Locale locale, int index)
I_CmsXmlDocument
null
if no such value exists.
getValue
in interface I_CmsXmlDocument
name
- the key 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 getValues(java.util.Locale locale)
I_CmsXmlDocument
If no element for the given locale is available, an empty list is returned.
getValues
in interface I_CmsXmlDocument
locale
- the locale
I_CmsXmlContentValue
)I_CmsXmlDocument.getValues(java.util.Locale)
public java.util.List getValues(java.lang.String name, java.util.Locale locale)
I_CmsXmlDocument
null
if no such value exists.
getValues
in interface I_CmsXmlDocument
name
- the key to get the content values forlocale
- the locale to get the content values for
I_CmsXmlDocument.getValues(java.lang.String, java.util.Locale)
public boolean hasLocale(java.util.Locale locale)
I_CmsXmlDocument
hasLocale
in interface I_CmsXmlDocument
locale
- the locale to check
I_CmsXmlDocument.hasLocale(java.util.Locale)
public boolean hasValue(java.lang.String name, java.util.Locale locale)
I_CmsXmlDocument
true
if a value exists with the given key name,
false
otherwise.You can provide an index for the value by appending a numer in aquare brackets to the name parameter like this "Title[1]". If no index is provided, 0 is used for the index position.
hasValue
in interface I_CmsXmlDocument
name
- the key to checklocale
- the locale to check
I_CmsXmlDocument.hasValue(java.lang.String, java.util.Locale)
public boolean hasValue(java.lang.String name, java.util.Locale locale, int index)
I_CmsXmlDocument
true
if a value exists with the given key name at the selected index,
false
otherwise.
hasValue
in interface I_CmsXmlDocument
name
- the key to checklocale
- the locale to checkindex
- the index position to check
I_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 name, java.util.Locale locale)
I_CmsXmlDocument
true
if a value exists with the given key name,
and that value is enabled,
false
otherwise.You can provide an index for the value by appending a numer in aquare brackets to the name parameter like this "Title[1]". If no index is provided, 0 is used for the index position.
isEnabled
in interface I_CmsXmlDocument
name
- the key to checklocale
- the locale to check
I_CmsXmlDocument.isEnabled(java.lang.String, java.util.Locale)
public boolean isEnabled(java.lang.String name, java.util.Locale locale, int index)
I_CmsXmlDocument
true
if a value exists with the given key name at the selected index,
and that value is enabled,
false
otherwise.
isEnabled
in interface I_CmsXmlDocument
name
- the key to checklocale
- the locale to checkindex
- the index position to check
I_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 did 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()
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 entitiy resolver to use
CmsXmlException
- if the validation failsprotected void addBookmark(java.lang.String name, java.util.Locale locale, boolean enabled, java.lang.Object value)
name
- the name 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 java.lang.Object getBookmark(java.lang.String bookmark)
getBookmarks()
to get the list of all valid bookmark names.
bookmark
- the bookmark name to look up
protected java.lang.Object getBookmark(java.lang.String name, java.util.Locale locale)
name
- the name to get the bookmark forlocale
- the locale to get the bookmark for
protected java.util.Set 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 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 name, java.util.Locale locale)
name
- the name of the elementlocale
- the locale of the element
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |