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.plugin.column;
017    
018    import java.util.Locale;
019    import java.util.Map;
020    import java.util.HashMap;
021    
022    import org.opengion.hayabusa.db.AbstractRenderer;
023    import org.opengion.hayabusa.db.CellRenderer;
024    import org.opengion.hayabusa.db.DBColumn;
025    
026    /**
027     * ICON レンãƒ?ƒ©ーは、カラãƒ??ファイル名ã?拡張子からアイコンファイルのイメージタグを作æ?しますã?
028     * イメージãƒ??タは、jsp/image/thumb を使用しますã?
029     *
030     * 実質çš?�«は、アイコンではなくã?サãƒ?ƒ�イルとして利用しますã?
031     * 
032     * 縦横比をそã?ままに、縦か横のæœ?¤§値に画像サイズを合わせるにはã€?
033     * style="max-width:100; max-height:100;" をセãƒ?ƒˆすることで対応できますã?
034     * class="ICON" 属æ?をå?力しておきますã?で、CSSファイルで記述してくださいã€?
035     *
036     * (例ï¼?
037     *<pre>
038     *  &lt;style type="text/css"&gt;
039     *      img.ICON { max-width:100px; max-height:100px; }
040     *  &lt;/style&gt;
041     *</pre>
042     *
043     * こã?クラスは、不変オブジェクトとして、å?有されますã?
044     *
045     * @og.rev 5.6.5.1 (2013/06/14) 新規作æ?
046     *
047     * @og.group ãƒ??タ表示
048     *
049     * @version  4.0
050     * @author       Kazuhiko Hasegawa
051     * @since    JDK5.0,
052     */
053    public class Renderer_ICON extends AbstractRenderer {
054            //* こã?プログラãƒ??VERSIONæ–?­—å?を設定しますã?       {@value} */
055            private static final String VERSION = "5.6.5.1 (2013/06/14)" ;
056    
057            private static final CellRenderer dbCell = new Renderer_ICON() ;
058    
059            // アイコンファイルに割り当てられる拡張子とファイルの関連(MAP)æƒ??
060            private static final Map<String,String> ICON_MAP ;
061            static {
062                    ICON_MAP = new HashMap<String,String>();
063    
064                    ICON_MAP.put( "doc"             ,       "../image/thumb/doc.png" );
065                    ICON_MAP.put( "docx"    ,       "../image/thumb/doc.png" );
066                    ICON_MAP.put( "xls"             ,       "../image/thumb/xls.png" );
067                    ICON_MAP.put( "xlsx"    ,       "../image/thumb/xls.png" );
068                    ICON_MAP.put( "ppt"             ,       "../image/thumb/ppt.png" );
069                    ICON_MAP.put( "pptx"    ,       "../image/thumb/ppt.png" );
070                    ICON_MAP.put( "pdf"             ,       "../image/thumb/pdf.png" );
071                    ICON_MAP.put( "txt"             ,       "../image/thumb/text.png" );
072                    ICON_MAP.put( "zip"             ,       "../image/thumb/zip.png" );
073            }
074            private static final String DOC_VIEW = "../image/thumb/docview.png" ;           // そã?他ã?アイコン
075    
076            /**
077             * å�?‚ªブジェクトからè?åˆ??インスタンスを返しますã?
078             * 自åˆ??身をキャãƒ?‚·ュするのかã?新たに作æ?するのかã?、各サブクラスの実è£?�«
079             * まかされますã?
080             *
081             * @param       clm     DBColumnオブジェクãƒ?
082             *
083             * @return      CellRendererオブジェクãƒ?
084             */
085            public CellRenderer newInstance( final DBColumn clm ) {
086                    return dbCell;
087            }
088    
089            /**
090             * ãƒ??タの表示用æ–?­—å?を返しますã?
091             *
092             * @param       value 入力å?
093             *
094             * @return      ãƒ??タの表示用æ–?­—å?
095             */
096            @Override
097            public String getValue( final String value ) {
098                    String icon = null;
099    
100                    if( value != null ) {
101                            String sufix = null;
102                            int idx = value.lastIndexOf(".");
103                            if( idx >= 0 ) {
104                                    sufix = value.substring( idx+1 ).toLowerCase( Locale.JAPAN );
105                                    icon = ICON_MAP.get( sufix );
106                            }
107                    }
108    
109                    if( icon == null ) { icon = DOC_VIEW; }
110    
111                    return "<img class=\"ICON\" src=\"" + icon + "\" alt=\"" + value + "\" />" ;
112            }
113    }