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