org.apache.tomcat.util.IntrospectionUtils Java Examples

The following examples show how to use org.apache.tomcat.util.IntrospectionUtils. 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: SetRootRule.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Process the end of this element.
 * 
 * @param namespace the namespace URI of the matching element, or an 
 *   empty string if the parser is not namespace aware or the element has
 *   no namespace
 * @param name the local name if the parser is namespace aware, or just 
 *   the element name otherwise
 */
@Override
public void end(String namespace, String name) throws Exception {

    // Identify the objects to be used
    Object child = digester.peek(0);
    Object parent = digester.root;
    if (digester.log.isDebugEnabled()) {
        if (parent == null) {
            digester.log.debug("[SetRootRule]{" + digester.match +
                    "} Call [NULL ROOT]." +
                    methodName + "(" + child + ")");
        } else {
            digester.log.debug("[SetRootRule]{" + digester.match +
                    "} Call " + parent.getClass().getName() + "." +
                    methodName + "(" + child + ")");
        }
    }

    // Call the specified method
    IntrospectionUtils.callMethod1(parent, methodName,
            child, paramType, digester.getClassLoader());

}
 
Example #2
Source File: StoreAppender.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Check if the attribute should be printed.
 * @param desc RegistryDescriptor from this bean
 * @param descriptor PropertyDescriptor from this bean property
 * @param attributeName The attribute name to store
 * @param bean The current bean
 * @param bean2 A default instance of the bean for comparison
 * @return null if the value should be skipped, the value to print otherwise
 */
protected Object checkAttribute(StoreDescription desc, PropertyDescriptor descriptor, String attributeName, Object bean, Object bean2) {
    if (descriptor instanceof IndexedPropertyDescriptor) {
        return null; // Indexed properties are not persisted
    }
    if (!isPersistable(descriptor.getPropertyType())
            || (descriptor.getReadMethod() == null)
            || (descriptor.getWriteMethod() == null)) {
        return null; // Must be a read-write primitive or String
    }
    if (desc.isTransientAttribute(descriptor.getName())) {
        return null; // Skip the specified exceptions
    }
    Object value = IntrospectionUtils.getProperty(bean, descriptor.getName());
    if (value == null) {
        return null; // Null values are not persisted
    }
    Object value2 = IntrospectionUtils.getProperty(bean2, descriptor.getName());
    if (value.equals(value2)) {
        // The property has its default value
        return null;
    }
    return value;
}
 
Example #3
Source File: FilterBase.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Override
public void init(FilterConfig filterConfig) throws ServletException {
    Enumeration<String> paramNames = filterConfig.getInitParameterNames();
    while (paramNames.hasMoreElements()) {
        String paramName = paramNames.nextElement();
        if (!IntrospectionUtils.setProperty(this, paramName,
                filterConfig.getInitParameter(paramName))) {
            String msg = sm.getString("filterbase.noSuchProperty",
                    paramName, this.getClass().getName());
            if (isConfigProblemFatal()) {
                throw new ServletException(msg);
            } else {
                getLogger().warn(msg);
            }
        }
    }    
}
 
