org.apache.el.util.MessageFactory Java Examples

The following examples show how to use org.apache.el.util.MessageFactory. 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: ELSupport.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
public static final Character coerceToCharacter(final Object obj)
        throws ELException {
    if (obj == null || "".equals(obj)) {
        return Character.valueOf((char) 0);
    }
    if (obj instanceof String) {
        return Character.valueOf(((String) obj).charAt(0));
    }
    if (ELArithmetic.isNumber(obj)) {
        return Character.valueOf((char) ((Number) obj).shortValue());
    }
    Class<?> objType = obj.getClass();
    if (obj instanceof Character) {
        return (Character) obj;
    }

    throw new ELException(MessageFactory.get("error.convert",
            obj, objType, Character.class));
}
 
Example #2
Source File: AstValue.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public void setValue(EvaluationContext ctx, Object value)
        throws ELException {
    Target t = getTarget(ctx);
    ctx.setPropertyResolved(false);
    ELResolver resolver = ctx.getELResolver();

    // coerce to the expected type
    Class<?> targetClass = resolver.getType(ctx, t.base, t.property);
    resolver.setValue(ctx, t.base, t.property,
            ELSupport.coerceToType(ctx, value, targetClass));
    if (!ctx.isPropertyResolved()) {
        throw new PropertyNotFoundException(MessageFactory.get(
                "error.resolver.unhandled", t.base, t.property));
    }
}
 
Example #3
Source File: AstFunction.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public Class<?> getType(EvaluationContext ctx)
        throws ELException {

    FunctionMapper fnMapper = ctx.getFunctionMapper();

    // quickly validate again for this request
    if (fnMapper == null) {
        throw new ELException(MessageFactory.get("error.fnMapper.null"));
    }
    Method m = fnMapper.resolveFunction(this.prefix, this.localName);
    if (m == null) {
        throw new ELException(MessageFactory.get("error.fnMapper.method",
                this.getOutputName()));
    }
    return m.getReturnType();
}
 
Example #4
Source File: AstIdentifier.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public void setValue(EvaluationContext ctx, Object value)
        throws ELException {
    VariableMapper varMapper = ctx.getVariableMapper();
    if (varMapper != null) {
        ValueExpression expr = varMapper.resolveVariable(this.image);
        if (expr != null) {
            expr.setValue(ctx.getELContext(), value);
            return;
        }
    }
    ctx.setPropertyResolved(false);
    ctx.getELResolver().setValue(ctx, null, this.image, value);
    if (!ctx.isPropertyResolved()) {
        throw new PropertyNotFoundException(MessageFactory.get(
                "error.resolver.unhandled.null", this.image));
    }
}
 
Example #5
Source File: AstIdentifier.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public boolean isReadOnly(EvaluationContext ctx) throws ELException {
    VariableMapper varMapper = ctx.getVariableMapper();
    if (varMapper != null) {
        ValueExpression expr = varMapper.resolveVariable(this.image);
        if (expr != null) {
            return expr.isReadOnly(ctx.getELContext());
        }
    }
    ctx.setPropertyResolved(false);
    boolean result = ctx.getELResolver().isReadOnly(ctx, null, this.image);
    if (!ctx.isPropertyResolved()) {
        throw new PropertyNotFoundException(MessageFactory.get(
                "error.resolver.unhandled.null", this.image));
    }
    return result;
}
 
Example #6
Source File: AstIdentifier.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public Class<?> getType(EvaluationContext ctx) throws ELException {
    VariableMapper varMapper = ctx.getVariableMapper();
    if (varMapper != null) {
        ValueExpression expr = varMapper.resolveVariable(this.image);
        if (expr != null) {
            return expr.getType(ctx.getELContext());
        }
    }
    ctx.setPropertyResolved(false);
    Class<?> result = ctx.getELResolver().getType(ctx, null, this.image);
    if (!ctx.isPropertyResolved()) {
        throw new PropertyNotFoundException(MessageFactory.get(
                "error.resolver.unhandled.null", this.image));
    }
    return result;
}
 
