2 * ============LICENSE_START=======================================================
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 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.openecomp.mso.adapters.sdnc.sdncrest;
23 import org.springframework.web.util.UriUtils;
24 import org.w3c.dom.Element;
25 import org.w3c.dom.Node;
26 import org.w3c.dom.NodeList;
28 import java.io.UnsupportedEncodingException;
29 import java.util.ArrayList;
30 import java.util.List;
31 import org.openecomp.mso.logger.MsoLogger;
34 * Utility methods used by SDNCAdapterRest.
36 public final class SDNCAdapterUtils {
37 private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
39 * Instantiation is not allowed.
41 private SDNCAdapterUtils() {
45 * Returns a node's child elements in a list.
47 public static List<Element> childElements(Node node) {
48 List<Element> elements = new ArrayList<>();
50 NodeList nodeList = node.getChildNodes();
51 for (int i = 0; i < nodeList.getLength(); i++) {
52 Node child = nodeList.item(i);
53 if (child.getNodeType() == Node.ELEMENT_NODE) {
54 elements.add((Element) child);
62 * Encodes a URL path segment according to RFC 3986 Section 2.
63 * @param pathSegment the path segment to encode
64 * @return the encoded path segment
66 public static String encodeURLPathSegment(String pathSegment) {
68 return UriUtils.encodePathSegment(pathSegment, "UTF-8");
69 } catch (UnsupportedEncodingException e) {
70 LOGGER.debug("Exception:", e);
71 throw new RuntimeException("UTF-8 encoding is not supported");