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.HybsSystemException; 019 import org.opengion.fukurou.util.HybsFileFilter; 020 021 import static org.opengion.fukurou.util.StringUtil.nval ; 022 023 /** 024 * fileOption でファイルを検索する場合?条件を指定するタグです? 025 * 026 * @og.formSample 027 * ●形式?lt;og:fileWhere name="…" startsWith="…" endsWith="…" … /> 028 * ●body?な? 029 * 030 * ●Tag定義?? 031 * <og:fileWhere 032 * startsWith 【TAG】指定された接頭辞で始まる?合?スルー(選?されま? 033 * endsWith 【TAG】指定された接頭辞で終わる?合?スルー(選?されま? 034 * instr 【TAG】指定された??がファイル名に含まれる場合?スルー(選?されま? 035 * equals 【TAG】ファイル名が??する場合?スルー(選?されま? 036 * matches 【TAG】ファイル名が、指定された正規表現と??する場合?スルー(選?されま? 037 * unMatches 【TAG】ファイル名が、指定された正規表現と??しな??合?スルー(選?されま? 038 * lastModified 【TAG】指定?タイ?タンプ以後に変更されて?場合?スルー(選?されま? 039 * isLarger 【TAG】指定?大きさより大きいファイルの場合?スルー(選?されま? 040 * isSmaller 【TAG】指定?大きさより小さ?ァイルの場合?スルー(選?されま? 041 * useDir 【TAG】フィルタによる対象の絞込みをディレクトリにも適用するかど?を指定しま? 042 * debug 【TAG】デバッグ??を?力するかど?[true/false]を指定しま?初期値:false) 043 * /> 044 * 045 * ●使用? 046 * <og:fileOption select="NAME" from="./jsp" > 047 * <og:fileWhere 048 * startsWith = "File" :?された接頭辞で始まる?合?選択される 049 * endsWith = ".java" :?された接頭辞で終わる?合?選択される 050 * instr = "Tag" :?された??がファイル名に含まれる場合?選択される 051 * fileEquals = "FileWhereTag.java" :ファイル名が??する場合?選択される(大?小文字?区別しな? 052 * matches = "File*Tag" :ファイル名が、指定された正規表現と??する場合?選択される(大?小文字?区別しな? 053 * unMatches = "File*Tag" :ファイル名が、指定された正規表現と??しな??合?選択される(大?小文字?区別しな? 054 * lastModified = "20050101" :??タイ?タンプ以後に変更された?合?選択される 055 * 日付けの??、YYYYMMDD 形?TODAY , YESTERDAY が使用できます? 056 * isLarger = "1024" :??大きさ(バイト単?より大きいファイルの場合?選択される 057 * isSmaller = "1024" :??大きさ(バイト単?より小さ?ァイルの場合?選択される 058 * useDir = "false" :フィルタによる対象の絞込みをディレクトリにも適用するかど? 059 * /> 060 * </og:fileOption> 061 * 062 * ・検索条件が?力された? 063 * 条件を?して全てのファイルを?挙します? 064 * 065 * ・検索条件が?力されなかった時 066 * 該当ディレクトリ??全てのファイルを?挙します? 067 * 068 * @og.rev 2.1.1.0 (2002/11/11) 新規作? 069 * @og.rev 4.0.0.0 (2005/01/31) ?ロジ?の全面見直? 070 * @og.group そ?他?? 071 * 072 * @version 4.0 073 * @author Kazuhiko Hasegawa 074 * @since JDK5.0, 075 */ 076 public class FileWhereTag extends CommonTagSupport { 077 //* こ?プログラ??VERSION??を設定します? {@value} */ 078 private static final String VERSION = "5.6.6.0 (2013/07/05)" ; 079 080 private static final long serialVersionUID = 566020130705L ; 081 082 private String startsWith = null; // ?された接頭辞で始まる?合?選択される 083 private String endsWith = null; // ?された接頭辞で終わる?合?選択される 084 private String instr = null; // ?された??がファイル名に含まれる場合?選択される 085 private String fileEquals = null; // ファイル名が??する場合?選択される(大?小文字?区別しな? 086 private String matches = null; // ファイル名が、指定された正規表現と??する場合?選択される(大?小文字?区別しな? 087 private String unMatches = null; // ファイル名が、指定された正規表現と??しな??合?選択される(大?小文字?区別しな? 088 private String lastModified = null; // ??タイ?タンプ以後に変更された?合?選択される 089 private int isLarger = -1; // ??大きさ(バイト単?より大きいファイルの場合?選択される 090 private int isSmaller = -1; // ??大きさ(バイト単?より小さ?ァイルの場合?選択される 091 private boolean useDir = false; // フィルタによる対象の絞込みをディレクトリにも適用するかど? 5.3.9.0 (2011/09/01) 092 093 /** 094 * Taglibの終?グが見つかったときに処??doEndTag() ?オーバ?ライドします? 095 * 096 * @og.rev 3.1.1.2 (2003/04/04) Tomcat4.1 対応?release2() ?doEndTag()で呼ぶ? 097 * @og.rev 5.1.2.0 (2010/01/01) unMatches メソ?で反転属?の追? 098 * @og.rev 5.3.9.0 (2011/09/01) useDir属?を追? 099 * @og.rev 5.6.6.0 (2013/07/05) unMatchesの引数間違??訂正 100 * 101 * @return 後続???? 102 */ 103 @Override 104 public int doEndTag() { 105 debugPrint(); // 4.0.0 (2005/02/28) 106 107 // 5.3.9.0 (2011/09/01) useDir属?を追? 108 // HybsFileFilter filter = new HybsFileFilter(); 109 HybsFileFilter filter = new HybsFileFilter( useDir ); 110 filter.startsWith( startsWith ); 111 filter.endsWith( endsWith ); 112 filter.instr( instr ); 113 filter.fileEquals( fileEquals ); 114 filter.matches( matches ); 115 // filter.matches( matches , true ); // 5.1.2.0 (2010/01/01) 反転属?の追? 116 filter.matches( unMatches , true ); // 5.6.6.0 (2013/07/05) 引数間違??訂正 117 // filter.unMatches( unMatches ); 118 filter.lastModified( lastModified ); 119 filter.isLarger( isLarger ); 120 filter.isSmaller( isSmaller ); 121 122 // ファイルフィルタを追? 123 FileQueryTag fileQuery = (FileQueryTag)findAncestorWithClass( this, FileQueryTag.class ); 124 if( fileQuery != null ) { 125 fileQuery.setFileFilter( filter ); 126 return(EVAL_PAGE); 127 } 128 129 FileOptionTag fileOption = (FileOptionTag)findAncestorWithClass( this, FileOptionTag.class ); 130 if( fileOption != null ) { 131 fileOption.setFileFilter( filter ); 132 return(EVAL_PAGE); 133 } 134 135 // どちらにも属して?かった?合?、エラーになる? 136 String errMsg = "こ?、FileWhereTag タグは、FileQueryTag か?FileOption の" 137 + "BODY 部にのみ??置できます?(それ以外??での使用はできません?" ; 138 throw new HybsSystemException( errMsg ); 139 } 140 141 /** 142 * タグリブオブジェクトをリリースします? 143 * キャ?ュされて再利用される?で、フィールド?初期設定を行います? 144 * 145 * @og.rev 2.0.0.4 (2002/09/27) カスタ?グの release() メソ?を?追? 146 * @og.rev 3.1.1.2 (2003/04/04) Tomcat4.1 対応?release2() ?doEndTag()で呼ぶ? 147 * @og.rev 4.0.0.0 (2005/01/31) ?ロジ?の全面見直? 148 * @og.rev 5.3.9.0 (2011/09/01) useDir属?追? 149 * 150 */ 151 @Override 152 protected void release2() { 153 super.release2(); 154 startsWith = null; 155 endsWith = null; 156 instr = null; 157 fileEquals = null; 158 matches = null; 159 unMatches = null; 160 lastModified = null; 161 isLarger = -1; 162 isSmaller = -1; 163 useDir = false; // 5.3.9.0 (2011/09/01) useDir属?追? 164 } 165 166 /** 167 * 【TAG】指定された接頭辞で始まる?合?スルー(選?されます? 168 * @og.tag 169 * 引数?null の場合?、追?ません? 170 * 171 * @param prefix 接頭? 172 * @see java.lang.String#startsWith(String) 173 */ 174 public void setStartsWith( final String prefix ) { 175 startsWith = nval( getRequestParameter( prefix ),startsWith ); 176 } 177 178 /** 179 * 【TAG】指定された接頭辞で終わる?合?スルー(選?されます? 180 * @og.tag 181 * 引数?null の場合?、追?ません? 182 * 183 * @param suffix 接尾? 184 * @see java.lang.String#endsWith(String) 185 */ 186 public void setEndsWith( final String suffix ) { 187 endsWith = nval( getRequestParameter( suffix ),endsWith ); 188 } 189 190 /** 191 * 【TAG】指定された??がファイル名に含まれる場合?スルー(選?されます? 192 * @og.tag 193 * 引数?null の場合?、追?ません? 194 * 195 * @param str ??部?字? 196 */ 197 public void setInstr( final String str ) { 198 instr = nval( getRequestParameter( str ),instr ); 199 } 200 201 /** 202 * 【TAG】ファイル名が??する場合?スルー(選?されます? 203 * @og.tag 204 * 大?小文字?区別しません? 205 * 引数?null の場合?、追?ません? 206 * 207 * @param str ファイル名文字? 208 * @see java.lang.String#equals(Object) 209 */ 210 public void setEquals( final String str ) { 211 fileEquals = nval( getRequestParameter( str ),fileEquals ); 212 } 213 214 /** 215 * 【TAG】ファイル名が、指定された正規表現と??する場合?スルー(選?されます? 216 * @og.tag 217 * 大?小文字?区別しません? 218 * Pattern.compile( str,Pattern.CASE_INSENSITIVE ) ; 219 * pattern.matcher( pathname.getName() ).find() == true と同じ結果が得られます? 220 * 引数?null の場合?、追?ません? 221 * 222 * @param str ファイル名文字?(正規表現) 223 * @see java.util.regex.Pattern#compile(String,int) 224 * @see java.util.regex.Matcher#find() 225 */ 226 public void setMatches( final String str ) { 227 matches = nval( getRequestParameter( str ),matches ); 228 } 229 230 /** 231 * 【TAG】ファイル名が、指定された正規表現と??しな??合?スルー(選?されます? 232 * @og.tag 233 * 大?小文字?区別しません? 234 * Pattern.compile( str,Pattern.CASE_INSENSITIVE ) ; 235 * pattern.matcher( pathname.getName() ).find() == false と同じ結果が得られます? 236 * 引数?null の場合?、追?ません? 237 * 238 * @param str ファイル名文字?(正規表現) とマッチしな? 239 * @see java.util.regex.Pattern#compile(String,int) 240 * @see java.util.regex.Matcher#find() 241 */ 242 public void setUnMatches( final String str ) { 243 unMatches = nval( getRequestParameter( str ),unMatches ); 244 } 245 246 /** 247 * 【TAG】指定?タイ?タンプ以後に変更されて?場合?スルー(選?されます? 248 * @og.tag 249 * ?レクトリは、ここ?判定では無視します?(? true を返しま? 250 * 日付けの?に、YYYYMMDD 形式? ?文字数字文字?以外に? 251 * TODAY ?YESTERDAY なども使用できます? 252 * TODAY は、実行日の 00:00:00 を基準時刻とし?YESTERDAY は、その前日になります? 253 * 引数?null の場合?、追?ません? 254 * 255 * @param modify 時刻を表?long 値(ミリ秒単? 256 */ 257 public void setLastModified( final String modify ) { 258 lastModified = nval( getRequestParameter( modify ),lastModified ); 259 } 260 261 /** 262 * 【TAG】指定?大きさより大きいファイルの場合?スルー(選?されます? 263 * @og.tag ファイルの大きさ(バイト単?は同?を含みます? 264 * 引数?0以?マイナス) の場合?、追?ません? 265 * 266 * @param len ファイルの大きさ(バイト単?。同値を含?? 267 */ 268 public void setIsLarger( final String len ) { 269 isLarger = nval( getRequestParameter( len ),isLarger ); 270 } 271 272 /** 273 * 【TAG】指定?大きさより小さ?ァイルの場合?スルー(選?されます? 274 * @og.tag ファイルの大きさ(バイト単?は同?を含みません? 275 * 引数?0以?マイナス) の場合?、追?ません? 276 * 277 * @param len ファイルの大きさ(バイト単?。同値を含まな?? 278 */ 279 public void setIsSmaller( final String len ) { 280 isSmaller = nval( getRequestParameter( len ),isSmaller ); 281 } 282 283 /** 284 * 【TAG】フィルタによる対象の絞込みをディレクトリにも適用するかど?を指定します? 285 * @og.tag 初期値は、false(?レクトリはフィルタによる絞込みをしな?です? 286 * 287 * @og.rev 5.3.9.0 (2011/09/01) 新規作? 288 * 289 * @param flg フィルタによる対象の絞込みをディレクトリにも適用するかど?(初期値:false) 290 */ 291 public void setUseDir( final String flg ) { 292 useDir = nval( getRequestParameter( flg ),useDir ); 293 } 294 295 /** 296 * こ?オブジェクト???表現を返します? 297 * 基本???目?使用します? 298 * 299 * @return String型?こ?クラスの??表現 300 */ 301 @Override 302 public String toString() { 303 return org.opengion.fukurou.util.ToString.title( this.getClass().getName() ) 304 .println( "VERSION" ,VERSION ) 305 .println( "startsWith" ,startsWith ) 306 .println( "endsWith" ,endsWith ) 307 .println( "instr" ,instr ) 308 .println( "fileEquals" ,fileEquals ) 309 .println( "matches" ,matches ) 310 .println( "unMatches" ,unMatches ) 311 .println( "lastModified" ,lastModified ) 312 .println( "isLarger" ,isLarger ) 313 .println( "isSmaller" ,isSmaller ) 314 .println( "useDir" ,useDir ) 315 .println( "Other..." ,getAttributes().getAttribute() ) 316 .fixForm().toString() ; 317 } 318 }