Class CmsXmlContentFactory


  • public final class CmsXmlContentFactory
    extends java.lang.Object
    Provides factory methods to unmarshal (read) an XML content object.

    Since:
    6.0.0
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static CmsXmlContent createDocument​(CmsObject cms, java.util.Locale locale, java.lang.String modelUri)
      Create a new instance of an XML content based on the given default content, hat will have all language nodes of the default content and ensures the presence of the given locale.
      static CmsXmlContent createDocument​(CmsObject cms, java.util.Locale locale, java.lang.String encoding, CmsXmlContentDefinition contentDefinition)
      Create a new instance of an XML content based on the given content definiton, that will have one language node for the given locale all initialized with default values.
      static CmsXmlContent createDocument​(CmsObject cms, java.util.Locale locale, CmsResourceTypeXmlContent resourceType)
      Creates a new XML content based on a resource type.
      static CmsXmlContent unmarshal​(java.lang.String xmlData, java.lang.String encoding, org.xml.sax.EntityResolver resolver)
      Factory method to unmarshal (generate) a XML content instance from a String that contains XML data.
      static CmsXmlContent unmarshal​(CmsObject cms, byte[] xmlData, java.lang.String encoding, org.xml.sax.EntityResolver resolver)
      Factory method to unmarshal (generate) a XML content instance from a byte array that contains XML data.
      static CmsXmlContent unmarshal​(CmsObject cms, java.lang.String xmlData, java.lang.String encoding, org.xml.sax.EntityResolver resolver)
      Factory method to unmarshal (generate) a XML content instance from a String that contains XML data.
      static CmsXmlContent unmarshal​(CmsObject cms, org.dom4j.Document document, java.lang.String encoding, org.xml.sax.EntityResolver resolver)
      Factory method to unmarshal (generate) a XML content instance from a XML document.
      static CmsXmlContent unmarshal​(CmsObject cms, CmsFile file)
      Factory method to unmarshal (read) a XML content instance from a OpenCms VFS file that contains XML data.
      static CmsXmlContent unmarshal​(CmsObject cms, CmsFile file, boolean keepEncoding)
      Factory method to unmarshal (read) a XML content instance from a OpenCms VFS file that contains XML data, using wither the encoding set in the XML file header, or the encoding set in the VFS file property.
      static CmsXmlContent unmarshal​(CmsObject cms, CmsResource resource, javax.servlet.ServletRequest req)
      Factory method to unmarshal (read) a XML content instance from a resource, using the request attributes as cache.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • createDocument

        public static CmsXmlContent createDocument​(CmsObject cms,
                                                   java.util.Locale locale,
                                                   CmsResourceTypeXmlContent resourceType)
                                            throws CmsXmlException
        Creates a new XML content based on a resource type.

        Parameters:
        cms - the current OpenCms context
        locale - the locale to generate the default content for
        resourceType - the resource type for which the document should be created
        Returns:
        the created XML content
        Throws:
        CmsXmlException - if something goes wrong
      • createDocument

        public static CmsXmlContent createDocument​(CmsObject cms,
                                                   java.util.Locale locale,
                                                   java.lang.String modelUri)
                                            throws CmsException
        Create a new instance of an XML content based on the given default content, hat 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
        Returns:
        the created XML content
        Throws:
        CmsException - in case the model file is not found or not valid
      • createDocument

        public static CmsXmlContent createDocument​(CmsObject cms,
                                                   java.util.Locale locale,
                                                   java.lang.String encoding,
                                                   CmsXmlContentDefinition contentDefinition)
        Create a new instance of an 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
        Returns:
        the created XML content
      • unmarshal

        public static CmsXmlContent unmarshal​(CmsObject cms,
                                              byte[] xmlData,
                                              java.lang.String encoding,
                                              org.xml.sax.EntityResolver resolver)
                                       throws CmsXmlException
        Factory method to unmarshal (generate) a XML content instance from a byte array that contains XML data.

        When unmarshalling, the encoding is read directly from the XML header of the byte array. The given encoding is used only when marshalling the XML again later.

        Warning:
        This method does not support requested historic versions, it always loads the most recent version. Use unmarshal(CmsObject, CmsResource, ServletRequest) for history support.

        Parameters:
        cms - the cms context
        xmlData - the XML data in a byte array
        encoding - the encoding to use when marshalling the XML content later
        resolver - the XML entitiy resolver to use
        Returns:
        a XML content instance unmarshalled from the byte array
        Throws:
        CmsXmlException - if something goes wrong
      • unmarshal

        public static CmsXmlContent unmarshal​(CmsObject cms,
                                              CmsFile file)
                                       throws CmsXmlException
        Factory method to unmarshal (read) a XML content instance from a OpenCms VFS file that contains XML data.

        Warning:
        This method does not support requested historic versions, it always loads the most recent version. Use unmarshal(CmsObject, CmsResource, ServletRequest) for history support.

        Parameters:
        cms - the current cms object
        file - the file with the XML data to unmarshal
        Returns:
        a XML page instance unmarshalled from the provided file
        Throws:
        CmsXmlException - if something goes wrong
      • unmarshal

        public static CmsXmlContent unmarshal​(CmsObject cms,
                                              CmsFile file,
                                              boolean keepEncoding)
                                       throws CmsXmlException
        Factory method to unmarshal (read) a XML content instance from a OpenCms VFS file that contains XML data, using wither the encoding set in the XML file header, or the encoding set in the VFS file property.

        If you are not sure about the implications of the encoding issues, use unmarshal(CmsObject, CmsFile) instead.

        Warning:
        This method does not support requested historic versions, it always loads the most recent version. Use unmarshal(CmsObject, CmsResource, ServletRequest) for history support.

        Parameters:
        cms - the current cms object
        file - the file with the XML data to unmarshal
        keepEncoding - if true, the encoding spefified in the XML header is used, otherwise the encoding from the VFS file property is used
        Returns:
        a XML content instance unmarshalled from the provided file
        Throws:
        CmsXmlException - if something goes wrong
      • unmarshal

        public static CmsXmlContent unmarshal​(CmsObject cms,
                                              org.dom4j.Document document,
                                              java.lang.String encoding,
                                              org.xml.sax.EntityResolver resolver)
        Factory method to unmarshal (generate) a XML content instance from a XML document.

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

        Warning:
        This method does not support requested historic versions, it always loads the most recent version. Use unmarshal(CmsObject, CmsResource, ServletRequest) for history support.

        Parameters:
        cms - the cms context, if null no link validation is performed
        document - the XML document to generate the XML content from
        encoding - the encoding to use when marshalling the XML content later
        resolver - the XML entitiy resolver to use
        Returns:
        a XML content instance unmarshalled from the String
      • unmarshal

        public static CmsXmlContent unmarshal​(CmsObject cms,
                                              java.lang.String xmlData,
                                              java.lang.String encoding,
                                              org.xml.sax.EntityResolver resolver)
                                       throws CmsXmlException
        Factory method to unmarshal (generate) a XML content instance from a String that contains XML data.

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

        Warning:
        This method does not support requested historic versions, it always loads the most recent version. Use unmarshal(CmsObject, CmsResource, ServletRequest) for history support.

        Parameters:
        cms - the cms context, if null no link validation is performed
        xmlData - the XML data in a String
        encoding - the encoding to use when marshalling the XML content later
        resolver - the XML entitiy resolver to use
        Returns:
        a XML content instance unmarshalled from the String
        Throws:
        CmsXmlException - if something goes wrong
      • unmarshal

        public static CmsXmlContent unmarshal​(java.lang.String xmlData,
                                              java.lang.String encoding,
                                              org.xml.sax.EntityResolver resolver)
                                       throws CmsXmlException
        Factory method to unmarshal (generate) a XML content instance from a String that contains XML data.

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

        Since no CmsObject is available, no link validation is performed!

        Warning:
        This method does not support requested historic versions, it always loads the most recent version. Use unmarshal(CmsObject, CmsResource, ServletRequest) for history support.

        Parameters:
        xmlData - the XML data in a String
        encoding - the encoding to use when marshalling the XML content later
        resolver - the XML entity resolver to use
        Returns:
        a XML content instance unmarshalled from the String
        Throws:
        CmsXmlException - if something goes wrong