View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.bean;
21  
22  import org.slf4j.Logger;
23  import org.slf4j.LoggerFactory;
24  
25  import java.io.IOException;
26  import java.io.InputStream;
27  import java.util.Properties;
28  
29  /**
30   * @deprecated
31   */
32  @Deprecated
33  public class ResourceMap extends Properties {
34  
35    private static final Logger LOG = LoggerFactory.getLogger(ResourceMap.class);
36    private static final long serialVersionUID = -6696019120255349519L;
37  
38    public ResourceMap() {
39      if (LOG.isDebugEnabled()) {
40        LOG.debug("creating ResourceMap");
41      }
42    }
43  
44    public void setFilename(final String filename) {
45      if (LOG.isDebugEnabled()) {
46        LOG.debug("filename = '" + filename + "'");
47      }
48      try {
49        final InputStream is = getClass().getClassLoader().getResourceAsStream(filename);
50        if (is == null) {
51          LOG.error("Cannot load resource map from file: " + filename);
52        }
53        load(is);
54      } catch (final IOException e) {
55        LOG.error("Cannot load resource map from file: " + filename, e);
56      }
57      if (LOG.isDebugEnabled()) {
58        LOG.debug("size() = \"" + size() + "\"");
59        for (final Object x : keySet()) {
60          LOG.debug("{}", x);
61        }
62      }
63    }
64  
65    // setFilename() is never called with myfaces implementation,
66    // because we implement Map. This hotfix enables filename setting via put().
67  
68    @Override
69    public Object put(final Object key, final Object value) {
70      if ("filename".equals(key)) {
71        if (LOG.isDebugEnabled()) {
72          LOG.debug("put(\"filename\", \"" + value + "\")");
73        }
74        setFilename(value.toString());
75      }
76      return super.put(key, value);
77    }
78  
79    @Override
80    public Object get(final Object key) {
81      final Object value = super.get(key);
82      if (LOG.isDebugEnabled()) {
83        LOG.debug("Query value for key='" + key + "' -> '" + value + "'");
84      }
85      if (value == null) {
86        LOG.warn("Unknown value for key='" + key + "'");
87      }
88      return value;
89    }
90  }