2 * Copyright 2015 Samsung Electronics All Rights Reserved.
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 oic.simulator.serviceprovider.resource;
20 import java.io.IOException;
22 import java.net.URISyntaxException;
24 import java.util.Date;
25 import java.util.Enumeration;
26 import java.util.HashMap;
29 import oic.simulator.serviceprovider.Activator;
30 import oic.simulator.serviceprovider.utils.Constants;
32 import org.eclipse.core.runtime.FileLocator;
33 import org.oic.simulator.ILogger.Level;
36 * Class which loads and maintains the standard RAML configuration file list.
38 public class StandardConfiguration {
40 // A map of filename of standard resources as the key and the complete
41 // location of the file(including the filename) as the value.
42 Map<String, String> stdConfigFiles;
44 public StandardConfiguration() {
45 stdConfigFiles = new HashMap<String, String>();
46 populateStandardConfigurationList();
49 private void populateStandardConfigurationList() {
50 Enumeration<URL> fileList = Activator.getDefault().getBundle()
51 .findEntries(Constants.CONFIG_DIRECTORY_PATH, "*", true);
52 if (null == fileList) {
56 .log(Level.ERROR.ordinal(), new Date(),
57 "No configuration files exist.");
66 while (fileList.hasMoreElements()) {
67 url = (URL) fileList.nextElement();
68 relPath = url.getPath();
69 System.out.println(url.getPath());
71 resolvedURL = FileLocator.toFileURL(url);
72 if (relPath.toLowerCase().endsWith(
73 Constants.RAML_FILE_EXTENSION)) {
74 resolvedURI = new URI(resolvedURL.getProtocol(),
75 resolvedURL.getPath(), null);
76 file = new File(resolvedURI);
77 absPath = file.getAbsolutePath();
78 stdConfigFiles.put(relPath, absPath);
79 System.out.println("File path:" + absPath);
81 } catch (URISyntaxException e) {
82 Activator.getDefault().getLogManager()
83 .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
84 } catch (IOException e) {
85 Activator.getDefault().getLogManager()
86 .log(Level.ERROR.ordinal(), new Date(), e.getMessage());
91 public Map<String, String> getStandardResourceConfigurationList() {
92 return stdConfigFiles;
95 public void setStandardResourceConfigurationList(
96 Map<String, String> stdConfigFiles) {
97 this.stdConfigFiles = stdConfigFiles;
100 public String getFilePath(String fileName) {
101 return stdConfigFiles.get(fileName);