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 */ 016package org.opengion.plugin.column; 017 018import java.util.Locale; 019import java.util.Map; 020import java.util.HashMap; 021 022import org.opengion.hayabusa.db.AbstractRenderer; 023import org.opengion.hayabusa.db.CellRenderer; 024import 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 * <style type="text/css"> 039 * img.ICON { max-width:100px; max-height:100px; } 040 * </style> 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 */ 053public 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 private static final String DOC_VIEW = "../image/thumb/docview.png" ; // その他のアイコン 060 061 // アイコンファイルに割り当てられる拡張子とファイルの関連(MAP)情報 062 private static final Map<String,String> ICON_MAP ; 063 static { 064 ICON_MAP = new HashMap<String,String>(); 065 066 ICON_MAP.put( "doc" , "../image/thumb/doc.png" ); 067 ICON_MAP.put( "docx" , "../image/thumb/doc.png" ); 068 ICON_MAP.put( "xls" , "../image/thumb/xls.png" ); 069 ICON_MAP.put( "xlsx" , "../image/thumb/xls.png" ); 070 ICON_MAP.put( "ppt" , "../image/thumb/ppt.png" ); 071 ICON_MAP.put( "pptx" , "../image/thumb/ppt.png" ); 072 ICON_MAP.put( "pdf" , "../image/thumb/pdf.png" ); 073 ICON_MAP.put( "txt" , "../image/thumb/text.png" ); 074 ICON_MAP.put( "zip" , "../image/thumb/zip.png" ); 075 } 076 077 /** 078 * 各オブジェクトから自分のインスタンスを返します。 079 * 自分自身をキャッシュするのか、新たに作成するのかは、各サブクラスの実装に 080 * まかされます。 081 * 082 * @param clm DBColumnオブジェクト 083 * 084 * @return CellRendererオブジェクト 085 */ 086 public CellRenderer newInstance( final DBColumn clm ) { 087 return dbCell; 088 } 089 090 /** 091 * データの表示用文字列を返します。 092 * 093 * @param value 入力値 094 * 095 * @return データの表示用文字列 096 */ 097 @Override 098 public String getValue( final String value ) { 099 String icon = null; 100 101 if( value != null ) { 102 String sufix = null; 103 int idx = value.lastIndexOf("."); 104 if( idx >= 0 ) { 105 sufix = value.substring( idx+1 ).toLowerCase( Locale.JAPAN ); 106 icon = ICON_MAP.get( sufix ); 107 } 108 } 109 110 if( icon == null ) { icon = DOC_VIEW; } 111 112 return "<img class=\"ICON\" src=\"" + icon + "\" alt=\"" + value + "\" />" ; 113 } 114}