Class CmsJsonRendererXmlContent
java.lang.Object
org.opencms.xml.xml2json.renderer.CmsJsonRendererXmlContent
- All Implemented Interfaces:
I_CmsConfigurationParameterHandler
,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
ConstructorDescriptionCreates a new instance.Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addConfigurationParameter
(String paramName, String paramValue) Adds a configuration parameter to this parameter configurable class instance.Returns the parameters of this configurable class instance, ornull
if the class does not need any parameters.void
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
(String link, String path, CmsObject cms) Builds a simple JSON object with link and path fields whose values are taken from the corresponding parameters.render
(CmsXmlContent content, 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 AbstractMap.SimpleEntry<String,
Object> Renders a tree field as a field in the given JSON object.Renders a tree node as JSON.protected Object
Renders a simple value (i.e.
-
Constructor Details
-
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
Creates a new instance.- Parameters:
cms
- the CMS context to use- Throws:
CmsException
- if something goes wrong
-
-
Method Details
-
linkAndPath
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
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:
-
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:
-
initConfiguration
Description copied from interface:I_CmsConfigurationParameterHandler
Initializes a configuration after all parameters have been added.- Specified by:
initConfiguration
in interfaceI_CmsConfigurationParameterHandler
- See Also:
-
initialize
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:
-
initialize
Initializes the renderer.- Specified by:
initialize
in interfaceI_CmsJsonRendererXmlContent
- Parameters:
cms
- the CMS context to use- Throws:
CmsException
- if something goes wrong
-
render
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:
-
renderNode
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 AbstractMap.SimpleEntry<String,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
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
-