1 package com.sun.syndication.io.impl;
2
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.net.URL;
6 import java.util.*;
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 public class PropertiesLoader {
25
26 private static final String MASTER_PLUGIN_FILE = "com/sun/syndication/rome.properties";
27 private static final String EXTRA_PLUGIN_FILE = "rome.properties";
28
29 private static PropertiesLoader PROPERTIES_LOADER;
30
31 static {
32 try {
33 PROPERTIES_LOADER = new PropertiesLoader(MASTER_PLUGIN_FILE,EXTRA_PLUGIN_FILE);
34 }
35 catch (IOException ioex) {
36 throw new RuntimeException(ioex.getMessage(),ioex);
37 }
38 }
39
40
41
42
43
44
45
46 public static PropertiesLoader getPropertiesLoader() {
47 return PROPERTIES_LOADER;
48 }
49
50 private Properties[] _properties;
51
52
53
54
55
56
57
58
59
60 private PropertiesLoader(String masterFileLocation,String extraFileLocation) throws IOException {
61 List propertiesList = new ArrayList();
62 ClassLoader classLoader = PluginManager.class.getClassLoader();
63
64 try {
65 InputStream is = classLoader.getResourceAsStream(masterFileLocation);
66 Properties p = new Properties();
67 p.load(is);
68 is.close();
69 propertiesList.add(p);
70 }
71 catch (IOException ioex) {
72 IOException ex = new IOException("could not load ROME master plugins file ["+masterFileLocation+"], "+
73 ioex.getMessage());
74 ex.setStackTrace(ioex.getStackTrace());
75 throw ex;
76 }
77
78 Enumeration urls = classLoader.getResources(extraFileLocation);
79 while (urls.hasMoreElements()) {
80 URL url = (URL) urls.nextElement();
81 Properties p = new Properties();
82 try {
83 InputStream is = url.openStream();
84 p.load(is);
85 is.close();
86 }
87 catch (IOException ioex) {
88 IOException ex = new IOException("could not load ROME extensions plugins file ["+url.toString()+"], "+
89 ioex.getMessage());
90 ex.setStackTrace(ioex.getStackTrace());
91 throw ex;
92 }
93 propertiesList.add(p);
94 }
95
96 _properties = new Properties[propertiesList.size()];
97 propertiesList.toArray(_properties);
98 }
99
100
101
102
103
104
105
106
107
108
109
110 public String[] getTokenizedProperty(String key,String separator) {
111 List entriesList = new ArrayList();
112 for (int i=0;i<_properties.length;i++) {
113 String values = _properties[i].getProperty(key);
114 if (values!=null) {
115 StringTokenizer st = new StringTokenizer(values,separator);
116 while (st.hasMoreTokens()) {
117 String token = st.nextToken();
118 entriesList.add(token);
119 }
120 }
121 }
122 String[] entries = new String[entriesList.size()];
123 entriesList.toArray(entries);
124 return entries;
125 }
126
127
128
129
130
131
132
133
134
135 public String[] getProperty(String key) {
136 List entriesList = new ArrayList();
137 for (int i=0;i<_properties.length;i++) {
138 String values = _properties[i].getProperty(key);
139 if (values!=null) {
140 entriesList.add(values);
141 }
142 }
143 String[] entries = new String[entriesList.size()];
144 entriesList.toArray(entries);
145 return entries;
146 }
147
148 }