Coverage Report - org.seasar.cubby.plugins.guice.FileUploadModule
 
Classes in this File Line Coverage Branch Coverage Complexity
FileUploadModule
71%
5/7
N/A
1
 
 1  
 /*
 2  
  * Copyright 2004-2009 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package org.seasar.cubby.plugins.guice;
 17  
 
 18  
 import javax.servlet.http.HttpServletRequest;
 19  
 
 20  
 import org.apache.commons.fileupload.FileItemFactory;
 21  
 import org.apache.commons.fileupload.FileUpload;
 22  
 import org.apache.commons.fileupload.RequestContext;
 23  
 import org.apache.commons.fileupload.disk.DiskFileItemFactory;
 24  
 import org.apache.commons.fileupload.servlet.ServletFileUpload;
 25  
 import org.apache.commons.fileupload.servlet.ServletRequestContext;
 26  
 
 27  
 import com.google.inject.AbstractModule;
 28  
 import com.google.inject.Provides;
 29  
 import com.google.inject.servlet.RequestScoped;
 30  
 
 31  
 /**
 32  
  * commons-fileupload の設定を行います。
 33  
  * <p>
 34  
  * {@link org.apache.commons.fileupload.disk.DiskFileItemFactory}
 35  
  * はテンポラリにローカルファイルシステムを使用します。Goolgle&nbsp;App&nbsp;Engine
 36  
  * のようにファイルシステムへの書き込みに制限がある場合は
 37  
  * {@link org.apache.commons.fileupload.disk.DiskFileItemFactory} ではなく、
 38  
  * {@link org.seasar.cubby.fileupload.StreamFileItemFactory} を試してみてください。
 39  
  * これはマルチパートのデータをテンポラリを使用せずにオンメモリで処理します。
 40  
  * </p>
 41  
  */
 42  1
 public class FileUploadModule extends AbstractModule {
 43  
 
 44  
         /**
 45  
          * {@inheritDoc}
 46  
          */
 47  
         @Override
 48  
         protected void configure() {
 49  1
         }
 50  
 
 51  
         @Provides
 52  
         FileUpload provideFileUpload() {
 53  2
                 final FileItemFactory fileItemFactory = new DiskFileItemFactory();
 54  2
                 final FileUpload fileUpload = new ServletFileUpload(fileItemFactory);
 55  2
                 return fileUpload;
 56  
         }
 57  
 
 58  
         @Provides
 59  
         @RequestScoped
 60  
         RequestContext provideRequestContext(final HttpServletRequest request) {
 61  0
                 final RequestContext requestContext = new ServletRequestContext(request);
 62  0
                 return requestContext;
 63  
         }
 64  
 
 65  
 }