2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
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 * ================================================================================
20 package org.openecomp.portalsdk.core.onboarding.util;
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.util.Properties;
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
30 * Singleton Class representing portal properties. Searches the classpath for
31 * the file "portal.properties".
33 * To put the file "portal.properties" on the classpath, it can be in the same
34 * directory where the first package folder is - 'myClasses' folder in the
35 * following case as an example:
38 public class PortalApiProperties {
40 private static final Log logger = LogFactory.getLog(PortalApiProperties.class);
42 private static Properties properties;
43 private static String propertyFileName = "portal.properties";
46 * Constructor is private.
48 private PortalApiProperties() {
52 * Gets the property value for the specified key. If a value is found,
53 * leading and trailing space is trimmed.
56 * @return Value for the named property; null if the property file was not
57 * loaded or the key was not found.
59 public static String getProperty(String property) {
60 if (properties == null) {
61 synchronized (propertyFileName) {
64 logger.error("Failed to read property file " + propertyFileName);
67 } catch (IOException e) {
68 logger.error("Failed to read property file " + propertyFileName, e);
73 String value = properties.getProperty(property);
80 * Reads properties from a portal.properties file on the classpath.
82 * Clients do NOT need to call this method. Clients MAY call this method to
83 * test whether the properties file can be loaded successfully.
85 * @return True if properties were successfully loaded, else false.
88 public static boolean initialize() throws IOException {
89 if (properties != null)
91 InputStream in = PortalApiProperties.class.getClassLoader().getResourceAsStream(propertyFileName);
94 properties = new Properties();