You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Ulrich Voigt (JIRA)" <ji...@apache.org> on 2010/03/01 13:18:05 UTC

[jira] Created: (LANG-596) StrSubstitutor should also handle the default properties of a java.util.Properties class

StrSubstitutor should also handle the default properties of a java.util.Properties class
----------------------------------------------------------------------------------------

                 Key: LANG-596
                 URL: https://issues.apache.org/jira/browse/LANG-596
             Project: Commons Lang
          Issue Type: Bug
          Components: lang.text.*
    Affects Versions: 2.5
            Reporter: Ulrich Voigt
            Priority: Minor


The following program show a problem with a shortcoming of the java.util.Properties class. 
The default properties are not substituted by the StrSubstitutor.

{code:title=StrSubstTest.java|borderStyle=solid}
import org.apache.commons.lang.text.StrSubstitutor;

public class StrSubstTest
{
    public static void main(String[] args)
    {
        String org = "${doesnotwork}";
        System.setProperty("doesnotwork", "It work's!");

        // create a new Poperties object with the System.getProperties as default
        Properties props = new Properties(System.getProperties());

        String subst = StrSubstitutor.replace(org, props);
        // is ${doesnotwork} substituted?
        System.out.println(subst);

    }
}
{code} 


The following method could be added to the StrSubstitutor class to fix this problem in an easy way:
{code:borderStyle=solid}
    /**
     * Replaces all the occurrences of variables in the given source object with their matching
     * values from the properties.
     * 
     * @param source the source text containing the variables to substitute, null returns null
     * @param properties the properties with values, may be null
     * @return the result of the replace operation
     */
    public static String replace(Object source, Properties valueProperties)
    {
        if (valueProperties == null) {
            return source;
        }
        Map valueMap = new HashMap();
        Enumeration propNames = valueProperties.propertyNames();
        while (propNames.hasMoreElements())
        {
            String propName = (String)propNames.nextElement();
            String propValue = valueProperties.getProperty(propName);
            valueMap.put(propName, propValue);
        }
        return StrSubstitutor.replace(source, valueMap);
    }
{code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (LANG-596) StrSubstitutor should also handle the default properties of a java.util.Properties class

Posted by "Tomas de Priede (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-596?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Tomas de Priede updated LANG-596:
---------------------------------

    Comment: was deleted

(was: hello,
I went up the patch with the code

Regards
Tom)

> StrSubstitutor should also handle the default properties of a java.util.Properties class
> ----------------------------------------------------------------------------------------
>
>                 Key: LANG-596
>                 URL: https://issues.apache.org/jira/browse/LANG-596
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.text.*
>    Affects Versions: 2.5
>            Reporter: Ulrich Voigt
>            Priority: Minor
>             Fix For: 3.1
>
>         Attachments: Patch_LANG-596_1.0
>
>   Original Estimate: 0.5h
>  Remaining Estimate: 0.5h
>
> The following program show a problem with a shortcoming of the java.util.Properties class. 
> The default properties are not substituted by the StrSubstitutor.
> {code:title=StrSubstTest.java|borderStyle=solid}
> import org.apache.commons.lang.text.StrSubstitutor;
> public class StrSubstTest
> {
>     public static void main(String[] args)
>     {
>         String org = "${doesnotwork}";
>         System.setProperty("doesnotwork", "It work's!");
>         // create a new Poperties object with the System.getProperties as default
>         Properties props = new Properties(System.getProperties());
>         String subst = StrSubstitutor.replace(org, props);
>         // is ${doesnotwork} substituted?
>         System.out.println(subst);
>     }
> }
> {code} 
> The following method could be added to the StrSubstitutor class to fix this problem in an easy way:
> {code:borderStyle=solid}
>     /**
>      * Replaces all the occurrences of variables in the given source object with their matching
>      * values from the properties.
>      * 
>      * @param source the source text containing the variables to substitute, null returns null
>      * @param properties the properties with values, may be null
>      * @return the result of the replace operation
>      */
>     public static String replace(Object source, Properties valueProperties)
>     {
>         if (valueProperties == null) {
>             return source;
>         }
>         Map valueMap = new HashMap();
>         Enumeration propNames = valueProperties.propertyNames();
>         while (propNames.hasMoreElements())
>         {
>             String propName = (String)propNames.nextElement();
>             String propValue = valueProperties.getProperty(propName);
>             valueMap.put(propName, propValue);
>         }
>         return StrSubstitutor.replace(source, valueMap);
>     }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (LANG-596) StrSubstitutor should also handle the default properties of a java.util.Properties class

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-596?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell closed LANG-596.
------------------------------

    Fix Version/s: 3.0
                       (was: 3.1)
       Resolution: Fixed

Thanks - patch commited.

svn ci -m "Adding Ulrich + Tomas' patch to LANG-596 adding a replace(String, Properties) variant to StrSubstitutor"
Sending        src/main/java/org/apache/commons/lang3/text/StrSubstitutor.java
Sending        src/test/java/org/apache/commons/lang3/text/StrSubstitutorTest.java
Transmitting file data ..
Committed revision 990671.


> StrSubstitutor should also handle the default properties of a java.util.Properties class
> ----------------------------------------------------------------------------------------
>
>                 Key: LANG-596
>                 URL: https://issues.apache.org/jira/browse/LANG-596
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.text.*
>    Affects Versions: 2.5
>            Reporter: Ulrich Voigt
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: Patch_LANG-596_1.0
>
>   Original Estimate: 0.5h
>  Remaining Estimate: 0.5h
>
> The following program show a problem with a shortcoming of the java.util.Properties class. 
> The default properties are not substituted by the StrSubstitutor.
> {code:title=StrSubstTest.java|borderStyle=solid}
> import org.apache.commons.lang.text.StrSubstitutor;
> public class StrSubstTest
> {
>     public static void main(String[] args)
>     {
>         String org = "${doesnotwork}";
>         System.setProperty("doesnotwork", "It work's!");
>         // create a new Poperties object with the System.getProperties as default
>         Properties props = new Properties(System.getProperties());
>         String subst = StrSubstitutor.replace(org, props);
>         // is ${doesnotwork} substituted?
>         System.out.println(subst);
>     }
> }
> {code} 
> The following method could be added to the StrSubstitutor class to fix this problem in an easy way:
> {code:borderStyle=solid}
>     /**
>      * Replaces all the occurrences of variables in the given source object with their matching
>      * values from the properties.
>      * 
>      * @param source the source text containing the variables to substitute, null returns null
>      * @param properties the properties with values, may be null
>      * @return the result of the replace operation
>      */
>     public static String replace(Object source, Properties valueProperties)
>     {
>         if (valueProperties == null) {
>             return source;
>         }
>         Map valueMap = new HashMap();
>         Enumeration propNames = valueProperties.propertyNames();
>         while (propNames.hasMoreElements())
>         {
>             String propName = (String)propNames.nextElement();
>             String propValue = valueProperties.getProperty(propName);
>             valueMap.put(propName, propValue);
>         }
>         return StrSubstitutor.replace(source, valueMap);
>     }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (LANG-596) StrSubstitutor should also handle the default properties of a java.util.Properties class

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-596?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell updated LANG-596:
-------------------------------

    Fix Version/s: 3.1

Sounds good - assigning to 3.1. Needs code/test patch.

> StrSubstitutor should also handle the default properties of a java.util.Properties class
> ----------------------------------------------------------------------------------------
>
>                 Key: LANG-596
>                 URL: https://issues.apache.org/jira/browse/LANG-596
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.text.*
>    Affects Versions: 2.5
>            Reporter: Ulrich Voigt
>            Priority: Minor
>             Fix For: 3.1
>
>   Original Estimate: 0.5h
>  Remaining Estimate: 0.5h
>
> The following program show a problem with a shortcoming of the java.util.Properties class. 
> The default properties are not substituted by the StrSubstitutor.
> {code:title=StrSubstTest.java|borderStyle=solid}
> import org.apache.commons.lang.text.StrSubstitutor;
> public class StrSubstTest
> {
>     public static void main(String[] args)
>     {
>         String org = "${doesnotwork}";
>         System.setProperty("doesnotwork", "It work's!");
>         // create a new Poperties object with the System.getProperties as default
>         Properties props = new Properties(System.getProperties());
>         String subst = StrSubstitutor.replace(org, props);
>         // is ${doesnotwork} substituted?
>         System.out.println(subst);
>     }
> }
> {code} 
> The following method could be added to the StrSubstitutor class to fix this problem in an easy way:
> {code:borderStyle=solid}
>     /**
>      * Replaces all the occurrences of variables in the given source object with their matching
>      * values from the properties.
>      * 
>      * @param source the source text containing the variables to substitute, null returns null
>      * @param properties the properties with values, may be null
>      * @return the result of the replace operation
>      */
>     public static String replace(Object source, Properties valueProperties)
>     {
>         if (valueProperties == null) {
>             return source;
>         }
>         Map valueMap = new HashMap();
>         Enumeration propNames = valueProperties.propertyNames();
>         while (propNames.hasMoreElements())
>         {
>             String propName = (String)propNames.nextElement();
>             String propValue = valueProperties.getProperty(propName);
>             valueMap.put(propName, propValue);
>         }
>         return StrSubstitutor.replace(source, valueMap);
>     }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-596) StrSubstitutor should also handle the default properties of a java.util.Properties class

