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 }