Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2008-2023 The Aspectran Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.aspectran.core.context.expr;
import com.aspectran.core.activity.Activity;
import com.aspectran.core.activity.request.FileParameter;
import com.aspectran.core.component.bean.NoSuchBeanException;
import com.aspectran.core.component.bean.NoUniqueBeanException;
import com.aspectran.core.component.template.TemplateRenderer;
import com.aspectran.core.context.expr.token.Token;
import com.aspectran.core.context.rule.type.TokenDirectiveType;
import com.aspectran.core.context.rule.type.TokenType;
import com.aspectran.core.util.BeanUtils;
import com.aspectran.core.util.PropertiesLoaderUtils;
import com.aspectran.core.util.ReflectionUtils;
import com.aspectran.core.util.SystemUtils;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
/**
* The Class TokenEvaluation.
*
*
Created: 2008. 03. 29 AM 12:59:16
*/
public class TokenEvaluation implements TokenEvaluator {
protected final Activity activity;
/**
* Instantiates a new token expression parser.
*
* @param activity the current Activity
*/
public TokenEvaluation(Activity activity) {
if (activity == null) {
throw new IllegalArgumentException("activity must not be null");
}
this.activity = activity;
}
@Override
public Activity getActivity() {
return activity;
}
@Override
public Object evaluate(Token token) {
try {
TokenType tokenType = token.getType();
Object value = null;
if (tokenType == TokenType.TEXT) {
value = token.getDefaultValue();
} else if (tokenType == TokenType.BEAN) {
value = getBean(token);
} else if (tokenType == TokenType.TEMPLATE) {
value = getTemplate(token);
} else if (tokenType == TokenType.PARAMETER) {
String[] values = getParameterValues(token.getName());
if (values == null || values.length == 0) {
value = token.getDefaultValue();
} else if (values.length > 1 && token.getDefaultValue() == null) {
value = values;
} else {
value = (values[0] != null ? values[0] : token.getDefaultValue());
}
} else if (tokenType == TokenType.ATTRIBUTE) {
value = getAttribute(token);
} else if (tokenType == TokenType.PROPERTY) {
value = getProperty(token);
}
return value;
} catch (Exception e) {
throw new TokenEvaluationException(token, e);
}
}
@Override
public Object evaluate(Token[] tokens) {
if (tokens == null || tokens.length == 0) {
return null;
}
if (tokens.length > 1) {
StringBuilder sb = new StringBuilder();
for (Token t : tokens) {
Object value = evaluate(t);
if (value != null) {
if (value instanceof Object[]) {
sb.append(Arrays.toString((Object[])value));
} else {
sb.append(value);
}
}
}
return sb.toString();
} else {
return evaluate(tokens[0]);
}
}
@Override
public void evaluate(Token[] tokens, Writer writer) throws IOException {
if (tokens == null || tokens.length == 0) {
return;
}
for (Token t : tokens) {
Object value = evaluate(t);
if (value != null) {
writer.write(value.toString());
}
}
writer.flush();
}
@Override
public String evaluateAsString(Token[] tokens) {
Object value = evaluate(tokens);
if (value instanceof Object[]) {
return Arrays.toString((Object[])value);
} else if (value != null) {
return value.toString();
} else {
return null;
}
}
@Override
public List