Posted by "Tomas de Priede (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-596?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12901715#action_12901715 ] 

Tomas de Priede commented on LANG-596:
--------------------------------------

hello,
I went up the patch with the code

Regards
Tom

> StrSubstitutor should also handle the default properties of a java.util.Properties class
> ----------------------------------------------------------------------------------------
>
>                 Key: LANG-596
>                 URL: https://issues.apache.org/jira/browse/LANG-596
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.text.*
>    Affects Versions: 2.5
>            Reporter: Ulrich Voigt
>            Priority: Minor
>             Fix For: 3.1
>
>   Original Estimate: 0.5h
>  Remaining Estimate: 0.5h
>
> The following program show a problem with a shortcoming of the java.util.Properties class. 
> The default properties are not substituted by the StrSubstitutor.
> {code:title=StrSubstTest.java|borderStyle=solid}
> import org.apache.commons.lang.text.StrSubstitutor;
> public class StrSubstTest
> {
>     public static void main(String[] args)
>     {
>         String org = "${doesnotwork}";
>         System.setProperty("doesnotwork", "It work's!");
>         // create a new Poperties object with the System.getProperties as default
>         Properties props = new Properties(System.getProperties());
>         String subst = StrSubstitutor.replace(org, props);
>         // is ${doesnotwork} substituted?
>         System.out.println(subst);
>     }
> }
> {code} 
> The following method could be added to the StrSubstitutor class to fix this problem in an easy way:
> {code:borderStyle=solid}
>     /**
>      * Replaces all the occurrences of variables in the given source object with their matching
>      * values from the properties.
>      * 
>      * @param source the source text containing the variables to substitute, null returns null
>      * @param properties the properties with values, may be null
>      * @return the result of the replace operation
>      */
>     public static String replace(Object source, Properties valueProperties)
>     {
>         if (valueProperties == null) {
>             return source;
>         }
>         Map valueMap = new HashMap();
>         Enumeration propNames = valueProperties.propertyNames();
>         while (propNames.hasMoreElements())
>         {
>             String propName = (String)propNames.nextElement();
>             String propValue = valueProperties.getProperty(propName);
>             valueMap.put(propName, propValue);
>         }
>         return StrSubstitutor.replace(source, valueMap);
>     }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (LANG-596) StrSubstitutor should also handle the default properties of a java.util.Properties class

