Package org.alfresco.util
Class WebScriptUtils
java.lang.Object
org.alfresco.util.WebScriptUtils
Utility class for handling webscript requests
- Since:
- 2.3
- Author:
- Tuna Aksoy
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
checkMandatoryJSONParam
(org.json.JSONObject jsonObject, String paramName) Checks if the json object contains an entry with the specified parameter namestatic void
checkMandatoryJSONParams
(org.json.JSONObject jsonObject, List<String> paramNames) Checks if the json object contains entries with the specified parameter namesstatic org.json.JSONArray
createJSONArray
(String json) Creates a json array from the givenString
static org.json.JSONObject
createJSONObject
(String json) Creates a json object from the givenString
static org.json.JSONArray
getJSONArrayFromJSONObject
(org.json.JSONObject jsonObject, String key) Gets theJSONArray
value of a given key from a json objectstatic Object
getJSONArrayValue
(org.json.JSONArray jsonArray, int index) Gets the value of an element from a json array at the given indexstatic org.json.JSONObject
getRequestContentAsJSONObject
(org.springframework.extensions.webscripts.WebScriptRequest req) Gets the request content as JSON objectstatic String
getRequestParameterValue
(org.springframework.extensions.webscripts.WebScriptRequest req, String parameter) Gets the value of a request parameterstatic String
getRequestParameterValue
(org.springframework.extensions.webscripts.WebScriptRequest req, String parameter, boolean checkValue) Gets the value of a request parameterstatic String
getStringValueFromJSONObject
(org.json.JSONObject jsonObject, String key) Gets theString
value of a given key from a json objectstatic String
getStringValueFromJSONObject
(org.json.JSONObject jsonObject, String key, boolean checkKey, boolean checkValue) Gets theString
value of a given key from a json objectgetTemplateVars
(org.springframework.extensions.webscripts.WebScriptRequest req) Gets the template variable substitutions mapstatic org.json.JSONObject
getValueFromJSONObject
(org.json.JSONObject jsonObject, String key) Gets theJSONObject
value of a given key from a json objectstatic boolean
is4xxError
(org.springframework.extensions.webscripts.WebScriptException e) Returnstrue
if the providedWebScriptException
represents an HTTP 4xx error, elsefalse
.static boolean
is5xxError
(org.springframework.extensions.webscripts.WebScriptException e) Returnstrue
if the providedWebScriptException
represents an HTTP 5xx error, elsefalse
.static void
putValueToJSONObject
(org.json.JSONObject jsonObject, String key, Object value) Puts the given key and value to the json object
-
Method Details
-
getTemplateVars
public static Map<String,String> getTemplateVars(org.springframework.extensions.webscripts.WebScriptRequest req) Gets the template variable substitutions map- Parameters:
req
- The webscript request- Returns:
- The template variable substitutions
-
getRequestParameterValue
public static String getRequestParameterValue(org.springframework.extensions.webscripts.WebScriptRequest req, String parameter) Gets the value of a request parameter- Parameters:
req
- The webscript requestparameter
- The request parameter- Returns:
- The value of the request parameter
-
getRequestParameterValue
public static String getRequestParameterValue(org.springframework.extensions.webscripts.WebScriptRequest req, String parameter, boolean checkValue) Gets the value of a request parameter- Parameters:
req
- The webscript requestparameter
- The request parametercheckValue
- Determines if the value of the parameter should be checked or not- Returns:
- The value of the request parameter
-
getRequestContentAsJSONObject
public static org.json.JSONObject getRequestContentAsJSONObject(org.springframework.extensions.webscripts.WebScriptRequest req) Gets the request content as JSON object- Parameters:
req
- The webscript request- Returns:
- The request content as JSON object
-
checkMandatoryJSONParam
Checks if the json object contains an entry with the specified parameter name- Parameters:
jsonObject
- The json objectparamName
- The parameter name to check for
-
checkMandatoryJSONParams
public static void checkMandatoryJSONParams(org.json.JSONObject jsonObject, List<String> paramNames) Checks if the json object contains entries with the specified parameter names- Parameters:
jsonObject
- The json object.paramNames
- The parameter names to check for
-
getStringValueFromJSONObject
Gets theString
value of a given key from a json object- Parameters:
jsonObject
- The json objectkey
- The key- Returns:
- The
String
value of the given key from the json object
-
getStringValueFromJSONObject
public static String getStringValueFromJSONObject(org.json.JSONObject jsonObject, String key, boolean checkKey, boolean checkValue) Gets theString
value of a given key from a json object- Parameters:
jsonObject
- The json objectkey
- The keycheckKey
- Determines if the existence of the key should be checkedcheckValue
- Determines if the value should be checked if it is blank or not- Returns:
- The
String
value of the given key from the json object
-
putValueToJSONObject
Puts the given key and value to the json object- Parameters:
jsonObject
- The json objectkey
- The keyvalue
- The value
-
getJSONArrayValue
Gets the value of an element from a json array at the given index- Parameters:
jsonArray
- The json arrayindex
- The index- Returns:
- The value of the element
-
createJSONObject
Creates a json object from the givenString
-
createJSONArray
Creates a json array from the givenString
-
getJSONArrayFromJSONObject
public static org.json.JSONArray getJSONArrayFromJSONObject(org.json.JSONObject jsonObject, String key) Gets theJSONArray
value of a given key from a json object- Parameters:
jsonObject
- The json objectkey
- The key- Returns:
- The
JSONArray
value of the given key from the json object
-
is4xxError
public static boolean is4xxError(org.springframework.extensions.webscripts.WebScriptException e) Returnstrue
if the providedWebScriptException
represents an HTTP 4xx error, elsefalse
. -
is5xxError
public static boolean is5xxError(org.springframework.extensions.webscripts.WebScriptException e) Returnstrue
if the providedWebScriptException
represents an HTTP 5xx error, elsefalse
. -
getValueFromJSONObject
public static org.json.JSONObject getValueFromJSONObject(org.json.JSONObject jsonObject, String key) Gets theJSONObject
value of a given key from a json object- Parameters:
jsonObject
- The json objectkey
- The key- Returns:
- The
JSONObject
value of the given key from the json object
-