Example #7
Source File: ELArithmetic.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
protected final Number coerce(final Object obj) {

        if (isNumber(obj)) {
            return coerce((Number) obj);
        }
        if (obj == null || "".equals(obj)) {
            return coerce(ZERO);
        }
        if (obj instanceof String) {
            return coerce((String) obj);
        }
        if (obj instanceof Character) {
            return coerce(Short.valueOf((short) ((Character) obj).charValue()));
        }

        throw new IllegalArgumentException(MessageFactory.get("error.convert",
                obj, obj.getClass(), "Number"));
    }
 
Example #8
Source File: ExpressionBuilder.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
public MethodExpression createMethodExpression(Class<?> expectedReturnType,
        Class<?>[] expectedParamTypes) throws ELException {
    Node n = this.build();
    if (!n.isParametersProvided() && expectedParamTypes == null) {
        throw new NullPointerException(MessageFactory
                .get("error.method.nullParms"));
    }
    if (n instanceof AstValue || n instanceof AstIdentifier) {
        return new MethodExpressionImpl(expression, n, this.fnMapper,
                this.varMapper, expectedReturnType, expectedParamTypes);
    } else if (n instanceof AstLiteralExpression) {
        return new MethodExpressionLiteral(expression, expectedReturnType,
                expectedParamTypes);
    } else {
        throw new ELException("Not a Valid Method Expression: "
                + expression);
    }
}
 
Example #9
Source File: AstFunction.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public Class<?> getType(EvaluationContext ctx)
        throws ELException {
    
    FunctionMapper fnMapper = ctx.getFunctionMapper();
    
    // quickly validate again for this request
    if (fnMapper == null) {
        throw new ELException(MessageFactory.get("error.fnMapper.null"));
    }
    Method m = fnMapper.resolveFunction(this.prefix, this.localName);
    if (m == null) {
        throw new ELException(MessageFactory.get("error.fnMapper.method",
                this.getOutputName()));
    }
    return m.getReturnType();
}
 
Example #10
Source File: AstValue.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public void setValue(EvaluationContext ctx, Object value)
        throws ELException {
    Target t = getTarget(ctx);
    ctx.setPropertyResolved(false);
    ELResolver resolver = ctx.getELResolver();

    // coerce to the expected type
    Class<?> targetClass = resolver.getType(ctx, t.base, t.property);
    if (COERCE_TO_ZERO == true
            || !isAssignable(value, targetClass)) {
        resolver.setValue(ctx, t.base, t.property,
                ELSupport.coerceToType(value, targetClass));
    } else {
        resolver.setValue(ctx, t.base, t.property, value);
    }
    if (!ctx.isPropertyResolved()) {
        throw new PropertyNotFoundException(MessageFactory.get(
                "error.resolver.unhandled", t.base, t.property));            
    }
}
 
Example #11
Source File: AstIdentifier.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public Class<?> getType(EvaluationContext ctx) throws ELException {
    VariableMapper varMapper = ctx.getVariableMapper();
    if (varMapper != null) {
        ValueExpression expr = varMapper.resolveVariable(this.image);
        if (expr != null) {
            return expr.getType(ctx.getELContext());
        }
    }
    ctx.setPropertyResolved(false);
    Class<?> result = ctx.getELResolver().getType(ctx, null, this.image);
    if (!ctx.isPropertyResolved()) {
        throw new PropertyNotFoundException(MessageFactory.get(
                "error.resolver.unhandled.null", this.image));
    }
    return result;
}
 
Example #12
Source File: AstIdentifier.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public Object getValue(EvaluationContext ctx) throws ELException {
    VariableMapper varMapper = ctx.getVariableMapper();
    if (varMapper != null) {
        ValueExpression expr = varMapper.resolveVariable(this.image);
        if (expr != null) {
            return expr.getValue(ctx.getELContext());
        }
    }
    ctx.setPropertyResolved(false);
    Object result = ctx.getELResolver().getValue(ctx, null, this.image);
    if (!ctx.isPropertyResolved()) {
        throw new PropertyNotFoundException(MessageFactory.get(
                "error.resolver.unhandled.null", this.image));
    }
    return result;
}
 
