1 /*
2 * $Id: LegacyPropertiesConfigurationProvider.java 498215 2007-01-20 23:59:10Z mrdon $
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "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 ConfigurationProvider {
46
47 public void destroy() {
48 Settings.reset();
49 }
50
51 public void init(Configuration configuration)
52 throws ConfigurationException {
53 Settings.reset();
54 }
55
56 public void loadPackages()
57 throws ConfigurationException {
58 }
59
60 public boolean needsReload() {
61 return false;
62 }
63
64 public void register(ContainerBuilder builder, LocatableProperties props)
65 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, final Settings settings) {
85 // We are calling the impl methods to get around the single instance of Settings that is expected
86 for (Iterator i = settings.listImpl(); i.hasNext(); ) {
87 String name = (String) i.next();
88 props.setProperty(name, settings.getImpl(name), settings.getLocationImpl(name));
89 }
90 }
91 }