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             *   <caption>POSTキーとして受け取るキーと値</caption>
049             *   <tr><th>キー           </th><th>?               </th><th>値                                                          </th></tr>
050             *   <tr><td>command        </td><td>更新種別   </td><td>COLUMN,LABEL,CODE,GUI                       </td></tr>
051             *   <tr><td>lang           </td><td>??       </td><td>更新リソースの??                  </td></tr>
052             *   <tr><td>CLM            </td><td>更新キー   </td><td>キーカラ?","で区?たCSV形?/td></tr>
053             * </table>
054             *
055             * 動作?command == "GUI"の場合とそれ以外?場合に?れます?
056             * ?、リソースの更新はResourceManagerのメソ?を利用する部??共通です?
057             * こ?時?langによって更新対象の?を選択しま?nullの場合?ja)
058             * ?ommand?GUI"の場?
059             * ?面リソースを更新する場合?command="GUI"で渡します?
060             * ?UIに限ってCLMパラメータは不要です?
061             * ?esourceManager.guiClear()がコールされて画面リソースがクリアされます?
062             * ?同時に画面リソースのラベルリソースも?読込しま?
063             * ②command?GUI"以外?場?
064             * ?ommand?GUI"以外?場合?動作?どれも同じです?
065             * ?け取ったCLMパラメータをCSV?し?ループで回して
066             * ?esourceManager.clear(key)をコールします?
067             * ?
068             * 返す値は XML形式???です?
069             * &lt;clear-resource&gt;
070             *   &lt;command&gt;command引数&lt;/command&gt;
071             *   &lt;lang&gt;lang引数&lt;/lang&gt;
072             *   &lt;keys&gt;
073             *     &lt;key&gt;CLM引数の更新キー??lt;/key&gt;
074             *     &lt;key&gt;CLM引数の更新キー??lt;/key&gt;
075             *     ...
076             *   &lt;/keys&gt;
077             * &lt;/clear-resource&gt;
078             * となります?
079             *
080             * @param       valMap   サーブレ?が受け取ったキーと値のマッ?
081             *
082             * @return      XML形式?実行結果
083             */
084            public String remoteControl( final Map<String,String> valMap ) {
085                    String                  command = valMap.get( "command" );
086                    String                  clms    = valMap.get( "CLM" );
087                    String                  lang    = valMap.get( "lang" );
088                    ResourceManager rscM    = ResourceFactory.newInstance( lang );
089    
090                    StringBuilder   rtnStr  = new StringBuilder();
091                    rtnStr.append( "<clear-resource>" );
092                    rtnStr.append( " <command>" ).append( command ).append( "</command>" );
093                    rtnStr.append( " <lang>"  ).append( lang    ).append( "</lang>" );
094                    rtnStr.append( " <keys>" );
095    
096                    if( "GUI".equals(command) ) {
097                            rscM.guiClear();
098                            rtnStr.append( "  <key>").append( clms ).append( "</key>" );
099                    }
100                    else {
101                            String[] vals = StringUtil.csv2Array( clms );
102                            for( int i = 0; i < vals.length; i++ ) {
103                                    rscM.clear( vals[i] );
104                                    rtnStr.append( "  <key>" ).append( vals[i] ).append( "</key>" );
105                            }
106                    }
107    
108                    rtnStr.append( " </keys>" );
109                    rtnStr.append( "</clear-resource>" );
110                    return rtnStr.toString();
111            }
112    }