2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019-2023 Nordix Foundation. All rights reserved.
4 * Copyright (C) 2020-2021 Nokia. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END=========================================================
20 package org.oran.datafile.commons;
22 import org.oran.datafile.exceptions.DatafileTaskException;
25 * Enum specifying the schemes that DFC support for downloading files.
29 FTPES, SFTP, HTTP, HTTPS;
31 public static final String DFC_DOES_NOT_SUPPORT_PROTOCOL_ERROR_MSG = "DFC does not support protocol ";
32 public static final String SUPPORTED_PROTOCOLS_ERROR_MESSAGE =
33 ". Supported protocols are FTPeS, sFTP, HTTP and HTTPS";
36 * Get a <code>Scheme</code> from a string.
38 * @param schemeString the string to convert to <code>Scheme</code>.
39 * @return The corresponding <code>Scheme</code>
40 * @throws DatafileTaskException if the value of the string doesn't match any
43 public static Scheme getSchemeFromString(String schemeString) throws DatafileTaskException {
45 if ("FTPES".equalsIgnoreCase(schemeString)) {
46 result = Scheme.FTPES;
47 } else if ("SFTP".equalsIgnoreCase(schemeString)) {
49 } else if ("HTTP".equalsIgnoreCase(schemeString)) {
51 } else if ("HTTPS".equalsIgnoreCase(schemeString)) {
52 result = Scheme.HTTPS;
54 throw new DatafileTaskException(
55 DFC_DOES_NOT_SUPPORT_PROTOCOL_ERROR_MSG + schemeString + SUPPORTED_PROTOCOLS_ERROR_MESSAGE);
61 * Check if <code>Scheme</code> is FTP type or HTTP type.
63 * @param scheme the <code>Scheme</code> which has to be checked.
64 * @return true if <code>Scheme</code> is FTP type or false if it is HTTP type
66 public static boolean isFtpScheme(Scheme scheme) {
67 return scheme == SFTP || scheme == FTPES;