2 * Copyright © 2017-2018 AT&T Intellectual Property.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.ccsdk.apps.controllerblueprints.core.utils
19 import org.apache.commons.io.FileUtils
20 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
21 import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmpty
22 import com.att.eelf.configuration.EELFLogger
23 import com.att.eelf.configuration.EELFManager
26 import java.nio.charset.Charset
30 * @author Brinda Santh
32 object ResourceResolverUtils {
33 private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())
36 fun getFileContent(filename : String, basePath : String?): String {
37 log.trace("file ({}), basePath ({}) ", filename, basePath)
39 var resolvedFileName : String = filename
40 if(filename.startsWith("http", true)
41 || filename.startsWith("https", true)){
42 val givenUrl : String = URL(filename).toString()
43 val systemUrl : String = File(".").toURI().toURL().toString()
44 log.trace("givenUrl ({}), systemUrl ({}) ", givenUrl, systemUrl)
45 if(givenUrl.startsWith(systemUrl)){
49 if(!filename.startsWith("/")){
50 if (checkNotEmpty(basePath)) {
51 resolvedFileName = basePath.plus(File.separator).plus(filename)
53 resolvedFileName = javaClass.classLoader.getResource(".").path.plus(filename)
57 return FileUtils.readFileToString(File(resolvedFileName), Charset.defaultCharset())
58 }catch (e : Exception){
59 throw BluePrintException(e, "failed to file (%s), basePath (%s) ", filename, basePath)