Example #4
Source File: FilterBase.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Iterates over the configuration parameters and either logs a warning,
 * or throws an exception for any parameter that does not have a matching
 * setter in this filter.
 *
 * @param filterConfig The configuration information associated with the
 *                     filter instance being initialised
 *
 * @throws ServletException if {@link #isConfigProblemFatal()} returns
 *                          {@code true} and a configured parameter does not
 *                          have a matching setter
 */
@Override
public void init(FilterConfig filterConfig) throws ServletException {
    Enumeration<String> paramNames = filterConfig.getInitParameterNames();
    while (paramNames.hasMoreElements()) {
        String paramName = paramNames.nextElement();
        if (!IntrospectionUtils.setProperty(this, paramName,
                filterConfig.getInitParameter(paramName))) {
            String msg = sm.getString("filterbase.noSuchProperty",
                    paramName, this.getClass().getName());
            if (isConfigProblemFatal()) {
                throw new ServletException(msg);
            } else {
                getLogger().warn(msg);
            }
        }
    }
}
 
Example #5
Source File: SetAllPropertiesRule.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Handle the beginning of an XML element.
 *
 * @param attributes The attributes of this element
 *
 * @exception Exception if a processing error occurs
 */
@Override
public void begin(String namespace, String nameX, Attributes attributes)
    throws Exception {

    for (int i = 0; i < attributes.getLength(); i++) {
        String name = attributes.getLocalName(i);
        if ("".equals(name)) {
            name = attributes.getQName(i);
        }
        String value = attributes.getValue(i);
        if ( !excludes.containsKey(name)) {
            if (!digester.isFakeAttribute(digester.peek(), name)
                    && !IntrospectionUtils.setProperty(digester.peek(), name, value)
                    && digester.getRulesValidation()) {
                digester.getLogger().warn("[SetAllPropertiesRule]{" + digester.getMatch() +
                        "} Setting property '" + name + "' to '" +
                        value + "' did not find a matching property.");
            }
        }
    }

}
 
Example #6
Source File: SetContextPropertiesRule.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Handle the beginning of an XML element.
 *
 * @param attributes The attributes of this element
 *
 * @exception Exception if a processing error occurs
 */
@Override
public void begin(String namespace, String nameX, Attributes attributes)
    throws Exception {

    for (int i = 0; i < attributes.getLength(); i++) {
        String name = attributes.getLocalName(i);
        if ("".equals(name)) {
            name = attributes.getQName(i);
        }
        if ("path".equals(name) || "docBase".equals(name)) {
            continue;
        }
        String value = attributes.getValue(i);
        if (!digester.isFakeAttribute(digester.peek(), name)
                && !IntrospectionUtils.setProperty(digester.peek(), name, value)
                && digester.getRulesValidation()) {
            digester.getLogger().warn("[SetContextPropertiesRule]{" + digester.getMatch() +
                    "} Setting property '" + name + "' to '" +
                    value + "' did not find a matching property.");
        }
    }

}
 
Example #7
Source File: ConnectorMBean.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Set the value of a specific attribute of this MBean.
 *
 * @param attribute The identification of the attribute to be set
 *  and the new value
 *
 * @exception AttributeNotFoundException if this attribute is not
 *  supported by this MBean
 * @exception MBeanException if the initializer of an object
 *  throws an exception
 * @exception ReflectionException if a Java reflection exception
 *  occurs when invoking the getter
 */
 @Override
public void setAttribute(Attribute attribute) throws AttributeNotFoundException, MBeanException,
        ReflectionException {

    // Validate the input parameters
    if (attribute == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException(
                "Attribute is null"), "Attribute is null");
    }
    String name = attribute.getName();
    Object value = attribute.getValue();
    if (name == null) {
        throw new RuntimeOperationsException(
                new IllegalArgumentException("Attribute name is null"),
                "Attribute name is null");
    }

    Connector connector = doGetManagedResource();
    IntrospectionUtils.setProperty(connector, name, String.valueOf(value));
}
 
Example #8
Source File: SetNextRule.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Process the end of this element.
 * 
 * @param namespace the namespace URI of the matching element, or an 
 *   empty string if the parser is not namespace aware or the element has
 *   no namespace
 * @param name the local name if the parser is namespace aware, or just 
 *   the element name otherwise
 */
@Override
public void end(String namespace, String name) throws Exception {

    // Identify the objects to be used
    Object child = digester.peek(0);
    Object parent = digester.peek(1);
    if (digester.log.isDebugEnabled()) {
        if (parent == null) {
            digester.log.debug("[SetNextRule]{" + digester.match +
                    "} Call [NULL PARENT]." +
                    methodName + "(" + child + ")");
        } else {
            digester.log.debug("[SetNextRule]{" + digester.match +
                    "} Call " + parent.getClass().getName() + "." +
                    methodName + "(" + child + ")");
        }
    }

    // Call the specified method
    IntrospectionUtils.callMethod1(parent, methodName,
            child, paramType, digester.getClassLoader());
            
}
 
Example #9
Source File: SetNextNamingRule.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Process the end of this element.
 *
 * @param namespace the namespace URI of the matching element, or an
 *   empty string if the parser is not namespace aware or the element has
 *   no namespace
 * @param name the local name if the parser is namespace aware, or just
 *   the element name otherwise
 */
@Override
public void end(String namespace, String name) throws Exception {

    // Identify the objects to be used
    Object child = digester.peek(0);
    Object parent = digester.peek(1);

    NamingResourcesImpl namingResources = null;
    if (parent instanceof Context) {
        namingResources = ((Context) parent).getNamingResources();
    } else {
        namingResources = (NamingResourcesImpl) parent;
    }

    // Call the specified method
    IntrospectionUtils.callMethod1(namingResources, methodName,
            child, paramType, digester.getClassLoader());

}
 
