[Jetspeed-japan-dev] Next build for jetspeed-japan & JetspeedUploadService

Back to archive index

Mamoru WATANABE mamor****@hotma*****
2003年 3月 10日 (月) 12:44:42 JST


----- Original Message ----- 
From: "Shinsuke SUGAYA" <shins****@yahoo*****>
To: <jetsp****@lists*****>
Sent: Saturday, March 08, 2003 1:18 AM
Subject: [Jetspeed-japan-dev] Next build for jetspeed-japan & JetspeedUploadService


> こんにちは.
> 
> そろそろ Jetspeed 日本語版を現在の CVS 版ベースでビルドしようと思います.
> Jakarta の方に統合されたパッチを取り除き,.vm の翻訳を確認する予定です.
> また,JetspeedUploadService も導入しようかと思っています.
> 
> その JetspeedUploadService ですが, eGroup にもありましたが,Turbine の
> MultipartStream に問題があるため使えないので Commons FileUpload を
> 使うことを考えています.(MultipartStream を Jetspeed 用に用意するのも
> あまり賢くないと思いますので・・・)ですので,ビルドと実行には,その jar ファイルが
> 必要になります.しかし,Commons FileUpload も完全に修正されていないので,
> Jetspeed の表示エンコーディングと App. サーバーのデフォルトエンコーディングが
> 異なる場合には文字化けを起こします・・・.バグ情報としては以下ものになります.
> ですので,Commons FileUpload に修正が入った時点で JetspeedUploadService
> も修正する予定です.何か JetspeedUploadService だけで修正する良い方法や
> コメントなどありましたら,お願いします.
> 
> http://issues.apache.org/bugzilla/show_bug.cgi?id=14120
> 
> shinsuke
> 


--------------------------------------------------------------------------------


