fr.paris.lutece.plugins.form.utils
Class JSONUtils

java.lang.Object
  extended by fr.paris.lutece.plugins.form.utils.JSONUtils

public final class JSONUtils
extends Object

Provides json utility methods for forms


Field Summary
static String JSON_KEY_ERROR_MESSAGE
           
static String JSON_KEY_FIELD_NAME
           
static String JSON_KEY_FILE_COUNT
           
static String JSON_KEY_FILE_EXTENSION
           
static String JSON_KEY_FILE_NAME
           
static String JSON_KEY_FORM_ERROR
           
static String JSON_KEY_ID_ENTRY
           
static String JSON_KEY_ID_FIELD
           
static String JSON_KEY_ID_FORM
           
static String JSON_KEY_ID_RESPONSE
           
static String JSON_KEY_MANDATORY_ERROR
           
static String JSON_KEY_MIME_TYPE
           
static String JSON_KEY_RESPONSE
           
static String JSON_KEY_SUCCESS
           
static String JSON_KEY_TITLE_QUESTION
           
static String JSON_KEY_UPLOADED_FILES
           
static String JSON_KEY_VALUE_RESPONSE
           
 
Method Summary
static fr.paris.lutece.plugins.genericattributes.business.GenericAttributeError buildFormError(String strJson)
          Builds GenericAttributeError from json string
static String buildJson(fr.paris.lutece.plugins.genericattributes.business.GenericAttributeError formError)
          Builds json form GenericAttributeError
static String buildJson(Map<Integer,List<fr.paris.lutece.plugins.genericattributes.business.Response>> mapResponse, int nIdForm, String strSessionId)
          Builds the json string for the response map
static net.sf.json.JSONObject buildJson(fr.paris.lutece.plugins.genericattributes.business.Response response, String strSessionId)
          Builds the json string for the Response
static void buildJsonError(net.sf.json.JSONObject json, String strMessage)
          Builds a json object with the error message.
static net.sf.json.JSONObject buildJsonErrorRemovingFile(javax.servlet.http.HttpServletRequest request)
          Builds a json object with the error message.
static Map<Integer,List<fr.paris.lutece.plugins.genericattributes.business.Response>> buildListResponses(String strJSON, Locale locale, javax.servlet.http.HttpSession session)
          Builds the responses list - null if JSON_KEY_RESPONSE is missing.
static List<String> getBlobIds(String strJSON)
          Get the list of blob id from a JSON string
static List<String> getBlobIds(String strJSON, int nIdEntry)
          Get the list of blob id from a JSON string
static net.sf.json.JSONObject getUploadedFileJSON(List<org.apache.commons.fileupload.FileItem> listFileItem)
          Builds a json object for the file item list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JSON_KEY_ID_FORM

public static final String JSON_KEY_ID_FORM
See Also:
Constant Field Values

JSON_KEY_RESPONSE

public static final String JSON_KEY_RESPONSE
See Also:
Constant Field Values

JSON_KEY_ID_ENTRY

public static final String JSON_KEY_ID_ENTRY
See Also:
Constant Field Values

JSON_KEY_ID_RESPONSE

public static final String JSON_KEY_ID_RESPONSE
See Also:
Constant Field Values

JSON_KEY_ID_FIELD

public static final String JSON_KEY_ID_FIELD
See Also:
Constant Field Values

JSON_KEY_VALUE_RESPONSE

public static final String JSON_KEY_VALUE_RESPONSE
See Also:
Constant Field Values

JSON_KEY_FILE_NAME

public static final String JSON_KEY_FILE_NAME
See Also:
Constant Field Values

JSON_KEY_FILE_EXTENSION

public static final String JSON_KEY_FILE_EXTENSION
See Also:
Constant Field Values

JSON_KEY_ERROR_MESSAGE

public static final String JSON_KEY_ERROR_MESSAGE
See Also:
Constant Field Values

JSON_KEY_MANDATORY_ERROR

