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