> package org.apache.jetspeed.services.upload;
> 
> import java.io.IOException;
> import java.io.InputStream;
> import java.io.OutputStream;
> import java.util.Map;
> 
> import javax.servlet.http.HttpServletRequest;
> 
> import org.apache.turbine.util.ParameterParser;
> import org.apache.turbine.util.TurbineException;
> import org.apache.turbine.util.upload.FileItem;
> import org.apache.turbine.util.Log;
> import org.apache.turbine.services.upload.TurbineUploadService;
> import org.apache.turbine.services.upload.TurbineUpload;
> 
> import org.apache.commons.fileupload.MultipartStream;
> 
> import org.apache.jetspeed.om.registry.MediaTypeEntry;
> import org.apache.jetspeed.services.Registry;
> import org.apache.jetspeed.capability.CapabilityMap;
> import org.apache.jetspeed.capability.CapabilityMapFactory;
> import org.apache.jetspeed.services.resources.JetspeedResources;
> 
> 
> /**
>  * <p> This class is an implementation of {@link 
>  * org.apache.turbine.services.upload.UploadService}.
>  *
>  * <p> Files will be stored in temporary disk storage on in memory,
>  * depending on request size, and will be available from the {@link
>  * org.apache.turbine.util.ParameterParser} as {@link
>  * org.apache.turbine.util.upload.FileItem}s.
>  *
>  * <p>This implementation of {@link 
>  * org.apache.turbine.services.upload.UploadService} handles multiple
>  * files per single html widget, sent using multipar/mixed encoding
>  * type, as specified by RFC 1867.  Use {@link
>  * org.apache.turbine.util.ParameterParser#getFileItems(String)} to
>  * acquire an array of {@link
>  * org.apache.turbine.util.upload.FileItem}s associated with given
>  * html widget.
>  *
>  * @author <a href="mailto:shins****@yahoo*****">Shinsuke SUGAYA</a>
>  */
> public class JetspeedUploadService
>     extends TurbineUploadService
> {
>     private String encoding;
> 
>     /**
>      * <p> Processes an <a href="http://rf.cx/rfc1867.html">RFC
>      * 1867</a> compliant <code>multipart/form-data</code> stream.
>      *
>      * @param req The servlet request to be parsed.
>      * @param params The ParameterParser instance to insert form
>      * fields into.
>      * @param path The location where the files should be stored.
>      * @exception TurbineException If there are problems reading/parsing
>      * the request or storing files.
>      */
>     public void parseRequest( HttpServletRequest req,
>                               ParameterParser params,
>                               String path )
>         throws TurbineException
>     {
>         String contentType = req.getHeader(CONTENT_TYPE);
>         if(!contentType.startsWith(MULTIPART_FORM_DATA))
>         {
>             throw new TurbineException("the request doesn't contain a " +
>                 MULTIPART_FORM_DATA + " stream");
>         }
>         int requestSize = req.getContentLength();
>         if(requestSize == -1)
>         {
>             throw new TurbineException("the request was rejected because " +
>                 "it's size is unknown");
>         }
>         if(requestSize > TurbineUpload.getSizeMax())
>         {
>             throw new TurbineException("the request was rejected because " +
>                 "it's size exceeds allowed range");
>         }
> 
>         // get encoding info
>         encoding = JetspeedResources.getString(JetspeedResources.CONTENT_ENCODING_KEY,"US-ASCII");
>         CapabilityMap cm = CapabilityMapFactory.getCapabilityMap( 
>         req.getHeader("User-Agent") );
>         String mimeCode = cm.getPreferredType().getCode();
>         if ( mimeCode != null )
>         {
>             MediaTypeEntry media = (MediaTypeEntry)Registry.getEntry(Registry.MEDIA_TYPE, mimeCode);
>             if ( media != null && media.getCharacterSet() != null)
>             {
>                 encoding = media.getCharacterSet();
>             }
>         }
>         if ( req.getCharacterEncoding() != null )
>         {
>             encoding = req.getCharacterEncoding();
>         }
> 
>         try
>         {
>             byte[] boundary = contentType.substring(
>                                 contentType.indexOf("boundary=")+9).getBytes();
>             InputStream input = (InputStream)req.getInputStream();
> 
>             MultipartStream multi = new MultipartStream(input, boundary);
>             boolean nextPart = multi.skipPreamble();
>             while(nextPart)
>             {
>                 String header = multi.readHeaders();
>                 Map headers;
>                 try
>                 {
>                     headers = parseHeaders(new String(header.getBytes(), encoding));
>                 }
>                 catch (Exception e)
>                 {
>                     Log.warn("JetspeedUploadService: Exception: " + e.toString());
>                     headers = parseHeaders(header);
>                 }
> 
>                 String fieldName = getFieldName(headers);
>                 if (fieldName != null)
>                 {
>                     String subContentType = getHeader(headers, CONTENT_TYPE);
>                     if (subContentType != null && subContentType
>                                                 .startsWith(MULTIPART_MIXED))
>                     {
>                         // Multiple files.
>                         byte[] subBoundary =
>                             subContentType.substring(
>                                 subContentType
>                                 .indexOf("boundary=")+9).getBytes();
>                         multi.setBoundary(subBoundary);
>                         boolean nextSubPart = multi.skipPreamble();
>                         while (nextSubPart)
>                         {
>                             header = multi.readHeaders();
>                             try
>                             {
>                                 headers = parseHeaders(new String(header.getBytes(), encoding));
>                             }
>                             catch (Exception e)
>                             {
>                                 Log.warn("JetspeedUploadService: Exception: " + e.toString());
>                                 headers = parseHeaders(header);
>                             }
>                             if (getFileName(headers) != null)
>                             {
>                                 FileItem item = createItem(path, headers,
>                                                            requestSize);
>                                 OutputStream os = item.getOutputStream();
>                                 try
>                                 {
>                                     multi.readBodyData(os);
>                                 }
>                                 finally
>                                 {
>                                     os.close();
>                                 }
>                                 params.append(getFieldName(headers), item);
>                             }
>                             else
>                             {
>                                 // Ignore anything but files inside
>                                 // multipart/mixed.
>                                 multi.discardBodyData();
>                             }
>                             nextSubPart = multi.readBoundary();
>                         }
>                         multi.setBoundary(boundary);
>                     }
>                     else
>                     {
>                         if (getFileName(headers) != null)
>                         {
>                             // A single file.
>                             FileItem item = createItem(path, headers,
>                                                        requestSize);
>                             OutputStream os = item.getOutputStream();
>                             try
>                             {
>                                 multi.readBodyData(os);
>                             }
>                             finally
>                             {
>                                 os.close();
>                             }
>                             params.append(getFieldName(headers), item);
>                         }
>                         else
>                         {
>                             // A form field.
>                             FileItem item = createItem(path, headers,
>                                                        requestSize);
>                             OutputStream os = item.getOutputStream();
>                             try
>                             {
>                                 multi.readBodyData(os);
>                             }
>                             finally
>                             {
>                                 os.close();
>                             }
>                             params.append(getFieldName(headers),
>                                           new String(item.get()));
>                         }
>                     }
>                 }
>                 else
>                 {
>                     // Skip this part.
>                     multi.discardBodyData();
>                 }
>                 nextPart = multi.readBoundary();
>             }
>         }
>         catch(IOException e)
>         {
>             throw new TurbineException("Processing of " + MULTIPART_FORM_DATA
>                                        + " request failed", e);
>         }
> 
>     }
> 
> }
> 



Jetspeed-japan-dev メーリングリストの案内
Back to archive index