[SO] Release so 1.13.0 image
[so.git] / adapters / mso-sdnc-adapter / src / main / java / org / onap / so / adapters / sdnc / sdncrest / SDNCAdapterUtils.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
7  * ================================================================================
8  * Modifications Copyright (c) 2019 Samsung
9  * ================================================================================
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  * 
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  * 
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.so.adapters.sdnc.sdncrest;
25
26 import java.util.ArrayList;
27 import java.util.List;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30 import org.springframework.web.util.UriUtils;
31 import org.w3c.dom.Element;
32 import org.w3c.dom.Node;
33 import org.w3c.dom.NodeList;
34
35 /**
36  * Utility methods used by SDNCAdapterRest.
37  */
38 public final class SDNCAdapterUtils {
39     private static final Logger logger = LoggerFactory.getLogger(SDNCAdapterUtils.class);
40
41     /**
42      * Instantiation is not allowed.
43      */
44     private SDNCAdapterUtils() {}
45
46     /**
47      * Returns a node's child elements in a list.
48      */
49     public static List<Element> childElements(Node node) {
50         List<Element> elements = new ArrayList<>();
51
52         NodeList nodeList = node.getChildNodes();
53         for (int i = 0; i < nodeList.getLength(); i++) {
54             Node child = nodeList.item(i);
55             if (child.getNodeType() == Node.ELEMENT_NODE) {
56                 elements.add((Element) child);
57             }
58         }
59
60         return elements;
61     }
62
63     /**
64      * Encodes a URL path segment according to RFC 3986 Section 2.
65      * 
66      * @param pathSegment the path segment to encode
67      * @return the encoded path segment
68      */
69     public static String encodeURLPathSegment(String pathSegment) {
70         return UriUtils.encodePathSegment(pathSegment, "UTF-8");
71     }
72 }