Java Code Examples for org.apache.tomcat.util.IntrospectionUtils#replaceProperties()

The following examples show how to use org.apache.tomcat.util.IntrospectionUtils#replaceProperties() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Digester.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
public static void replaceSystemProperties() {
    Log log = LogFactory.getLog(Digester.class);
    if (propertySource != null) {
        IntrospectionUtils.PropertySource[] propertySources =
                new IntrospectionUtils.PropertySource[] { propertySource };
        Properties properties = System.getProperties();
        Set<String> names = properties.stringPropertyNames();
        for (String name : names) {
            String value = System.getProperty(name);
            if (value != null) {
                try {
                    String newValue = IntrospectionUtils.replaceProperties(value, null, propertySources, null);
                    if (!value.equals(newValue)) {
                        System.setProperty(name, newValue);
                    }
                } catch (Exception e) {
                    log.warn(sm.getString("digester.failedToUpdateSystemProperty", name, value), e);
                }
            }
        }
    }
}
 
Example 2
Source File: Digester.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Return a new StringBuilder containing the same contents as the
 * input buffer, except that data of form ${varname} have been
 * replaced by the value of that var as defined in the system property.
 */
private StringBuilder updateBodyText(StringBuilder bodyText) {
    String in = bodyText.toString();
    String out;
    try {
        out = IntrospectionUtils.replaceProperties(in, null, source, getClassLoader());
    } catch (Exception e) {
        return bodyText; // return unchanged data
    }

    if (out == in) {
        // No substitutions required. Don't waste memory creating
        // a new buffer
        return bodyText;
    } else {
        return new StringBuilder(out);
    }
}
 
Example 3
Source File: Digester.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Returns an attributes list which contains all the attributes
 * passed in, with any text of form "${xxx}" in an attribute value
 * replaced by the appropriate value from the system property.
 */
private Attributes updateAttributes(Attributes list) {

    if (list.getLength() == 0) {
        return list;
    }
    
    AttributesImpl newAttrs = new AttributesImpl(list);
    int nAttributes = newAttrs.getLength();
    for (int i = 0; i < nAttributes; ++i) {
        String value = newAttrs.getValue(i);
        try {
            String newValue = 
                IntrospectionUtils.replaceProperties(value, null, source);
            if (value != newValue) {
                newAttrs.setValue(i, newValue);
            }
        }
        catch (Exception e) {
            // ignore - let the attribute have its original value
        }
    }

    return newAttrs;

}
 
Example 4
Source File: Digester.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Return a new StringBuilder containing the same contents as the
 * input buffer, except that data of form ${varname} have been
 * replaced by the value of that var as defined in the system property.
 */
private StringBuilder updateBodyText(StringBuilder bodyText) {
    String in = bodyText.toString();
    String out;
    try {
        out = IntrospectionUtils.replaceProperties(in, null, source);
    } catch(Exception e) {
        return bodyText; // return unchanged data
    }

    if (out == in)  {
        // No substitutions required. Don't waste memory creating
        // a new buffer
        return bodyText;
    } else {
        return new StringBuilder(out);
    }
}
 
Example 5
Source File: Digester.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Returns an attributes list which contains all the attributes
 * passed in, with any text of form "${xxx}" in an attribute value
 * replaced by the appropriate value from the system property.
 */
private Attributes updateAttributes(Attributes list) {

    if (list.getLength() == 0) {
        return list;
    }
    
    AttributesImpl newAttrs = new AttributesImpl(list);
    int nAttributes = newAttrs.getLength();
    for (int i = 0; i < nAttributes; ++i) {
        String value = newAttrs.getValue(i);
        try {
            String newValue = 
                IntrospectionUtils.replaceProperties(value, null, source);
            if (value != newValue) {
                newAttrs.setValue(i, newValue);
            }
        }
        catch (Exception e) {
            // ignore - let the attribute have its original value
        }
    }

    return newAttrs;

}
 
Example 6
Source File: Digester.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Return a new StringBuilder containing the same contents as the
 * input buffer, except that data of form ${varname} have been
 * replaced by the value of that var as defined in the system property.
 */
private StringBuilder updateBodyText(StringBuilder bodyText) {
    String in = bodyText.toString();
    String out;
    try {
        out = IntrospectionUtils.replaceProperties(in, null, source);
    } catch(Exception e) {
        return bodyText; // return unchanged data
    }

    if (out == in)  {
        // No substitutions required. Don't waste memory creating
        // a new buffer
        return bodyText;
    } else {
        return new StringBuilder(out);
    }
}