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.taglib; 017 018 import org.opengion.hayabusa.common.HybsSystem; 019 import org.opengion.hayabusa.common.HybsSystemException; 020 import org.opengion.fukurou.util.FileString; 021 import org.opengion.fukurou.util.FileUtil; 022 023 import org.opengion.fukurou.util.StringUtil ; 024 import static org.opengion.fukurou.util.StringUtil.nval ; 025 026 import java.io.File; 027 import java.io.InputStream; 028 import java.io.IOException; 029 030 /** 031 * å?¨®ã‚¢ã‚¯ã‚·ãƒ§ãƒ³ã‚’指定ã—ã¦ã€ãƒ•ã‚¡ã‚¤ãƒ«é–¢é€£ã®æ“作をãŠã“ãªã?‚¿ã‚°ã§ã™ã? 032 * 033 * å?¨®ã‚¢ã‚¯ã‚·ãƒ§ãƒ³ ã«å¿œã˜ãŸæŒ¯ã‚‹è?ã?‚’行ã„ã¾ã™ã? 034 * çµæžœã«ã¤ã?¦ã¯ã€false ã®å ´åˆã?ã€body è¦ç´?‚’表示ã—ã¦ã€çµ‚äº?—ã¾ã™ã? 035 * ã“れã¯ã€BODYã«ã‚¨ãƒ©ãƒ¼ãƒ¡ãƒ?‚»ãƒ¼ã‚¸ã‚’書ã?¦ãŠãã“ã¨ã‚’想定ã—ãŸä½œã‚Šã«ãªã£ã¦ã?¾ã™ã? 036 037 * åˆ¤å®šçµæžœã‚’å転ã—ãŸã??åˆã?ã€notEquals 属æ?を使用ã—ã¦ãã ã•ã„。ã¾ãŸã? 038 * çµæžœã«å¿œã˜ã¦ã€å?ç?‚’æ¢ã‚ãŸããªã??åˆã?ã€useStop 属æ?ã‚?false ã«æŒ?®šã™ã‚‹ã“ã¨ã§ã€? 039 * 後続å?ç?‚’実行ã§ãã¾ã™ã? 040 * 041 * [å?¨®ã‚¢ã‚¯ã‚·ãƒ§ãƒ³] 042 * canRead èªã¿è¾¼ã‚ã‚‹ã‹ã©ã?‹ã‚’判定ã? 043 * canWrite 変更ã§ãã‚‹ã‹ã©ã?‹åˆ¤å®šã? 044 * createNewFile ç©ºã®æ–°ã—ã„ファイルをä¸å¯åˆ?(atomic) ã«ç”Ÿæ?ã€?ãã?ファイルãŒã¾ã?˜åœ¨ã—ãªã??åˆã ã? 045 * delete ファイルã¾ãŸã?ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’削除ã€? 046 * renameTo ファイルã¾ãŸã?ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªåを変更ã€? 047 * exists ファイルãŒå˜åœ¨ã™ã‚‹ã‹ã©ã?‹åˆ¤å®šã? 048 * isDirectory ファイルãŒãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã§ã‚ã‚‹ã‹ã©ã?‹åˆ¤å®šã? 049 * isFile ãƒ•ã‚¡ã‚¤ãƒ«ãŒæ™®é€šã?ファイルã‹ã©ã?‹åˆ¤å®šã? 050 * isHidden ファイルãŒéš ã—ファイルã‹ã©ã?‹åˆ¤å®šã? 051 * mkdir ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’生æˆã? 052 * mkdirs ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’è¤?•°ç”Ÿæ?ã€? 053 * read ファイルをèªã¿è¾¼ã‚“ã§jspWriterã«å‡ºåŠ? 054 * existsLength ファイルサイズãŒï¼Byte以上ã?ファイルãŒå˜åœ¨ã™ã‚‹ã‹ã©ã?‹åˆ¤å®šã? 055 * copy ファイルã¾ãŸã?ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’コピã?(file1 â‡?file2 ã«ã‚³ãƒ”ã?)ã€? 056 * 057 * @og.formSample 058 * â—å½¢å¼ï¼?lt;og:file action="…" fileURL="…" >?¥?¥?¥</og:file> 059 * â—body?šã‚ã‚?EVAL_BODY_INCLUDE:BODYをインクルードã—ã€{@XXXX} ã¯è§£æžã—ã¾ã›ã‚“) 060 * 061 * â—Tag定義?? 062 * <og:file 063 * action â—‹ã?TAG】アクション(canRead,canWrite,createNewFile,delete,exists,isDirectory,isFile,isHidden,mkdir,mkdirs)を指定ã—ã¾ã?å¿??)ã€? 064 * fileURL ã€TAG】æ“作ã™ã‚‹ãƒ•ァイルã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’指定ã—ã¾ã?(åˆæœŸå€¤:FILE_URL[=filetemp/]) 065 * file1 ã€TAG】基準ã¨ãªã‚‹ãƒ•ァイルåã‚’æŒ?®šã—ã¾ã?コマンドã?左辺ã®ãƒ•ァイルåã§ã? 066 * file2 ã€TAG】å?ç?µæžœã¨ãªã‚‹ãƒ•ァイルåã‚’æŒ?®šã—ã¾ã?コマンドã?å³è¾ºã®ãƒ•ァイルåã§ã? 067 * notEquals ã€TAGã€‘åˆ¤å®šçµæžœã‚’å転ã•ã›ã‚‹ã‹ã©ã?‹[true/false]を指定ã—ã¾ã?åˆæœŸå€¤:false) 068 * useStop ã€TAG】エラーæ™?ODYã‚’å?ç?¾Œã«åœæ¢ã™ã‚‹ã‹ã©ã?‹[true/false]を指定ã—ã¾ã?åˆæœŸå€¤:true) 069 * encode ã€TAG】ファイルをèªã¿è¾¼ã‚?action="READ")éš›ã?エンコードをæŒ?®šã—ã¾ã?åˆæœŸå€¤:OSä¾å˜æ–‡å—コーãƒ? 070 * debug ã€TAG】デãƒãƒƒã‚°æƒ??ã‚’å?力ã™ã‚‹ã‹ã©ã?‹[true/false]を指定ã—ã¾ã?åˆæœŸå€¤:false) 071 * > ... Body ... 072 * </og:file> 073 * 074 * â—使用ä¾? 075 * ・ファイルã®å˜åœ¨ãƒã‚§ãƒ?‚¯â†’å˜åœ¨ã—ãªã‘れã°ã‚¨ãƒ©ãƒ¼ãƒ¡ãƒ?‚»ãƒ¼ã‚¸ã‚’表示ã€? 076 * <og:file action="exists" fileURL="N:/CIR/" file1="{@USER.LKISB}/{@USER.LDNO1KAI}.cir/001.sht"> 077 * <og:message lbl="RKE_0157" comment="回路図ãŒå˜åœ¨ã—ã¾ã›ã‚“ã€? /> 078 * </og:file> 079 * 080 * ・N:/Filetemp/ã«ãƒ¦ãƒ¼ã‚¶ãƒ¼ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªãŒå˜åœ¨ã—ãªã‘れã°ä½œæ?。â?失敗ã—ãŸå?åˆã‚¨ãƒ©ãƒ¼ãƒ¡ãƒ?‚»ãƒ¼ã‚¸ã‚’表示ã€? 081 * <og:file action="mkdir" fileURL="N:/Filetemp/{@USER.ID}" > 082 * <og:message comment="エラーãŒç™ºç”Ÿã—ã¾ã—ãŸã€‚シスãƒ?ƒ 管ç??ã«é€£çµ¡ã—ã¦ãã ã•ã„ã€? /> 083 * </og:file> 084 * 085 * ・N:/Filetemp/test.txt ファイルã®å‰Šé™¤ã€‚ファイルãŒå˜åœ¨ã—ãªãã¦ã‚‚å?ç?‚’ç¶šã‘ã‚‹ã? 086 * <og:file action="delete" fileURL="N:/Filetemp/" file1="test.txt" useStop="false" > 087 * <og:message comment="ファイルã¯å˜åœ¨ã—ã¾ã›ã‚“ã§ã—ãŸã€? /> 088 * </og:file> 089 * 090 * @og.group ãã?他部å“? 091 * 092 * @version 4.0 093 * @author Kazuhiko Hasegawa 094 * @since JDK5.0, 095 */ 096 public class FileTag extends CommonTagSupport { 097 //* ã“ã?プãƒã‚°ãƒ©ãƒ??VERSIONæ–?—å?ã‚’è¨å®šã—ã¾ã™ã? {@value} */ 098 private static final String VERSION = "5.7.1.1 (2013/12/13)" ; 099 100 private static final long serialVersionUID = 571120131213L ; 101 102 /** action å¼•æ•°ã«æ¸¡ã™äº‹ã?出æ¥ã‚?アクションコマンãƒ? èªã¿è¾¼ã‚ã‚‹ã‹ã©ã?‹ {@value} */ 103 public static final String ACT_CANREAD = "canRead" ; 104 /** action å¼•æ•°ã«æ¸¡ã™äº‹ã?出æ¥ã‚?アクションコマンãƒ? 変更ã§ãã‚‹ã‹ã©ã?‹ {@value} */ 105 public static final String ACT_CANWRITE = "canWrite" ; 106 /** action å¼•æ•°ã«æ¸¡ã™äº‹ã?出æ¥ã‚?アクションコマンãƒ? ç©ºã®æ–°ã—ã„ファイルをä¸å¯åˆ?(atomic) ã«ç”Ÿæ?ã—ã¾ã?(ãã?ファイルãŒã¾ã?˜åœ¨ã—ãªã??åˆã ã?{@value} */ 107 public static final String ACT_CREATENEWFILE = "createNewFile" ; 108 /** action å¼•æ•°ã«æ¸¡ã™äº‹ã?出æ¥ã‚?アクションコマンãƒ? ファイルã¾ãŸã?ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’削除{@value} */ 109 public static final String ACT_DELETE = "delete" ; 110 /** action å¼•æ•°ã«æ¸¡ã™äº‹ã?出æ¥ã‚?アクションコマンãƒ? ファイルãŒå˜åœ¨ã™ã‚‹ã‹ã©ã?‹ {@value} */ 111 public static final String ACT_EXISTS = "exists" ; 112 /** action å¼•æ•°ã«æ¸¡ã™äº‹ã?出æ¥ã‚?アクションコマンãƒ? ファイルãŒãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã§ã‚ã‚‹ã‹ã©ã?‹{@value} */ 113 public static final String ACT_ISDIRECTORY = "isDirectory" ; 114 /** action å¼•æ•°ã«æ¸¡ã™äº‹ã?出æ¥ã‚?アクションコマンãƒ? ãƒ•ã‚¡ã‚¤ãƒ«ãŒæ™®é€šã?ファイルã‹ã©ã?‹{@value} */ 115 public static final String ACT_ISFILE = "isFile" ; 116 /** action å¼•æ•°ã«æ¸¡ã™äº‹ã?出æ¥ã‚?アクションコマンãƒ? ファイルãŒéš ã—ファイルã‹ã©ã?‹ {@value} */ 117 public static final String ACT_ISHIDDEN = "isHidden" ; 118 /** action å¼•æ•°ã«æ¸¡ã™äº‹ã?出æ¥ã‚?アクションコマンãƒ? ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’生æˆã—ã¾ã™ã? {@value} */ 119 public static final String ACT_MKDIR = "mkdir" ; 120 /** action å¼•æ•°ã«æ¸¡ã™äº‹ã?出æ¥ã‚?アクションコマンãƒ? ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’生æˆã—ã¾ã™ã? {@value} */ 121 public static final String ACT_MKDIRS = "mkdirs" ; 122 /** action å¼•æ•°ã«æ¸¡ã™äº‹ã?出æ¥ã‚?アクションコマンãƒ? ファイルåを変更ã—ã¾ã™ã? {@value} */ 123 public static final String ACT_RENAMETO = "renameTo" ; // 3.5.6.5 (2004/08/09) 124 /** action å¼•æ•°ã«æ¸¡ã™äº‹ã?出æ¥ã‚?アクションコマンãƒ? ファイルをèªã¿è¾¼ã‚“ã§è¡¨ç¤ºã—ã¾ã™ã? {@value} */ 125 public static final String ACT_READ = "read" ; // 3.6.0.0 (2004/09/25) 126 /** action å¼•æ•°ã«æ¸¡ã™äº‹ã?出æ¥ã‚?アクションコマンãƒ? ファイルサイズãŒï¼Byte以上ã?ファイルãŒå˜åœ¨ã™ã‚‹ã‹ã©ã?‹åˆ¤å®šã? {@value} */ 127 public static final String ACT_EXISTSLENGTH = "existsLength" ; // 3.8.5.2 (2006/05/31) 128 /** action å¼•æ•°ã«æ¸¡ã™äº‹ã?出æ¥ã‚?アクションコマンãƒ? ファイルã¾ãŸã?ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’コピã?ã—ã¾ã™ã? {@value} */ 129 public static final String ACT_COPY = "copy" ; // 5.3.6.0 (2011/06/01) 130 131 /** action å¼•æ•°ã«æ¸¡ã™äº‹ã?出æ¥ã‚?コマンãƒ?リスãƒ? */ 132 private static final String[] ACTION_LIST = new String[] { 133 ACT_CANREAD , ACT_CANWRITE , ACT_CREATENEWFILE , ACT_DELETE , ACT_EXISTS , ACT_ISDIRECTORY , 134 ACT_ISFILE , ACT_ISHIDDEN , ACT_MKDIR , ACT_MKDIRS , ACT_RENAMETO , ACT_READ , ACT_EXISTSLENGTH , ACT_COPY }; 135 136 private String fileURL = HybsSystem.sys( "FILE_URL" ); 137 private String file1 = ""; 138 private String file2 = null; 139 private String action = null; 140 private boolean rtnCode = false; 141 142 private boolean notEquals = false; // 3.8.5.2 (2006/05/31) åˆ¤å®šçµæžœã‚’å転ã•ã›ã¦å‡¦ç?—ã¾ã™ã? 143 private boolean useStop = true; // 3.8.5.2 (2006/05/31) エラーæ™?ODYã‚’å?ç?¾Œã«åœæ¢(true)ã™ã‚‹ã‹ã©ã?‹ 144 145 private String encode = null; // 5.1.9.0 (2010/08/01) READ時ã?エンコード指å®? 146 147 /** 148 * Taglibã®é–‹å§‹ã‚¿ã‚°ãŒè¦‹ã¤ã‹ã£ãŸã¨ãã«å‡¦ç?™ã‚?doStartTag() ã‚?オーãƒã?ライドã—ã¾ã™ã? 149 * 150 * @og.rev 3.6.0.0 (2004/09/25) file オブジェクトã?作æ?ã‚?actionExec ç§»å‹? 151 * @og.rev 3.8.5.2 (2006/05/31) notEquals追åŠ?? åˆ¤å®šçµæžœã‚’å転ã•ã›ã¦å‡¦ç?—ã¾ã™ã? 152 * 153 * @return 後続å?ç??æŒ?¤º 154 */ 155 @Override 156 public int doStartTag() { 157 try { 158 rtnCode = notEquals ^ actionExec( action ); // 3.8.5.2 (2006/05/31) 排他的論ç†å’?XOR) 159 } 160 catch( IOException ex ) { 161 String errMsg = "æŒ?®šã?アクションã¯å®Ÿè¡Œã§ãã¾ã›ã‚“。アクションエラー" 162 + HybsSystem.CR 163 + "action=[" + action + "] , " 164 + " fileURL=[" + fileURL + "]" 165 + " file1=[" + file1 + "]" 166 + " file2=[" + file2 + "]" ; 167 throw new HybsSystemException( errMsg,ex ); // 3.5.5.4 (2004/04/15) 引数ã®ä¸¦ã³é ?¤‰æ›´ 168 } 169 170 if( rtnCode ) { return(SKIP_BODY); } // Body を評価ã—ãªã? 171 else { return( EVAL_BODY_INCLUDE ); } // Body インクルーãƒ? extends TagSupport æ™? 172 } 173 174 /** 175 * Taglibã®çµ‚äº?‚¿ã‚°ãŒè¦‹ã¤ã‹ã£ãŸã¨ãã«å‡¦ç?™ã‚?doEndTag() ã‚?オーãƒã?ライドã—ã¾ã™ã? 176 * 177 * @og.rev 3.1.1.2 (2003/04/04) Tomcat4.1 対応ã?release2() ã‚?doEndTag()ã§å‘¼ã¶ã€? 178 * @og.rev 3.8.5.2 (2006/05/31) useStop 追åŠ?? エラーæ™?ODYã‚’å?ç?¾Œã«åœæ¢(true)ã™ã‚‹ã‹ã©ã?‹ 179 * 180 * @return 後続å?ç??æŒ?¤º 181 */ 182 @Override 183 public int doEndTag() { 184 debugPrint(); // 4.0.0 (2005/02/28) 185 int rtn = ( useStop && !rtnCode ) ? SKIP_PAGE : EVAL_PAGE ; 186 187 return( rtn ); 188 } 189 190 /** 191 * タグリブオブジェクトをリリースã—ã¾ã™ã? 192 * ã‚ャãƒ?‚·ãƒ¥ã•れã¦å†åˆ©ç”¨ã•れるã?ã§ã€ãƒ•ィールドã?åˆæœŸè¨å®šã‚’行ã„ã¾ã™ã? 193 * 194 * @og.rev 2.0.0.4 (2002/09/27) カスタãƒ?‚¿ã‚°ã® release() メソãƒ?ƒ‰ã‚’ã?追åŠ? 195 * @og.rev 3.1.1.2 (2003/04/04) Tomcat4.1 対応ã?release2() ã‚?doEndTag()ã§å‘¼ã¶ã€? 196 * @og.rev 3.6.0.0 (2004/09/24) columns ã€tableId ã€file 削除 197 * @og.rev 3.8.5.2 (2006/05/31) notEquals ã€useStop 追åŠ? 198 * @og.rev 5.1.9.0 (2010/08/01) READ時ã?エンコード指å®? 199 * 200 */ 201 @Override 202 protected void release2() { 203 super.release2(); 204 fileURL = HybsSystem.sys( "FILE_URL" ); 205 file1 = ""; 206 file2 = null; 207 action = null; 208 rtnCode = false; 209 notEquals = false; // 3.8.5.2 (2006/05/31) åˆ¤å®šçµæžœã‚’å転ã•ã›ã¦å‡¦ç?—ã¾ã™ã? 210 useStop = true; // 3.8.5.2 (2006/05/31) エラーæ™?ODYã‚’å?ç?¾Œã«åœæ¢(true)ã™ã‚‹ã‹ã©ã?‹ 211 encode = null; // 5.1.9.0 (2010/08/01) READ時ã?エンコード指å®? 212 } 213 214 /** 215 * アクションを実行ã—ã¾ã™ã? 216 * アクションã¯,æŒ?®šã?アクションコマンドã«å¯¾å¿œã™ã‚‹å?ç?‚’入力データ㫠217 * 対ã—ã¦è¡Œã„ã¾ã™ã? 218 * 219 * @og.rev 3.0.0.0 (2002/12/25) ACTION_LIST ã®ãƒã‚§ãƒ?‚¯ã‚’削除 220 * @og.rev 3.6.0.0 (2004/09/25) ACT_read を追åŠ?, file オブジェクトを移å‹? 221 * @og.rev 3.8.5.2 (2006/05/31) existsLength 追åŠ? 222 * @og.rev 4.0.0.0 (2007/11/28) メソãƒ?ƒ‰ã®æˆ»ã‚Šå?ã‚’ãƒã‚§ãƒ?‚¯ã—ã¾ã™ã? 223 * @og.rev 5.1.9.0 (2010/08/01) READ時ã?エンコード指å®? 224 * @og.rev 5.3.6.0 (2011/06/01) ACT_copy 対å¿? 225 * @og.rev 5.7.1.1 (2013/12/13) copyå…?file1)ã®ãƒ•ァイルãŒå˜åœ¨ã—ãªã‘れã°ã€ã‚¨ãƒ©ãƒ¼ã«ã—ã¾ã™ã? 226 * 227 * @param action アクションコマンãƒ?public static final 宣è¨?•れã¦ã?‚‹æ–?—å?) 228 * 229 * @return 実行後ã?ãƒ??ã‚¿ 230 */ 231 private boolean actionExec( final String action ) throws IOException { 232 String directory = HybsSystem.url2dir( fileURL ); 233 File file = new File( StringUtil.urlAppend( directory,file1 ) ); 234 235 boolean rtnVal = false; 236 if( action != null ) { 237 if( ACT_CANREAD.equalsIgnoreCase( action ) ) { rtnVal = file.canRead(); } 238 else if( ACT_CANWRITE.equalsIgnoreCase( action ) ) { rtnVal = file.canWrite(); } 239 else if( ACT_CREATENEWFILE.equalsIgnoreCase( action ) ) { rtnVal = file.createNewFile(); } 240 else if( ACT_DELETE.equalsIgnoreCase( action ) ) { rtnVal = file.delete(); } 241 else if( ACT_EXISTS.equalsIgnoreCase( action ) ) { rtnVal = file.exists(); } 242 else if( ACT_ISDIRECTORY.equalsIgnoreCase( action ) ) { rtnVal = file.isDirectory(); } 243 else if( ACT_ISFILE.equalsIgnoreCase( action ) ) { rtnVal = file.isFile(); } 244 else if( ACT_ISHIDDEN.equalsIgnoreCase( action ) ) { rtnVal = file.isHidden(); } 245 else if( ACT_MKDIR.equalsIgnoreCase( action ) ) { 246 if( file.isDirectory() ) { rtnVal = true; } 247 else { rtnVal = file.mkdir(); } 248 } 249 else if( ACT_MKDIRS.equalsIgnoreCase( action ) ) { rtnVal = file.mkdirs(); } 250 else if( ACT_RENAMETO.equalsIgnoreCase( action ) ) { 251 if( file2 != null ) { 252 File newFile = new File( StringUtil.urlAppend( directory,file2 ) ); 253 // if( newFile.exists() ) { newFile.delete(); } 254 if( newFile.exists() && !newFile.delete() ) { 255 String errMsg = "æ‰?®šã?ファイルを削除ã§ãã¾ã›ã‚“ã§ã—ãŸã€?" + newFile + "]" ; 256 throw new RuntimeException( errMsg ); 257 } 258 rtnVal = file.renameTo( newFile ); 259 } 260 } 261 // 3.6.0.0 (2004/09/25) ACT_read を追åŠ? 262 else if( ACT_READ.equalsIgnoreCase( action ) ) { 263 if( file.isFile() ) { 264 FileString fs = new FileString(); 265 fs.setFilename( StringUtil.urlAppend( directory,file1 ) ); 266 if( encode != null ) { fs.setEncode( encode ); } // 5.1.9.0 (2010/08/01) READ時ã?エンコード指å®? 267 String val = fs.getValue(); 268 269 jspPrint( nval( getRequestParameter( val ),"" ) ); 270 rtnVal = true; 271 } 272 else { 273 String errMsg = "ファイルãŒå˜åœ¨ã—ãªã?‹ã€ãƒ•ァイルã§ã¯ã‚りã¾ã›ã‚“ã€? 274 + HybsSystem.CR 275 + "action=[" + action + "] , " 276 + " fileURL=[" + fileURL + "]" 277 + " directory=[" + directory + "]" 278 + " file1=[" + file1 + "]" ; 279 throw new HybsSystemException( errMsg ); 280 } 281 } 282 // 3.8.5.2 (2006/05/31) ファイルサイズãŒï¼Byte以上ã?ファイルãŒå˜åœ¨ã™ã‚‹ã‹ã©ã?‹åˆ¤å®šã? 283 else if( ACT_EXISTSLENGTH.equalsIgnoreCase( action ) ) { 284 rtnVal = ( file.exists() && file.length() > 0L ); 285 } 286 // 5.3.6.0 (2011/06/01) ファイルコピã?対å¿? 287 else if( ACT_COPY.equalsIgnoreCase( action ) ) { 288 if( file2 != null ) { 289 File newFile = new File( StringUtil.urlAppend( directory,file2 ) ); 290 if( file.isFile() ) { 291 // FileUtil.copy å´ã§ã€toFile ã®ãƒ•ォルãƒ?‚’作æ?ã—ã¾ã™ã? 292 rtnVal = FileUtil.copy( file, newFile ); 293 } 294 else if( file.isDirectory() ) { 295 rtnVal = FileUtil.copyDirectry( file, newFile ); 296 } 297 // 5.7.1.1 (2013/12/13) copyå…?file1)ã®ãƒ•ァイルãŒå˜åœ¨ã—ãªã‘れã°ã€ã‚¨ãƒ©ãƒ¼ã«ã—ã¾ã™ã? 298 else if( !file.exists() ) { 299 String errMsg = "copyå…?file1)ã®ãƒ•ァイルãŒå˜åœ¨ã—ã¾ã›ã‚“ã€? 300 + HybsSystem.CR 301 + "action=[" + action + "] , " 302 + " fileURL=[" + fileURL + "]" 303 + " directory=[" + directory + "]" 304 + " file1=[" + file1 + "]" 305 + " file2=[" + file2 + "]" ; 306 throw new HybsSystemException( errMsg ); 307 } 308 } 309 } 310 } 311 else { 312 String errMsg = "ã‚¢ã‚¯ã‚·ãƒ§ãƒ³ãŒæŒ‡å®šã•れã¦ã?¾ã›ã‚“。アクション NULL エラー" 313 + HybsSystem.CR 314 + " file=[" + file1 + "]" ; 315 throw new HybsSystemException( errMsg ); 316 } 317 318 return rtnVal; 319 } 320 321 /** 322 * ã€TAG】アクション(canRead,canWrite,createNewFile,delete,exists,isDirectory,isFile,isHidden,mkdir,mkdirs)を指定ã—ã¾ã™ã? 323 * 324 * @og.tag 325 * アクションã¯,HTMLã‹ã‚‰(get/post)æŒ?®šã•れã¾ã™ã?ã§,ACT_xxx ã§è¨å®šã•れる 326 * フィールド定数値ã®ã?¥ã‚Œã‹ã‚’ã?æŒ?®šã§ãã¾ã™ã? 327 * 処ç??çµæžœãŒã?false ã®å ´åˆã?ã€body è¦ç´?‚’表示ã—ã¦çµ‚äº?—ã¾ã™ã? 328 * useStop 属æ?ã¨ã€notEquals 属æ?ã«ã‚ˆã£ã¦ã€ä¸Šè¨˜ã?振るè?ã?‚’ã‘ã‚‹ã“ã¨ãŒå¯èƒ½ã§ã™ã? 329 * 330 * canRead èªã¿è¾¼ã‚ã‚‹ã‹ã©ã?‹ã‚’判定ã? 331 * canWrite 変更ã§ãã‚‹ã‹ã©ã?‹åˆ¤å®šã? 332 * createNewFile ç©ºã®æ–°ã—ã„ファイルをä¸å¯åˆ?(atomic) ã«ç”Ÿæ?ã€?ãã?ファイルãŒã¾ã?˜åœ¨ã—ãªã??åˆã ã? 333 * delete ファイルã¾ãŸã?ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’削除ã€? 334 * renameTo ファイルã¾ãŸã?ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªåを変更ã€? 335 * exists ファイルãŒå˜åœ¨ã™ã‚‹ã‹ã©ã?‹åˆ¤å®šã? 336 * isDirectory ファイルãŒãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã§ã‚ã‚‹ã‹ã©ã?‹åˆ¤å®šã? 337 * isFile ãƒ•ã‚¡ã‚¤ãƒ«ãŒæ™®é€šã?ファイルã‹ã©ã?‹åˆ¤å®šã? 338 * isHidden ファイルãŒéš ã—ファイルã‹ã©ã?‹åˆ¤å®šã? 339 * mkdir ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’生æˆã? 340 * mkdirs ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’è¤?•°ç”Ÿæ?ã€? 341 * read ファイルをèªã¿è¾¼ã‚“ã§jspWriterã«å‡ºåŠ? 342 * existsLength ファイルサイズãŒï¼Byte以上ã?ファイルãŒå˜åœ¨ã™ã‚‹ã‹ã©ã?‹åˆ¤å®šã? 343 * copy ファイルã¾ãŸã?ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’コピã?(file1 â‡?file2 ã«ã‚³ãƒ”ã?)ã€? 344 * 345 * @og.rev 3.0.0.0 (2002/12/25) ACTION_LIST ã®ãƒã‚§ãƒ?‚¯ã‚’å°Žå? 346 * @og.rev 3.5.6.2 (2004/07/05) æ–?—å?ã®é€£çµã«StringBuilderを使用ã—ã¾ã™ã? 347 * 348 * @param cmd アクションæ–?—å? 349 * @see <a href="{@docRoot}/constant-values.html#org.opengion.hayabusa.taglib.FileTag.ACT_canRead">アクション定数</a> 350 */ 351 public void setAction( final String cmd ) { 352 action = getRequestParameter( cmd ); 353 354 if( ! check( action, ACTION_LIST ) ) { 355 356 StringBuilder errMsg = new StringBuilder( HybsSystem.BUFFER_MIDDLE ); 357 errMsg.append( "æŒ?®šã?アクションã¯å®Ÿè¡Œã§ãã¾ã›ã‚“。アクションエラー" ); 358 errMsg.append( HybsSystem.CR ); 359 errMsg.append( "action=[" ).append( action ).append( "] " ); 360 errMsg.append( HybsSystem.CR ); 361 362 for( int i=0; i<ACTION_LIST.length; i++ ) { 363 errMsg.append( " | " ); 364 errMsg.append( ACTION_LIST[i] ); 365 } 366 errMsg.append( " | " ); 367 throw new HybsSystemException( errMsg.toString() ); 368 } 369 } 370 371 /** 372 * ã€TAG】æ“作ã™ã‚‹ãƒ•ァイルã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’指定ã—ã¾ã? 373 * (åˆæœŸå€¤:FILE_URL[={@og.value org.opengion.hayabusa.common.SystemData#FILE_URL}])ã€? 374 * 375 * @og.tag 376 * ã“ã?属æ?ã§æŒ?®šã•れるãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã®ãƒ•ァイルをæ“作ã—ã¾ã™ã? 377 * æŒ?®šæ–¹æ³•ã?ã€??常㮠fileURL 属æ?ã¨åŒæ§˜ã«ã€å?é ãŒã?'/' (UNIX) ã¾ãŸã?ã€?¼’æ–‡å—ç›®ãŒã? 378 * ":" (Windows)ã®å ´åˆã?ã€æŒ‡å®šã?URLãã?ã¾ã¾ã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã«ã€ãã?§ãªã??åˆã?ã€? 379 * (åˆæœŸå€¤:シスãƒ?ƒ 定数ã®FILE_URL[={@og.value org.opengion.hayabusa.common.SystemData#FILE_URL}])ã€? 380 * 381 * @og.rev 4.0.0.0 (2005/01/31) urlAppend メソãƒ?ƒ‰ã®åˆ©ç”¨ 382 * @og.rev 4.0.0.0 (2007/11/20) æŒ?®šã•れãŸãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªåã?æœ?¾ŒãŒ"\"or"/"ã§çµ‚ã‚ã£ã¦ã?ªã??åˆã«ã€?/"ã‚’ä»˜åŠ ã™ã‚‹ã€? 383 * 384 * @param url ファイルURL 385 * @see org.opengion.hayabusa.common.SystemData#FILE_URL 386 */ 387 public void setFileURL( final String url ) { 388 String furl = nval( getRequestParameter( url ),null ); 389 if( furl != null ) { 390 char ch = furl.charAt( furl.length()-1 ); 391 if( ch != '/' && ch != '\\' ) { furl = furl + "/"; } 392 fileURL = StringUtil.urlAppend( fileURL,furl ); 393 } 394 } 395 396 /** 397 * ã€TAG】基準ã¨ãªã‚‹ãƒ•ァイルåã‚’æŒ?®šã—ã¾ã?コマンドã?左辺ã®ãƒ•ァイルåã§ã?ã€? 398 * 399 * @og.tag 400 * コマンドã?左辺ã®ãƒ•ァイルåã§ã™ã? 401 * 402 * @param fname ファイルåï¼? 403 */ 404 public void setFile1( final String fname ) { 405 file1 = nval( getRequestParameter( fname ),file1 ); 406 } 407 408 /** 409 * ã€TAG】å?ç?µæžœã¨ãªã‚‹ãƒ•ァイルåã‚’æŒ?®šã—ã¾ã?コマンドã?å³è¾ºã®ãƒ•ァイルåã§ã?ã€? 410 * 411 * @og.tag 412 * コマンドã?å³è¾ºã®ãƒ•ァイルåã§ã™ã? 413 * 414 * @param fname ファイルåï¼? 415 */ 416 public void setFile2( final String fname ) { 417 file2 = nval( getRequestParameter( fname ),file2 ); 418 } 419 420 /** 421 * ã€TAGã€‘åˆ¤å®šçµæžœã‚’å転ã•ã›ã‚‹ã‹ã©ã?‹[true/false]を指定ã—ã¾ã?åˆæœŸå€¤:false)ã€? 422 * 423 * @og.tag 424 * 通常ã®åˆ¤å®šçµæžœã«ãŠã„ã¦ã€ä¸æ?ç«?false)ã®å ´åˆã«ã€BODY を実行ã—ã¾ã™ã? 425 * 通常ã®å‡¦ç?µæžœã®æ£å対ã®å‡¦ç?‚’行ã„ã¾ã™ã? 426 * åˆæœŸå€¤ã¯ã€??常 (true 以å¤?ã§ã™ã? 427 * 428 * @og.rev 3.8.5.2 (2006/05/31) æ–°è¦è¿½åŠ? 429 * 430 * @param flag [true:å転ã™ã‚‹/ãれ以å¤?通常] 431 */ 432 public void setNotEquals( final String flag ) { 433 notEquals = nval( getRequestParameter( flag ),notEquals ); 434 } 435 436 /** 437 * ã€TAG】エラーæ™?ODYã‚’å?ç?¾Œã«åœæ¢ã™ã‚‹ã‹ã©ã?‹[true/false]を指定ã—ã¾ã?åˆæœŸå€¤:true)ã€? 438 * 439 * @og.tag 440 * 処ç?µæžœãªã©ã«å¿œã˜ã¦ã€ä»¥ä¸‹ã?処ç?‚’åœæ¢ã—ãŸã??åˆã«ã€ä½¿ç”¨ã—ã¾ã™ã? 441 * 通常ã¯ã€æ¡ä»¶ã‚’判定後ã?false ã®å ´åˆã«ã€BODY部をå?åŠ?処ç?ã—ãŸå¾Œã«ã€? 442 * 処ç?‚’åœæ¢ã—ã¾ã™ã?(useStop="true") 443 * false を指定ã™ã‚‹ã¨ã€åˆ¤å®šçµæžœã«ç„¡é–¢ä¿‚ã«ã€ä»¥ä¸‹ã?処ç?‚’実行ã—ã¾ã™ã? 444 * 処ç??継続ã—ãŸã„ãŒã?è¦å‘Šè¡¨ç¤ºã™ã‚‹å ´åˆã«ã€useStop="false" を指定ã—ã¾ã™ã? 445 * åˆæœŸå€¤ã¯ã€åœæ¢ã™ã‚‹ ("true")ã§ã™ã? 446 * 447 * @og.rev 3.8.5.2 (2006/05/31) æ–°è¦è¿½åŠ? 448 * 449 * @param flag [true:判定ã™ã‚?ãれ以å¤?ã—ãªã„] 450 */ 451 public void setUseStop( final String flag ) { 452 useStop = nval( getRequestParameter( flag ),useStop ); 453 } 454 455 /** 456 * ã€TAG】ファイルをèªã¿è¾¼ã‚?action="READ")éš›ã?エンコードをæŒ?®šã—ã¾ã?åˆæœŸå€¤:OSä¾å˜æ–‡å—コーãƒ?ã€? 457 * 458 * @og.tag 459 * ファイルをèªã¿è¾¼ã‚?action="READ")éš›ã?エンコードをæŒ?®šã—ã¾ã™ã? 460 * action="READ"以外å?åˆã«ã¯ã€ã“ã®å±žæ?値ã¯åˆ©ç”¨ã•れã¾ã›ã‚“ã€? 461 * æŒ?®šã—ãªã??åˆã?ã€OSä¾å˜æ–‡å—コードã§èªã¿è¾¼ã¾ã‚Œã¾ã™ã? 462 * 463 * @og.rev 5.1.9.0 (2010/08/01) æ–°è¦ä½œæ? 464 * 465 * @param enc ファイルèªã¿è¾¼ã¿ã®ã‚¨ãƒ³ã‚³ãƒ¼ãƒ? 466 */ 467 public void setEncode( final String enc ) { 468 encode = nval( getRequestParameter( enc ),encode ); 469 } 470 471 /** 472 * ã“ã?オブジェクトã?æ–?—å?表ç¾ã‚’è¿”ã—ã¾ã™ã? 473 * 基本çš?«ãƒ?ƒãƒ?‚°ç›®çš?«ä½¿ç”¨ã—ã¾ã™ã? 474 * 475 * @return ã“ã?ã‚¯ãƒ©ã‚¹ã®æ–?—å?è¡¨ç¾ 476 */ 477 @Override 478 public String toString() { 479 return org.opengion.fukurou.util.ToString.title( this.getClass().getName() ) 480 .println( "VERSION" ,VERSION ) 481 .println( "fileURL" ,fileURL ) 482 .println( "file1" ,file1 ) 483 .println( "file2" ,file2 ) 484 .println( "action" ,action ) 485 .println( "rtnCode" ,rtnCode ) 486 .println( "notEquals" ,notEquals ) 487 .println( "useStop" ,useStop ) 488 .println( "Other..." ,getAttributes().getAttribute() ) 489 .fixForm().toString() ; 490 } 491 }