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.fukurou.taglet; 017 018import com.sun.tools.doclets.Taglet; 019import com.sun.javadoc.Tag; 020import java.util.Map; 021import org.opengion.fukurou.util.StringUtil; 022 023/** 024 * ソースコメントから、Javadoc を作成する場合のカスタムタグ情報を作成する 025 * Taglet インターフェースの実装クラスを作成します。 026 * og.rev タグ(変更履歴)を処理します。 027 * 028 * @version 4.0 029 * @author Kazuhiko Hasegawa 030 * @since JDK5.0, 031 */ 032public class TagletRev extends AbstractTaglet { 033 034 private static final String NAME = "og.rev"; 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 TagletRev tagRev = new TagletRev(); 051 Taglet tag = tagletMap.get(NAME); 052 if(tag != null) { 053 tagletMap.remove(NAME); 054 } 055 tagletMap.put(NAME, tagRev); 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 "<li />" 077 + StringUtil.htmlFilter( tagTag.text() ) ; 078 } 079 080 /** 081 * このカスタムタグのタグ表現の配列を受け取り、 082 * 文字列としての表現を返し、生成されたページに出力します。 083 * このタグレットがインラインタグを表す場合、 084 * このメソッドは null を返します。 085 * 086 * @og.rev 5.1.9.0 (2010/08/01) dtタグをきちんと記述する。 087 * 088 * @param tagTags このカスタムタグを表すタグの配列 089 * 090 * @return このタグの文字列としての表現 091 */ 092 public String toString( final Tag[] tagTags ) { 093 if(tagTags.length == 0) { 094 return null; 095 } 096 StringBuilder result = new StringBuilder(); 097 result.append( "<dt><b>" ).append( HEADER ).append( "</b></dt>" ); // 5.1.9.0 (2010/08/01) 098 result.append( "<dd><table cellpadding=\"2\" cellspacing=\"0\">" ); 099 for(int i = 0; i < tagTags.length; i++) { 100 result.append( "<tr><td>" ); 101 result.append( link( tagTags[i].text() ) ); 102 result.append( "</td></tr>" ); 103 } 104 result.append( "</table></dd>\n" ); 105 return result.toString(); 106 } 107}