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