Class CmsXmlPageFactory

java.lang.Object
org.opencms.xml.page.CmsXmlPageFactory

public final class CmsXmlPageFactory extends Object
Provides factory methods to unmarshal (read) an XML page object.

Since:
6.0.0
  • Method Details

    • createDocument

      public static org.dom4j.Document createDocument(Locale locale)
      Creates a valid XML page document, containing one empty element in the given locale.

      Parameters:
      locale - the locale to create the XML page for
      Returns:
      a valid XML page document
    • createDocument

      public static String createDocument(Locale locale, String encoding)
      Creates a valid XML page String representation, containing one empty element in the given locale.

      Parameters:
      locale - the locale to create the XML page for
      encoding - the encoding to use when creating the String from the XML
      Returns:
      a valid XML page document as a String
    • unmarshal

      public static CmsXmlPage unmarshal(byte[] xmlData, String encoding, EntityResolver resolver) throws CmsXmlException
      Factory method to unmarshal (read) a XML page instance from a byte array that contains XML data.

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

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

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

      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 CmsXmlPage unmarshal(CmsObject cms, CmsFile file, boolean keepEncoding) throws CmsXmlException
      Factory method to unmarshal (read) a XML page 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.

      Parameters:
      cms - the current OpenCms user context
      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 page instance unmarshalled from the provided file
      Throws:
      CmsXmlException - if something goes wrong
    • unmarshal

      public static CmsXmlPage unmarshal(CmsObject cms, CmsResource resource, javax.servlet.ServletRequest req) throws CmsException
      Factory method to unmarshal (read) a XML page instance from a resource, using the request attributes as cache.

      Parameters:
      cms - the current OpenCms user context
      resource - the resource to unmarshal
      req - the current request
      Returns:
      the unmarshaled XML page, or null if the given resource was not of type CmsResourceTypeXmlPage
      Throws:
      CmsException - in something goes wrong
    • unmarshal

      public static I_CmsXmlDocument unmarshal(CmsObject cms, String filename, javax.servlet.ServletRequest req) throws CmsException
      Factory method to unmarshal (read) a XML document instance from a filename in the VFS, using the request attributes as cache.

      Parameters:
      cms - the current OpenCms user context
      filename - the filename of the resource to unmarshal
      req - the current request
      Returns:
      the unmarshaled XML document, or null if the given resource was not of type I_CmsXmlDocument
      Throws:
      CmsException - in something goes wrong
    • unmarshal

      public static CmsXmlPage unmarshal(String xmlData, String encoding, EntityResolver resolver) throws CmsXmlException
      Factory method to unmarshal (read) a XML page instance from a String that contains XML data.

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

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