Example usage for org.springframework.web.multipart.support ByteArrayMultipartFileEditor ByteArrayMultipartFileEditor

List of usage examples for org.springframework.web.multipart.support ByteArrayMultipartFileEditor ByteArrayMultipartFileEditor

Introduction

In this page you can find the example usage for org.springframework.web.multipart.support ByteArrayMultipartFileEditor ByteArrayMultipartFileEditor.

Prototype

ByteArrayMultipartFileEditor

Source Link

Usage

From source file:com.jaspersoft.jasperserver.war.action.FileResourceAction.java

/**
 * Registers a byte array editor to allow spring handle File uploads as byte
 * arrays//from w  w  w . j  a  v a 2s  .  c  o  m
 */
protected void initBinder(RequestContext context, DataBinder binder) {
    binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor());
}

From source file:com.jaspersoft.jasperserver.war.action.ViewReportAction.java

protected void initBinder(RequestContext context, DataBinder binder) {
    binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor());
}

From source file:org.codehaus.groovy.grails.web.binding.GrailsDataBinder.java

/**
 * Utility method for creating a GrailsDataBinder instance
 *
 * @param target The target object to bind to
 * @param objectName The name of the object
 * @return A GrailsDataBinder instance//from   www .ja v a2s.  co m
 */
public static GrailsDataBinder createBinder(Object target, String objectName) {
    GrailsDataBinder binder = new GrailsDataBinder(target, objectName);
    binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor());
    binder.registerCustomEditor(String.class, new StringMultipartFileEditor());
    binder.registerCustomEditor(Currency.class, new CurrencyEditor());
    binder.registerCustomEditor(Locale.class, new LocaleEditor());
    binder.registerCustomEditor(TimeZone.class, new TimeZoneEditor());
    binder.registerCustomEditor(URI.class, new UriEditor());
    //        GenericConversionService conversionService = new GenericConversionService();
    //        conversionService.addConverter(new GenericConverter() {
    //
    //            @Override
    //            public Set<ConvertiblePair> getConvertibleTypes() {
    //                return Collections.singleton(new ConvertiblePair(Map.class, Object.class));
    //            }
    //
    //            @Override
    //            public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
    //                Object obj = BeanUtils.instantiate(targetType.getObjectType());
    //                createBinder(obj, obj.getClass().getName()).bind(new MutablePropertyValues((Map<?, ?>) source));
    //                return obj;
    //            }
    //        });
    //        binder.setConversionService(conversionService);

    final GrailsWebRequest webRequest = GrailsWebRequest.lookup();
    if (webRequest == null) {
        registerCustomEditors(null, binder);
    } else {
        initializeFromWebRequest(binder, webRequest);
        Locale locale = RequestContextUtils.getLocale(webRequest.getCurrentRequest());
        registerCustomEditors(webRequest, binder, locale);
    }

    return binder;
}

From source file:org.sakaiproject.gradebook.gwt.sakai.GradebookImportController.java

public void initializeBinder(HttpServletRequest request, ServletRequestDataBinder binder)
        throws ServletException {
    // to actually be able to convert Multipart instance to byte[]
    // we have to register a custom editor
    binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor());
    // now Spring knows how to handle multipart object and convert them
}

From source file:org.sakaiproject.myshowcase.tool.MyShowcaseFileUploadController.java

protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws ServletException {
    System.out.println("MyShowcaseFileUploadController initBinder Start");
    try {/*from   www  .ja  v  a2 s. c o m*/
        binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor());
    } catch (Exception e) {
        System.out.println("MyShowcaseFileController initBinder Error");
        System.out.println(e.toString());
    }
    System.out.println("MyShowcaseFileUploadController initBinder End");
}

From source file:org.springframework.web.multipart.commons.CommonsMultipartResolverTests.java

