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.value タグ(形式サンプル)を??ます?
027     *
028     * こ?タグは、インラインタグ 定義されて?ため、@og.tag などに含まれると処?れません?
029     * そこで?DocletTagWriter#printTag( final Tag[] tag ) に処?追?る?があります?
030     *
031     * @og.rev 5.5.4.1 (2012/07/06) 新規作?
032     *
033     * @version  4.0
034     * @author   Kazuhiko Hasegawa
035     * @since    JDK5.0,
036     */
037    public class TagletValue extends AbstractTaglet {
038    
039            private static final String NAME   = "og.value";
040    
041            /**
042             * こ?タグレ?がインラインタグで
043             * 使用されて?場合?true を返します?
044             * そうでな??合につ?は false が設定されます?
045             *
046             * @return インラインタグの場合? true、そ?な??合? false を返しま?
047             */
048            @Override
049            public boolean isInlineTag() {
050                    return true;
051            }
052    
053            /**
054             * 実行時にドックレ?がタグレ?を読み込んで使用するには?
055             * そ?タグレ?が?次のシグニチャでマッ?を引数として受け取る?
056             * レジスタ と呼ばれる static メソ?をもって??があります?
057             * こ?メソ?は、タグレ?名をキーとして、カスタ?グレ?の
058             * インスタンスを???に追?ます? タグレ?をオーバ?ライドする?合?
059             * 名前の競合を避けるため、新しいタグレ?のインスタンスを???に
060             * 追?る前に、オーバ?ライドされる側のタグレ?を???から
061             * 削除する?があります?
062             *
063             * @param tagletMap タグレ?マッ?
064             */
065            public static void register( final Map<String,Taglet> tagletMap ) {
066               TagletValue tagTag = new TagletValue();
067               Taglet tag = tagletMap.get(NAME);
068               if(tag != null) {
069                       tagletMap.remove(NAME);
070               }
071               tagletMap.put(NAME, tagTag);
072            }
073    
074            /**
075             * こ?カスタ?グの名前を返します?
076             *
077             * @return カスタ?グの名前
078             */
079            public String getName() {
080                    return NAME;
081            }
082    
083            /**
084             * こ?カスタ?グのタグ表現を受け取り?
085             * ??としての表現を返し、生成されたペ?ジに出力します?
086             *
087             * @param tagTag こ?カスタ?グのタグ表現
088             *
089             * @return こ?タグの??としての表現
090             */
091            public String toString( final Tag tagTag ) {
092                    return DocletUtil.valueTag( tagTag );
093            }
094    
095            /**
096             * こ?カスタ?グのタグ表現の配?を受け取り?
097             * ??としての表現を返し、生成されたペ?ジに出力します?
098             * こ?タグレ?がインラインタグを表す?合?
099             * こ?メソ?は null を返します?
100             *
101             * @param tagTags       こ?カスタ?グを表すタグの配?
102             *
103             * @return こ?タグの??としての表現
104             */
105            public String toString( final Tag[] tagTags ) {
106                    if(tagTags.length == 0) {
107                            return null;
108                    }
109                    StringBuilder result = new StringBuilder();
110                    for(int i = 0; i < tagTags.length; i++) {
111                            result.append( DocletUtil.valueTag( tagTags[i] ) );
112                    }
113                    return result.toString();
114            }
115    }