Example #10
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 #11
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);
    }
}
 
Example #12
Source File: SetTopRule.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Process the end of this element.
 * 
 * @param namespace the namespace URI of the matching element, or an 
 *   empty string if the parser is not namespace aware or the element has
 *   no namespace
 * @param name the local name if the parser is namespace aware, or just 
 *   the element name otherwise
 */
@Override
public void end(String namespace, String name) throws Exception {

    // Identify the objects to be used
    Object child = digester.peek(0);
    Object parent = digester.peek(1);
    
    if (digester.log.isDebugEnabled()) {
        if (child == null) {
            digester.log.debug("[SetTopRule]{" + digester.match +
                    "} Call [NULL CHILD]." +
                    methodName + "(" + parent + ")");
        } else {
            digester.log.debug("[SetTopRule]{" + digester.match +
                    "} Call " + child.getClass().getName() + "." +
                    methodName + "(" + parent + ")");
        }
    }

    // Call the specified method
    IntrospectionUtils.callMethod1(child, methodName,
            parent, paramType, digester.getClassLoader());

}
 
Example #13
Source File: SetRootRule.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Process the end of this element.
 * 
 * @param namespace the namespace URI of the matching element, or an 
 *   empty string if the parser is not namespace aware or the element has
 *   no namespace
 * @param name the local name if the parser is namespace aware, or just 
 *   the element name otherwise
 */
@Override
public void end(String namespace, String name) throws Exception {

    // Identify the objects to be used
    Object child = digester.peek(0);
    Object parent = digester.root;
    if (digester.log.isDebugEnabled()) {
        if (parent == null) {
            digester.log.debug("[SetRootRule]{" + digester.match +
                    "} Call [NULL ROOT]." +
                    methodName + "(" + child + ")");
        } else {
            digester.log.debug("[SetRootRule]{" + digester.match +
                    "} Call " + parent.getClass().getName() + "." +
                    methodName + "(" + child + ")");
        }
    }

    // Call the specified method
    IntrospectionUtils.callMethod1(parent, methodName,
            child, paramType, digester.getClassLoader());

}
 
Example #14
Source File: SetNextNamingRule.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Process the end of this element.
 * 
 * @param namespace the namespace URI of the matching element, or an 
 *   empty string if the parser is not namespace aware or the element has
 *   no namespace
 * @param name the local name if the parser is namespace aware, or just 
 *   the element name otherwise
 */
@Override
public void end(String namespace, String name) throws Exception {

    // Identify the objects to be used
    Object child = digester.peek(0);
    Object parent = digester.peek(1);

    NamingResources namingResources = null;
    if (parent instanceof Context) {
        namingResources = ((Context) parent).getNamingResources();
    } else {
        namingResources = (NamingResources) parent;
    }
    
    // Call the specified method
    IntrospectionUtils.callMethod1(namingResources, methodName,
            child, paramType, digester.getClassLoader());

}
 
Example #15
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 #16
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 #17
Source File: SetNextRule.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Process the end of this element.
 *
 * @param namespace the namespace URI of the matching element, or an
 *   empty string if the parser is not namespace aware or the element has
 *   no namespace
 * @param name the local name if the parser is namespace aware, or just
 *   the element name otherwise
 */
@Override
public void end(String namespace, String name) throws Exception {

    // Identify the objects to be used
    Object child = digester.peek(0);
    Object parent = digester.peek(1);
    if (digester.log.isDebugEnabled()) {
        if (parent == null) {
            digester.log.debug("[SetNextRule]{" + digester.match +
                    "} Call [NULL PARENT]." +
                    methodName + "(" + child + ")");
        } else {
            digester.log.debug("[SetNextRule]{" + digester.match +
                    "} Call " + parent.getClass().getName() + "." +
                    methodName + "(" + child + ")");
        }
    }

    // Call the specified method
    IntrospectionUtils.callMethod1(parent, methodName,
            child, paramType, digester.getClassLoader());

}
 
Example #18
Source File: SetContextPropertiesRule.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Handle the beginning of an XML element.
 *
 * @param attributes The attributes of this element
 *
 * @exception Exception if a processing error occurs
 */
