-
- public static final String EMAIL_PATTERN =
- "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
- + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
- private static final String PACKAGE_ERROR = "mismatched input '{' expecting one of the following tokens: '[package";
- private static final String SUCCESS = "success";
-
- private PolicyUtils(){
- // Private Constructor
- }
- public static String objectToJsonString(Object o) throws JsonProcessingException{
- ObjectMapper mapper = new ObjectMapper();
- return mapper.writeValueAsString(o);
- }
-
- public static <T> T jsonStringToObject(String jsonString, Class<T> className) throws IOException{
- ObjectMapper mapper = new ObjectMapper();
- return mapper.readValue(jsonString, className);
- }
-
- public static String decode(String encodedString) throws UnsupportedEncodingException {
- if(encodedString!=null && !encodedString.isEmpty()){
- return new String(Base64.getDecoder().decode(encodedString) ,"UTF-8");
- }else{
- return null;
- }
- }
-
- public static String[] decodeBasicEncoding(String encodedValue) throws UnsupportedEncodingException {
- if(encodedValue!=null && encodedValue.contains("Basic ")){
- String encodedUserPassword = encodedValue.replaceFirst("Basic" + " ", "");
- String usernameAndPassword = null;
- byte[] decodedBytes = Base64.getDecoder().decode(encodedUserPassword);
- usernameAndPassword = new String(decodedBytes, "UTF-8");
- StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":");
- String username = tokenizer.nextToken();
- String password = tokenizer.nextToken();
- return new String[]{username, password};
- }else{
- return new String[]{};
- }
- }
-
- public static String emptyPolicyValidator(String field){
+ private static final Logger LOGGER = FlexLogger.getLogger(PolicyUtils.class);
+ private static final String PACKAGE_ERROR = "mismatched input '{' expecting one of the following tokens: '[package";
+
+ public static final String CATCH_EXCEPTION = "PE500: An exception was caught.";
+ public static final String EMAIL_PATTERN =
+ "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@" + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
+ public static final String SUCCESS = "success";
+ public static final String CHARACTER_ENCODING = "UTF-8";
+ public static final String APPLICATION_JSON = "application/json";
+
+ private PolicyUtils() {
+ // Private Constructor
+ }
+
+ /**
+ * Converts an Object to JSON String.
+ *
+ * @param object Object
+ * @return String format of Object JSON.
+ * @throws JsonProcessingException JsonProcessingException
+ */
+ public static String objectToJsonString(Object object) throws JsonProcessingException {
+ return new ObjectMapper().writeValueAsString(object);
+ }
+
+ /**
+ * Converts JSON string into Object.
+ *
+ * @param jsonString Input JSON String
+ * @param className equivalent Class of the given JSON string
+ * @return T instance of the class given.
+ * @throws IOException IOException
+ */
+ public static <T> T jsonStringToObject(String jsonString, Class<T> className) throws IOException {
+ ObjectMapper mapper = new ObjectMapper();
+ return mapper.readValue(jsonString, className);
+ }
+
+ /**
+ * Decode a base64 string.
+ *
+ * @param encodedString String to encode
+ * @return String
+ * @throws UnsupportedEncodingException UnsupportedEncodingException
+ */
+ public static String decode(String encodedString) throws UnsupportedEncodingException {
+ if (encodedString != null && !encodedString.isEmpty()) {
+ return new String(Base64.getDecoder().decode(encodedString), "UTF-8");
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Decodes Basic Authentication.
+ *
+ * @param encodedValue value to encode
+ * @return list of String
+ * @throws UnsupportedEncodingException UnsupportedEncodingException
+ */
+ public static String[] decodeBasicEncoding(String encodedValue) throws UnsupportedEncodingException {
+ if (encodedValue != null && encodedValue.contains("Basic ")) {
+ String encodedUserPassword = encodedValue.replaceFirst("Basic" + " ", "");
+ String usernameAndPassword;
+ byte[] decodedBytes = Base64.getDecoder().decode(encodedUserPassword);
+ usernameAndPassword = new String(decodedBytes, "UTF-8");
+ StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":");
+ String username = tokenizer.nextToken();
+ String password = tokenizer.nextToken();
+ return new String[] {username, password};
+ } else {
+ return new String[] {};
+ }
+ }
+
+ /**
+ * Validate a field if contains space or unacceptable policy input and return "success" if good.
+ *
+ * @param field String
+ * @return String
+ */
+ public static String policySpecialCharValidator(String field) {