001 /* 002 * Copyright (c) 2009 The openGion Project. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 013 * either express or implied. See the License for the specific language 014 * governing permissions and limitations under the License. 015 */ 016 package org.opengion.hayabusa.servlet; 017 018 import org.opengion.hayabusa.common.HybsSystem; 019 import org.opengion.hayabusa.servlet.multipart.MultipartParser; 020 import org.opengion.hayabusa.servlet.multipart.Part; 021 import org.opengion.hayabusa.servlet.multipart.FilePart; 022 import org.opengion.hayabusa.servlet.multipart.ParamPart; 023 024 import java.io.File; 025 import java.io.IOException; 026 import java.util.Map; 027 // import java.util.HashMap; 028 import java.util.TreeMap; 029 import java.util.List; 030 import java.util.ArrayList; 031 import java.util.Set; 032 import java.util.Random ; 033 import java.util.concurrent.atomic.AtomicInteger; // 5.5.2.6 (2012/05/25) findbugs対å¿? 034 import javax.servlet.http.HttpServletRequest; 035 036 /** 037 * ファイルをサーãƒã?ã«ã‚¢ãƒ??ãƒãƒ¼ãƒ‰ã™ã‚‹å?åˆã«ä½¿ç”¨ã•れるã?ルãƒãƒ‘ートå?ç?‚µãƒ¼ãƒ–レãƒ?ƒˆã§ã™ã? 038 * 039 * 通常ã®ãƒ•ァイルアãƒ??ãƒãƒ¼ãƒ‰æ™‚ã®ã€form ã§ä½¿ç”¨ã™ã‚‹ã€enctype="multipart/form-data" 040 * を指定ã—ãŸå?åˆã?ã€ä»–ã?ãƒªã‚¯ã‚¨ã‚¹ãƒˆæƒ…å ±ã‚‚ã?å–り出ã™ã“ã¨ãŒå¯èƒ½ã§ã™ã? 041 * 042 * ファイルをアãƒ??ãƒãƒ¼ãƒ‰å¾Œã«ã€æŒ‡å®šã?ファイルåã«å¤‰æ›´ã™ã‚‹æ©Ÿè?ãŒã‚りã¾ã™ã? 043 * file 登録ãƒ?‚¤ã‚¢ãƒã‚°ã§æŒ?®šã—ã?name ã«ã€?_NEW" ã¨ã?†å称を付ã‘ãŸãƒªã‚¯ã‚¨ã‚¹ãƒˆå?ã‚? 044 * ファイルã®ã‚¢ãƒ??ãƒãƒ¼ãƒ‰ã¨åŒæ™‚ã«é€ä¿¡ã™ã‚‹ã“ã¨ã§ã€ã“ã®åå‰ã«ãƒ•ã‚¡ã‚¤ãƒ«ã‚’ä»˜ã‘æ›¿ãˆã¾ã™ã? 045 * ã¾ãŸã?ã‚¢ãƒ??ãƒãƒ¼ãƒ‰å¾Œã?ファイルåã?ã€name æŒ?®šã?åç§°ã§ã€å–りå?ã›ã¾ã™ã? 046 * クライアントã‹ã‚‰ç™»éŒ²ã—ãŸã‚ªãƒªã‚¸ãƒŠãƒ«ã®ãƒ•ァイルåã?ã€name ã«ã€?_ORG" ã¨ã?†åç§° 047 * ã§å–り出ã™ã“ã¨ãŒå¯èƒ½ã§ã™ã? 048 * 049 * maxPostSize : æœ?¤§è»¢é€ã‚µã‚¤ã‚º(Byte)を指定ã—ã¾ã™ã? 0,ã¾ãŸã?マイナスã§ç„¡åˆ¶é™ã§ã™ã? 050 * useBackup : ファイルアãƒ??ãƒãƒ¼ãƒ‰æ™‚ã«ã€ã™ã§ã«åŒåã®ãƒ•ァイルãŒå˜åœ¨ã—ãŸå ´åˆã«ã€? 051 * ãƒãƒƒã‚¯ã‚¢ãƒ??処ç?renameTo)ã™ã‚‹ã‹ã©ã?‹[true/false]を指定ã—ã¾ã?åˆæœŸå€¤:false) 052 * 053 * ファイルアãƒ??ãƒãƒ¼ãƒ‰æ™‚ã«ã€ã‚¢ãƒ??ãƒãƒ¼ãƒ‰å?ã«ã€åŒåã?ファイルãŒå˜åœ¨ã—ãŸå ´åˆã?ã€æ—¢å˜æ©Ÿè?ã¯ã€ãã®ã¾ã¾ 054 * ç½®ãæ›ãˆã¦ã?¾ã—ãŸãŒã?簡易ãƒãƒ¼ã‚¸ãƒ§ãƒ³ã‚¢ãƒ??機è?ã¨ã—ã¦ã€useBackup="true" を指定ã™ã‚‹ã¨ã€æ—¢å˜ã?ファイルã‚? 055 * リãƒã?ãƒ?—ã¦ã€ãƒãƒ?‚¯ã‚¢ãƒ??ファイルを作æ?ã—ã¾ã™ã? 056 * ãƒãƒƒã‚¯ã‚¢ãƒ??ファイルã¯ã€ã‚¢ãƒ??ãƒãƒ¼ãƒ‰ãƒ•ォルãƒ?‚’基準ã¨ã—ã¦ã€_backup/ファイルå?æ‹¡å¼µå_処ç?™‚刻ã®long値.æ‹¡å¼µå?ã«ãªã‚Šã¾ã™ã? 057 * オリジナルã®ãƒ•ァイルå(拡張å付)を残ã—ãŸã¾ã¾ã€?_処ç?™‚刻ã®long値" を追åŠ?—ã€ã•らã«ã€ã‚ªãƒªã‚¸ãƒŠãƒ«ã®æ‹¡å¼µåを追åŠ?—ã¾ã™ã? 058 * ãƒãƒƒã‚¯ã‚¢ãƒ??ファイルã®å½¢å¼ã?æŒ?®šã§ãã¾ã›ã‚“ã€? 059 * 060 * @og.group ãã?他機è? 061 * 062 * @version 4.0 063 * @author Kazuhiko Hasegawa 064 * @since JDK5.0, 065 */ 066 public final class MultipartRequest { 067 // private static volatile int dumyNewFileCnt = 1 ; // 3.8.1.4 (2006/03/17) 068 private static AtomicInteger dumyNewFileCnt = new AtomicInteger(1); // 5.5.2.6 (2012/05/25) findbugs対å¿? 069 070 private static String RANDOM_KEY = new Random().nextInt() + "_" ; // 5.6.5.3 (2013/06/28) ã‚¢ãƒ??ãƒãƒ¼ãƒ‰æ™‚ã®ãƒ?ƒŸãƒ¼ãƒ•ァイルåã‚’ã‚‚ã†å°‘ã—ã?‘ランãƒ?ƒ ã«ã™ã‚‹ã€? 071 072 // private final Map<String,List<String>> parameters = new HashMap<String,List<String>>(); 073 // private final Map<String,UploadedFile> files = new HashMap<String,UploadedFile>(); 074 private final Map<String,List<String>> parameters = new TreeMap<String,List<String>>(); // 5.6.5.2 (2013/06/21) ソートã—ã¾ã™ã? 075 076 // 5.7.1.1 (2013/12/13) HTML5 ファイルアãƒ??ãƒãƒ¼ãƒ‰ã?è¤?•°é¸æŠžï¼?ultiple?‰å¯¾å¿? 077 // private final Map<String,UploadedFile> files = new TreeMap<String,UploadedFile>(); // 5.6.5.2 (2013/06/21) ソートã—ã¾ã™ã? 078 private final List<UploadedFile> files = new ArrayList<UploadedFile>(); // 5.7.1.1 (2013/12/13) HTML5対å¿? 079 080 /** 081 * MultipartRequest オブジェクトを構築ã—ã¾ã™ã? 082 * 083 * 引数ã¨ã—ã¦ã€ãƒ•ァイルアãƒ??ãƒãƒ¼ãƒ‰æ™‚ã®ä¿å˜ãƒ•ォルãƒ??æœ?¤§ã‚µã‚¤ã‚ºã€ã‚¨ãƒ³ã‚³ãƒ¼ãƒ‰ã? 084 * æ–°ã—ã„ファイルåãªã©ã‚’指定ã§ãã¾ã™ã?æ–°ã—ã„ファイルåã?ã€ã‚¢ãƒ??ãƒãƒ¼ãƒ‰ã•れる 085 * ファイルãŒä¸?¤ã?‘ã®å ´åˆã«ä½¿ç”¨ã§ãã¾ã™ã?è¤?•°ã®ãƒ•ã‚¡ã‚¤ãƒ«ã‚’åŒæ™‚ã«å¤‰æ›´ã—ãŸã? 086 * å ´åˆã?ã€ã‚¢ãƒ??ãƒãƒ¼ãƒ‰ãƒ«ãƒ¼ãƒ«ã«ã®ã£ã¨ã‚Šã?ãƒªã‚¯ã‚¨ã‚¹ãƒˆãƒ‘ãƒ©ãƒ¡ãƒ¼ã‚¿ã§æŒ?®šã—ã¦ãã ã•ã„ã€? 087 * 088 * HTML5 ã§ã¯ã€ãƒ•ァイルアãƒ??ãƒãƒ¼ãƒ‰æ™‚ã«ã€multiple 属æ???nputã‚¿ã‚°ã®type="file"?‰ã‚’ 089 * 付ã‘る事ã§ã€ãƒ•ァイルをè¤?•°é¸æŠžã§ãã¾ã™ã? 090 * ãã?å ´åˆã?ã€inputã®name属æ?ã¯ã€ä¸?¤ãªã®ã§ã€_NEW ã«ã‚ˆã‚‹åå‰ã®æ›¸ãæ›ãˆã?ã§ãã¾ã›ã‚“ã€? 091 * 092 * @og.rev 3.8.1.3A (2006/01/30) 新ファイルåã«ã‚ªãƒªã‚¸ãƒŠãƒ«ãƒ•ァイルåã?æ‹¡å¼µåã‚’ã‚»ãƒ?ƒˆã—ã¾ã? 093 * @og.rev 4.0.0.0 (2007/11/28) メソãƒ?ƒ‰ã®æˆ»ã‚Šå?ã‚’ãƒã‚§ãƒ?‚¯ã—ã¾ã™ã? 094 * @og.rev 5.5.2.6 (2012/05/25) findbugs対応ã?staticフィールドã¸ã®æ›¸ãè¾¼ã¿ã«ã€AtomicInteger を利用ã—ã¾ã™ã? 095 * @og.rev 5.6.5.3 (2013/06/28) useBackup引数追åŠ? 096 * @og.rev 5.7.1.1 (2013/12/13) HTML5 ファイルアãƒ??ãƒãƒ¼ãƒ‰ã?è¤?•°é¸æŠžï¼?ultiple?‰å¯¾å¿? 097 * 098 * @param request HttpServletRequestオブジェクãƒ? 099 * @param saveDirectory ファイルアãƒ??ãƒãƒ¼ãƒ‰ãŒã‚ã£ãŸå?åˆã?ä¿å˜ãƒ•ォルãƒ? 100 * @param maxPostSize ファイルアãƒ??ãƒãƒ¼ãƒ‰æ™‚ã®æœ?¤§ãƒ•ァイルサイズ(Byte)0,ã¾ãŸã?マイナスã§ç„¡åˆ¶é™? 101 * @param encoding ファイルã®ã‚¨ãƒ³ã‚³ãƒ¼ãƒ? 102 * @param inputFilename ã‚¢ãƒ??ãƒãƒ¼ãƒ‰ã•れãŸãƒ•ã‚¡ã‚¤ãƒ«ã®æ–°ã—ã„åå‰ 103 * @param useBackup ファイルアãƒ??ãƒãƒ¼ãƒ‰æ™‚ã«ã€ãƒãƒ?‚¯ã‚¢ãƒ??処ç?™ã‚‹ã‹ã©ã?‹[true/false]を指å®? 104 * @throws IOException 105 */ 106 public MultipartRequest(final HttpServletRequest request, 107 final String saveDirectory, 108 final int maxPostSize, 109 final String encoding, 110 // final String inputFilename ) throws IOException { 111 final String inputFilename, 112 final boolean useBackup ) throws IOException { // 5.6.5.3 (2013/06/28) 追åŠ? 113 114 if(request == null) { 115 throw new IllegalArgumentException("request cannot be null"); 116 } 117 if(saveDirectory == null) { 118 throw new IllegalArgumentException("saveDirectory cannot be null"); 119 } 120 // 5.5.2.6 (2012/05/25) 0,ã¾ãŸã?マイナスã§ç„¡åˆ¶é™? 121 // if(maxPostSize <= 0) { 122 // throw new IllegalArgumentException("maxPostSize must be positive"); 123 // } 124 125 // Save the dir 126 File dir = new File(saveDirectory); 127 128 // Check saveDirectory is truly a directory 129 if(!dir.isDirectory()) { 130 throw new IllegalArgumentException("Not a directory: " + saveDirectory); 131 } 132 133 // Check saveDirectory is writable 134 if(!dir.canWrite()) { 135 throw new IllegalArgumentException("Not writable: " + saveDirectory); 136 } 137 138 // Parse the incoming multipart, storing files in the dir provided, 139 // and populate the meta objects which describe what we found 140 MultipartParser parser = new MultipartParser(request, maxPostSize); 141 if(encoding != null) { 142 parser.setEncoding(encoding); 143 } 144 145 // 5.7.1.1 (2013/12/13) HTML5 ファイルアãƒ??ãƒãƒ¼ãƒ‰ã?è¤?•°é¸æŠžï¼?ultiple?‰å¯¾å¿? 146 // List<String> list = new ArrayList<String>(); 147 148 Part part; 149 while ((part = parser.readNextPart()) != null) { 150 String name = part.getName(); 151 if( part.isParam() && part instanceof ParamPart ) { 152 ParamPart paramPart = (ParamPart)part; 153 String value = paramPart.getStringValue(); 154 List<String> existingValues = parameters.get(name); 155 if(existingValues == null) { 156 existingValues = new ArrayList<String>(); 157 parameters.put(name, existingValues); 158 } 159 existingValues.add(value); 160 } 161 else if( part.isFile() && part instanceof FilePart ) { 162 FilePart filePart = (FilePart)part; 163 // String fileName = filePart.getFilename(); 164 String orgName = filePart.getFilename(); // 5.7.1.1 (2013/12/13) 判りやã™ã„よã†ã«å¤‰æ•°å変更 165 // if(fileName != null) { 166 if(orgName != null) { 167 // 5.7.1.1 (2013/12/13) HTML5 ファイルアãƒ??ãƒãƒ¼ãƒ‰ã?è¤?•°é¸æŠžï¼?ultiple?‰å¯¾å¿? 168 // åŒä¸?name ã§ã€è¤?•°ãƒ•ァイルを扱ã?¿?¦ãŒã‚りã¾ã™ã? 169 // list.add( name ); // 3.5.6.5 (2004/08/09) æŒ?®šã? name 属æ? 170 // 3.8.1.2 (2005/12/19) 仮ファイルã§ã‚»ãƒ¼ãƒ–ã™ã‚‹ã? 171 // String newName = String.valueOf( dumyNewFileCnt++ ) ; // 3.8.1.4 (2006/03/17) 172 // String newName = String.valueOf( dumyNewFileCnt.getAndIncrement() ) ; // 5.5.2.6 (2012/05/25) findbugs対å¿? 173 String tempName = RANDOM_KEY + dumyNewFileCnt.getAndIncrement() ; // 5.6.5.3 (2013/06/28) ã‚¢ãƒ??ãƒãƒ¼ãƒ‰æ™‚ã®ãƒ?ƒŸãƒ¼ãƒ•ァイルåã‚’ã‚‚ã†å°‘ã—ã?‘ランãƒ?ƒ ã«ã™ã‚‹ã€? 174 // filePart.setFilename( newName ); // 5.6.5.3 (2013/06/28) newName ã¯ã‚?‚„ã“ã—ã??ã§ã€å¤‰æ›´ 175 filePart.setFilename( tempName ); 176 filePart.writeTo(dir); 177 178 // 5.7.1.1 (2013/12/13) HTML5 ファイルアãƒ??ãƒãƒ¼ãƒ‰ã?è¤?•°é¸æŠžï¼?ultiple?‰å¯¾å¿? 179 files.add( new UploadedFile( 180 tempName, // 5.7.1.1 (2013/12/13) é ?•ªå¤‰æ›´ 181 dir.toString(), 182 name, // 5.7.1.1 (2013/12/13) é ?›®è¿½åŠ? 183 // fileName, 184 orgName, 185 filePart.getContentType())); 186 187 // files.put(name, 188 // new UploadedFile( dir.toString(), 189 //// newName, // 3.8.1.2 (2005/12/19) 190 // tempName, // 3.8.1.2 (2005/12/19) 191 // fileName, 192 // filePart.getContentType())); 193 } 194 // else { 195 // files.put(name, new UploadedFile(null, null, null, null)); 196 // } 197 } 198 else { 199 String errMsg = "PartオブジェクトãŒã€ParamPartã§ã‚?ilePartã§ã‚‚ã‚りã¾ã›ã‚“ã€? 200 + " class=[" + part.getClass() + "]"; 201 throw new RuntimeException( errMsg ); 202 } 203 } 204 205 // 3.5.6.5 (2004/08/09) 登録後ã«ãƒ•ァイルをリãƒã?ãƒ?—ã¾ã™ã? 206 // 5.7.1.1 (2013/12/13) HTML5 ファイルアãƒ??ãƒãƒ¼ãƒ‰ã?è¤?•°é¸æŠžï¼?ultiple?‰å¯¾å¿? 207 // int size = list.size(); 208 int size = files.size(); 209 for( int i=0; i<size; i++ ) { 210 // String name = list.get(i); 211 // File file = getFile( name ); 212 UploadedFile upFile = files.get(i); 213 String name = upFile.getName(); // 5.7.1.1 (2013/12/13) 214 215 String newName = inputFilename; 216 if( newName == null && name != null ) { 217 int adrs = name.lastIndexOf( HybsSystem.JOINT_STRING ); // カラãƒ?_è¡Œç•ªå· ã® __ ã®ä½ç½® 218 if( adrs < 0 ) { 219 newName = getParameter( name + "_NEW" ); 220 } 221 else { 222 newName = getParameter( name.substring( 0,adrs ) + "_NEW" + name.substring( adrs ) ); 223 } 224 } 225 226 // 5.7.1.1 (2013/12/13) UploadedFile å†?§å‡¦ç?™ã‚‹ã‚ˆã?«å¤‰æ›´ 227 upFile.renameTo( newName,useBackup ); 228 229 // // 3.8.1.3 (2006/02/06) 新ファイルåã«æ‹¡å¼µåãŒãªã?¨ã? 230 // // 旧ファイルåã‹ã‚‰æ‹¡å¼µåå–å¾—ã—æ–°ãƒ•ァイルåã«æ–?—å?連çµ? 231 // if( newName != null && newName.length() > 0 ) { 232 // // 新ファイルåã‹ã‚‰æ‹¡å¼µåå–å¾? 233 // String newExt = getExtension( newName ); 234 // if( newExt == null || newExt.length() == 0 ) { 235 //// String oldExt = getExtension( getOriginalFileName( name ) ); // 5.7.1.1 (2013/12/13) 236 // String oldExt = getExtension( upFile.getOriginalFileName() ); 237 //// newName = new StringBuilder().append( newName ).append( "." ).append( oldExt ).toString(); 238 // newName = newName + "." + oldExt ; 239 // } 240 // } 241 // else { 242 //// newName = getOriginalFileName( name ); // 5.7.1.1 (2013/12/13) 243 // newName = upFile.getOriginalFileName(); 244 // } 245 // 246 // // 3.8.1.2 (2005/12/19) 基本çš?«ã¯ã™ã¹ã¦ã®ã‚±ãƒ¼ã‚¹ã§ãƒ•ァイルå変更ãŒç™ºç”Ÿã™ã‚‹ã? 247 // File file = upFile.getFile(); // 5.7.1.1 (2013/12/13) 248 // if( file != null && newName != null && newName.length() > 0 ) { 249 // File newFile = new File( dir,newName ); 250 // 251 // // 5.6.5.3 (2013/06/28) useBackup ファイルアãƒ??ãƒãƒ¼ãƒ‰æ™‚ã«ã€ãƒãƒ?‚¯ã‚¢ãƒ??処ç?™ã‚‹ã‹ã©ã?‹[true/false]を指å®? 252 //// if( newFile.exists() && !newFile.delete() ) { 253 //// String errMsg = "æ—¢å˜ã?ファイル[" + newName + "]ãŒå‰Šé™¤ã§ãã¾ã›ã‚“ã§ã—ãŸã€?; 254 //// throw new RuntimeException( errMsg ); 255 //// } 256 // if( newFile.exists() ) { 257 // if( useBackup ) { 258 // // newName ã«ãƒ•ォルãƒ?šŽå±¤ã‚’å«ã‚??åˆã«ã€ããªãˆã¦ã€? 259 // File parent = newFile.getParentFile(); // ãƒãƒƒã‚¯ã‚¢ãƒ??ã™ã¹ãファイルã®ãƒ•ォルãƒ? 260 // File backup = new File( parent , "_backup" ); // ãã?直下ã«ã€?_backup" フォルãƒ?‚’作æ? 261 // if( backup != null && !backup.exists() && !backup.mkdirs() ) { 262 // String errMsg = "ãƒãƒƒã‚¯ã‚¢ãƒ??処ç?§backupフォルãƒ??作æ?ã«å¤±æ•—ã—ã¾ã—ãŸã€?" + backup + "]"; 263 // throw new RuntimeException( errMsg ); 264 // } 265 // // ãƒãƒƒã‚¯ã‚¢ãƒ??ファイルåã?ã€å?ã®ãƒ•ァイルå?æ‹¡å¼µåå«ã‚? ??"_" + ç¾åœ¨æ™‚刻ã®long値 + "." + å…??ãƒ•ã‚¡ã‚¤ãƒ«ã®æ‹¡å¼µå? 266 // String bkupName = newFile.getName() + "_" + System.currentTimeMillis() + "." + getExtension( newName ) ; 267 // File fromFile = new File( dir,newName ); // オリジナル㮠newFile ã‚’rename ã™ã‚‹ã¨ã¾ãšã„ã®ã§ã€åŒåã?Fileオブジェクトを作æ? 268 // File bkupFile = new File( backup,bkupName ); 269 // 270 // if( !fromFile.renameTo( bkupFile ) ) { 271 // String errMsg = "ãƒãƒƒã‚¯ã‚¢ãƒ??処ç?§ãƒãƒƒã‚¯ã‚¢ãƒ??ファイルをリãƒã?ãƒ?§ãã¾ã›ã‚“ã§ã—ãŸã€?" + bkupFile + "]" ; 272 // throw new RuntimeException( errMsg ); 273 // } 274 // } 275 // else if( !newFile.delete() ) { 276 // String errMsg = "æ—¢å˜ã?ファイル[" + newName + "]ãŒå‰Šé™¤ã§ãã¾ã›ã‚“ã§ã—ãŸã€?; 277 // throw new RuntimeException( errMsg ); 278 // } 279 // } 280 // 281 //// file.renameTo( newFile ); 282 // if( !file.renameTo( newFile ) ) { 283 // String errMsg = "æ‰?®šã?ファイルをリãƒã?ãƒ?§ãã¾ã›ã‚“ã§ã—ãŸã€?" + file + "]" ; 284 // throw new RuntimeException( errMsg ); 285 // } 286 //// UploadedFile fup = files.get( name ); 287 //// fup.setFilesystemName( newName ); 288 // upFile.setFilesystemName( newName ); 289 // } 290 } 291 } 292 293 /** 294 * リクエストパラメータã®åå‰é…å?ã‚’å–å¾—ã—ã¾ã™ã? 295 * 296 * @return リクエストパラメータã®åå‰é…å? 297 */ 298 public String[] getParameterNames() { 299 Set<String> keyset = parameters.keySet(); 300 return keyset.toArray( new String[keyset.size()] ); 301 } 302 303 /** 304 * ファイルアãƒ??ãƒãƒ¼ãƒ‰ã•れãŸãƒ•ァイル群ã®ãƒ•ァイルåé?列をå–å¾—ã—ã¾ã™ã? 305 * 306 * @og.rev 5.7.1.1 (2013/12/13) HTML5 ファイルアãƒ??ãƒãƒ¼ãƒ‰ã?è¤?•°é¸æŠžï¼?ultiple?‰å¯¾å¿œã?為ã€å»?¢ 307 * 308 * @return ã‚¢ãƒ??ãƒãƒ¼ãƒ‰ã•れãŸãƒ•ァイルåé?åˆ? 309 */ 310 // public String[] getFilenames() { 311 // Set<String> keyset = files.keySet(); 312 // return keyset.toArray( new String[keyset.size()] ); 313 // } 314 315 /** 316 * ファイルアãƒ??ãƒãƒ¼ãƒ‰ã•れãŸãƒ•ァイル群ã®ãƒ•ァイルé…å?ã‚’å–å¾—ã—ã¾ã™ã? 317 * 318 * @og.rev 5.7.1.1 (2013/12/13) HTML5 ファイルアãƒ??ãƒãƒ¼ãƒ‰ã?è¤?•°é¸æŠžï¼?ultiple?‰å¯¾å¿? 319 * 320 * @return ã‚¢ãƒ??ãƒãƒ¼ãƒ‰ã•れãŸãƒ•ァイル群 321 */ 322 public UploadedFile[] getUploadedFile() { 323 return files.toArray( new UploadedFile[files.size()] ); 324 } 325 326 /** 327 * æŒ?®šã?åå‰ã®ãƒªã‚¯ã‚¨ã‚¹ãƒˆãƒ‘ラメータã®å€¤ã‚’å–å¾—ã—ã¾ã™ã? 328 * 329 * è¤?•°å˜åœ¨ã™ã‚‹å ´åˆã?ã€ä¸?•ªæœ?¾Œã?値を返ã—ã¾ã™ã? 330 * 331 * @param name リクエストパラメータå? 332 * 333 * @return パラメータã®å€¤ 334 */ 335 public String getParameter( final String name ) { 336 List<String> values = parameters.get(name); 337 if( values == null || values.isEmpty() ) { 338 return null; 339 } 340 return values.get(values.size() - 1); 341 } 342 343 /** 344 * æŒ?®šã?åå‰ã®ãƒªã‚¯ã‚¨ã‚¹ãƒˆãƒ‘ラメータã®å€¤ã‚’é?列型å¼ã§å–å¾—ã—ã¾ã™ã? 345 * 346 * @og.rev 5.3.2.0 (2011/02/01) æ–°è¦ä½œæ? 347 * 348 * @param name リクエストパラメータå? 349 * 350 * @return パラメータã®å€¤é…å? 351 */ 352 public String[] getParameters( final String name ) { 353 List<String> values = parameters.get(name); 354 if( values == null || values.isEmpty() ) { 355 return null; 356 } 357 // return values.toArray( new String[0] ); 358 return values.toArray( new String[values.size()] ); 359 } 360 361 /** 362 * æŒ?®šã?åå‰ã®ãƒªã‚¯ã‚¨ã‚¹ãƒˆãƒ‘ラメータã®å€¤ã‚’é?åˆ?int)åž‹å¼ã§å–å¾—ã—ã¾ã™ã? 363 * 364 * @og.rev 5.3.2.0 (2011/02/01) æ–°è¦ä½œæ? 365 * @og.rev 5.3.6.0 (2011/06/01) é…å?値ã?"ã®å ´åˆã«NumberFormatExceptionãŒç™ºç”Ÿã™ã‚‹ãƒã‚°ã‚’ä¿®æ£ 366 * 367 * @param name リクエストパラメータå? 368 * 369 * @return パラメータã®å€¤é…å? 370 */ 371 public int[] getIntParameters( final String name ) { 372 List<String> values = parameters.get(name); 373 if( values == null || values.isEmpty() ) { 374 return null; 375 } 376 377 // int[] rtn = new int[values.size()]; 378 // for( int i=0; i<values.size(); i++ ) { 379 // rtn[i] = Integer.valueOf( values.get(i) ); 380 // } 381 382 // 5.3.6.0 (2011/06/01) ゼãƒã‚¹ãƒˆãƒªãƒ³ã‚°("")ã¯int変æ›å¯¾è±¡ã‹ã‚‰äºˆã‚除外ã™ã‚? 383 List<Integer> intVals = new ArrayList<Integer>(); 384 for( int i=0; i<values.size(); i++ ) { 385 String str = values.get(i); 386 if( str != null && str.length() > 0 ) { 387 intVals.add( Integer.parseInt( str ) ); 388 } 389 } 390 if( intVals.isEmpty() ) { 391 return null; 392 } 393 394 int[] rtn = new int[intVals.size()]; 395 for( int i=0; i<intVals.size(); i++ ) { 396 rtn[i] = intVals.get(i).intValue(); 397 } 398 399 return rtn; 400 } 401 402 /** 403 * æŒ?®šã?åå‰ã® UploadedFile オブジェクトã‹ã‚?登録ã•れるファイルåã‚’å–å¾—ã—ã¾ã™ã? 404 * 405 * 登録ã•れるファイルåã¨ã¯ã€æ–°ãŸã«æ›¸ãæ›ãˆã‚‰ã‚ŒãŸãƒ•ァイルåã?ã“ã¨ã§ã™ã? 406 * 407 * @og.rev 5.6.6.1 (2013/07/12) null 対ç? 408 * @og.rev 5.7.1.1 (2013/12/13) HTML5 ファイルアãƒ??ãƒãƒ¼ãƒ‰ã?è¤?•°é¸æŠžï¼?ultiple?‰å¯¾å¿œã?ãŸã‚å»?¢ 409 * 410 * @param name ã‚ーæƒ?? 411 * 412 * @return æ–°ãŸã«æ›¸ãæ›ãˆã‚‰ã‚ŒãŸãƒ•ァイルå? 413 */ 414 // public String getFilesystemName( final String name ) { 415 // UploadedFile file = files.get(name); 416 //// return file.getFilesystemName(); // may be null 417 // return (file == null) ? null : file.getFilesystemName(); // may be null 418 // } 419 420 /** 421 * æŒ?®šã?åå‰ã® UploadedFile オブジェクトã‹ã‚?ã‚¢ãƒ??ãƒãƒ¼ãƒ‰ã•れãŸãƒ•ァイルåã‚’å–å¾—ã—ã¾ã™ã? 422 * 423 * ã‚¢ãƒ??ãƒãƒ¼ãƒ‰ã•れãŸãƒ•ァイルåã¨ã¯ã€ã‚ªãƒªã‚¸ãƒŠãƒ«ã®ãƒ•ァイルåã?ã“ã¨ã§ã™ã? 424 * 425 * @og.rev 5.6.6.1 (2013/07/12) null 対ç? 426 * @og.rev 5.7.1.1 (2013/12/13) HTML5 ファイルアãƒ??ãƒãƒ¼ãƒ‰ã?è¤?•°é¸æŠžï¼?ultiple?‰å¯¾å¿œã?ãŸã‚å»?¢ 427 * 428 * @param name ã‚ーæƒ?? 429 * 430 * @return オリジナルã®ãƒ•ァイルå? 431 */ 432 // public String getOriginalFileName( final String name ) { 433 // UploadedFile file = files.get(name); 434 //// return file.getOriginalFileName(); // may be null 435 // return (file == null) ? null : file.getOriginalFileName(); // may be null 436 // } 437 438 /** 439 * æŒ?®šã?åå‰ã® UploadedFile オブジェクトã‹ã‚?File オブジェクトをå–å¾—ã—ã¾ã™ã? 440 * 441 * @og.rev 5.6.6.1 (2013/07/12) null 対ç? 442 * @og.rev 5.7.1.1 (2013/12/13) HTML5 ファイルアãƒ??ãƒãƒ¼ãƒ‰ã?è¤?•°é¸æŠžï¼?ultiple?‰å¯¾å¿? 443 * 444 * @param name ã‚ーæƒ?? 445 * 446 * @return Fileオブジェクãƒ? 447 */ 448 // public File getFile( final String name ) { 449 // UploadedFile file = files.get(name); 450 //// return file.getFile(); // may be null 451 // return (file == null) ? null : file.getFile(); // may be null 452 // } 453 454 /** 455 * ファイルåã‹ã‚?æ‹¡å¼µåã‚’å–å¾—ã—ã¾ã™ã? 456 * 457 * @og.rev 5.7.1.1 (2013/12/13) UploadedFileクラスã«ç§»å‹? 458 * 459 * @param fileName ファイルå? 460 * @return æ‹¡å¼µå? 461 */ 462 // private String getExtension( final String fileName ) { 463 // int index = fileName.lastIndexOf('.'); 464 // if(index!=-1) { 465 // return fileName.substring(index + 1, fileName.length()); 466 // } 467 // return ""; 468 // } 469 } 470 471 /** 472 * ファイルをサーãƒã?ã«ã‚¢ãƒ??ãƒãƒ¼ãƒ‰ã™ã‚‹å?åˆã«ä½¿ç”¨ã•れるファイル管ç??部クラスã§ã™ã? 473 * 474 * @og.group ãã?他機è? 475 * @og.rev 5.7.1.1 (2013/12/13) HTML5 ファイルアãƒ??ãƒãƒ¼ãƒ‰ã?è¤?•°é¸æŠžï¼?ultiple?‰å¯¾å¿œã?ãŸã‚ã€publicåŒ? 476 * 477 * @version 4.0 478 * @author Kazuhiko Hasegawa 479 * @since JDK5.0, 480 */ 481 //final class UploadedFile { 482 // 483 // private String filename; 484 // private final String name; 485 // private final String dir; 486 // private final String original; 487 // private final String type; 488 // 489 // /** 490 // * ã‚¢ãƒ??ãƒãƒ¼ãƒ‰ãƒ•ァイルã®ç®¡ç?‚ªãƒ–ジェクトを作æ?ã—ã¾ã™ã? 491 // * 492 // * @og.rev 5.7.1.1 (2013/12/13) HTML5 ファイルアãƒ??ãƒãƒ¼ãƒ‰ã?è¤?•°é¸æŠžï¼?ultiple?‰å¯¾å¿? 493 // * 494 // * @param dir ファイルをä¿ç®¡ã™ã‚‹ãƒ•ォルãƒ? 495 // * @param name ファイルアãƒ??ãƒãƒ¼ãƒ‰ã•ã‚ŒãŸæ™‚ã?name属æ? 496 // * @param filename ファイルå?ç½®ãæ›ãˆå¾? 497 // * @param original ファイルå?オリジナル) 498 // * @param type コンãƒ?ƒ³ãƒˆã‚¿ã‚¤ãƒ? 499 // */ 500 // UploadedFile( final String dir, final String name, final String filename, final String original, final String type) { 501 // this.dir = dir; 502 // this.name = name; 503 // this.filename = filename; 504 // this.original = original; 505 // this.type = type; 506 // } 507 // 508 // /** 509 // * ファイルアãƒ??ãƒãƒ¼ãƒ‰ã•ã‚ŒãŸæ™‚ã?name属æ?ã‚’å–å¾—ã—ã¾ã™ã? 510 // * 511 // * @og.rev 5.7.1.1 (2013/12/13) HTML5 ファイルアãƒ??ãƒãƒ¼ãƒ‰ã?è¤?•°é¸æŠžï¼?ultiple?‰å¯¾å¿? 512 // * 513 // * @return ファイルアãƒ??ãƒãƒ¼ãƒ‰ã•ã‚ŒãŸæ™‚ã?name属æ? 514 // */ 515 // public String getName() { 516 // return name; 517 // } 518 // 519 // /** 520 // * コンãƒ?ƒ³ãƒˆã‚¿ã‚¤ãƒ—ã‚’å–å¾—ã—ã¾ã™ã? 521 // * 522 // * @return コンãƒ?ƒ³ãƒˆã‚¿ã‚¤ãƒ? 523 // */ 524 // public String getContentType() { 525 // return type; 526 // } 527 // 528 // /** 529 // * ファイルå?ç½®ãæ›ãˆå¾?ã‚’å–å¾—ã—ã¾ã™ã? 530 // * 531 // * @return ファイルå?ç½®ãæ›ãˆå¾? 532 // */ 533 // public String getFilesystemName() { 534 // return filename; 535 // } 536 // 537 // /** 538 // * ファイルå?ç½®ãæ›ãˆå¾?ã‚’ã‚»ãƒ?ƒˆã—ã¾ã™ã? 539 // * 540 // * @param name ファイルå?ç½®ãæ›ãˆå¾? 541 // */ 542 // public void setFilesystemName( final String name ) { 543 // filename = name; 544 // } 545 // 546 // /** 547 // * ファイルå?オリジナル)ã‚’å–å¾—ã—ã¾ã™ã? 548 // * 549 // * @return ファイルå?オリジナル) 550 // */ 551 // public String getOriginalFileName() { 552 // return original; 553 // } 554 // 555 // /** 556 // * ファイルå?ç½®ãæ›ãˆå¾?ã® File オブジェクトをå–å¾—ã—ã¾ã™ã? 557 // * 558 // * @return File File オブジェクãƒ? 559 // */ 560 // public File getFile() { 561 // if(dir == null || filename == null) { 562 // return null; 563 // } 564 // else { 565 // return new File(dir + File.separator + filename); 566 // } 567 // } 568 //}