01: /*
02: * $Id: LegacyPropertiesConfigurationProvider.java 498215 2007-01-20 23:59:10Z mrdon $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
20: */
21: package org.apache.struts2.config;
22:
23: import java.io.IOException;
24: import java.net.URL;
25: import java.util.ArrayList;
26: import java.util.Iterator;
27: import java.util.Locale;
28: import java.util.Properties;
29: import java.util.StringTokenizer;
30:
31: import org.apache.struts2.StrutsConstants;
32: import org.apache.struts2.StrutsException;
33: import org.apache.struts2.dispatcher.mapper.ActionMapper;
34:
35: import com.opensymphony.xwork2.ObjectFactory;
36: import com.opensymphony.xwork2.config.Configuration;
37: import com.opensymphony.xwork2.config.ConfigurationException;
38: import com.opensymphony.xwork2.config.ConfigurationProvider;
39: import com.opensymphony.xwork2.inject.ContainerBuilder;
40: import com.opensymphony.xwork2.inject.Context;
41: import com.opensymphony.xwork2.inject.Factory;
42: import com.opensymphony.xwork2.util.LocalizedTextUtil;
43: import com.opensymphony.xwork2.util.location.LocatableProperties;
44:
45: public class LegacyPropertiesConfigurationProvider implements
46: ConfigurationProvider {
47:
48: public void destroy() {
49: Settings.reset();
50: }
51:
52: public void init(Configuration configuration)
53: throws ConfigurationException {
54: Settings.reset();
55: }
56:
57: public void loadPackages() throws ConfigurationException {
58: }
59:
60: public boolean needsReload() {
61: return false;
62: }
63:
64: public void register(ContainerBuilder builder,
65: LocatableProperties props) throws ConfigurationException {
66:
67: final Settings settings = Settings.getInstance();
68:
69: loadSettings(props, settings);
70:
71: // Set default locale
72: final Locale locale = settings.getLocale();
73: builder.factory(Locale.class, new Factory() {
74: public Object create(Context context) throws Exception {
75: return locale;
76: }
77: });
78: }
79:
80: /**
81: * @param props
82: * @param settings
83: */
84: protected void loadSettings(LocatableProperties props,
85: final Settings settings) {
86: // We are calling the impl methods to get around the single instance of Settings that is expected
87: for (Iterator i = settings.listImpl(); i.hasNext();) {
88: String name = (String) i.next();
89: props.setProperty(name, settings.getImpl(name), settings
90: .getLocationImpl(name));
91: }
92: }
93: }
|