public static final String JSON_KEY_MANDATORY_ERROR
See Also:
Constant Field Values

JSON_KEY_TITLE_QUESTION

public static final String JSON_KEY_TITLE_QUESTION
See Also:
Constant Field Values

JSON_KEY_FORM_ERROR

public static final String JSON_KEY_FORM_ERROR
See Also:
Constant Field Values

JSON_KEY_FIELD_NAME

public static final String JSON_KEY_FIELD_NAME
See Also:
Constant Field Values

JSON_KEY_MIME_TYPE

public static final String JSON_KEY_MIME_TYPE
See Also:
Constant Field Values

JSON_KEY_UPLOADED_FILES

public static final String JSON_KEY_UPLOADED_FILES
See Also:
Constant Field Values

JSON_KEY_FILE_COUNT

public static final String JSON_KEY_FILE_COUNT
See Also:
Constant Field Values

JSON_KEY_SUCCESS

public static final String JSON_KEY_SUCCESS
See Also:
Constant Field Values
Method Detail

buildJson

public static String buildJson(Map<Integer,List<fr.paris.lutece.plugins.genericattributes.business.Response>> mapResponse,
                               int nIdForm,
                               String strSessionId)
Builds the json string for the response map

Parameters:
mapResponse - the response map
nIdForm - the id form
strSessionId - the session id
Returns:
the json string

buildListResponses

public static Map<Integer,List<fr.paris.lutece.plugins.genericattributes.business.Response>> buildListResponses(String strJSON,
                                                                                                                Locale locale,
                                                                                                                javax.servlet.http.HttpSession session)
Builds the responses list - null if JSON_KEY_RESPONSE is missing.

Parameters:
strJSON - the json
locale - the locale
session - the session
Returns:
the responses list - null if JSON_KEY_RESPONSE is missing

buildJson

public static net.sf.json.JSONObject buildJson(fr.paris.lutece.plugins.genericattributes.business.Response response,
                                               String strSessionId)
Builds the json string for the Response

Parameters:
response - the response
strSessionId - The session id
Returns:
the json string

buildJson

public static String buildJson(fr.paris.lutece.plugins.genericattributes.business.GenericAttributeError formError)
Builds json form GenericAttributeError

Parameters:
formError - GenericAttributeError
Returns:
json string

buildFormError

public static fr.paris.lutece.plugins.genericattributes.business.GenericAttributeError buildFormError(String strJson)
Builds GenericAttributeError from json string

Parameters:
strJson - json string
Returns:
the GenericAttributeError

getUploadedFileJSON

public static net.sf.json.JSONObject getUploadedFileJSON(List<org.apache.commons.fileupload.FileItem> listFileItem)
Builds a json object for the file item list. Key is JSON_KEY_UPLOADED_FILES, value is the array of uploaded file.

Parameters:
listFileItem - the fileItem list
Returns:
the json

buildJsonErrorRemovingFile

public static net.sf.json.JSONObject buildJsonErrorRemovingFile(javax.servlet.http.HttpServletRequest request)
Builds a json object with the error message.

Parameters:
request - the request
Returns:
the json object.

buildJsonError

public static void buildJsonError(net.sf.json.JSONObject json,
                                  String strMessage)
Builds a json object with the error message.

Parameters:
json - the JSON
strMessage - the error message

getBlobIds

public static List<String> getBlobIds(String strJSON)
Get the list of blob id from a JSON string

Parameters:
strJSON - The JSON to get blob id from
Returns:
The list of blob id, or an empty list if no blob id was found in the JSON string

getBlobIds

public static List<String> getBlobIds(String strJSON,
                                      int nIdEntry)
Get the list of blob id from a JSON string

Parameters:
strJSON - The JSON to get blob id from
nIdEntry - The id of the entry to get blob id from, or GenericAttributesUtils.CONSTANT_ID_NULL to get blob id from any entry
Returns:
The list of blob id, or an empty list if no blob id was found in the JSON string


Copyright © 2014 Mairie de Paris. All Rights Reserved.