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    }