Class CmsJsonRendererXmlContent
- java.lang.Object
-
- org.opencms.xml.xml2json.renderer.CmsJsonRendererXmlContent
-
- All Implemented Interfaces:
I_CmsConfigurationParameterHandler
,I_CmsJsonRendererXmlContent
public class CmsJsonRendererXmlContent extends java.lang.Object implements I_CmsJsonRendererXmlContent
Converts an XML content to JSON by creating a CmsXmlContentTree and then recursively processing its nodes.This specific renderer class does not need to be initialized with a CmsJsonHandlerContext, you can just initialize it with a CmsObject.
-
-
Field Summary
-
Fields inherited from interface org.opencms.configuration.I_CmsConfigurationParameterHandler
ADD_PARAMETER_METHOD, INIT_CONFIGURATION_METHOD
-
-
Constructor Summary
Constructors Constructor Description CmsJsonRendererXmlContent()
Creates a new instance.CmsJsonRendererXmlContent(CmsObject cms)
Creates a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addConfigurationParameter(java.lang.String paramName, java.lang.String paramValue)
Adds a configuration parameter to this parameter configurable class instance.CmsParameterConfiguration
getConfiguration()
Returns the parameters of this configurable class instance, ornull
if the class does not need any parameters.void
initConfiguration()
Initializes a configuration after all parameters have been added.void
initialize(CmsObject cms)
Initializes the renderer.void
initialize(CmsJsonHandlerContext context)
Initializes the context for the renderer.static JSONObject
linkAndPath(java.lang.String link, java.lang.String path, CmsObject cms)
Builds a simple JSON object with link and path fields whose values are taken from the corresponding parameters.java.lang.Object
render(CmsXmlContent content, java.util.Locale locale)
Converts the XML content for a single locale to a JSON objectstatic JSONObject
renderAllLocales(CmsXmlContent content, I_CmsJsonRendererXmlContent renderer)
Helper method to apply renderer to all locales of an XML content, and put the resulting objects into a JSON object with the locales as keys.protected java.util.AbstractMap.SimpleEntry<java.lang.String,java.lang.Object>
renderField(CmsXmlContentTree.Field field)
Renders a tree field as a field in the given JSON object.java.lang.Object
renderNode(CmsXmlContentTree.Node node)
Renders a tree node as JSON.protected java.lang.Object
renderSimpleValue(CmsXmlContentTree.Node node)
Renders a simple value (i.e.
-
-
-
Constructor Detail
-
CmsJsonRendererXmlContent
public CmsJsonRendererXmlContent()
Creates a new instance. If this constructor is used, you still have to call one of the initialize() methods before rendering XML content to JSON.
-
CmsJsonRendererXmlContent
public CmsJsonRendererXmlContent(CmsObject cms) throws CmsException
Creates a new instance.- Parameters:
cms
- the CMS context to use- Throws:
CmsException
- if something goes wrong
-
-
Method Detail
-
linkAndPath
public static JSONObject linkAndPath(java.lang.String link, java.lang.String path, CmsObject cms) throws JSONException
Builds a simple JSON object with link and path fields whose values are taken from the corresponding parameters.If path is null, it will not be added to the result JSON.
- Parameters:
link
- the value for the link fieldpath
- the value for the path field- Returns:
- the link-and-path object
- Throws:
JSONException
- if something goes wrong
-
renderAllLocales
public static JSONObject renderAllLocales(CmsXmlContent content, I_CmsJsonRendererXmlContent renderer) throws JSONException
Helper method to apply renderer to all locales of an XML content, and put the resulting objects into a JSON object with the locales as keys.- Parameters:
content
- the contentrenderer
- the renderer to use- Returns:
- the result JSON
- Throws:
JSONException
- if something goes wrong
-
addConfigurationParameter
public void addConfigurationParameter(java.lang.String paramName, java.lang.String paramValue)
Description copied from interface:I_CmsConfigurationParameterHandler
Adds a configuration parameter to this parameter configurable class instance.- Specified by:
addConfigurationParameter
in interfaceI_CmsConfigurationParameterHandler
- Parameters:
paramName
- the name of the parameterparamValue
- the value for the parameter- See Also:
I_CmsConfigurationParameterHandler.addConfigurationParameter(java.lang.String, java.lang.String)
-
getConfiguration
public CmsParameterConfiguration getConfiguration()
Description copied from interface:I_CmsConfigurationParameterHandler
Returns the parameters of this configurable class instance, ornull
if the class does not need any parameters.- Specified by:
getConfiguration
in interfaceI_CmsConfigurationParameterHandler
- Returns:
- the parameters of this configurable class instance,
or
null
if the class does not need any parameters - See Also:
I_CmsConfigurationParameterHandler.getConfiguration()
-
initConfiguration
public void initConfiguration()
Description copied from interface:I_CmsConfigurationParameterHandler
Initializes a configuration after all parameters have been added.- Specified by:
initConfiguration
in interfaceI_CmsConfigurationParameterHandler
- See Also:
I_CmsConfigurationParameterHandler.initConfiguration()
-
initialize
public void initialize(CmsJsonHandlerContext context) throws CmsException
Description copied from interface:I_CmsJsonRendererXmlContent
Initializes the context for the renderer.- Specified by:
initialize
in interfaceI_CmsJsonRendererXmlContent
- Parameters:
context
- the context to set- Throws:
CmsException
- if something goes wrong- See Also:
I_CmsJsonRendererXmlContent.initialize(org.opencms.xml.xml2json.handler.CmsJsonHandlerContext)
-
initialize
public void initialize(CmsObject cms) throws CmsException
Initializes the renderer.- Specified by:
initialize
in interfaceI_CmsJsonRendererXmlContent
- Parameters:
cms
- the CMS context to use- Throws:
CmsException
- if something goes wrong
-
render
public java.lang.Object render(CmsXmlContent content, java.util.Locale locale) throws JSONException
Description copied from interface:I_CmsJsonRendererXmlContent
Converts the XML content for a single locale to a JSON object- Specified by:
render
in interfaceI_CmsJsonRendererXmlContent
- Parameters:
content
- the contentlocale
- the locale- Returns:
- the JSON object
- Throws:
JSONException
- if something goes wrong- See Also:
I_CmsJsonRendererXmlContent.render(org.opencms.xml.content.CmsXmlContent, java.util.Locale)
-
renderNode
public java.lang.Object renderNode(CmsXmlContentTree.Node node) throws JSONException
Renders a tree node as JSON.- Parameters:
node
- the tree node- Returns:
- the JSON (may be JSONObject, JSONArray, or String)
- Throws:
JSONException
- if something goes wrong
-
renderField
protected java.util.AbstractMap.SimpleEntry<java.lang.String,java.lang.Object> renderField(CmsXmlContentTree.Field field) throws JSONException
Renders a tree field as a field in the given JSON object.- Parameters:
field
- the field to render- Returns:
- the key/value pair for the field
- Throws:
JSONException
- if something goes wrong
-
renderSimpleValue
protected java.lang.Object renderSimpleValue(CmsXmlContentTree.Node node) throws JSONException
Renders a simple value (i.e. not a nested content).- Parameters:
node
- the node- Returns:
- the JSON representation for the value
- Throws:
JSONException
- if something goes wrong
-
-