atg.rest.output
Class JSONOutputCustomizer

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.rest.output.RestOutputCustomizerImpl
              extended by atg.rest.output.JSONOutputCustomizer
All Implemented Interfaces:
atg.naming.AbsoluteNameable, NameContextBindingListener, NameContextElement, atg.naming.NameContextParentable, NameResolver, AdminableService, atg.nucleus.Configured, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, RestOutputCustomizer, java.util.EventListener

public class JSONOutputCustomizer
extends RestOutputCustomizerImpl

This class implements a JSON REST output customizer.

See Also:
RestOutputCustomizer

Nested Class Summary
 
Nested classes/interfaces inherited from class atg.rest.output.RestOutputCustomizerImpl
RestOutputCustomizerImpl.NucleusComponentReferenceObject, RestOutputCustomizerImpl.RepositoryItemReferenceObject
 
Field Summary
static java.lang.String CLASS_VERSION
          Class version string
 
Fields inherited from class atg.rest.output.RestOutputCustomizerImpl
REQUEST_SCOPE_PATH, SESSION_SCOPE_PATH, SPACE
 
Fields inherited from class atg.nucleus.GenericService
SERVICE_INFO_KEY
 
Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging
DEFAULT_LOG_TRACE_STATUS
 
Fields inherited from interface atg.nucleus.logging.ApplicationLogging
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
 
Constructor Summary
JSONOutputCustomizer()
          Constructor, sets the format to "json"
 
