org.opencms.xml.page
Class CmsXmlPage

java.lang.Object
  extended by org.opencms.xml.A_CmsXmlDocument
      extended by org.opencms.xml.page.CmsXmlPage
All Implemented Interfaces:
I_CmsXmlDocument

public class CmsXmlPage
extends A_CmsXmlDocument

Implementation of a page object used to access and manage xml data.

This implementation consists of several named elements optionally available for various languages. The data of each element is accessible via its name and language. The content of each element is stored as CDATA, links within the content are processed and are separately accessible as entries of a CmsLinkTable.

Since:
6.0.0
Version:
$Revision: 1.42 $
Author:
Carsten Weinholz, Alexander Kandzior

Field Summary
static java.lang.String ATTRIBUTE_ENABLED
          Name of the name attribute of the elements node.
static java.lang.String ATTRIBUTE_LANGUAGE
          Name of the language attribute of the elements node.
static java.lang.String ATTRIBUTE_NAME
          Name of the name attribute of the elements node.
static java.lang.String NODE_CONTENT
          Name of the element node.
static java.lang.String NODE_ELEMENTS
          Name of the elements node.
static java.lang.String NODE_LINK
          Name of the link node.
static java.lang.String NODE_LINKS
          Name of the links node.
static java.lang.String NODE_PAGE
          Name of the page node.
static java.lang.String NODE_PAGES
          Name of the page node.
static java.lang.String PROPERTY_ALLOW_RELATIVE
          Property to check if relative links are allowed.
static java.lang.String XMLPAGE_XSD_SYSTEM_ID
          The DTD address of the OpenCms xmlpage.
 
Fields inherited from class org.opencms.xml.A_CmsXmlDocument
m_conversion, m_document, m_elementLocales, m_elementNames, m_encoding, m_file, m_locales
 
Constructor Summary
CmsXmlPage(org.dom4j.Document document, java.lang.String encoding)
          Creates a new CmsXmlPage based on the provided document and encoding.
CmsXmlPage(java.util.Locale locale, java.lang.String encoding)
          Creates an empty XML page in the provided locale using the provided encoding.
 
Method Summary
 void addLocale(CmsObject cms, java.util.Locale locale)
          Adds the given locale to this XML document.
 void addValue(java.lang.String name, java.util.Locale locale)
          Adds a new, empty value with the given name and locale to this XML document.
 boolean getAllowRelativeLinks()
          Returns if relative links are accepted (and left unprocessed).
 CmsXmlContentDefinition getContentDefinition()
          Returns the content definition object used for this XML document.
 CmsLinkProcessor getLinkProcessor(CmsObject cms, CmsLinkTable linkTable)
          Returns a link processor for the values of this XML document.
 CmsLinkTable getLinkTable(java.lang.String name, java.util.Locale locale)
          Returns the link table of an element.
 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.
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 isEnabled(java.lang.String name, java.util.Locale locale)
          Checks if the element of a page object is enabled.
 void removeValue(java.lang.String name, java.util.Locale locale)
          Removes an existing value with the given name and locale from this XML document.
 void renameValue(java.lang.String oldValue, java.lang.String newValue, java.util.Locale locale)
          Renames the page-element value from the old to the new one.
protected  void setAllowRelativeLinks(boolean value)
          Sets the parameter that controls the relative link generation.
 void setEnabled(java.lang.String name, java.util.Locale locale, boolean isEnabled)
          Sets the enabled flag of an already existing element.
protected  void setFile(CmsFile file)
          Sets the file this XML page content is written to.
 void setStringValue(CmsObject cms, java.lang.String name, java.util.Locale locale, java.lang.String content)
          Sets the data of an already existing value.
 CmsXmlContentErrorHandler validate(CmsObject cms)
          Validates the content of this XML document.
 
Methods inherited from class org.opencms.xml.A_CmsXmlDocument
addBookmark, addLocale, clearBookmarks, copyLocale, copyLocale, correctXmlStructure, createDeepElementCopy, getBookmark, getBookmark, getBookmarkName, getBookmarks, getConversion, getEncoding, getFile, getIndexCount, getLocales, getLocales, getStringValue, getStringValue, getValue, getValue, getValues, getValues, hasLocale, hasValue, hasValue, initDocument, isAutoCorrectionEnabled, isEnabled, marshal, marshal, moveLocale, removeBookmark, removeLocale, setConversion, toString, validateXmlStructure
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ATTRIBUTE_ENABLED