Example #13
Source File: AstIdentifier.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public void setValue(EvaluationContext ctx, Object value)
        throws ELException {
    VariableMapper varMapper = ctx.getVariableMapper();
    if (varMapper != null) {
        ValueExpression expr = varMapper.resolveVariable(this.image);
        if (expr != null) {
            expr.setValue(ctx.getELContext(), value);
            return;
        }
    }
    ctx.setPropertyResolved(false);
    ctx.getELResolver().setValue(ctx, null, this.image, value);
    if (!ctx.isPropertyResolved()) {
        throw new PropertyNotFoundException(MessageFactory.get(
                "error.resolver.unhandled.null", this.image));
    }
}
 
Example #14
Source File: ExpressionBuilder.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
public MethodExpression createMethodExpression(Class<?> expectedReturnType,
        Class<?>[] expectedParamTypes) throws ELException {
    Node n = this.build();
    if (!n.isParametersProvided() && expectedParamTypes == null) {
        throw new NullPointerException(MessageFactory
                .get("error.method.nullParms"));
    }
    if (n instanceof AstValue || n instanceof AstIdentifier) {
        return new MethodExpressionImpl(expression, n, this.fnMapper,
                this.varMapper, expectedReturnType, expectedParamTypes);
    } else if (n instanceof AstLiteralExpression) {
        return new MethodExpressionLiteral(expression, expectedReturnType,
                expectedParamTypes);
    } else {
        throw new ELException("Not a Valid Method Expression: "
                + expression);
    }
}
 
Example #15
Source File: ELArithmetic.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
protected final Number coerce(final Object obj) {

        if (isNumber(obj)) {
            return coerce((Number) obj);
        }
        if (obj == null || "".equals(obj)) {
            return coerce(ZERO);
        }
        if (obj instanceof String) {
            return coerce((String) obj);
        }
        if (obj instanceof Character) {
            return coerce(Short.valueOf((short) ((Character) obj).charValue()));
        }

        throw new IllegalArgumentException(MessageFactory.get("error.convert",
                obj, obj.getClass(), "Number"));
    }
 
Example #16
Source File: ELSupport.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static final Enum<?> coerceToEnum(final Object obj,
        @SuppressWarnings("rawtypes") Class type) {
    if (obj == null || "".equals(obj)) {
        return null;
    }
    if (type.isAssignableFrom(obj.getClass())) {
        return (Enum<?>) obj;
    }
    
    if (!(obj instanceof String)) {
        throw new ELException(MessageFactory.get("error.convert",
                obj, obj.getClass(), type));
    }

    Enum<?> result;
    try {
         result = Enum.valueOf(type, (String) obj);
    } catch (IllegalArgumentException iae) {
        throw new ELException(MessageFactory.get("error.convert",
                obj, obj.getClass(), type));
    }
    return result;
}
 
Example #17
Source File: ELSupport.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
public static final Character coerceToCharacter(final Object obj)
        throws ELException {
    if (obj == null || "".equals(obj)) {
        return Character.valueOf((char) 0);
    }
    if (obj instanceof String) {
        return Character.valueOf(((String) obj).charAt(0));
    }
    if (ELArithmetic.isNumber(obj)) {
        return Character.valueOf((char) ((Number) obj).shortValue());
    }
    Class<?> objType = obj.getClass();
    if (obj instanceof Character) {
        return (Character) obj;
    }

    throw new ELException(MessageFactory.get("error.convert",
            obj, objType, Character.class));
}
 
Example #18
Source File: ELSupport.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
public static final Number coerceToNumber(final Object obj,
        final Class<?> type) throws ELException {
    if (obj == null || "".equals(obj)) {
        return coerceToNumber(ZERO, type);
    }
    if (obj instanceof String) {
        return coerceToNumber((String) obj, type);
    }
    if (ELArithmetic.isNumber(obj)) {
        return coerceToNumber((Number) obj, type);
    }

    if (obj instanceof Character) {
        return coerceToNumber(Short.valueOf((short) ((Character) obj)
                .charValue()), type);
    }

    throw new ELException(MessageFactory.get("error.convert",
            obj, obj.getClass(), type));
}
 
Example #19
Source File: AstFunction.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Override
public Class<?> getType(EvaluationContext ctx)
        throws ELException {
    
    FunctionMapper fnMapper = ctx.getFunctionMapper();
    
    // quickly validate again for this request
    if (fnMapper == null) {
        throw new ELException(MessageFactory.get("error.fnMapper.null"));
    }
    Method m = fnMapper.resolveFunction(this.prefix, this.localName);
    if (m == null) {
        throw new ELException(MessageFactory.get("error.fnMapper.method",
                this.getOutputName()));
    }
    return m.getReturnType();
}
 
