Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.analogweb.acf;
  
  import static org.analogweb.acf.CommonsFileUploadModulesConfig.PLUGIN_MESSAGE_RESOURCE;
  
  import java.io.File;
 import java.util.List;
 
 
 
 
     private static final Log log = Logs.getLog(MultipartParameterResolver.class);
     private FileItemFactory fileItemFactory;
     private FileUploadFactory<? extends FileUploadfileUploadFactory = new ServletFileUploadFactory();
     private final String defaultEncoding = "UTF-8";
             .getCanonicalName() + ".IS_MULTIPART_CONTENT";
 
     @Override
     public Object resolveValue(RequestContext requestContextInvocationMetadata metadata,
             String nameClass<?> requiredType,Annotation[] annotations) {
         if (requestContext instanceof ServletRequestContext) {
             HttpServletRequest request = ((ServletRequestContextrequestContext)
                     .getServletRequest();
             MultipartParameters<Multipartparameters = CurrentMultipartParameters.get(request);
             if (parameters == null) {
                 if (isMultipartContentOnCurrentRequest(request)) {
                     .log("DACF000001");
                     FileUpload fileUpload = getFileUpload(getFileItemFactory());
                     .log("DACF000002"new Object[] { fileUpload });
                     String encoding = resolveEncoding(request);
                     .log("DACF000003"new Object[] { encoding });
                     try {
                         parameters = createMultipartParameters(request,
                                 createRequestContext(request), fileUploadencoding);
                         CurrentMultipartParameters.put(requestparameters);
                     } catch (FileUploadException e) {
                         throw new FileUploadFailureException(e);
                     } catch (IOException e) {
                         throw new FileUploadFailureException(e);
                     }
                 } else {
                     return super.resolveValue(requestContextmetadatanamerequiredType,annotations);
                 }
             }
             if (isEqualsType(Iterable.classrequiredType)) {
                 return parameters;
             }
             Multipart[] value = parameters.getMultiparts(name);
             if (ArrayUtils.isNotEmpty(value)) {
                 .log("TACF000004"new Object[] { namevalue });
                 if (isEqualsType(File[].classrequiredType)) {
                     List<Filefiles = new ArrayList<File>();
                     for (Multipart mp : value) {
                         files.add(TemporaryUploadFolder.require(requestContextmp));
                     }
                     return files.toArray(new File[files.size()]);
                 } else if (isEqualsType(Multipart[].classrequiredType)) {
                     return value;
                 }
                 Multipart mp = value[0];
                 if (isEqualsType(InputStream.classrequiredType)) {
                     return mp.getInputStream();
                 } else if (isEqualsType(File.classrequiredType)) {
                     return TemporaryUploadFolder.require(requestContextmp);
                 } else if (isEqualsType(byte[].classrequiredType)) {
                     return mp.getBytes();
                 } else if (isEqualsType(Multipart.classrequiredType)) {
                     return mp;
                 } else {
                     throw new UnsupportedParameterTypeException(namerequiredType);
                 }
             }
         }
         return super.resolveValue(requestContextmetadatanamerequiredTypeannotations);
     }
 
     protected boolean isMultipartContentOnCurrentRequest(HttpServletRequest request) {
         Object value = request.getAttribute();
        Boolean isMultipartContentOnCurrentRequest;
        if (value instanceof Boolean) {
            isMultipartContentOnCurrentRequest = (Booleanvalue;
        } else {
            isMultipartContentOnCurrentRequest = ServletFileUpload.isMultipartContent(request);
            request.setAttribute(isMultipartContentOnCurrentRequest);
        }
        return isMultipartContentOnCurrentRequest;
    }
    protected String resolveEncoding(HttpServletRequest request) {
        String encoding = request.getCharacterEncoding();
        if (StringUtils.isNotEmpty(encoding)) {
            return encoding;
        }
        return this.;
    }
    @SuppressWarnings("unchecked")
    protected <T extends MultipartMultipartParameters<T> createMultipartParameters(
            HttpServletRequest requestorg.apache.commons.fileupload.RequestContext context,
            FileUpload fileUploadString resolvedEncodingthrows FileUploadExceptionIOException {
        List<FileItemfileItems = fileUpload.parseRequest(context);
        .log("TACF000003"fileItems.size());
        FileItemIterator iterator = fileUpload.getItemIterator(context);
        return (MultipartParameters<T>) new FileItemIteratorMultipartParameters(iterator,
                resolvedEncoding);
    }
            HttpServletRequest request) {
        return new org.apache.commons.fileupload.servlet.ServletRequestContext(request);
    }
    protected FileItemFactory getFileItemFactory() {
        return this.;
    }
    protected FileUpload getFileUpload(FileItemFactory fileItemFactory) {
        if (fileItemFactory != null) {
            return .createFileUpload(fileItemFactory);
        } else {
            return .createFileUpload();
        }
    }
    private boolean isEqualsType(Class<?> clazzClass<?> clazz2) {
        return (clazz == clazz2) || clazz.getCanonicalName().equals(clazz2.getCanonicalName());
    }
    public void setFileItemFactory(FileItemFactory fileItemFactory) {
        this. = fileItemFactory;
    }
    public void setFileUploadFactory(FileUploadFactory<? extends FileUploadfileUploadFactory) {
        this. = fileUploadFactory;
    }
New to GrepCode? Check out our FAQ X