jodd.props
Class Props

java.lang.Object
  extended by jodd.props.Props
All Implemented Interfaces:
java.lang.Cloneable

public class Props
extends java.lang.Object
implements java.lang.Cloneable

Super properties: fast, configurable, supports (ini) sections, profiles.

Basic parsing rules:

  • By default, props files are UTF8 encoded.
  • Leading and trailing spaces will be trimmed from section names and property names.
  • Leading and/or trailing spaces may be trimmed from property values.
  • You can use either equal sign (=) or colon (:) to assign property values
  • Comments begin with either a semicolon (;), or a sharp sign (#) and extend to the end of line. It doesn't have to be the first character.
  • A backslash (\) escapes the next character (e.g., \# is a literal #, \\ is a literal \).
  • If the last character of a line is backslash (\), the value is continued on the next line with new line character included.
  • \\uXXXX is encoded as character
  • \t, \r and \f are encoded as characters

    Sections rules:

  • Section names are enclosed between [ and ].
  • Properties following a section header belong to that section. Section name is added as a prefix to section properties.
  • Section ends with empty section definition [] or with new section start

    Profiles rules:

  • Profile names are enclosed between < and > in property key.
  • Each property key may contain zero, one or more profile definitions.

    Macro rules:

  • Profile values may contain references to other properties using ${ and }
  • Inner references are supported
  • References are resolved first in the profile context and then in the base props context.


    Field Summary
    protected  java.lang.String[] activeProfiles
               
    protected  java.lang.String activeProfilesProp
               
    protected  PropsData data
               
    protected  boolean initialized
               
    protected  PropsParser parser
               
     
    Constructor Summary
      Props()
              Creates new props.
    protected Props(PropsParser parser)
               
     
    Method Summary
    protected  Props clone()
              Clones props by creating new instance and copying current configuration.
     int countTotalProperties()
              Counts the total number of properties, including all profiles.
     java.util.Properties extractBaseProperties()
              Extract base props to properties.
     java.util.Properties extractProperties()
              Extracts properties belonging to active profiles. s
     java.util.Properties extractProperties(java.lang.String... profiles)
              Extract props to properties.
     java.lang.String getBaseValue(java.lang.String key)
              Returns string value of base property.
     java.lang.String getValue(java.lang.String key)
              Returns value of property, using active profiles.
     java.lang.String getValue(java.lang.String key, java.lang.String... profiles)
              Returns string value of given profiles.
    protected  void initialize()
              Initializes props by replacing macros in values with the lookup values.
     void load(java.io.File file)
              Loads props from the file.
     void load(java.io.File file, java.lang.String encoding)
              Loads properties from the file in provided encoding.
     void load(java.io.InputStream in)
              Loads properties from input stream.
     void load(java.io.InputStream in, java.lang.String encoding)
              Loads properties from input stream and provided encoding.
     void load(java.util.Map<?,?> map, java.lang.String prefix)
              Loads base properties from java Map using provided prefix.
     void load(java.util.Properties p)
              Loads base properties from the provided java properties.
     void load(java.util.Properties p, java.lang.String prefix)
              Loads base properties from java properties using provided prefix.
     void load(java.lang.String data)
              Loads props from the string.
     void loadEnvironment(java.lang.String prefix)
              Loads environment properties with given prefix.
     void loadSystemProperties(java.lang.String prefix)
              Loads system properties with given prefix.
    protected  void parse(java.lang.String data)
              Parses input string and loads provided properties map.
    protected  void resolveActiveProfiles()
              Resolves active profiles from property.
     void setAppendDuplicateProps(boolean appendDuplicateProps)
              Appends duplicate props.
     void setEscapeNewLineValue(java.lang.String escapeNewLineValue)
              Specifies the new line string when EOL is escaped.
     void setIgnorePrefixWhitespacesOnNewLine(boolean ignorePrefixWhitespacesOnNewLine)
              Defines if the prefix whitespaces should be ignored when value is split into the lines.
     void setSkipEmptyProps(boolean skipEmptyProps)
              Skips empty properties.
     void setValue(java.lang.String key, java.lang.String value)
              Sets default value.
     void setValue(java.lang.String key, java.lang.String value, java.lang.String profile)
              Sets value on some profile.
     void setValueTrimLeft(boolean valueTrimLeft)
              Specifies should the values be trimmed from the left.
     void setValueTrimRight(boolean valueTrimRight)
              Specifies should the values be trimmed from the right.
     
    Methods inherited from class java.lang.Object
    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    parser

    protected final PropsParser parser

    data

    protected final PropsData data

    activeProfilesProp

    protected java.lang.String activeProfilesProp

    activeProfiles

    protected java.lang.String[] activeProfiles

    initialized

    protected volatile boolean initialized
    Constructor Detail

    Props

    public Props()
    Creates new props.


    Props

    protected Props(PropsParser parser)
    Method Detail

    clone

    protected Props clone()
    Clones props by creating new instance and copying current configuration.

    Overrides:
    clone in class java.lang.Object

    setEscapeNewLineValue

    public void setEscapeNewLineValue(java.lang.String escapeNewLineValue)
    Specifies the new line string when EOL is escaped. Default value is an empty string.


    setValueTrimLeft

    public void setValueTrimLeft(boolean valueTrimLeft)
    Specifies should the values be trimmed from the left. Default is true.


    setValueTrimRight

    public void setValueTrimRight(boolean valueTrimRight)
    Specifies should the values be trimmed from the right. Default is true.


    setIgnorePrefixWhitespacesOnNewLine

    public void setIgnorePrefixWhitespacesOnNewLine(boolean ignorePrefixWhitespacesOnNewLine)
    Defines if the prefix whitespaces should be ignored when value is split into the lines.


    setSkipEmptyProps

    public void setSkipEmptyProps(boolean skipEmptyProps)
    Skips empty properties.


    setAppendDuplicateProps

    public void setAppendDuplicateProps(boolean appendDuplicateProps)
    Appends duplicate props.


    parse

    protected void parse(java.lang.String data)
    Parses input string and loads provided properties map.


    load

    public void load(java.lang.String data)
    Loads props from the string.


    load

    public void load(java.io.File file)
              throws java.io.IOException
    Loads props from the file. Assumes UTF8 encoding unless the file ends with '.properties', than it uses ISO 8859-1.

    Throws:
    java.io.IOException

    load

    public void load(java.io.File file,
                     java.lang.String encoding)
              throws java.io.IOException
    Loads properties from the file in provided encoding.

    Throws:
    java.io.IOException

    load

    public void load(java.io.InputStream in)
              throws java.io.IOException
    Loads properties from input stream. Stream is not closed at the end.

    Throws:
    java.io.IOException

    load

    public void load(java.io.InputStream in,
                     java.lang.String encoding)
              throws java.io.IOException
    Loads properties from input stream and provided encoding. Stream is not closed at the end.

    Throws:
    java.io.IOException

    load

    public void load(java.util.Properties p)
    Loads base properties from the provided java properties. Null values are ignored.


    load

    public void load(java.util.Properties p,
                     java.lang.String prefix)
    Loads base properties from java properties using provided prefix. Null values are ignored.


    load

    public void load(java.util.Map<?,?> map,
                     java.lang.String prefix)
    Loads base properties from java Map using provided prefix. Null values are ignored.


    loadSystemProperties

    public void loadSystemProperties(java.lang.String prefix)
    Loads system properties with given prefix. If prefix is null it will not be ignored.


    loadEnvironment

    public void loadEnvironment(java.lang.String prefix)
    Loads environment properties with given prefix. If prefix is null it will not be used.


    countTotalProperties

    public int countTotalProperties()
    Counts the total number of properties, including all profiles. This operation performs calculation each time and it might be more time consuming then expected.


    getBaseValue

    public java.lang.String getBaseValue(java.lang.String key)
    Returns string value of base property. Returns null if property doesn't exist.


    getValue

    public java.lang.String getValue(java.lang.String key)
    Returns value of property, using active profiles.


    getValue

    public java.lang.String getValue(java.lang.String key,
                                     java.lang.String... profiles)
    Returns string value of given profiles. If key is not found under listed profiles, base properties will be searched. Returns null if property doesn't exist.


    setValue

    public void setValue(java.lang.String key,
                         java.lang.String value)
    Sets default value.


    setValue

    public void setValue(java.lang.String key,
                         java.lang.String value,
                         java.lang.String profile)
    Sets value on some profile.


    extractBaseProperties

    public java.util.Properties extractBaseProperties()
    Extract base props to properties.


    extractProperties

    public java.util.Properties extractProperties()
    Extracts properties belonging to active profiles. s


    extractProperties

    public java.util.Properties extractProperties(java.lang.String... profiles)
    Extract props to properties.


    initialize

    protected void initialize()
    Initializes props by replacing macros in values with the lookup values.


    resolveActiveProfiles

    protected void resolveActiveProfiles()
    Resolves active profiles from property.



    Copyright © 2003-2012 Jodd Team