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 voidcheckMandatoryJSONParam(org.json.JSONObject jsonObject, String paramName) Checks if the json object contains an entry with the specified parameter namestatic voidcheckMandatoryJSONParams(org.json.JSONObject jsonObject, List<String> paramNames) Checks if the json object contains entries with the specified parameter namesstatic org.json.JSONArraycreateJSONArray(String json) Creates a json array from the givenStringstatic org.json.JSONObjectcreateJSONObject(String json) Creates a json object from the givenStringstatic org.json.JSONArraygetJSONArrayFromJSONObject(org.json.JSONObject jsonObject, String key) Gets theJSONArrayvalue of a given key from a json objectstatic ObjectgetJSONArrayValue(org.json.JSONArray jsonArray, int index) Gets the value of an element from a json array at the given indexstatic org.json.JSONObjectgetRequestContentAsJSONObject(org.springframework.extensions.webscripts.WebScriptRequest req) Gets the request content as JSON objectstatic StringgetRequestParameterValue(org.springframework.extensions.webscripts.WebScriptRequest req, String parameter) Gets the value of a request parameterstatic StringgetRequestParameterValue(org.springframework.extensions.webscripts.WebScriptRequest req, String parameter, boolean checkValue) Gets the value of a request parameterstatic StringgetStringValueFromJSONObject(org.json.JSONObject jsonObject, String key) Gets theStringvalue of a given key from a json objectstatic StringgetStringValueFromJSONObject(org.json.JSONObject jsonObject, String key, boolean checkKey, boolean checkValue) Gets theStringvalue of a given key from a json objectgetTemplateVars(org.springframework.extensions.webscripts.WebScriptRequest req) Gets the template variable substitutions mapstatic org.json.JSONObjectgetValueFromJSONObject(org.json.JSONObject jsonObject, String key) Gets theJSONObjectvalue of a given key from a json objectstatic booleanis4xxError(org.springframework.extensions.webscripts.WebScriptException e) Returnstrueif the providedWebScriptExceptionrepresents an HTTP 4xx error, elsefalse.static booleanis5xxError(org.springframework.extensions.webscripts.WebScriptException e) Returnstrueif the providedWebScriptExceptionrepresents an HTTP 5xx error, elsefalse.static voidputValueToJSONObject(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 theStringvalue of a given key from a json object- Parameters:
jsonObject- The json objectkey- The key- Returns:
- The
Stringvalue of the given key from the json object
-
getStringValueFromJSONObject
public static String getStringValueFromJSONObject(org.json.JSONObject jsonObject, String key, boolean checkKey, boolean checkValue) Gets theStringvalue 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
Stringvalue 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 theJSONArrayvalue of a given key from a json object- Parameters:
jsonObject- The json objectkey- The key- Returns:
- The
JSONArrayvalue of the given key from the json object
-
is4xxError
public static boolean is4xxError(org.springframework.extensions.webscripts.WebScriptException e) Returnstrueif the providedWebScriptExceptionrepresents an HTTP 4xx error, elsefalse. -
is5xxError
public static boolean is5xxError(org.springframework.extensions.webscripts.WebScriptException e) Returnstrueif the providedWebScriptExceptionrepresents an HTTP 5xx error, elsefalse. -
getValueFromJSONObject
public static org.json.JSONObject getValueFromJSONObject(org.json.JSONObject jsonObject, String key) Gets theJSONObjectvalue of a given key from a json object- Parameters:
jsonObject- The json objectkey- The key- Returns:
- The
JSONObjectvalue of the given key from the json object
-