Example #20
Source File: AstValue.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Override
public void setValue(EvaluationContext ctx, Object value)
        throws ELException {
    Target t = getTarget(ctx);
    ctx.setPropertyResolved(false);
    ELResolver resolver = ctx.getELResolver();

    // coerce to the expected type
    Class<?> targetClass = resolver.getType(ctx, t.base, t.property);
    if (COERCE_TO_ZERO == true
            || !isAssignable(value, targetClass)) {
        resolver.setValue(ctx, t.base, t.property,
                ELSupport.coerceToType(value, targetClass));
    } else {
        resolver.setValue(ctx, t.base, t.property, value);
    }
    if (!ctx.isPropertyResolved()) {
        throw new PropertyNotFoundException(MessageFactory.get(
                "error.resolver.unhandled", t.base, t.property));            
    }
}
 
Example #21
Source File: AstIdentifier.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Override
public Class<?> getType(EvaluationContext ctx) throws ELException {
    VariableMapper varMapper = ctx.getVariableMapper();
    if (varMapper != null) {
        ValueExpression expr = varMapper.resolveVariable(this.image);
        if (expr != null) {
            return expr.getType(ctx.getELContext());
        }
    }
    ctx.setPropertyResolved(false);
    Class<?> result = ctx.getELResolver().getType(ctx, null, this.image);
    if (!ctx.isPropertyResolved()) {
        throw new PropertyNotFoundException(MessageFactory.get(
                "error.resolver.unhandled.null", this.image));
    }
    return result;
}
 
Example #22
Source File: AstIdentifier.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Override
public Object getValue(EvaluationContext ctx) throws ELException {
    VariableMapper varMapper = ctx.getVariableMapper();
    if (varMapper != null) {
        ValueExpression expr = varMapper.resolveVariable(this.image);
        if (expr != null) {
            return expr.getValue(ctx.getELContext());
        }
    }
    ctx.setPropertyResolved(false);
    Object result = ctx.getELResolver().getValue(ctx, null, this.image);
    if (!ctx.isPropertyResolved()) {
        throw new PropertyNotFoundException(MessageFactory.get(
                "error.resolver.unhandled.null", this.image));
    }
    return result;
}
 
Example #23
Source File: AstIdentifier.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isReadOnly(EvaluationContext ctx) throws ELException {
    VariableMapper varMapper = ctx.getVariableMapper();
    if (varMapper != null) {
        ValueExpression expr = varMapper.resolveVariable(this.image);
        if (expr != null) {
            return expr.isReadOnly(ctx.getELContext());
        }
    }
    ctx.setPropertyResolved(false);
    boolean result = ctx.getELResolver().isReadOnly(ctx, null, this.image);
    if (!ctx.isPropertyResolved()) {
        throw new PropertyNotFoundException(MessageFactory.get(
                "error.resolver.unhandled.null", this.image));
    }
    return result;
}
 
Example #24
Source File: AstIdentifier.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Override
public void setValue(EvaluationContext ctx, Object value)
        throws ELException {
    VariableMapper varMapper = ctx.getVariableMapper();
    if (varMapper != null) {
        ValueExpression expr = varMapper.resolveVariable(this.image);
        if (expr != null) {
            expr.setValue(ctx.getELContext(), value);
            return;
        }
    }
    ctx.setPropertyResolved(false);
    ctx.getELResolver().setValue(ctx, null, this.image, value);
    if (!ctx.isPropertyResolved()) {
        throw new PropertyNotFoundException(MessageFactory.get(
                "error.resolver.unhandled.null", this.image));
    }
}
 