Method Summary
protected  JSONArray addArrayToJSONObject(java.lang.String pResourceName, java.lang.Object pValue, java.lang.Object pJSON, java.lang.Object pContainer, int pNestingDepth, ParsedURI pParsedURI, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          This method will add an array to the JSONObject.
protected  JSONArray addListToJSONObject(java.lang.String pResourceName, java.util.List<?> pValue, java.lang.Object pJSON, java.lang.Object pContainer, int pNestingDepth, ParsedURI pParsedURI, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          This method will add a java.util.List object to the JSONObject.
protected  java.util.Map addMapToJSONObject(java.lang.String pResourceName, java.util.Map<?,?> pValue, java.lang.Object pJSON, java.lang.Object pContainer, int pNestingDepth, ParsedURI pParsedURI, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          This method will add a java.util.Map object to the JSONObject.
protected  JSONArray addObjectArrayToJSONObject(java.lang.String pResourceName, java.lang.Object[] pValue, int pIndex, int pCount, java.lang.Object pJSON, java.lang.Object pContainer, int pNestingDepth, ParsedURI pParsedURI, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          This method will add an array of Objects to the JSONObject.
protected  void addObjectToJSONObject(java.lang.String pResourceName, java.lang.Object pValue, java.lang.Object pJSON, java.lang.Object pContainer, int pNestingDepth, ParsedURI pParsedURI, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          This method will add the given object value to the given json object
protected  JSONArray addPrimitiveArrayToJSONObject(java.lang.String pResourceName, java.lang.Object pValue, int pIndex, int pCount, java.lang.Object pJSON, java.lang.Object pContainer, int pNestingDepth, ParsedURI pParsedURI, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          This method will add an array of primitives to the JSONObject.
protected  JSONArray addSetToJSONObject(java.lang.String pResourceName, java.util.Set<?> pValue, java.lang.Object pJSON, java.lang.Object pContainer, int pNestingDepth, ParsedURI pParsedURI, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          This method will add a java.util.Set object to the JSONObject.
 void addValueToOutputObject(java.lang.String pResourceName, java.lang.Object pValue, ParsedURI pParsedURI, java.lang.Object pContainer, java.lang.Object pParent, int pNestingDepth, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          This method will add the given value to the JSON Object
 java.lang.Object createOutputContainer()
          This method creates the output container, a JSONObject.
protected  JSONObject getNucleusComponentReferenceObject(GenericService pService, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Returns a skeleton JSON Object for the given nucleus component
protected  JSONObject getRepositoryItemReferenceObject(RepositoryItem pItem, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Returns a skeleton JSON object for the given repository item
 void sendToOutputStream(java.lang.Object pJSON, DynamoHttpServletResponse pResponse)
          Writes the JSONObject to the servlet output stream
 
Methods inherited from class atg.rest.output.RestOutputCustomizerImpl
checkAgainstNonExpandableList, createBeanOutput, createBeanValueOutput, createComponentConfiguration, createOutputObject, createOutputObjectNoFiltering, createOutputObjectWithDefaultIncludes, createOutputObjectWithoutDefaultIncludes, enableShowRESTPaths, findComponentConfigJSON, getArrayElementString, getBooleanControlParam, getCollectionElementString, getComponentConfiguration, getComponentConfiguration, getComponentResolver, getContentType, getEncoding, getFilteringManager, getFormat, getHostAndPortString, getIndentSize, getMapElementString, getMapKeyElementString, getMapValueElementString, getNucleusComponentPropertyReferenceString, getNucleusComponentPropertyReferenceString, getNucleusComponentReferenceString, getNucleusComponentReferenceString, getReferenceStringRoot, getRepositoryItemPropertyReferenceString, getRepositoryItemReferenceString, getRootElementString, getStringControlParam, getTimeZoneId, isEnableFormatDateOutput, isEnablePerRequestClassFilters, isEnablePerRequestComponentFilters, isEnablePerRequestFilters, isEnablePerRequestRepositoryFilters, isLoggingPropertyDebug, isObjectANonGenericServiceNucleusComponent, isShowRESTPaths, loadNucleusComponentIntoMap, loadNucleusComponentIntoMap, outputBean, outputBeanProperty, outputBeanValue, outputFilteredProperty, outputNonFilteredProperty, searchComponentConfigs, setArrayElementString, setCollectionElementString, setContentType, setEnableFormatDateOutput, setEnablePerRequestClassFilters, setEnablePerRequestComponentFilters, setEnablePerRequestFilters, setEnablePerRequestRepositoryFilters, setEncoding, setFormat, setIndentSize, setLoggingPropertyDebug, setMapElementString, setMapKeyElementString, setMapValueElementString, setRootElementString, setShowRESTPaths, setTimeZoneId
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, doStartService, doStopService, getAbsoluteName, getAdminServlet, getAdminServletOutputStreamEncoding, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isAdminServletUseServletOutputStream, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, reResolveThis, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setAdminServletOutputStreamEncoding, setAdminServletUseServletOutputStream, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogDebugTrace, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string

Constructor Detail

JSONOutputCustomizer

public JSONOutputCustomizer()
Constructor, sets the format to "json"

Method Detail

createOutputContainer

public java.lang.Object createOutputContainer()
This method creates the output container, a JSONObject.

Returns:
the output container, a JSONObject

sendToOutputStream

public void sendToOutputStream(java.lang.Object pJSON,
                               DynamoHttpServletResponse pResponse)
                        throws RestException,
                               java.io.IOException
Writes the JSONObject to the servlet output stream

Parameters:
pJSON - the JSONObject to write
pResponse - the servlet response
Throws:
RestException - if a JSONException occurs
java.io.IOException - if an input or output stream exception occurs

addValueToOutputObject

public void addValueToOutputObject(java.lang.String pResourceName,
                                   java.lang.Object pValue,
                                   ParsedURI pParsedURI,
                                   java.lang.Object pContainer,
                                   java.lang.Object pParent,
                                   int pNestingDepth,
                                   DynamoHttpServletRequest pRequest,
                                   DynamoHttpServletResponse pResponse)
                            throws RestException,
                                   java.io.IOException
This method will add the given value to the JSON Object

Parameters:
pResourceName - the name of the property value
pValue - the object representing the value
pParsedURI - an object containing the parsed URI
pContainer - the parent object of the given property name
pParent - the element to add the value to as a text element
pNestingDepth - the current nesting depth in the object tree
pRequest - the servlet request
pResponse - the servlet response
Throws:
RestException - if an error occurs processing the REST request
java.io.IOException - if an error occurs writing to the output stream

addListToJSONObject

protected JSONArray addListToJSONObject(java.lang.String pResourceName,
                                        java.util.List<?> pValue,
                                        java.lang.Object pJSON,
                                        java.lang.Object pContainer,
                                        int pNestingDepth,
                                        ParsedURI pParsedURI,
                                        DynamoHttpServletRequest pRequest,
                                        DynamoHttpServletResponse pResponse)
                                 throws RestException,
                                        java.io.IOException,
                                        JSONException
This method will add a java.util.List object to the JSONObject. If atg-rest-index and/or atg-rest-count parameters were submitted in the request, they will be taken into account and include only the requested elements from the list.

Parameters:
pResourceName - the name of the resource
pValue - the List object to add
pJSON - the JSONObject to populate, if null, no attempt will be made to populate any object with the resulting JSONArray
pContainer - the parent object of the given property name
pNestingDepth - the current nesting depth in the object tree
pParsedURI - an object containing the parsed URI
pRequest - the servlet request
pResponse - the servlet response
Returns:
the created JSONArray
Throws:
RestException - if an error occurs processing the REST request
java.io.IOException - if an error occurs writing to the output stream
JSONException - if an error occurs writing to the JSONObject

addSetToJSONObject

protected JSONArray addSetToJSONObject(java.lang.String pResourceName,
                                       java.util.Set<?> pValue,
                                       java.lang.Object pJSON,
                                       java.lang.Object pContainer,
                                       int pNestingDepth,
                                       ParsedURI pParsedURI,
                                       DynamoHttpServletRequest pRequest,
                                       DynamoHttpServletResponse pResponse)
                                throws RestException,
                                       java.io.IOException,
                                       JSONException
This method will add a java.util.Set object to the JSONObject. If atg-rest-index and/or atg-rest-count parameters were submitted in the request, they will be ignored because Sets do not have order.

Parameters:
pResourceName - the name of the resource
pValue - the Set object to add
pJSON - the JSONObject to populate, if null, no attempt will be made to populate any object with the resulting JSONArray
pContainer - the parent object of the given property name
pNestingDepth - the current nesting depth in the object tree
pParsedURI - an object containing the parsed URI
pRequest - the servlet request
pResponse - the servlet response
Returns:
the created JSONArray
Throws:
RestException - if an error occurs processing the REST request
java.io.IOException - if an error occurs writing to the output stream
JSONException - if an error occurs writing to the JSONObject

addMapToJSONObject

protected java.util.Map addMapToJSONObject(java.lang.String pResourceName,
                                           java.util.Map<?,?> pValue,
                                           java.lang.Object pJSON,
                                           java.lang.Object pContainer,
                                           int pNestingDepth,
                                           ParsedURI pParsedURI,
                                           DynamoHttpServletRequest pRequest,
                                           DynamoHttpServletResponse pResponse)
                                    throws RestException,
                                           java.io.IOException,
                                           JSONException
This method will add a java.util.Map object to the JSONObject. If atg-rest-index and/or atg-rest-count parameters were submitted in the request, they will be ignored because Maps do not have order.

Parameters:
pResourceName - the name of the resource
pValue - the Map object to add
pJSON - the JSONObject to populate, if null, no attempt will be made to populate any object with the resulting JSONObject
pContainer - the parent object of the given property name
pNestingDepth - the current nesting depth in the object tree
pParsedURI - an object containing the parsed URI
pRequest - the servlet request
pResponse - the servlet response
Returns:
the created JSONObject
Throws:
RestException - if an error occurs processing the REST request
java.io.IOException - if an error occurs writing to the output stream
JSONException - if an error occurs writing to the JSONObject

addArrayToJSONObject

protected JSONArray addArrayToJSONObject(java.lang.String pResourceName,
                                         java.lang.Object pValue,
                                         java.lang.Object pJSON,
                                         java.lang.Object pContainer,
                                         int pNestingDepth,
                                         ParsedURI pParsedURI,
                                         DynamoHttpServletRequest pRequest,
                                         DynamoHttpServletResponse pResponse)
                                  throws RestException,
                                         java.io.IOException,
                                         JSONException
This method will add an array to the JSONObject. If atg-rest-index and/or atg-rest-count parameters were submitted in the request, they will be taken into account and include only the requested elements from the array.

Parameters:
pResourceName - the name of the resource
pValue - the array to add
pJSON - the JSONObject to populate, if null, no attempt will be made to populate any object with the resulting JSONArray
pContainer - the parent object of the given property name
pNestingDepth - the current nesting depth in the object tree
pParsedURI - an object containing the parsed URI
pRequest - the servlet request
pResponse - the servlet response
Returns:
the created JSONArray
Throws:
RestException - if an error occurs processing the REST request
java.io.IOException - if an error occurs writing to the output stream
JSONException - if an error occurs writing to the JSONObject

addPrimitiveArrayToJSONObject

protected JSONArray addPrimitiveArrayToJSONObject(java.lang.String pResourceName,
                                                  java.lang.Object pValue,
                                                  int pIndex,
                                                  int pCount,
                                                  java.lang.Object pJSON,
                                                  java.lang.Object pContainer,
                                                  int pNestingDepth,
                                                  ParsedURI pParsedURI,
                                                  DynamoHttpServletRequest pRequest,
                                                  DynamoHttpServletResponse pResponse)
                                           throws RestException,
                                                  JSONException
This method will add an array of primitives to the JSONObject. If atg-rest-index and/or atg-rest-count parameters were submitted in the request, they will be taken into account and include only the requested elements from the array.

Parameters:
pResourceName - the name of the resource
pValue - the array to add
pIndex - the value from the atg-rest-index parameter or -1 if parameter does not exist in the request
pIndex - the value from the atg-rest-count parameter or -1 if parameter does not exist in the request
pJSON - the JSONObject to populate, if null, no attempt will be made to populate any object with the resulting JSONArray
pContainer - the parent object of the given property name
pNestingDepth - the current nesting depth in the object tree
pParsedURI - an object containing the parsed URI
pRequest - the servlet request
pResponse - the servlet response
Returns:
the created JSONArray
Throws:
RestException - if an error occurs processing the REST request
JSONException - if an error occurs writing to the JSONObject

addObjectArrayToJSONObject

protected JSONArray addObjectArrayToJSONObject(java.lang.String pResourceName,
                                               java.lang.Object[] pValue,
                                               int pIndex,
                                               int pCount,
                                               java.lang.Object pJSON,
                                               java.lang.Object pContainer,
                                               int pNestingDepth,
                                               ParsedURI pParsedURI,
                                               DynamoHttpServletRequest pRequest,
                                               DynamoHttpServletResponse pResponse)
                                        throws RestException,
                                               java.io.IOException,
                                               JSONException
This method will add an array of Objects to the JSONObject. If atg-rest-index and/or atg-rest-count parameters were submitted in the request, they will be taken into account and include only the requested elements from the array.

Parameters:
pResourceName - the name of the resource
pValue - the array to add
pIndex - the value from the atg-rest-index parameter or -1 if parameter does not exist in the request
pIndex - the value from the atg-rest-count parameter or -1 if parameter does not exist in the request
pJSON - the JSONObject to populate, if null, no attempt will be made to populate any object with the resulting JSONArray
pContainer - the parent object of the given property name
pNestingDepth - the current nesting depth in the object tree
pParsedURI - an object containing the parsed URI
pRequest - the servlet request
pResponse - the servlet response
Returns:
the created JSONArray
Throws:
RestException - if an error occurs processing the REST request
java.io.IOException - if an error occurs writing to the output stream
JSONException - if an error occurs writing to the JSONObject

addObjectToJSONObject

protected void addObjectToJSONObject(java.lang.String pResourceName,
                                     java.lang.Object pValue,
                                     java.lang.Object pJSON,
                                     java.lang.Object pContainer,
                                     int pNestingDepth,
                                     ParsedURI pParsedURI,
                                     DynamoHttpServletRequest pRequest,
                                     DynamoHttpServletResponse pResponse)
                              throws RestException,
                                     java.io.IOException
This method will add the given object value to the given json object

Parameters:
pResourceName - the name of the resource
pValue - the object representing the object value
pJSON - the JSONObject to populate
pContainer - the parent object of the given property name
pNestingDepth - the current nesting depth in the object tree
pParsedURI - an object containing the parsed URI
pRequest - the servlet request
pResponse - the servlet response
Throws:
RestException - if an error occurs processing the REST request
java.io.IOException - if an error occurs writing to the output stream

getRepositoryItemReferenceObject

protected JSONObject getRepositoryItemReferenceObject(RepositoryItem pItem,
                                                      DynamoHttpServletRequest pRequest,
                                                      DynamoHttpServletResponse pResponse)
                                               throws RestException
Returns a skeleton JSON object for the given repository item

Parameters:
pItem - the repository item to generate the reference object for
pRequest - the servlet request
pResponse - the servlet response
Returns:
the JSON string
Throws:
RestException - if an exception occurs determining the item descriptor type

getNucleusComponentReferenceObject

protected JSONObject getNucleusComponentReferenceObject(GenericService pService,
                                                        DynamoHttpServletRequest pRequest,
                                                        DynamoHttpServletResponse pResponse)
                                                 throws RestException
Returns a skeleton JSON Object for the given nucleus component

Parameters:
pService - the nucleus component to generate the JSONObject for
pRequest - the servlet request
pResponse - the servlet response
Returns:
the JSON object
Throws:
RestException - if an exception occurs determining the item descriptor type