org.apache.shiro.config
Class Ini

java.lang.Object
  extended by org.apache.shiro.config.Ini
All Implemented Interfaces:
Map<String,Ini.Section>

public class Ini
extends Object
implements Map<String,Ini.Section>

A class representing the INI text configuration format.

An Ini instance is a map of Sections, keyed by section name. Each Section is itself a map of String name/value pairs. Name/value pairs are guaranteed to be unique within each Section only - not across the entire Ini instance.

Since:
1.0

Nested Class Summary
static class Ini.Section
          An Ini.Section is String-key-to-String-value Map, identifiable by a name unique within an Ini instance.
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
static String COMMENT_POUND
           
static String COMMENT_SEMICOLON
           
static String DEFAULT_CHARSET_NAME
           
static String DEFAULT_SECTION_NAME
           
protected static char ESCAPE_TOKEN
           
static String SECTION_PREFIX
           
static String SECTION_SUFFIX
           
 
Constructor Summary
Ini()
          Creates a new empty Ini instance.
Ini(Ini defaults)
          Creates a new Ini instance with the specified defaults.
 
Method Summary
 Ini.Section addSection(String sectionName)
          Ensures a section with the specified name exists, adding a new one if it does not yet exist.
 void clear()
           
 boolean containsKey(Object key)
           
 boolean containsValue(Object value)
           
 Set<Map.Entry<String,Ini.Section>> entrySet()
           
 boolean equals(Object obj)
           
static Ini fromResourcePath(String resourcePath)
          Creates a new Ini instance loaded with the INI-formatted data in the resource at the given path.
 Ini.Section get(Object key)
           
 Ini.Section getSection(String sectionName)
          Returns the Ini.Section with the given name or null if no section with that name exists.
protected static String getSectionName(String line)
           
 Set<String> getSectionNames()
          Returns the names of all sections managed by this Ini instance or an empty collection if there are no sections.
 String getSectionProperty(String sectionName, String propertyName)
          Returns the value of the specified section property, or null if the section or property do not exist.
 String getSectionProperty(String sectionName, String propertyName, String defaultValue)
          Returns the value of the specified section property, or the defaultValue if the section or property do not exist.
 Collection<Ini.Section> getSections()
          Returns the sections managed by this Ini instance or an empty collection if there are no sections.
 int hashCode()
           
 boolean isEmpty()
          Returns true if no sections have been configured, or if there are sections, but the sections themselves are all empty, false otherwise.
protected static boolean isSectionHeader(String line)
           
 Set<String> keySet()
           
 void load(InputStream is)
          Loads the INI-formatted text backed by the given InputStream into this instance.
 void load(Reader reader)
          Loads the INI-formatted text backed by the given Reader into this instance.
 void load(Scanner scanner)
          Loads the INI-formatted text backed by the given Scanner.
 void load(String iniConfig)
          Loads the specified raw INI-formatted text into this instance.
 void loadFromPath(String resourcePath)
          Loads data from the specified resource path into this current Ini instance.
 Ini.Section put(String key, Ini.Section value)
           
 void putAll(Map<? extends String,? extends Ini.Section> m)
           
 Ini.Section remove(Object key)
           
 Ini.Section removeSection(String sectionName)
          Removes the section with the specified name and returns it, or null if the section did not exist.
 void setSectionProperty(String sectionName, String propertyName, String propertyValue)
          Sets a name/value pair for the section with the given sectionName.
 int size()
           
 String toString()
           
 Collection<Ini.Section> values()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_SECTION_NAME

public static final String DEFAULT_SECTION_NAME
See Also:
Constant Field Values

DEFAULT_CHARSET_NAME

public static final String DEFAULT_CHARSET_NAME
See Also:
Constant Field Values

COMMENT_POUND

public static final String COMMENT_POUND
See Also:
Constant Field Values

COMMENT_SEMICOLON

public static final String COMMENT_SEMICOLON
See Also:
Constant Field Values

SECTION_PREFIX

public static final String SECTION_PREFIX
See Also:
Constant Field Values

SECTION_SUFFIX

public static final String SECTION_SUFFIX
See Also:
Constant Field Values

ESCAPE_TOKEN

protected static final char ESCAPE_TOKEN
See Also:
Constant Field Values
Constructor Detail

Ini

public Ini()
Creates a new empty Ini instance.


Ini

public Ini(Ini defaults)
Creates a new Ini instance with the specified defaults.

Parameters:
defaults - the default sections and/or key-value pairs to copy into the new instance.
Method Detail

isEmpty

public boolean isEmpty()
Returns true if no sections have been configured, or if there are sections, but the sections themselves are all empty, false otherwise.

Specified by:
isEmpty in interface Map<String,Ini.Section>
Returns:
true if no sections have been configured, or if there are sections, but the sections themselves are all empty, false otherwise.

getSectionNames

public Set<String> getSectionNames()
Returns the names of all sections managed by this Ini instance or an empty collection if there are no sections.

Returns:
the names of all sections managed by this Ini instance or an empty collection if there are no sections.

getSections

public Collection<Ini.Section> getSections()
Returns the sections managed by this Ini instance or an empty collection if there are no sections.

Returns:
the sections managed by this Ini instance or an empty collection if there are no sections.

getSection

public Ini.Section getSection(String sectionName)
Returns the Ini.Section with the given name or null if no section with that name exists.

