001 package org.apache.myfaces.tobago.bean; 002 003 /* 004 * Licensed to the Apache Software Foundation (ASF) under one or more 005 * contributor license agreements. See the NOTICE file distributed with 006 * this work for additional information regarding copyright ownership. 007 * The ASF licenses this file to You under the Apache License, Version 2.0 008 * (the "License"); you may not use this file except in compliance with 009 * the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019 020 /* 021 * Created 26.10.2004 11:51:00. 022 * $Id: ResourceMap.java 516215 2007-03-08 22:50:57Z bommel $ 023 */ 024 025 import org.apache.commons.logging.Log; 026 import org.apache.commons.logging.LogFactory; 027 028 import java.io.IOException; 029 import java.io.InputStream; 030 import java.util.Properties; 031 032 public class ResourceMap extends Properties { 033 034 private static final Log LOG = LogFactory.getLog(ResourceMap.class); 035 private static final long serialVersionUID = -6696019120255349519L; 036 037 public ResourceMap() { 038 if (LOG.isDebugEnabled()) { 039 LOG.debug("creating ResourceMap"); 040 } 041 } 042 043 public void setFilename(String filename) { 044 if (LOG.isDebugEnabled()) { 045 LOG.debug("filename = '" + filename + "'"); 046 } 047 try { 048 InputStream is = getClass().getClassLoader().getResourceAsStream(filename); 049 if (is == null) { 050 LOG.error("Cannot load resource map from file: " + filename); 051 } 052 load(is); 053 } catch (IOException e) { 054 LOG.error("Cannot load resource map from file: " + filename, e); 055 } 056 if (LOG.isDebugEnabled()) { 057 LOG.debug("size() = \"" + size() + "\""); 058 for (Object x : keySet()) { 059 LOG.debug(x); 060 } 061 } 062 } 063 064 // setFilename() is never called with myfaces implementation, 065 // because we implement Map. This hotfix enables filename setting via put(). 066 public Object put(Object key, Object value) { 067 if ("filename".equals(key)) { 068 if (LOG.isDebugEnabled()) { 069 LOG.debug("put(\"filename\", \"" + value + "\")"); 070 } 071 setFilename(value.toString()); 072 } 073 return super.put(key, value); 074 } 075 076 public Object get(Object key) { 077 Object value = super.get(key); 078 if (LOG.isDebugEnabled()) { 079 LOG.debug("Query value for key='" + key + "' -> '" + value + "'"); 080 } 081 if (value == null) { 082 LOG.warn("Unknown value for key='" + key + "'"); 083 } 084 return value; 085 } 086 }