Class WebScriptUtils

java.lang.Object
org.alfresco.util.WebScriptUtils

public final class WebScriptUtils extends Object
Utility class for handling webscript requests
Since:
2.3
Author:
Tuna Aksoy
  • 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 request
      parameter - 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 request
      parameter - The request parameter
      checkValue - 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

      public static void checkMandatoryJSONParam(org.json.JSONObject jsonObject, String paramName)
      Checks if the json object contains an entry with the specified parameter name
      Parameters:
      jsonObject - The json object
      paramName - 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

      public static String getStringValueFromJSONObject(org.json.JSONObject jsonObject, String key)
      Gets the String value of a given key from a json object
      Parameters:
      jsonObject - The json object
      key - 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 the String value of a given key from a json object
      Parameters:
      jsonObject - The json object
      key - The key
      checkKey - Determines if the existence of the key should be checked
      checkValue - 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

      public static void putValueToJSONObject(org.json.JSONObject jsonObject, String key, Object value)
      Puts the given key and value to the json object
      Parameters:
      jsonObject - The json object
      key - The key
      value - The value
    • getJSONArrayValue

      public static Object getJSONArrayValue(org.json.JSONArray jsonArray, int index)
      Gets the value of an element from a json array at the given index
      Parameters:
      jsonArray - The json array
      index - The index
      Returns:
      The value of the element
    • createJSONObject

      public static org.json.JSONObject createJSONObject(String json)
      Creates a json object from the given String
      Parameters:
      json - The json object as String
      Returns:
      The json object created from the given String
    • createJSONArray

      public static org.json.JSONArray createJSONArray(String json)
      Creates a json array from the given String
      Parameters:
      json - The json array as String
      Returns:
      The json array created from the given String
    • getJSONArrayFromJSONObject

      public static org.json.JSONArray getJSONArrayFromJSONObject(org.json.JSONObject jsonObject, String key)
      Gets the JSONArray value of a given key from a json object
      Parameters:
      jsonObject - The json object
      key - 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)
      Returns true if the provided WebScriptException represents an HTTP 4xx error, else false.
    • is5xxError

      public static boolean is5xxError(org.springframework.extensions.webscripts.WebScriptException e)
      Returns true if the provided WebScriptException represents an HTTP 5xx error, else false.
    • getValueFromJSONObject

      public static org.json.JSONObject getValueFromJSONObject(org.json.JSONObject jsonObject, String key)
      Gets the JSONObject value of a given key from a json object
      Parameters:
      jsonObject - The json object
      key - The key
      Returns:
      The JSONObject value of the given key from the json object