Parameters:
sectionName - the name of the section to retrieve.
Returns:
the Ini.Section with the given name or null if no section with that name exists.

addSection

public Ini.Section addSection(String sectionName)
Ensures a section with the specified name exists, adding a new one if it does not yet exist.

Parameters:
sectionName - the name of the section to ensure existence
Returns:
the section created if it did not yet exist, or the existing Section that already existed.

removeSection

public Ini.Section removeSection(String sectionName)
Removes the section with the specified name and returns it, or null if the section did not exist.

Parameters:
sectionName - the name of the section to remove.
Returns:
the section with the specified name or null if the section did not exist.

setSectionProperty

public void setSectionProperty(String sectionName,
                               String propertyName,
                               String propertyValue)
Sets a name/value pair for the section with the given sectionName. If the section does not yet exist, it will be created. If the sectionName is null or empty, the name/value pair will be placed in the default (unnamed, empty string) section.

Parameters:
sectionName - the name of the section to add the name/value pair
propertyName - the name of the property to add
propertyValue - the property value

getSectionProperty

public String getSectionProperty(String sectionName,
                                 String propertyName)
Returns the value of the specified section property, or null if the section or property do not exist.

Parameters:
sectionName - the name of the section to retrieve to acquire the property value
propertyName - the name of the section property for which to return the value
Returns:
the value of the specified section property, or null if the section or property do not exist.

getSectionProperty

public String getSectionProperty(String sectionName,
                                 String propertyName,
                                 String defaultValue)
Returns the value of the specified section property, or the defaultValue if the section or property do not exist.

Parameters:
sectionName - the name of the section to add the name/value pair
propertyName - the name of the property to add
defaultValue - the default value to return if the section or property do not exist.
Returns:
the value of the specified section property, or the defaultValue if the section or property do not exist.

fromResourcePath

public static Ini fromResourcePath(String resourcePath)
                            throws ConfigurationException
Creates a new Ini instance loaded with the INI-formatted data in the resource at the given path. The resource path may be any value interpretable by the ResourceUtils.getInputStreamForPath method.

Parameters:
resourcePath - the resource location of the INI data to load when creating the Ini instance.
Returns:
a new Ini instance loaded with the INI-formatted data in the resource at the given path.
Throws:
ConfigurationException - if the path cannot be loaded into an Ini instance.

loadFromPath

public void loadFromPath(String resourcePath)
                  throws ConfigurationException
Loads data from the specified resource path into this current Ini instance. The resource path may be any value interpretable by the ResourceUtils.getInputStreamForPath method.

Parameters:
resourcePath - the resource location of the INI data to load into this instance.
Throws:
ConfigurationException - if the path cannot be loaded

load

public void load(String iniConfig)
          throws ConfigurationException
Loads the specified raw INI-formatted text into this instance.

Parameters:
iniConfig - the raw INI-formatted text to load into this instance.
Throws:
ConfigurationException - if the text cannot be loaded

load

public void load(InputStream is)
          throws ConfigurationException
Loads the INI-formatted text backed by the given InputStream into this instance. This implementation will close the input stream after it has finished loading. It is expected that the stream's contents are UTF-8 encoded.

Parameters:
is - the InputStream from which to read the INI-formatted text
Throws:
ConfigurationException - if unable

load

public void load(Reader reader)
Loads the INI-formatted text backed by the given Reader into this instance. This implementation will close the reader after it has finished loading.

Parameters:
reader - the Reader from which to read the INI-formatted text

load

public void load(Scanner scanner)
Loads the INI-formatted text backed by the given Scanner. This implementation will close the scanner after it has finished loading.

Parameters:
scanner - the Scanner from which to read the INI-formatted text

isSectionHeader

protected static boolean isSectionHeader(String line)

getSectionName

protected static String getSectionName(String line)

equals

public boolean equals(Object obj)
Specified by:
equals in interface Map<String,Ini.Section>
Overrides:
equals in class Object

hashCode

public int hashCode()
Specified by:
hashCode in interface Map<String,Ini.Section>
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

size

public int size()
Specified by:
size in interface Map<String,Ini.Section>

containsKey

public boolean containsKey(Object key)
Specified by:
containsKey in interface Map<String,Ini.Section>

containsValue

public boolean containsValue(Object value)
Specified by:
containsValue in interface Map<String,Ini.Section>

get

public Ini.Section get(Object key)
Specified by:
get in interface Map<String,Ini.Section>

put

public Ini.Section put(String key,
                       Ini.Section value)
Specified by:
put in interface Map<String,Ini.Section>

remove

public Ini.Section remove(Object key)
Specified by:
remove in interface Map<String,Ini.Section>

putAll

public void putAll(Map<? extends String,? extends Ini.Section> m)
Specified by:
putAll in interface Map<String,Ini.Section>

clear

public void clear()
Specified by:
clear in interface Map<String,Ini.Section>

keySet

public Set<String> keySet()
Specified by:
keySet in interface Map<String,Ini.Section>

values

public Collection<Ini.Section> values()
Specified by:
values in interface Map<String,Ini.Section>

entrySet

public Set<Map.Entry<String,Ini.Section>> entrySet()
Specified by:
entrySet in interface Map<String,Ini.Section>


Copyright © 2004-2012 The Apache Software Foundation. All Rights Reserved.