<commit_before>/*
 * The Gemma project
 * 
 * Copyright (c) 2005 Columbia University
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package edu.columbia.gemma.web.flow;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.validation.DataBinder;
import org.springframework.validation.Errors;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.springframework.web.multipart.support.ByteArrayMultipartFileEditor;
import org.springframework.webflow.Event;
import org.springframework.webflow.RequestContext;
import org.springframework.webflow.execution.servlet.ServletEvent;

import edu.columbia.gemma.web.Constants;
import edu.columbia.gemma.web.controller.common.auditAndSecurity.FileUpload;

/**
 * A flow version of the Spring MVC-based FileUploadController. Code taken partly from example.
 * <hr>
 * <p>
 * Copyright (c) 2004-2005 Columbia University
 * 
 * @spring.bean name="uploadFileAction"
 * @author keshav
 * @author pavlidis
 * @version $Id$
 */
public class FileUploadAction extends AbstractFlowFormAction {

    private static Log log = LogFactory.getLog( FileUploadAction.class.getName() );

    public FileUploadAction() {
        setFormObjectName( "file" );
        setFormObjectClass( FileUpload.class );
    }

    /**
     * 
     */
    @SuppressWarnings("unused")
    @Override
    protected void initBinder( RequestContext context, DataBinder binder ) {
        /*
         * to actually be able to convert a multipart object to a byte[] we have to register a custom editor (in this
         * case the ByteArrayMultipartFileEditor)
         */
        binder.registerCustomEditor( byte[].class, new ByteArrayMultipartFileEditor() );
        /* now Spring knows how to handle multipart objects and convert them */
    }

    /**
     * @param context
     * @return Event
     * @throws Exception
     */
    @Override
    public Event doExecute( RequestContext context ) throws Exception {
        assert context != null;

        CommonsMultipartFile file = ( CommonsMultipartFile ) context.getSourceEvent().getAttribute( "file" );
        log.debug( file );

        String filename = ( String ) context.getSourceEvent().getAttribute( "name" );

        /* validate a file was entered */
        if ( file.getBytes().length == 0 ) {
            // Errors errors = getFormObjectAccessor( context ).getFormErrors();
            // FIXME - errors are not getting displayed.
            Errors errors = this.getFormErrors( context );
            errors.reject( "file", "Must enter a file." );
            return error();
        }
<commit_msg>*** empty log message ***<commit_after>/*
 * The Gemma project
 * 
 * Copyright (c) 2005 Columbia University
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package edu.columbia.gemma.web.flow;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.validation.DataBinder;
import org.springframework.validation.Errors;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.springframework.web.multipart.support.ByteArrayMultipartFileEditor;
import org.springframework.webflow.Event;
import org.springframework.webflow.RequestContext;
import org.springframework.webflow.action.FormObjectAccessor;
import org.springframework.webflow.execution.servlet.ServletEvent;

import edu.columbia.gemma.web.Constants;
import edu.columbia.gemma.web.controller.common.auditAndSecurity.FileUpload;

/**
 * A flow version of the Spring MVC-based FileUploadController. Code taken partly from example.
 * <hr>
 * <p>
 * Copyright (c) 2004-2005 Columbia University
 * 
 * @spring.bean name="uploadFileAction"
 * @author keshav
 * @author pavlidis
 * @version $Id$
 */
public class FileUploadAction extends AbstractFlowFormAction {

    private static Log log = LogFactory.getLog( FileUploadAction.class.getName() );

    public FileUploadAction() {
        setFormObjectName( "file" );
        setFormObjectClass( FileUpload.class );
    }

    /**
     * 
     */
    @SuppressWarnings("unused")
    @Override
    protected void initBinder( RequestContext context, DataBinder binder ) {
        /*
         * to actually be able to convert a multipart object to a byte[] we have to register a custom editor (in this
         * case the ByteArrayMultipartFileEditor)
         */
        binder.registerCustomEditor( byte[].class, new ByteArrayMultipartFileEditor() );
        /* now Spring knows how to handle multipart objects and convert them */
    }

    /**
     * @param context
     * @return Event
     * @throws Exception
     */
    @Override
    public Event doExecute( RequestContext context ) throws Exception {
        assert context != null;

        CommonsMultipartFile file = ( CommonsMultipartFile ) context.getSourceEvent().getAttribute( "file" );
        log.debug( file );

        String filename = ( String ) context.getSourceEvent().getAttribute( "name" );

        /* validate the file that was entered */
        if ( file.getBytes().length == 0 ) {
            // Errors errors = getFormObjectAccessor( context ).getFormErrors();
            // FIXME - errors are not getting displayed.
            Errors errors = this.getFormErrors( context );
            log.debug(errors);
            errors.reject( "file", "Must enter a file." );
            return error();
        }

{'fraction_non_alphanumeric': 0.09566894096707208, 'fraction_numerical': 0.005043013942450311, 'mean_word_length': 3.294904458598726, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6124797', 'n_tokens_mistral': 1803, 'n_tokens_neox': 1763, 'n_words': 556}