Class CmsXmlContent

java.lang.Object
org.opencms.xml.A_CmsXmlDocument
org.opencms.xml.content.CmsXmlContent
All Implemented Interfaces:
I_CmsXmlDocument
Direct Known Subclasses:
CmsXmlContainerPage, CmsXmlGroupContainer

public class CmsXmlContent extends A_CmsXmlDocument
Implementation of a XML content object, used to access and manage structured content.

Use the CmsXmlContentFactory to generate an instance of this class.

Since:
6.0.0
  • Field Details

  • Constructor Details

    • CmsXmlContent

      protected CmsXmlContent()
      Hides the public constructor.

    • CmsXmlContent

      protected CmsXmlContent(CmsObject cms, org.dom4j.Document document, String encoding, EntityResolver resolver)
      Creates a new XML content based on the provided XML document.

      The given encoding is used when marshalling the XML again later.

      Parameters:
      cms - the cms context, if null no link validation is performed
      document - the document to create the xml content from
      encoding - the encoding of the xml content
      resolver - the XML entitiy resolver to use
    • CmsXmlContent

      protected CmsXmlContent(CmsObject cms, Locale locale, String modelUri) throws CmsException
      Create a new XML content based on the given default content, that will have all language nodes of the default content and ensures the presence of the given locale.

      The given encoding is used when marshalling the XML again later.

      Parameters:
      cms - the current users OpenCms content
      locale - the locale to generate the default content for
      modelUri - the absolute path to the XML content file acting as model
      Throws:
      CmsException - in case the model file is not found or not valid
    • CmsXmlContent

      protected CmsXmlContent(CmsObject cms, Locale locale, String encoding, CmsXmlContentDefinition contentDefinition)
      Create a new XML content based on the given content definiton, that will have one language node for the given locale all initialized with default values.

      The given encoding is used when marshalling the XML again later.

      Parameters:
      cms - the current users OpenCms content
      locale - the locale to generate the default content for
      encoding - the encoding to use when marshalling the XML content later
      contentDefinition - the content definiton to create the content for
  • Method Details

    • addLocale

      public void addLocale(CmsObject cms, 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:
    • addValue

      Adds a new XML content value for the given element name and locale at the given index position to this XML content document.

      Parameters:
      cms - the current users OpenCms context
      path - the path to the XML content value element
      locale - the locale where to add the new value
      index - the index where to add the value (relative to all other values of this type)
      Returns:
      the created XML content value
      Throws:
      CmsIllegalArgumentException - if the given path is invalid
      CmsRuntimeException - if the element identified by the path already occurred I_CmsXmlSchemaType.getMaxOccurs() or the given index is invalid (too high).
    • clone

      public CmsXmlContent clone()
      Overrides:
      clone in class Object
      See Also:
    • copyLocale

      public void copyLocale(Locale source, Locale destination, Set<String> elements) throws CmsXmlException
      Copies the content of the given source locale to the given destination locale in this XML document.

      Parameters:
      source - the source locale
      destination - the destination loacle
      elements - the set of elements to copy
      Throws:
      CmsXmlException - if something goes wrong
    • getAllSimpleSubValues

      Returns all simple type sub values.

      Parameters:
      value - the value
      Returns:
      the simple type sub values
    • getChoiceOptions

      Returns the list of choice options for the given xpath in the selected locale.

      In case the xpath does not select a nested choice content definition, or in case the xpath does not exist at all, null is returned.

      Parameters:
      xpath - the xpath to check the choice options for
      locale - the locale to check
      Returns:
      the list of choice options for the given xpath
    • getContentDefinition

      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
      See Also:
    • getHandler

      Description copied from interface: I_CmsXmlDocument
      Returns the content handler associated with the content definition of this XML document.

      This is a shortcut for getContentDefinition().getContentHandler().

      Returns:
      the content handler associated with the content definition of this XML document
      See Also:
    • getLinkProcessor

      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:
    • getLocaleNode

      public org.dom4j.Element getLocaleNode(Locale locale) throws CmsRuntimeException
      Returns the XML root element node for the given locale.

      Parameters:
      locale - the locale to get the root element for
      Returns:
      the XML root element node for the given locale
      Throws:
      CmsRuntimeException - if no language element is found in the document
    • getSchemaVersion

      public int getSchemaVersion()
      Gets the schema version (or 0 if no schema version is set).
      Returns:
      the schema version
    • getSimpleValuesBelowPath

      Returns all simple type values below a given path.

      Parameters:
      elementPath - the element path
      locale - the content locale
      Returns:
      the simple type values
    • getSubValues

      Returns the list of sub-value for the given xpath in the selected locale.

      Specified by:
      getSubValues in interface I_CmsXmlDocument
      Overrides:
      getSubValues in class A_CmsXmlDocument
      Parameters:
      path - the xpath to look up the sub-value for
      locale - the locale to use
      Returns:
      the list of sub-value for the given xpath in the selected locale
      See Also:
    • getValuesByPath

      public List<I_CmsXmlContentValue> getValuesByPath(String elementPath, Locale locale)
      Returns all values of the given element path.

      Parameters:
      elementPath - the element path
      locale - the content locale
      Returns:
      the values
    • getValueSequence

      Returns the value sequence for the selected element xpath in this XML content.

      If the given element xpath is not valid according to the schema of this XML content, null is returned.

      Parameters:
      xpath - the element xpath to get the value sequence for
      locale - the locale to get the value sequence for
      Returns:
      the value sequence for the selected element name in this XML content
    • hasChoiceOptions

      public boolean hasChoiceOptions(String xpath, Locale locale)
      Returns true if choice options exist for the given xpath in the selected locale.

      In case the xpath does not select a nested choice content definition, or in case the xpath does not exist at all, false is returned.

      Parameters:
      xpath - the xpath to check the choice options for
      locale - the locale to check
      Returns:
      true if choice options exist for the given xpath in the selected locale
    • hasInvalidatedBrokenLinks

      public boolean hasInvalidatedBrokenLinks()
      Checks if any broken links have been invalidated in this content.
      Returns:
      true if broken links have been invalidated
    • isAutoCorrectionEnabled

      public boolean isAutoCorrectionEnabled()
      Description copied from class: A_CmsXmlDocument
      Returns true if the auto correction feature is enabled for saving this XML content.

      Overrides:
      isAutoCorrectionEnabled in class A_CmsXmlDocument
      Returns:
      true if the auto correction feature is enabled for saving this XML content
      See Also:
    • isLocaleIndependent

      public boolean isLocaleIndependent()
      Checks if the content is locale independent.

      Returns:
      true if the content is locale independent
    • isTransformedVersion

      public boolean isTransformedVersion()
      Checks if a version transformation was used when creating this content object.
      Returns:
      true if a version transformation was used when creating this content object
    • removeValue

      public void removeValue(String name, Locale locale, int index)
      Removes an existing XML content value of the given element name and locale at the given index position from this XML content document.

      Parameters:
      name - the name of the XML content value element
      locale - the locale where to remove the value
      index - the index where to remove the value (relative to all other values of this type)
    • resolveMappings

      public void resolveMappings(CmsObject cms)
      Resolves the mappings for all values of this XML content.

      Parameters:
      cms - the current users OpenCms context
    • setAutoCorrectionEnabled

      public void setAutoCorrectionEnabled(boolean value)
      Sets the flag to control if auto correction is enabled when saving this XML content.

      Parameters:
      value - the flag to control if auto correction is enabled when saving this XML content
    • synchronizeLocaleIndependentValues

      public void synchronizeLocaleIndependentValues(CmsObject cms, Collection<String> skipPaths, Locale sourceLocale)
      Synchronizes the locale independent fields for the given locale.

      Parameters:
      cms - the cms context
      skipPaths - the paths to skip
      sourceLocale - the source locale
    • validate

      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:
    • visitAllValuesWith

      Visits all values of this XML content with the given value visitor.

      Please note that the order in which the values are visited may NOT be the order they appear in the XML document. It is ensured that the parent of a nested value is visited before the element it contains.

      Parameters:
      visitor - the value visitor implementation to visit the values with
    • addBookmarkForElement

      protected void addBookmarkForElement(org.dom4j.Element element, Locale locale, org.dom4j.Element parent, String parentPath, CmsXmlContentDefinition parentDef)
      Creates a new bookmark for the given element.

      Parameters:
      element - the element to create the bookmark for
      locale - the locale
      parent - the parent node of the element
      parentPath - the parent's path
      parentDef - the parent's content definition
    • addBookmarkForValue

      protected void addBookmarkForValue(I_CmsXmlContentValue value, String path, Locale locale, boolean enabled)
      Adds a bookmark for the given value.

      Parameters:
      value - the value to bookmark
      path - the lookup path to use for the bookmark
      locale - the locale to use for the bookmark
      enabled - if true, the value is enabled, if false it is disabled
    • addValue

      protected I_CmsXmlContentValue addValue(CmsObject cms, org.dom4j.Element parent, I_CmsXmlSchemaType type, Locale locale, int insertIndex)
      Adds a new XML schema type with the default value to the given parent node.

      Parameters:
      cms - the cms context
      parent - the XML parent element to add the new value to
      type - the type of the value to add
      locale - the locale to add the new value for
      insertIndex - the index in the XML document where to add the XML node
      Returns:
      the created XML content value
    • getBookmark

      protected I_CmsXmlContentValue getBookmark(String bookmark)
      Description copied from class: A_CmsXmlDocument
      Returns the bookmarked value for the given bookmark, which must be a valid bookmark name. Use A_CmsXmlDocument.getBookmarks() to get the list of all valid bookmark names.

      Overrides:
      getBookmark in class A_CmsXmlDocument
      Parameters:
      bookmark - the bookmark name to look up
      Returns:
      the bookmarked value for the given bookmark
      See Also:
    • getBookmarks

      protected Set<String> getBookmarks()
      Description copied from class: A_CmsXmlDocument
      Returns the names of all bookmarked elements.

      Overrides:
      getBookmarks in class A_CmsXmlDocument
      Returns:
      the names of all bookmarked elements
      See Also:
    • getContentDefinition

      Returns the content definition object for this xml content object.

      Parameters:
      resolver - the XML entity resolver to use, required for VFS access
      Returns:
      the content definition object for this xml content object
      Throws:
      CmsRuntimeException - if the schema location attribute (systemId)cannot be found, parsing of the schema fails, an underlying IOException occurs or unmarshalling fails
    • initDocument

      protected void initDocument(CmsObject cms, org.dom4j.Document document, String encoding, CmsXmlContentDefinition definition)
      Initializes an XML document based on the provided document, encoding and content definition.

      Checks the links and removes invalid ones in the initialized document.

      Parameters:
      cms - the current users OpenCms content
      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
    • initDocument

      protected void initDocument(org.dom4j.Document document, 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:
    • processSchemaNode

      protected void processSchemaNode(org.dom4j.Element root, String rootPath, Locale locale, CmsXmlContentDefinition definition)
      Processes a document node and extracts the values of the node according to the provided XML content definition.

      Parameters:
      root - the root node element to process
      rootPath - the Xpath of the root node in the document
      locale - the locale
      definition - the XML content definition to use for processing the values
    • setFile

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

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