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=========================================================
21 package org.openecomp.sdnc.config.generator.tool;
23 import java.io.StringReader;
25 import javax.xml.parsers.DocumentBuilder;
26 import javax.xml.parsers.DocumentBuilderFactory;
28 import org.codehaus.jettison.json.JSONArray;
29 import org.codehaus.jettison.json.JSONException;
30 import org.codehaus.jettison.json.JSONObject;
31 import org.openecomp.sdnc.config.generator.ConfigGeneratorConstant;
32 import org.w3c.dom.Document;
33 import org.xml.sax.InputSource;
35 public class CheckDataTool {
37 public static String checkData(String data){
38 boolean isJSON = isJSON(data);
40 return ConfigGeneratorConstant.DATA_TYPE_JSON;
43 boolean isXML = isXML(data);
45 return ConfigGeneratorConstant.DATA_TYPE_XML;
48 return ConfigGeneratorConstant.DATA_TYPE_TEXT;
51 public static boolean isJSON(String data) {
54 } catch (JSONException ex) {
57 } catch (JSONException ex1) {
64 // final ObjectMapper mapper = new ObjectMapper();
65 // mapper.readTree(data);
67 // } catch (IOException e) {
72 public static boolean isXML(String data) {
74 DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
75 DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
76 Document doc = dBuilder.parse(new InputSource(new StringReader(data)));
78 } catch (Exception ex) {