1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts2.config;
23
24 import java.util.ArrayList;
25 import java.util.Iterator;
26 import java.util.StringTokenizer;
27
28 import org.apache.struts2.StrutsConstants;
29
30 import com.opensymphony.xwork2.util.logging.Logger;
31 import com.opensymphony.xwork2.util.logging.LoggerFactory;
32
33
34
35 /***
36 * DefaultSettings implements optional methods of Settings.
37 * <p>
38 * This class creates and delegates to other settings by using an internal
39 * {@link DelegatingSettings} object.
40 */
41 public class DefaultSettings extends Settings {
42
43 /***
44 * The logging instance for this class.
45 */
46 protected Logger log = LoggerFactory.getLogger(this.getClass());
47
48 /***
49 * The Settings object that handles API calls.
50 */
51 Settings delegate;
52
53 /***
54 * Constructs an instance by loading the standard property files,
55 * any custom property files (<code>struts.custom.properties</code>),
56 * and any custom message resources ().
57 * <p>
58 * Since this constructor combines Settings from multiple resources,
59 * it utilizes a {@link DelegatingSettings} instance,
60 * and all API calls are handled by that instance.
61 */
62 public DefaultSettings() {
63
64 ArrayList<Settings> list = new ArrayList<Settings>();
65
66
67 try {
68 list.add(new PropertiesSettings("struts"));
69 } catch (Exception e) {
70 log.warn("DefaultSettings: Could not find or error in struts.properties", e);
71 }
72
73 Settings[] settings = new Settings[list.size()];
74 delegate = new DelegatingSettings(list.toArray(settings));
75
76
77 try {
78 StringTokenizer customProperties = new StringTokenizer(delegate.getImpl(StrutsConstants.STRUTS_CUSTOM_PROPERTIES), ",");
79
80 while (customProperties.hasMoreTokens()) {
81 String name = customProperties.nextToken();
82
83 try {
84 list.add(new PropertiesSettings(name));
85 } catch (Exception e) {
86 log.error("DefaultSettings: Could not find " + name + ".properties. Skipping.");
87 }
88 }
89
90 settings = new Settings[list.size()];
91 delegate = new DelegatingSettings(list.toArray(settings));
92 } catch (IllegalArgumentException e) {
93
94
95
96 }
97
98 }
99
100
101 public void setImpl(String name, String value) throws IllegalArgumentException, UnsupportedOperationException {
102 delegate.setImpl(name, value);
103 }
104
105
106 public String getImpl(String aName) throws IllegalArgumentException {
107 return delegate.getImpl(aName);
108 }
109
110
111 public boolean isSetImpl(String aName) {
112 return delegate.isSetImpl(aName);
113 }
114
115
116 public Iterator listImpl() {
117 return delegate.listImpl();
118 }
119 }