@Override
public void begin(String namespace, String nameX, Attributes attributes)
    throws Exception {

    for (int i = 0; i < attributes.getLength(); i++) {
        String name = attributes.getLocalName(i);
        if ("".equals(name)) {
            name = attributes.getQName(i);
        }
        if ("path".equals(name) || "docBase".equals(name)) {
            continue;
        }
        String value = attributes.getValue(i);
        if (!digester.isFakeAttribute(digester.peek(), name) 
                && !IntrospectionUtils.setProperty(digester.peek(), name, value) 
                && digester.getRulesValidation()) {
            digester.getLogger().warn("[SetContextPropertiesRule]{" + digester.getMatch() +
                    "} Setting property '" + name + "' to '" +
                    value + "' did not find a matching property.");
        }
    }

}
 
Example #19
Source File: SetAllPropertiesRule.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Handle the beginning of an XML element.
 *
 * @param attributes The attributes of this element
 *
 * @exception Exception if a processing error occurs
 */
@Override
public void begin(String namespace, String nameX, Attributes attributes)
    throws Exception {

    for (int i = 0; i < attributes.getLength(); i++) {
        String name = attributes.getLocalName(i);
        if ("".equals(name)) {
            name = attributes.getQName(i);
        }
        String value = attributes.getValue(i);
        if ( !excludes.containsKey(name)) {
            if (!digester.isFakeAttribute(digester.peek(), name) 
                    && !IntrospectionUtils.setProperty(digester.peek(), name, value) 
                    && digester.getRulesValidation()) {
                digester.getLogger().warn("[SetAllPropertiesRule]{" + digester.getMatch() +
                        "} Setting property '" + name + "' to '" +
                        value + "' did not find a matching property.");
            }
        }
    }

}
 
Example #20
Source File: TesterInjectionServlet.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

    resp.setContentType("text/plain");
    resp.setCharacterEncoding("UTF-8");

    String injectionName = req.getParameter("injectionName");

    PrintWriter pw = resp.getWriter();
    pw.print(IntrospectionUtils.getProperty(this, injectionName));

    // The property should tyake precedence over the field and this should
    // be null
    if (getProperty2a() != null) {
        pw.println();
        pw.print(getProperty2a());
    }
}
 
Example #21
Source File: SetAllPropertiesRule.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Handle the beginning of an XML element.
 *
 * @param attributes The attributes of this element
 *
 * @exception Exception if a processing error occurs
 */
@Override
public void begin(String namespace, String nameX, Attributes attributes)
    throws Exception {

    for (int i = 0; i < attributes.getLength(); i++) {
        String name = attributes.getLocalName(i);
        if ("".equals(name)) {
            name = attributes.getQName(i);
        }
        String value = attributes.getValue(i);
        if ( !excludes.containsKey(name)) {
            if (!digester.isFakeAttribute(digester.peek(), name) 
                    && !IntrospectionUtils.setProperty(digester.peek(), name, value) 
                    && digester.getRulesValidation()) {
                digester.getLogger().warn("[SetAllPropertiesRule]{" + digester.getMatch() +
                        "} Setting property '" + name + "' to '" +
                        value + "' did not find a matching property.");
            }
        }
    }

}
 
Example #22
Source File: SetContextPropertiesRule.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Handle the beginning of an XML element.
 *
 * @param attributes The attributes of this element
 *
 * @exception Exception if a processing error occurs
 */
@Override
public void begin(String namespace, String nameX, Attributes attributes)
    throws Exception {

    for (int i = 0; i < attributes.getLength(); i++) {
        String name = attributes.getLocalName(i);
        if ("".equals(name)) {
            name = attributes.getQName(i);
        }
        if ("path".equals(name) || "docBase".equals(name)) {
            continue;
        }
        String value = attributes.getValue(i);
        if (!digester.isFakeAttribute(digester.peek(), name) 
                && !IntrospectionUtils.setProperty(digester.peek(), name, value) 
                && digester.getRulesValidation()) {
            digester.getLogger().warn("[SetContextPropertiesRule]{" + digester.getMatch() +
                    "} Setting property '" + name + "' to '" +
                    value + "' did not find a matching property.");
        }
    }

}
 
