2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.sdnc.config.generator.tool;
27 import java.io.StringReader;
28 import javax.xml.parsers.DocumentBuilder;
29 import javax.xml.parsers.DocumentBuilderFactory;
30 import org.codehaus.jettison.json.JSONArray;
31 import org.codehaus.jettison.json.JSONException;
32 import org.codehaus.jettison.json.JSONObject;
33 import org.onap.sdnc.config.generator.ConfigGeneratorConstant;
34 import org.w3c.dom.Document;
35 import org.xml.sax.InputSource;
37 public class CheckDataTool {
39 public static String checkData(String data) {
40 boolean isJSON = isJSON(data);
42 return ConfigGeneratorConstant.DATA_TYPE_JSON;
45 boolean isXML = isXML(data);
47 return ConfigGeneratorConstant.DATA_TYPE_XML;
50 return ConfigGeneratorConstant.DATA_TYPE_TEXT;
53 public static boolean isJSON(String data) {
56 } catch (JSONException ex) {
59 } catch (JSONException ex1) {
66 // final ObjectMapper mapper = new ObjectMapper();
67 // mapper.readTree(data);
69 // } catch (IOException e) {
74 public static boolean isXML(String data) {
76 DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
77 DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
78 Document doc = dBuilder.parse(new InputSource(new StringReader(data)));
80 } catch (Exception ex) {