org.hibernate.search.util.configuration.impl

## Class ConfigurationParseHelper

- java.lang.Object
- - org.hibernate.search.util.configuration.impl.ConfigurationParseHelper

-     public class ConfigurationParseHelper
      extends Object

  Helper class:
  - to avoid managing `NumberFormatException`s and similar
  - to ensure consistent error messages across configuration parsing
  - to locate resources
  Author:
    Sanne Grinovero, Steve Ebersole, Emmanuel Bernard, Hardy Ferentschik

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static URL` | `findAsResource(String path)` Try to locate a local URL representing the incoming path.
    `static boolean` | `getBooleanValue(Properties cfg, String key, boolean defaultValue)` Extracts a boolean value from configuration properties
    `static Integer` | `getIntValue(Properties cfg, String key)` Retrieves a configuration property and parses it as an Integer if it exists, or returns null if the property is not set (undefined).
    `static int` | `getIntValue(Properties cfg, String key, int defValue)` Looks for a numeric value in the Properties, returning defValue if not found or if an empty string is found.
    `static long` | `getLongValue(Properties cfg, String key, long defaultValue)` Looks for a numeric value in the Properties, returning defValue if not found or if an empty string is found.
    `static String` | `getString(Properties cfg, String key, String defaultValue)` Get the string property or defaults if not present
    `static URL` | `locateConfig(String path)` Try to locate a local URL representing the incoming path.
    `static boolean` | `parseBoolean(String value, String errorMsgOnParseFailure)` Parses a string to recognize exactly either "true" or "false".
    `static int` | `parseInt(String value, int defValue, String errorMsgOnParseFailure)` In case value is null or an empty string the defValue is returned.
    `static int` | `parseInt(String value, String errorMsgOnParseFailure)` Parses a string into an integer value.
    `static long` | `parseLong(String value, long defValue, String errorMsgOnParseFailure)` In case value is null or an empty string the defValue is returned
    `static long` | `parseLong(String value, String errorMsgOnParseFailure)` Parses a String to get an long value.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### locateConfig

          public static URL locateConfig(String path)

      Try to locate a local URL representing the incoming path. The first attempt assumes that the incoming path is an actual URL string (file://, etc). If this does not work, then the next attempts try to locate this UURL as a java system resource.
      Parameters:
        `path` - The path representing the config location.
      Returns:
        An appropriate URL or null.

    - #### findAsResource

          public static URL findAsResource(String path)

      Try to locate a local URL representing the incoming path. This method only attempts to locate this URL as a java system resource.
      Parameters:
        `path` - The path representing the config location.
      Returns:
        An appropriate URL or null.

    - #### parseInt

          public static int parseInt(String value,
                                     String errorMsgOnParseFailure)

      Parses a string into an integer value.
      Parameters:
        `value` - a string containing an int value to parse
        `errorMsgOnParseFailure` - message being wrapped in a SearchException if value is `null` or not an integer
      Returns:
        the parsed integer value
      Throws:
        `SearchException` - both for null values and for Strings not containing a valid int.

    - #### parseLong

          public static long parseLong(String value,
                                       String errorMsgOnParseFailure)

      Parses a String to get an long value.
      Parameters:
        `value` - A string containing an long value to parse
        `errorMsgOnParseFailure` - message being wrapped in a SearchException if value is null or not correct.
      Returns:
        the parsed value
      Throws:
        `SearchException` - both for null values and for Strings not containing a valid int.

    - #### parseInt

          public static final int parseInt(String value,
                                           int defValue,
                                           String errorMsgOnParseFailure)

      In case value is null or an empty string the defValue is returned.
      Parameters:
        `value` - the text to parse
        `defValue` - the value to return in case the text is null
        `errorMsgOnParseFailure` - message in case of error
      Returns:
        the converted int.
      Throws:
        `SearchException` - if value can't be parsed.

    - #### parseLong

          public static final long parseLong(String value,
                                             long defValue,
                                             String errorMsgOnParseFailure)

      In case value is null or an empty string the defValue is returned
      Parameters:
        `value` - the text to parse
        `defValue` - the value to return in case the text is null
        `errorMsgOnParseFailure` - message in case of error
      Returns:
        the converted long.
      Throws:
        `SearchException` - if value can't be parsed.

    - #### getIntValue

          public static final int getIntValue(Properties cfg,
                                              String key,
                                              int defValue)

      Looks for a numeric value in the Properties, returning defValue if not found or if an empty string is found. When the key the value is found but not in valid format a standard error message is generated.
      Parameters:
        `cfg` - the properties
        `key` - the property identifier
        `defValue` - the value to return if the property is not found or empty
      Returns:
        the converted int.
      Throws:
        `SearchException` - for invalid format.

    - #### getLongValue

          public static long getLongValue(Properties cfg,
                                          String key,
                                          long defaultValue)

      Looks for a numeric value in the Properties, returning defValue if not found or if an empty string is found. When the key the value is found but not in valid format a standard error message is generated.
      Parameters:
        `cfg` - the properties
        `key` - the property identifier
        `defaultValue` - the value to return if the property is not found or empty
      Returns:
        the converted long value.
      Throws:
        `SearchException` - for invalid format.

    - #### parseBoolean

          public static final boolean parseBoolean(String value,
                                                   String errorMsgOnParseFailure)

      Parses a string to recognize exactly either "true" or "false".
      Parameters:
        `value` - the string to be parsed
        `errorMsgOnParseFailure` - the message to be put in the exception if thrown
      Returns:
        true if value is "true", false if value is "false"
      Throws:
        `SearchException` - for invalid format or values.

    - #### getBooleanValue

          public static final boolean getBooleanValue(Properties cfg,
                                                      String key,
                                                      boolean defaultValue)

      Extracts a boolean value from configuration properties
      Parameters:
        `cfg` - configuration Properties
        `key` - the property key
        `defaultValue` - a boolean.
      Returns:
        the defaultValue if the property was not defined
      Throws:
        `SearchException` - for invalid format or values.

    - #### getString

          public static final String getString(Properties cfg,
                                               String key,
                                               String defaultValue)

      Get the string property or defaults if not present
      Parameters:
        `cfg` - configuration Properties
        `key` - the property key
        `defaultValue` - the value to return if the property value is null
      Returns:
        the String or default value

    - #### getIntValue

          public static Integer getIntValue(Properties cfg,
                                            String key)

      Retrieves a configuration property and parses it as an Integer if it exists, or returns null if the property is not set (undefined).
      Parameters:
        `cfg` - configuration Properties
        `key` - the property key
      Returns:
        the Integer or null
      Throws:
        `SearchException` - both for empty (non-null) values and for Strings not containing a valid int representation.

Copyright © 2006-2017 Red Hat, Inc. All Rights Reserved