Example #25
Source File: ExpressionBuilder.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
public MethodExpression createMethodExpression(Class<?> expectedReturnType,
        Class<?>[] expectedParamTypes) throws ELException {
    Node n = this.build();
    if (!n.isParametersProvided() && expectedParamTypes == null) {
        throw new NullPointerException(MessageFactory
                .get("error.method.nullParms"));
    }
    if (n instanceof AstValue || n instanceof AstIdentifier) {
        return new MethodExpressionImpl(expression, n, this.fnMapper,
                this.varMapper, expectedReturnType, expectedParamTypes);
    } else if (n instanceof AstLiteralExpression) {
        return new MethodExpressionLiteral(expression, expectedReturnType,
                expectedParamTypes);
    } else {
        throw new ELException("Not a Valid Method Expression: "
                + expression);
    }
}
 
Example #26
Source File: ELArithmetic.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
protected final Number coerce(final Object obj) {

        if (isNumber(obj)) {
            return coerce((Number) obj);
        }
        if (obj == null || "".equals(obj)) {
            return coerce(ZERO);
        }
        if (obj instanceof String) {
            return coerce((String) obj);
        }
        if (obj instanceof Character) {
            return coerce(Short.valueOf((short) ((Character) obj).charValue()));
        }

        throw new IllegalArgumentException(MessageFactory.get("error.convert",
                obj, obj.getClass(), "Number"));
    }
 
Example #27
Source File: ELSupport.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
public static final Number coerceToNumber(final Object obj,
        final Class<?> type) throws ELException {
    if (obj == null || "".equals(obj)) {
        return coerceToNumber(ZERO, type);
    }
    if (obj instanceof String) {
        return coerceToNumber((String) obj, type);
    }
    if (ELArithmetic.isNumber(obj)) {
        return coerceToNumber((Number) obj, type);
    }

    if (obj instanceof Character) {
        return coerceToNumber(Short.valueOf((short) ((Character) obj)
                .charValue()), type);
    }

    throw new ELException(MessageFactory.get("error.convert",
            obj, obj.getClass(), type));
}
 
Example #28
Source File: ELSupport.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Convert an object to Boolean.
 * Null and empty string are false.
 * @param obj the object to convert
 * @return the Boolean value of the object
 * @throws ELException if object is not Boolean or String
 */
public static final Boolean coerceToBoolean(final Object obj)
        throws ELException {
    if (obj == null || "".equals(obj)) {
        return Boolean.FALSE;
    }
    if (obj instanceof Boolean) {
        return (Boolean) obj;
    }
    if (obj instanceof String) {
        return Boolean.valueOf((String) obj);
    }

    throw new ELException(MessageFactory.get("error.convert",
            obj, obj.getClass(), Boolean.class));
}
 
Example #29
Source File: AstIdentifier.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isReadOnly(EvaluationContext ctx) throws ELException {
    VariableMapper varMapper = ctx.getVariableMapper();
    if (varMapper != null) {
        ValueExpression expr = varMapper.resolveVariable(this.image);
        if (expr != null) {
            return expr.isReadOnly(ctx.getELContext());
        }
    }
    ctx.setPropertyResolved(false);
    boolean result = ctx.getELResolver().isReadOnly(ctx, null, this.image);
    if (!ctx.isPropertyResolved()) {
        throw new PropertyNotFoundException(MessageFactory.get(
                "error.resolver.unhandled.null", this.image));
    }
    return result;
}
 
Example #30
Source File: AstValue.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Override
public Object getValue(EvaluationContext ctx) throws ELException {
    Object base = this.children[0].getValue(ctx);
    int propCount = this.jjtGetNumChildren();
    int i = 1;
    Object suffix = null;
    ELResolver resolver = ctx.getELResolver();
    while (base != null && i < propCount) {
        suffix = this.children[i].getValue(ctx);
        if (i + 1 < propCount &&
                (this.children[i+1] instanceof AstMethodParameters)) {
            AstMethodParameters mps =
                (AstMethodParameters) this.children[i+1];
            // This is a method
            Object[] paramValues = mps.getParameters(ctx);
            base = resolver.invoke(ctx, base, suffix,
                    getTypesFromValues(paramValues), paramValues);
            i+=2;
        } else {
            // This is a property
            if (suffix == null) {
                return null;
            }
            
            ctx.setPropertyResolved(false);
            base = resolver.getValue(ctx, base, suffix);
            i++;
        }
    }
    if (!ctx.isPropertyResolved()) {
        throw new PropertyNotFoundException(MessageFactory.get(
                "error.resolver.unhandled", base, suffix));            
    }
    return base;
}