Search in sources :

Example 16 with FormFile

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;
}
Also used : ServletException(javax.servlet.ServletException) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) FormFile(org.apache.struts.upload.FormFile)

Aggregations

FormFile (org.apache.struts.upload.FormFile)16 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)6 InputStream (java.io.InputStream)5 ArrayList (java.util.ArrayList)4 ClientCustActionForm (org.mifos.customers.client.struts.actionforms.ClientCustActionForm)4 BirtReportsUploadActionForm (org.mifos.reports.struts.actionforms.BirtReportsUploadActionForm)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ClientNameDetailDto (org.mifos.dto.screen.ClientNameDetailDto)3 UploadedFileDto (org.mifos.dto.screen.UploadedFileDto)3 ReportsBO (org.mifos.reports.business.ReportsBO)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 List (java.util.List)2 ActionMessage (org.apache.struts.action.ActionMessage)2 Test (org.junit.Test)2 AccountActionEntity (org.mifos.accounts.business.AccountActionEntity)2 AccountStateEntity (org.mifos.accounts.business.AccountStateEntity)2 CustomFieldDto (org.mifos.dto.domain.CustomFieldDto)2