Package org.apache.shiro.config
Class Ini
- java.lang.Object
-
- 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 ofSections, keyed by section name. EachSectionis itself a map ofStringname/value pairs. Name/value pairs are guaranteed to be unique within eachSectiononly - not across the entireIniinstance.- Since:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description static StringCOMMENT_POUNDstatic StringCOMMENT_SEMICOLONstatic StringDEFAULT_CHARSET_NAMEstatic StringDEFAULT_SECTION_NAMEprotected static charESCAPE_TOKENstatic StringSECTION_PREFIXstatic StringSECTION_SUFFIX
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Ini.SectionaddSection(String sectionName)Ensures a section with the specified name exists, adding a new one if it does not yet exist.voidclear()booleancontainsKey(Object key)booleancontainsValue(Object value)Set<Map.Entry<String,Ini.Section>>entrySet()booleanequals(Object obj)static InifromResourcePath(String resourcePath)Creates a newIniinstance loaded with the INI-formatted data in the resource at the given path.Ini.Sectionget(Object key)Ini.SectiongetSection(String sectionName)Returns theIni.Sectionwith the given name ornullif no section with that name exists.protected static StringgetSectionName(String line)Set<String>getSectionNames()Returns the names of all sections managed by thisIniinstance or an empty collection if there are no sections.StringgetSectionProperty(String sectionName, String propertyName)Returns the value of the specified section property, ornullif the section or property do not exist.StringgetSectionProperty(String sectionName, String propertyName, String defaultValue)Returns the value of the specified section property, or thedefaultValueif the section or property do not exist.Collection<Ini.Section>getSections()Returns the sections managed by thisIniinstance or an empty collection if there are no sections.inthashCode()booleanisEmpty()Returnstrueif no sections have been configured, or if there are sections, but the sections themselves are all empty,falseotherwise.protected static booleanisSectionHeader(String line)Set<String>keySet()voidload(InputStream is)Loads the INI-formatted text backed by the given InputStream into this instance.voidload(Reader reader)Loads the INI-formatted text backed by the given Reader into this instance.voidload(String iniConfig)Loads the specified raw INI-formatted text into this instance.voidload(Scanner scanner)Loads the INI-formatted text backed by the given Scanner.voidloadFromPath(String resourcePath)Loads data from the specified resource path into this currentIniinstance.voidmerge(Map<String,Ini.Section> m)Merges the contents ofm'sIni.Sectionobjects into self.Ini.Sectionput(String key, Ini.Section value)voidputAll(Map<? extends String,? extends Ini.Section> m)Ini.Sectionremove(Object key)Ini.SectionremoveSection(String sectionName)Removes the section with the specified name and returns it, ornullif the section did not exist.voidsetSectionProperty(String sectionName, String propertyName, String propertyValue)Sets a name/value pair for the section with the givensectionName.intsize()StringtoString()Collection<Ini.Section>values()-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
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 emptyIniinstance.
-
Ini
public Ini(Ini defaults)
Creates a newIniinstance 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()
Returnstrueif no sections have been configured, or if there are sections, but the sections themselves are all empty,falseotherwise.- Specified by:
isEmptyin interfaceMap<String,Ini.Section>- Returns:
trueif no sections have been configured, or if there are sections, but the sections themselves are all empty,falseotherwise.
-
getSectionNames
public Set<String> getSectionNames()
Returns the names of all sections managed by thisIniinstance or an empty collection if there are no sections.- Returns:
- the names of all sections managed by this
Iniinstance or an empty collection if there are no sections.
-
getSections
public Collection<Ini.Section> getSections()
Returns the sections managed by thisIniinstance or an empty collection if there are no sections.- Returns:
- the sections managed by this
Iniinstance or an empty collection if there are no sections.
-
getSection
public Ini.Section getSection(String sectionName)
Returns theIni.Sectionwith the given name ornullif no section with that name exists.- Parameters:
sectionName- the name of the section to retrieve.- Returns:
- the
Ini.Sectionwith the given name ornullif 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, ornullif the section did not exist.- Parameters:
sectionName- the name of the section to remove.- Returns:
- the section with the specified name or
nullif 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 givensectionName. If the section does not yet exist, it will be created. If thesectionNameis 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 pairpropertyName- the name of the property to addpropertyValue- the property value
-
getSectionProperty
public String getSectionProperty(String sectionName, String propertyName)
Returns the value of the specified section property, ornullif the section or property do not exist.- Parameters:
sectionName- the name of the section to retrieve to acquire the property valuepropertyName- the name of the section property for which to return the value- Returns:
- the value of the specified section property, or
nullif 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 thedefaultValueif the section or property do not exist.- Parameters:
sectionName- the name of the section to add the name/value pairpropertyName- the name of the property to adddefaultValue- the default value to return if the section or property do not exist.- Returns:
- the value of the specified section property, or the
defaultValueif the section or property do not exist.
-
fromResourcePath
public static Ini fromResourcePath(String resourcePath) throws ConfigurationException
Creates a newIniinstance loaded with the INI-formatted data in the resource at the given path. The resource path may be any value interpretable by theResourceUtils.getInputStreamForPathmethod.- Parameters:
resourcePath- the resource location of the INI data to load when creating theIniinstance.- Returns:
- a new
Iniinstance loaded with the INI-formatted data in the resource at the given path. - Throws:
ConfigurationException- if the path cannot be loaded into anIniinstance.
-
loadFromPath
public void loadFromPath(String resourcePath) throws ConfigurationException
Loads data from the specified resource path into this currentIniinstance. The resource path may be any value interpretable by theResourceUtils.getInputStreamForPathmethod.- 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- theInputStreamfrom 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- theReaderfrom which to read the INI-formatted text
-
merge
public void merge(Map<String,Ini.Section> m)
Merges the contents ofm'sIni.Sectionobjects into self. This differs fromputAll(Map), in that each section is merged with the existing one. For example the following two ini blocks are merged and the result is the third
Initial:
To be merged:[section1] key1 = value1 [section2] key2 = value2
Result:[section1] foo = bar [section2] key2 = new value[section1] key1 = value1 foo = bar [section2] key2 = new value- Parameters:
m- map to be merged- Since:
- 1.4
-
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- theScannerfrom which to read the INI-formatted text
-
isSectionHeader
protected static boolean isSectionHeader(String line)
-
equals
public boolean equals(Object obj)
-
hashCode
public int hashCode()
-
size
public int size()
- Specified by:
sizein interfaceMap<String,Ini.Section>
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKeyin interfaceMap<String,Ini.Section>
-
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValuein interfaceMap<String,Ini.Section>
-
get
public Ini.Section get(Object key)
- Specified by:
getin interfaceMap<String,Ini.Section>
-
put
public Ini.Section put(String key, Ini.Section value)
- Specified by:
putin interfaceMap<String,Ini.Section>
-
remove
public Ini.Section remove(Object key)
- Specified by:
removein interfaceMap<String,Ini.Section>
-
putAll
public void putAll(Map<? extends String,? extends Ini.Section> m)
- Specified by:
putAllin interfaceMap<String,Ini.Section>
-
clear
public void clear()
- Specified by:
clearin interfaceMap<String,Ini.Section>
-
values
public Collection<Ini.Section> values()
- Specified by:
valuesin interfaceMap<String,Ini.Section>
-
entrySet
public Set<Map.Entry<String,Ini.Section>> entrySet()
- Specified by:
entrySetin interfaceMap<String,Ini.Section>
-
-