Class CmsXmlContent

    • Constructor Detail

      • CmsXmlContent

        protected CmsXmlContent()
        Hides the public constructor.

      • CmsXmlContent

        protected CmsXmlContent​(CmsObject cms,
                                org.dom4j.Document document,
                                java.lang.String encoding,
                                org.xml.sax.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,
                                java.util.Locale locale,
                                java.lang.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,
                                java.util.Locale locale,
                                java.lang.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 Detail

      • clone

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

        public void copyLocale​(java.util.Locale source,
                               java.util.Locale destination,
                               java.util.Set<java.lang.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
      • getChoiceOptions

        public java.util.List<I_CmsXmlSchemaTypegetChoiceOptions​(java.lang.String xpath,
                                                                   java.util.Locale locale)
        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
      • getHandler

        public I_CmsXmlContentHandler 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:
        I_CmsXmlDocument.getHandler()
      • getLocaleNode

        public org.dom4j.Element getLocaleNode​(java.util.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

        public java.util.List<I_CmsXmlContentValuegetSimpleValuesBelowPath​(java.lang.String elementPath,
                                                                             java.util.Locale locale)
        Returns all simple type values below a given path.

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

        public java.util.List<I_CmsXmlContentValuegetValuesByPath​(java.lang.String elementPath,
                                                                    java.util.Locale locale)
        Returns all values of the given element path.

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

        public CmsXmlContentValueSequence getValueSequence​(java.lang.String xpath,
                                                           java.util.Locale locale)
        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​(java.lang.String xpath,
                                        java.util.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
      • 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​(java.lang.String name,
                                java.util.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,
                                                       java.util.Collection<java.lang.String> skipPaths,
                                                       java.util.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
      • visitAllValuesWith

        public void visitAllValuesWith​(I_CmsXmlContentValueVisitor visitor)
        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,
                                             java.util.Locale locale,
                                             org.dom4j.Element parent,
                                             java.lang.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,
                                           java.lang.String path,
                                           java.util.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,
                                                java.util.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
      • getContentDefinition

        protected CmsXmlContentDefinition getContentDefinition​(org.xml.sax.EntityResolver resolver)
                                                        throws CmsRuntimeException
        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,
                                    java.lang.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
      • processSchemaNode

        protected void processSchemaNode​(org.dom4j.Element root,
                                         java.lang.String rootPath,
                                         java.util.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