Package org.opencms.xml.page
Class CmsXmlPageFactory
java.lang.Object
org.opencms.xml.page.CmsXmlPageFactory
Provides factory methods to unmarshal (read) an XML page object.
- Since:
- 6.0.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic org.dom4j.Document
createDocument
(Locale locale) Creates a valid XML page document, containing one empty element in the given locale.static String
createDocument
(Locale locale, String encoding) Creates a valid XML page String representation, containing one empty element in the given locale.static CmsXmlPage
unmarshal
(byte[] xmlData, String encoding, EntityResolver resolver) Factory method to unmarshal (read) a XML page instance from a byte array that contains XML data.static CmsXmlPage
unmarshal
(String xmlData, String encoding, EntityResolver resolver) Factory method to unmarshal (read) a XML page instance from a String that contains XML data.static I_CmsXmlDocument
Factory method to unmarshal (read) a XML document instance from a filename in the VFS, using the request attributes as cache.static CmsXmlPage
Factory method to unmarshal (read) a XML page instance from a OpenCms VFS file that contains XML data.static CmsXmlPage
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.static CmsXmlPage
unmarshal
(CmsObject cms, CmsResource resource, javax.servlet.ServletRequest req) Factory method to unmarshal (read) a XML page instance from a resource, using the request attributes as cache.
-
Method Details
-
createDocument
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
Creates a valid XML page String representation, containing one empty element in the given locale.- Parameters:
locale
- the locale to create the XML page forencoding
- 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 arrayencoding
- the encoding to use when marshalling the XML page laterresolver
- the XML entity resolver to use- Returns:
- a XML page instance unmarshalled from the byte array
- Throws:
CmsXmlException
- if something goes wrong
-
unmarshal
Factory method to unmarshal (read) a XML page instance from a OpenCms VFS file that contains XML data.- Parameters:
cms
- the current cms objectfile
- 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 contextfile
- the file with the XML data to unmarshalkeepEncoding
- 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 contextresource
- the resource to unmarshalreq
- 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 contextfilename
- the filename of the resource to unmarshalreq
- the current request- Returns:
- the unmarshaled XML document, or
null
if the given resource was not of typeI_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 Stringencoding
- the encoding to use when marshalling the XML page laterresolver
- the XML entity resolver to use- Returns:
- a XML page instance unmarshalled from the String
- Throws:
CmsXmlException
- if something goes wrong
-