2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.policy.pdp.rest.api.utils;
22 import java.io.StringReader;
24 import javax.json.Json;
25 import javax.json.JsonException;
26 import javax.json.JsonObject;
27 import javax.json.JsonReader;
28 import javax.json.stream.JsonParsingException;
30 import org.onap.policy.common.logging.flexlogger.FlexLogger;
31 import org.onap.policy.common.logging.flexlogger.Logger;
33 import com.google.common.base.CharMatcher;
35 public class PolicyApiUtils {
36 private static Logger LOGGER = FlexLogger.getLogger(PolicyApiUtils.class
39 public static Boolean validateNONASCIICharactersAndAllowSpaces(
41 Boolean isValidForm = false;
42 if (jsonString.isEmpty()) {
43 LOGGER.error("The Value is empty.");
46 if (CharMatcher.ASCII.matchesAllOf((CharSequence) jsonString)) {
47 LOGGER.info("The Value does not contain ASCII Characters");
50 LOGGER.error("The Value Contains Non ASCII Characters");
57 public static String formatResponse(StringBuilder responseString){
59 LOGGER.info("Formatting response message from Policy Validator");
60 String response = null;
61 response = responseString.toString().replace("<br>", " | ");
62 response = response.replaceAll("(<b>|<\\/b>|<br>|<i>|<\\/i>|@#)", "");
67 public static boolean isNumeric(String str) {
68 for (char c : str.toCharArray()) {
69 if (!Character.isDigit(c))
75 public static JsonObject stringToJsonObject(String value)
76 throws JsonException, JsonParsingException, IllegalStateException {
77 JsonReader jsonReader = Json.createReader(new StringReader(value));
78 JsonObject object = jsonReader.readObject();