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.fukurou.taglet; 017 018 import com.sun.tools.doclets.Taglet; 019 import com.sun.javadoc.Tag; 020 import java.util.Map; 021 import org.opengion.fukurou.util.StringUtil; 022 023 /** 024 * ソースコメントから?Javadoc を作?する場合?カスタ?グ??を作?する 025 * Taglet インターフェースの実?ラスを作?します? 026 * og.formSample タグ(形式サンプル)を??ます? 027 * 028 * @version 4.0 029 * @author Kazuhiko Hasegawa 030 * @since JDK5.0, 031 */ 032 public class TagletFormSample extends AbstractTaglet { 033 034 private static final String NAME = "og.formSample"; 035 private static final String HEADER = "形式サンプル:"; 036 037 /** 038 * 実行時にドックレ?がタグレ?を読み込んで使用するには? 039 * そ?タグレ?が?次のシグニチャでマッ?を引数として受け取る? 040 * レジスタ と呼ばれる static メソ?をもって??があります? 041 * こ?メソ?は、タグレ?名をキーとして、カスタ?グレ?の 042 * インスタンスを???に追?ます? タグレ?をオーバ?ライドする?合? 043 * 名前の競合を避けるため、新しいタグレ?のインスタンスを???に 044 * 追?る前に、オーバ?ライドされる側のタグレ?を???から 045 * 削除する?があります? 046 * 047 * @param tagletMap タグレ?マッ? 048 */ 049 public static void register( final Map<String,Taglet> tagletMap ) { 050 TagletFormSample tagForm = new TagletFormSample(); 051 Taglet tag = tagletMap.get(NAME); 052 if(tag != null) { 053 tagletMap.remove(NAME); 054 } 055 tagletMap.put(NAME, tagForm); 056 } 057 058 /** 059 * こ?カスタ?グの名前を返します? 060 * 061 * @return カスタ?グの名前 062 */ 063 public String getName() { 064 return NAME; 065 } 066 067 /** 068 * こ?カスタ?グのタグ表現を受け取り? 069 * ??としての表現を返し、生成されたペ?ジに出力します? 070 * 071 * @param tagTag こ?カスタ?グのタグ表現 072 * 073 * @return こ?タグの??としての表現 074 */ 075 public String toString( final Tag tagTag ) { 076 return "<span bgcolor=\"yellow\">" 077 + StringUtil.htmlFilter( tagTag.text() ) 078 + "</span>"; 079 } 080 081 /** 082 * こ?カスタ?グのタグ表現の配?を受け取り? 083 * ??としての表現を返し、生成されたペ?ジに出力します? 084 * こ?タグレ?がインラインタグを表す?合? 085 * こ?メソ?は null を返します? 086 * 087 * @param tagTags こ?カスタ?グを表すタグの配? 088 * 089 * @return こ?タグの??としての表現 090 */ 091 public String toString( final Tag[] tagTags ) { 092 if(tagTags.length == 0) { 093 return null; 094 } 095 StringBuilder result = new StringBuilder(); 096 result.append( "<dt><b>" ).append( HEADER ).append( "</b></dt>" ); 097 result.append( "<dd><pre> " ); 098 for( int i=0; i<tagTags.length; i++ ) { 099 result.append( link( tagTags[i].text() ) ); 100 } 101 result.append( "</pre></dd>\n" ); 102 return result.toString(); 103 } 104 }