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.remote;
017    
018    import java.util.Map;
019    
020    import org.opengion.fukurou.util.StringUtil;
021    import org.opengion.hayabusa.resource.ResourceFactory;
022    import org.opengion.hayabusa.resource.ResourceManager;
023    
024    /**
025     * RemoteControllableインタフェイスを実è£?�—ã�?
026     * サーブレãƒ?ƒˆ経由でé�?š”リソース更新を行うためのクラスですã?
027     *
028     * POSTキーとしてcommandとCLM、langがå¿?¦�ですã?
029     * commandは更新リソースの種別(COLUMN,LABEL,CODE,GUI)
030     * CLMはCLM値をカンマで区åˆ?�£たCSV形å¼?
031     * langは更新対象のè¨?ª?例:ja)ですã?
032     * 詳しくはremoteControlメソãƒ?ƒ‰のJavaDocをご覧下さã�??
033     *
034     * @og.rev 4.1.0.0 (2007/12/20) 新規作æ?
035     *
036     * @version  4.1
037     * @author   Masakazu Takahashi
038     * @since    JDK6.0,
039     *
040     */
041    public class ClearResource implements RemoteControllable {
042            /**
043             * RemoteControllableインタフェイスの実è£?ƒ¡ソãƒ?ƒ‰ですã?
044             * ClearResourceでは受け取ったパラメータによってコンãƒ?‚­ストã?リソースの再読込をしますã?
045             *
046             * POSTキーとして受け取るキーと値は次の通りとなりまã�?
047             * <table border="1" frame="box" rules="all" >
048             *  <tr><th>キー    </th><th>å†?®¹               </th><th>値                                                          </th></tr>
049             *  <tr><td>command </td><td>更新種別   </td><td>COLUMN,LABEL,CODE,GUI                       </td></tr>
050             *  <tr><td>lang    </td><td>è¨?ª?       </td><td>更新リソースのè¨?ª?                  </td></tr>
051             *  <tr><td>CLM             </td><td>更新キー   </td><td>キーカラãƒ?‚’","で区åˆ?�£たCSV形å¼?/td></tr>
052             * </table>
053             *
054             * 動作ã?command == "GUI"の場合とそれ以外ã?場合にåˆ?�‹れますã?
055             * ä½?�—、リソースの更新はResourceManagerのメソãƒ?ƒ‰を利用する部åˆ??共通ですã?
056             * こã?時ã?langによって更新対象のè¨?ªžを選択しまã�?nullの場合ã?ja)
057             * â‘?ommandã�?GUI"の場å�?
058             * ã€?”»面リソースを更新する場合ã?command="GUI"で渡しますã?
059             * ã€?UIに限ってCLMパラメータは不要ですã?
060             * ã€?esourceManager.guiClear()がコールされて画面リソースがクリアされますã?
061             * ã€?同時に画面リソースのラベルリソースもå?読込しまã�?
062             * ②commandã�?GUI"以外ã?場å�?
063             * ã€?ommandã�?GUI"以外ã?場合ã?動作ã?どれも同じですã?
064             * ã€?�—け取ったCLMパラメータをCSVåˆ?§£しã?ループで回して
065             * ã€?esourceManager.clear(key)をコールしますã?
066             * �
067             * 返す値は XML形式ã?æ–?­—å?ですã?
068             * <clear-resource>
069             *   <command>command引数</command>
070             *   <lang>lang引数</lang>
071             *   <keys>
072             *     <key>CLM引数の更新キー??/key>
073             *     <key>CLM引数の更新キー??/key>
074             *     ...
075             *   </keys>
076             * </clear-resource>
077             * となりますã?
078             *
079             * @param       valMap   サーブレãƒ?ƒˆが受け取ったキーと値のマッãƒ?
080             *
081             * @return      XML形式ã?実行結果
082             */
083            public String remoteControl( final Map<String,String> valMap ) {
084                    String                  command = valMap.get( "command" );
085                    String                  clms    = valMap.get( "CLM" );
086                    String                  lang    = valMap.get( "lang" );
087                    ResourceManager rscM    = ResourceFactory.newInstance( lang );
088    
089                    StringBuilder   rtnStr  = new StringBuilder();
090                    rtnStr.append( "<clear-resource>" );
091                    rtnStr.append( " <command>" ).append( command ).append( "</command>" );
092                    rtnStr.append( " <lang>"  ).append( lang    ).append( "</lang>" );
093                    rtnStr.append( " <keys>" );
094    
095                    if( "GUI".equals(command) ) {
096                            rscM.guiClear();
097                            rtnStr.append( "  <key>").append( clms ).append( "</key>" );
098                    }
099                    else {
100                            String[] vals = StringUtil.csv2Array( clms );
101                            for( int i = 0; i < vals.length; i++ ) {
102                                    rscM.clear( vals[i] );
103                                    rtnStr.append( "  <key>" ).append( vals[i] ).append( "</key>" );
104                            }
105                    }
106    
107                    rtnStr.append( " </keys>" );
108                    rtnStr.append( "</clear-resource>" );
109                    return rtnStr.toString();
110            }
111    }