FormData getFormData(HttpServletRequest request, FilterConfig filterConfig, boolean create) throws Exception {
if (filterConfig == null) {
return null;
}
Object data = null;
ParamConfig attribute = filterConfig.getParamConfig("attribute");
if (attribute != null) {
ParamConfig scope = filterConfig.getParamConfig("scope");
if (scope != null && "request".equals(scope.getValue())) {
data = request.getAttribute(attribute.getValue());
} else {
data = request.getSession().getAttribute(attribute.getValue());
}
}
if (data == null && create) {
ParamConfig clazz = filterConfig.getParamConfig("class");
if (clazz != null) {
data = loader.loadClass(clazz.getValue()).newInstance();
} else if (defaultDataClass != null) { // use default class
data = defaultDataClass.newInstance();
}
if (data != null) {
if (attribute != null) {
ParamConfig scope = filterConfig.getParamConfig("scope");
if (scope != null && "request".equals(scope.getValue())) {
request.setAttribute(attribute.getValue(), data);
} else {
request.getSession().setAttribute(attribute.getValue(), data);
}
}