Example #23
Source File: SetNextRule.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Process the end of this element.
 * 
 * @param namespace the namespace URI of the matching element, or an 
 *   empty string if the parser is not namespace aware or the element has
 *   no namespace
 * @param name the local name if the parser is namespace aware, or just 
 *   the element name otherwise
 */
@Override
public void end(String namespace, String name) throws Exception {

    // Identify the objects to be used
    Object child = digester.peek(0);
    Object parent = digester.peek(1);
    if (digester.log.isDebugEnabled()) {
        if (parent == null) {
            digester.log.debug("[SetNextRule]{" + digester.match +
                    "} Call [NULL PARENT]." +
                    methodName + "(" + child + ")");
        } else {
            digester.log.debug("[SetNextRule]{" + digester.match +
                    "} Call " + parent.getClass().getName() + "." +
                    methodName + "(" + child + ")");
        }
    }

    // Call the specified method
    IntrospectionUtils.callMethod1(parent, methodName,
            child, paramType, digester.getClassLoader());
            
}
 
Example #24
Source File: SetTopRule.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Process the end of this element.
 * 
 * @param namespace the namespace URI of the matching element, or an 
 *   empty string if the parser is not namespace aware or the element has
 *   no namespace
 * @param name the local name if the parser is namespace aware, or just 
 *   the element name otherwise
 */
@Override
public void end(String namespace, String name) throws Exception {

    // Identify the objects to be used
    Object child = digester.peek(0);
    Object parent = digester.peek(1);
    
    if (digester.log.isDebugEnabled()) {
        if (child == null) {
            digester.log.debug("[SetTopRule]{" + digester.match +
                    "} Call [NULL CHILD]." +
                    methodName + "(" + parent + ")");
        } else {
            digester.log.debug("[SetTopRule]{" + digester.match +
                    "} Call " + child.getClass().getName() + "." +
                    methodName + "(" + parent + ")");
        }
    }

    // Call the specified method
    IntrospectionUtils.callMethod1(child, methodName,
            parent, paramType, digester.getClassLoader());

}
 
Example #25
Source File: SetNextNamingRule.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Process the end of this element.
 * 
 * @param namespace the namespace URI of the matching element, or an 
 *   empty string if the parser is not namespace aware or the element has
 *   no namespace
 * @param name the local name if the parser is namespace aware, or just 
 *   the element name otherwise
 */
@Override
public void end(String namespace, String name) throws Exception {

    // Identify the objects to be used
    Object child = digester.peek(0);
    Object parent = digester.peek(1);

    NamingResources namingResources = null;
    if (parent instanceof Context) {
        namingResources = ((Context) parent).getNamingResources();
    } else {
        namingResources = (NamingResources) parent;
    }
    
    // Call the specified method
    IntrospectionUtils.callMethod1(namingResources, methodName,
            child, paramType, digester.getClassLoader());

}
 
Example #26
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 #27
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 #28
Source File: FilterBase.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public void init(FilterConfig filterConfig) throws ServletException {
    Enumeration<String> paramNames = filterConfig.getInitParameterNames();
    while (paramNames.hasMoreElements()) {
        String paramName = paramNames.nextElement();
        if (!IntrospectionUtils.setProperty(this, paramName,
                filterConfig.getInitParameter(paramName))) {
            String msg = sm.getString("filterbase.noSuchProperty",
                    paramName, this.getClass().getName());
            if (isConfigProblemFatal()) {
                throw new ServletException(msg);
            } else {
                getLogger().warn(msg);
            }
        }
    }    
}
 
Example #29
Source File: Digester.java    From Tomcat8-Source-Read with MIT License 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 {
            newAttrs.setValue(i, IntrospectionUtils.replaceProperties(value, null, source, getClassLoader()).intern());
        } catch (Exception e) {
            log.warn(sm.getString("digester.failedToUpdateAttributes", newAttrs.getLocalName(i), value), e);
        }
    }

    return newAttrs;
}
 
Example #30
Source File: NioEndpoint.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Generic properties, introspected
 */
@Override
public boolean setProperty(String name, String value) {
    final String selectorPoolName = "selectorPool.";
    try {
        if (name.startsWith(selectorPoolName)) {
            return IntrospectionUtils.setProperty(selectorPool, name.substring(selectorPoolName.length()), value);
        } else {
            return super.setProperty(name, value);
        }
    }catch ( Exception x ) {
        log.error("Unable to set attribute \""+name+"\" to \""+value+"\"",x);
        return false;
    }
}