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    }