Posted by "Tomas de Priede (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-596?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Tomas de Priede updated LANG-596:
---------------------------------

    Attachment: Patch_LANG-596_1.0

hello,
I went up the patch with the code

Regards
Tom

> StrSubstitutor should also handle the default properties of a java.util.Properties class
> ----------------------------------------------------------------------------------------
>
>                 Key: LANG-596
>                 URL: https://issues.apache.org/jira/browse/LANG-596
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.text.*
>    Affects Versions: 2.5
>            Reporter: Ulrich Voigt
>            Priority: Minor
>             Fix For: 3.1
>
>         Attachments: Patch_LANG-596_1.0
>
>   Original Estimate: 0.5h
>  Remaining Estimate: 0.5h
>
> The following program show a problem with a shortcoming of the java.util.Properties class. 
> The default properties are not substituted by the StrSubstitutor.
> {code:title=StrSubstTest.java|borderStyle=solid}
> import org.apache.commons.lang.text.StrSubstitutor;
> public class StrSubstTest
> {
>     public static void main(String[] args)
>     {
>         String org = "${doesnotwork}";
>         System.setProperty("doesnotwork", "It work's!");
>         // create a new Poperties object with the System.getProperties as default
>         Properties props = new Properties(System.getProperties());
>         String subst = StrSubstitutor.replace(org, props);
>         // is ${doesnotwork} substituted?
>         System.out.println(subst);
>     }
> }
> {code} 
> The following method could be added to the StrSubstitutor class to fix this problem in an easy way:
> {code:borderStyle=solid}
>     /**
>      * Replaces all the occurrences of variables in the given source object with their matching
>      * values from the properties.
>      * 
>      * @param source the source text containing the variables to substitute, null returns null
>      * @param properties the properties with values, may be null
>      * @return the result of the replace operation
>      */
>     public static String replace(Object source, Properties valueProperties)
>     {
>         if (valueProperties == null) {
>             return source;
>         }
>         Map valueMap = new HashMap();
>         Enumeration propNames = valueProperties.propertyNames();
>         while (propNames.hasMoreElements())
>         {
>             String propName = (String)propNames.nextElement();
>             String propValue = valueProperties.getProperty(propName);
>             valueMap.put(propName, propValue);
>         }
>         return StrSubstitutor.replace(source, valueMap);
>     }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.