public static final java.lang.String ATTRIBUTE_ENABLED
Name of the name attribute of the elements node.

See Also:
Constant Field Values

ATTRIBUTE_LANGUAGE

public static final java.lang.String ATTRIBUTE_LANGUAGE
Name of the language attribute of the elements node.

See Also:
Constant Field Values

ATTRIBUTE_NAME

public static final java.lang.String ATTRIBUTE_NAME
Name of the name attribute of the elements node.

See Also:
Constant Field Values

NODE_CONTENT

public static final java.lang.String NODE_CONTENT
Name of the element node.

See Also:
Constant Field Values

NODE_ELEMENTS

public static final java.lang.String NODE_ELEMENTS
Name of the elements node.

See Also:
Constant Field Values

NODE_LINK

public static final java.lang.String NODE_LINK
Name of the link node.

See Also:
Constant Field Values

NODE_LINKS

public static final java.lang.String NODE_LINKS
Name of the links node.

See Also:
Constant Field Values

NODE_PAGE

public static final java.lang.String NODE_PAGE
Name of the page node.

See Also:
Constant Field Values

NODE_PAGES

public static final java.lang.String NODE_PAGES
Name of the page node.

See Also:
Constant Field Values

PROPERTY_ALLOW_RELATIVE

public static final java.lang.String PROPERTY_ALLOW_RELATIVE
Property to check if relative links are allowed.

See Also:
Constant Field Values

XMLPAGE_XSD_SYSTEM_ID

public static final java.lang.String XMLPAGE_XSD_SYSTEM_ID
The DTD address of the OpenCms xmlpage.

See Also:
Constant Field Values
Constructor Detail

CmsXmlPage

public CmsXmlPage(org.dom4j.Document document,
                  java.lang.String encoding)
Creates a new CmsXmlPage based on the provided document and encoding.

The encoding is used for marshalling the XML document later.

Parameters:
document - the document to create the CmsXmlPage from
encoding - the encoding of the xml page

CmsXmlPage

public CmsXmlPage(java.util.Locale locale,
                  java.lang.String encoding)
Creates an empty XML page in the provided locale using the provided encoding.

The page is initialized according to the minimal necessary xml structure. The encoding is used for marshalling the XML document later.

Parameters:
locale - the initial locale of the XML page
encoding - the encoding of the XML page
Method Detail

addLocale

public void addLocale(CmsObject cms,
                      java.util.Locale locale)
               throws CmsXmlException
Description copied from interface: I_CmsXmlDocument
Adds the given locale to this XML document.

Parameters:
cms - the current users OpenCms context
locale - the locale to add
Throws:
CmsXmlException - in case the locale already existed, or if something else goes wrong
See Also:
I_CmsXmlDocument.addLocale(org.opencms.file.CmsObject, java.util.Locale)

addValue

public void addValue(java.lang.String name,
                     java.util.Locale locale)
              throws CmsIllegalArgumentException
Adds a new, empty value with the given name and locale to this XML document.

Parameters:
name - the name of the value
locale - the locale of the value
Throws:
CmsIllegalArgumentException - if the name contains an index ("[<number>]") or the value for the given locale already exists in the xmlpage.

getAllowRelativeLinks

public boolean getAllowRelativeLinks()
Returns if relative links are accepted (and left unprocessed).

Returns:
true if relative links are allowed

getContentDefinition

public CmsXmlContentDefinition getContentDefinition()
                                             throws CmsRuntimeException
Description copied from interface: I_CmsXmlDocument
Returns the content definition object used for this XML document.

Returns:
the content definition object used for this XML document
Throws:
CmsRuntimeException
See Also:
I_CmsXmlDocument.getContentDefinition()

getLinkProcessor

public CmsLinkProcessor getLinkProcessor(CmsObject cms,
                                         CmsLinkTable linkTable)
