Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  // Copyright 2004, 2005 The Apache Software Foundation
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  //     http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
 // distributed under the License is distributed on an "AS IS" BASIS,
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
 package org.apache.tapestry.util.text;
 
 import java.io.Reader;
 import java.util.Map;

A version of java.util.Properties that can read the properties from files using an encoding other than ISO-8859-1. All non-latin characters are read correctly using the given encoding and no longer need to be quoted using native2ascii. In addition, the properties may be stored in an arbitrary map, rather than only in Properties. For example, using LinkedHashMap will preserve the order of the properties as defined in the file.

Author(s):
mb
Since:
4.0
 
 public class LocalizedProperties
 {
 
     private Map _propertyMap;

    
Create a new object with an empty property storage.
 
     public LocalizedProperties()
     {
         this(new HashMap());
     }

    
Use the provided argument as the storage location for the properties managed by this object. This allows different types of Map implementations to be used, such as a LinkedHashMap to preserve the order of the keys, for example. The provided map may contain the default property values as well.

Parameters:
propertyMap the map where properties are to be stored
 
     public LocalizedProperties(Map propertyMap)
     {
          = propertyMap;
     }

    
Returns the property value corresponding the provided key. If there is no such property, or the value in the provided map is not of type String, null is returned.

Parameters:
key the property key
Returns:
the value of the property, or null if there is no such property
 
     public String getProperty(String key)
     {
         Object value = .get(key);
         if (value instanceof Stringreturn (Stringvalue;
         return null;
     }

    
Returns the property value corresponding to the provided key, or the provided default value if no such property exists.

Parameters:
key the property key
defaultValue the default value of the property
Returns:
the value of the property, or the default value if there is no such property
 
     public String getProperty(String keyString defaultValue)
     {
         String value = getProperty(key);
         if (value != nullreturn value;
         return defaultValue;
     }

    
Stores a property value.

Parameters:
key the property key
value the property value
    public void setProperty(String keyString value)
    {
        .put(keyvalue);
    }

    
Returns the map containing all properties. The map can be used to enumerate the properties or their keys.

Returns:
a map containing the properties
    public Map getPropertyMap()
    {
        return ;
    }

    
Loads the properties from the given stream using the default character encoding. This method operates in the same way as the equivalent method in java.util.Properties, but it also handles non-ascii symbols.

Parameters:
ins the stream to load the properties from
Throws:
java.io.IOException
    public void load(InputStream ins)
        throws IOException
    {
        LocalizedPropertiesLoader loader = new LocalizedPropertiesLoader(ins);
        loader.load();
    }

    
Loads the properties from the given stream using the provided character encoding. This method operates in the same way as the equivalent method in java.util.Properties, but it also handles non-ascii symbols.

Parameters:
ins the stream to load the properties from
encoding the encoding the use when parsing the stream
Throws:
java.io.IOException
    public void load(InputStream insString encoding)
        throws IOException
    {
        LocalizedPropertiesLoader loader = new LocalizedPropertiesLoader(ins,
                encoding);
        loader.load();
    }

    
Loads the properties from the given reader. This method operates in the same way as the equivalent method in java.util.Properties, but it also handles non-ascii symbols.

Parameters:
reader the reader to load the properties from
Throws:
java.io.IOException
    public void load(Reader reader)
        throws IOException
    {
        LocalizedPropertiesLoader loader = new LocalizedPropertiesLoader(reader);
        loader.load();
    }
New to GrepCode? Check out our FAQ X