1 package net.sourceforge.argval.utils;
2
3 import java.io.File;
4 import java.util.List;
5 import java.util.Map;
6 import java.util.Properties;
7 import java.util.Set;
8
9 public interface PropertiesUtil {
10
11 /** The default separator for property key parts. */
12 public final static String PROP_SEP = ".";
13
14 /**
15 * Creates a new <code>key</code> value, by concatinating the <code>key</code> with
16 * the <code>keyPart</code>.
17 *
18 * <p>When <code>createKey(current_key, "window")</code> is called it will return the
19 * String <code>current_key + PROP_SEP + "window"</code>.
20 * </p>
21 *
22 * @param key The existing <code>key</code>, to which the <code>keyPart</code> is added.
23 * @param keyPart The key part to add.
24 * @return The new concatinated key.
25 */
26 String createKey(String key, String keyPart);
27
28 /**
29 * Creates a new <code>key</code> value, by concatinating the <code>key</code> with the two
30 * key parts.
31 *
32 * <p>When <code>createKey(current_key, "window", "name")</code> is called it will return the
33 * String <code>current_key + ".window.name"</code>.
34 * </p>
35 *
36 * @param key The existing <code>key</code>, to which the <code>keyPart</code>'s are added.
37 * @param firstKeyPart The key part to add.
38 * @param secondKeyPart The key part to add.
39 * @return The new concatinated key.
40 *
41 * @see #createKey(String, String)
42 */
43 String createKey(String key, String firstKeyPart, String secondKeyPart);
44
45 //String createKeyWithMapKey(String key, String mapKey, String extention);
46
47 //String createKeyWithListKey(String key, Integer index, String extention);
48
49 /**
50 * Creates a new <code>key</code> value, by concatinating the <code>key</code> with the two
51 * key parts.
52 *
53 * <p>When <code>createKey(new String[] {"company", "module", "project"})</code> is called it will return the
54 * String <code>"company.module.project"</code>.
55 * </p>
56 *
57 * @param keyArray An array of key parts which need to be concatinated.
58 * @return The new concatinated key.
59 */
60 String createKey(String keyArray[]);
61
62 Properties loadProperties(File propertyFile);
63
64 /**
65 * Returns the values of an multiple value property key as a Set instance, which contains
66 * all the values. As the separator character of the values, a space character is used.
67 * @param properties The Properties instance, from which to get the multiple values.
68 * @param key The key under which the values are stored.
69 * @return A Set instances, containing the values, stored under the property key.
70 */
71 Set<String> getPropertyAsSet(Properties properties, String key);
72
73 /**
74 * Returns the values of an multiple value property key as a Set instance, which contains
75 * all the values.
76 * @param properties The Properties instance, from which to get the multiple values.
77 * @param key The key under which the values are stored.
78 * @param separator The separator used to separate the values. If <code>null</code>
79 * is given, the default space ' ' separator is used.
80 * @return An Set instances, containing the values, stored under the property key.
81 */
82 Set<String> getPropertyAsSet(Properties properties, String key, String separator);
83
84 List<String> getPropertyAsList(Properties properties, String key);
85
86 List<String> getPropertyAsList(Properties properties, String key, String separator);
87
88 /**
89 * Creates a String which contains all the property key's and their values, separated by
90 * the equals sign '='. Each property is separated by a line separator.
91 *
92 * @param properties
93 * @return
94 */
95 String toString(Properties properties);
96
97 /**
98 * Returns a sub set of {@link Properties}, which keys start with the baseKey.
99 *
100 * Creating the <code>Properties</code> instance <code>prop</code>:
101 * <pre>
102 * web.proxy.hostname = proxy
103 * web.proxy.port = 8080
104 * web.application.name = Web application
105 * </pre>
106 *
107 * And using the method <code>getProperties("web.proxy", prop)</code> will return a new Properties instance
108 * like this:
109 * <pre>
110 * hostname = proxy
111 * port = 8080
112 * </pre>
113 *
114 * @param baseKey The key under which the sub set Properties are stored.
115 * @param prop The Properties from which the sub set is extracted.
116 * @return
117 */
118 Properties getProperties(String baseKey, Properties prop);
119
120 Properties getProperties(Class<?> clazz, Properties prop);
121
122 Properties addProperties(Properties prop, String baseKey, Properties extraProp);
123
124 Properties addProperties(Properties prop, Class<?> clazz, Properties extraProp);
125
126 List<Properties> getPropertiesList(Properties prop, String listPrefixKey);
127
128 List<Properties> getPropertiesList(Properties prop, String listPrefixKey, String openingBracket, String closingBracket);
129
130 Map <String, Properties>getPropertiesMap(Properties prop, String mapPrefixKey);
131
132 /**
133 *
134 * <pre>
135 * person[tjeerd].name = Mickey Mouse
136 * person[tjeerd].mobile = +31.6.1111 1111
137 * person[esther].name = Donald Duck
138 * person[estehr].mobile = +31.6.1111 2222
139 * </pre>
140 *
141 * <pre>
142 * person(01).name = Mickey Mouse
143 * person(01).mobile = +31.6.1111 1111
144 * person(02).name = Donald Duck
145 * person(02).mobile = +31.6.1111 2222
146 * </pre>
147 *
148 * @param prop
149 * @param mapPrefixKey
150 * @param openingBracket
151 * @param closingBracket
152 * @return
153 */
154 Map<String, Properties> getPropertiesMap(Properties prop, String mapPrefixKey, String openingBracket, String closingBracket);
155
156 }