Description copied from interface: I_CmsXmlDocument
Returns a link processor for the values of this XML document.

Parameters:
cms - the current OpenCms user context that provides access to the link processor
linkTable - the table with the links to process
Returns:
a link processor for the values of this XML document
See Also:
I_CmsXmlDocument.getLinkProcessor(org.opencms.file.CmsObject, org.opencms.staticexport.CmsLinkTable)

getLinkTable

public CmsLinkTable getLinkTable(java.lang.String name,
                                 java.util.Locale locale)
Returns the link table of an element.

Parameters:
name - name of the element
locale - locale of the element
Returns:
the link table

getNames

public java.util.List<java.lang.String> getNames(java.util.Locale locale)
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 interface I_CmsXmlDocument
Overrides:
getNames in class A_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:
A_CmsXmlDocument.getNames(java.util.Locale)

isEnabled

public boolean isEnabled(java.lang.String name,
                         java.util.Locale locale)
Checks if the element of a page object is enabled.

Specified by:
isEnabled in interface I_CmsXmlDocument
Overrides:
isEnabled in class A_CmsXmlDocument
Parameters:
name - the name of the element
locale - the locale of the element
Returns:
true if the element exists and is not disabled
See Also:
I_CmsXmlDocument.isEnabled(java.lang.String, java.util.Locale)

removeValue

public void removeValue(java.lang.String name,
                        java.util.Locale locale)
Removes an existing value with the given name and locale from this XML document.

Parameters:
name - the name of the value
locale - the locale of the value

renameValue

public void renameValue(java.lang.String oldValue,
                        java.lang.String newValue,
                        java.util.Locale locale)
                 throws CmsIllegalArgumentException
Renames the page-element value from the old to the new one.

Parameters:
oldValue - the old value
newValue - the new value
locale - the locale
Throws:
CmsIllegalArgumentException - if the name contains an index ("[<number>]"), the new value for the given locale already exists in the xmlpage or the the old value does not exist for the locale in the xmlpage.

setEnabled

public void setEnabled(java.lang.String name,
                       java.util.Locale locale,
                       boolean isEnabled)
Sets the enabled flag of an already existing element.

Note: if isEnabled is set to true, the attribute is removed since true is the default

Parameters:
name - name name of the element
locale - locale of the element
isEnabled - enabled flag for the element

setStringValue

public void setStringValue(CmsObject cms,
                           java.lang.String name,
                           java.util.Locale locale,
                           java.lang.String content)
                    throws CmsXmlException
Sets the data of an already existing value.

The data will be enclosed as CDATA within the xml page structure. When setting the element data, the content of this element will be processed automatically.

Parameters:
cms - the cms object
name - name of the element
locale - locale of the element
content - character data (CDATA) of the element
Throws:
CmsXmlException - if something goes wrong

validate

public CmsXmlContentErrorHandler validate(CmsObject cms)
Description copied from interface: I_CmsXmlDocument
Validates the content of this XML document.

To check for errors in a single document locale only, use CmsXmlContentErrorHandler.hasErrors(Locale) in the result object.

Parameters:
cms - the current OpenCms user context
Returns:
an error handler instance that provides information about the errors or warnings that have been found
See Also:
I_CmsXmlDocument.validate(org.opencms.file.CmsObject)

initDocument

protected void initDocument(org.dom4j.Document document,
                            java.lang.String encoding,
                            CmsXmlContentDefinition definition)
Description copied from class: A_CmsXmlDocument
Initializes an XML document based on the provided document, encoding and content definition.

Specified by:
initDocument in class A_CmsXmlDocument
Parameters:
document - the base XML document to use for initializing
encoding - the encoding to use when marshalling the document later
definition - the content definition to use
See Also:
A_CmsXmlDocument.initDocument(org.dom4j.Document, java.lang.String, org.opencms.xml.CmsXmlContentDefinition)

setAllowRelativeLinks

protected void setAllowRelativeLinks(boolean value)
Sets the parameter that controls the relative link generation.

Parameters:
value - the parameter that controls the relative link generation

setFile

protected void setFile(CmsFile file)
Sets the file this XML page content is written to.

Parameters:
file - the file this XML page content is written to