private void doTestBinding(MockCommonsMultipartResolver resolver, MockHttpServletRequest originalRequest,
        MultipartHttpServletRequest request) throws UnsupportedEncodingException {

    MultipartTestBean1 mtb1 = new MultipartTestBean1();
    assertArrayEquals(null, mtb1.getField1());
    assertEquals(null, mtb1.getField2());
    ServletRequestDataBinder binder = new ServletRequestDataBinder(mtb1, "mybean");
    binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor());
    binder.bind(request);//from  w  w w  .  ja  v a2  s.c o  m
    List<MultipartFile> file1List = request.getFiles("field1");
    CommonsMultipartFile file1a = (CommonsMultipartFile) file1List.get(0);
    CommonsMultipartFile file1b = (CommonsMultipartFile) file1List.get(1);
    CommonsMultipartFile file2 = (CommonsMultipartFile) request.getFile("field2");
    assertEquals(file1a, mtb1.getField1()[0]);
    assertEquals(file1b, mtb1.getField1()[1]);
    assertEquals(new String(file2.getBytes()), new String(mtb1.getField2()));

    MultipartTestBean2 mtb2 = new MultipartTestBean2();
    assertArrayEquals(null, mtb2.getField1());
    assertEquals(null, mtb2.getField2());
    binder = new ServletRequestDataBinder(mtb2, "mybean");
    binder.registerCustomEditor(String.class, "field1", new StringMultipartFileEditor());
    binder.registerCustomEditor(String.class, "field2", new StringMultipartFileEditor("UTF-16"));
    binder.bind(request);
    assertEquals(new String(file1a.getBytes()), mtb2.getField1()[0]);
    assertEquals(new String(file1b.getBytes()), mtb2.getField1()[1]);
    assertEquals(new String(file2.getBytes(), "UTF-16"), mtb2.getField2());

    resolver.cleanupMultipart(request);
    assertTrue(((MockFileItem) file1a.getFileItem()).deleted);
    assertTrue(((MockFileItem) file1b.getFileItem()).deleted);
    assertTrue(((MockFileItem) file2.getFileItem()).deleted);

    resolver.setEmpty(true);
    request = resolver.resolveMultipart(originalRequest);
    binder.setBindEmptyMultipartFiles(false);
    String firstBound = mtb2.getField2();
    binder.bind(request);
    assertFalse(mtb2.getField2().isEmpty());
    assertEquals(firstBound, mtb2.getField2());

    request = resolver.resolveMultipart(originalRequest);
    binder.setBindEmptyMultipartFiles(true);
    binder.bind(request);
    assertTrue(mtb2.getField2().isEmpty());
}

From source file:org.webcurator.ui.target.controller.TargetSeedsHandler.java

@Override
public void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
    // Determine the necessary formats.
    NumberFormat nf = NumberFormat.getInstance(request.getLocale());

    // Register the binders.
    binder.registerCustomEditor(Long.class, new CustomNumberEditor(Long.class, nf, true));

    // to actually be able to convert Multipart instance to byte[]
    // we have to register a custom editor (in this case the
    // ByteArrayMultipartEditor
    binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor());
    // now Spring knows how to handle multipart object and convert them
}

From source file:org.webcurator.ui.tools.controller.TreeToolController.java

@Override
public void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
    // Determine the necessary formats.
    NumberFormat nf = NumberFormat.getInstance(request.getLocale());

    // Register the binders.
    binder.registerCustomEditor(Long.class, new CustomNumberEditor(Long.class, nf, true));
    binder.registerCustomEditor(Boolean.class, "propagateDelete", new CustomBooleanEditor(true));

    // to actually be able to convert Multipart instance to byte[]
    // we have to register a custom editor (in this case the
    // ByteArrayMultipartEditor
    binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor());
    // now Spring knows how to handle multipart object and convert them
}

From source file:ubic.gemma.web.controller.BaseFormController.java

/**
 * Set up a custom property editor for converting form inputs to real objects. Override this to add additional
 * custom editors (call super.initBinder() in your implementation)
 *//*  w  ww.j ava2 s.  com*/
@InitBinder
protected void initBinder(WebDataBinder binder) {
    NumberFormat nf = NumberFormat.getNumberInstance();
    binder.registerCustomEditor(Integer.class, null, new CustomNumberEditor(Integer.class, nf, true));
    binder.registerCustomEditor(Long.class, null, new CustomNumberEditor(Long.class, nf, true));
    binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor());
}