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.rev タグ(変更履歴)を??ます?
027     *
028     * @version  4.0
029     * @author   Kazuhiko Hasegawa
030     * @since    JDK5.0,
031     */
032    public 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    }