use of org.apache.struts.upload.FormFile in project sonarqube by SonarSource.
the class RequestUtils method rationalizeMultipleFileProperty.
/**
* <p>If the given form bean can accept multiple FormFile objects but the user only uploaded a single, then
* the property will not match the form bean type. This method performs some simple checks to try to accommodate
* that situation.</p>
* @param bean
* @param name
* @param parameterValue
* @return
* @throws ServletException if the introspection has any errors.
*/
private static Object rationalizeMultipleFileProperty(Object bean, String name, Object parameterValue) throws ServletException {
if (!(parameterValue instanceof FormFile))
return parameterValue;
FormFile formFileValue = (FormFile) parameterValue;
try {
Class propertyType = PropertyUtils.getPropertyType(bean, name);
if (propertyType.isAssignableFrom(List.class)) {
ArrayList list = new ArrayList(1);
list.add(formFileValue);
return list;
}
if (propertyType.isArray() && propertyType.getComponentType().equals(FormFile.class)) {
return new FormFile[] { formFileValue };
}
} catch (IllegalAccessException e) {
throw new ServletException(e);
} catch (InvocationTargetException e) {
throw new ServletException(e);
} catch (NoSuchMethodException e) {
throw new ServletException(e);
}
// no changes
return parameterValue;
}
Aggregations