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    
020    /**
021     * ソースコメントから?Javadoc を作?する場合?カスタ?グ??を作?する
022     * Taglet インターフェースのAbstract 実?ラスを作?します?
023     * ?ォルト? タグレ?としての初期値を設定します?
024     * つまり?isInlineTag() のみ false を返すメソ?を定義してあります?
025     *
026     * @version  4.0
027     * @author   Kazuhiko Hasegawa
028     * @since    JDK5.0,
029     */
030    public abstract class AbstractTaglet implements Taglet {
031    
032            /**
033             * こ?タグレ?がフィールドドキュメン??ションで
034             * 使用されて?場合?true を返します?
035             * インラインタグにつ?は false が設定されます?
036             *
037             * @return フィールドドキュメン??ションの場合? true、そ?な??合? false を返しま?
038             */
039            public boolean inField() {
040                    return true;
041            }
042    
043            /**
044             * こ?タグレ?がコンストラクタドキュメン??ションで
045             * 使用されて?場合?true を返します?
046             * インラインタグにつ?は false が設定されます?
047             *
048             * @return コンストラクタドキュメン??ションの場合? true、そ?な??合? false を返しま?
049             */
050            public boolean inConstructor() {
051                    return true;
052            }
053    
054            /**
055             * こ?タグレ?がメソ?ドキュメン??ションで
056             * 使用されて?場合?true を返します?
057             * インラインタグにつ?は false が設定されます?
058             *
059             * @return メソ?ドキュメン??ションの場合? true、そ?な??合? false を返しま?
060             */
061            public boolean inMethod() {
062                    return true;
063            }
064    
065            /**
066             * こ?タグレ?が概要ドキュメン??ションで
067             * 使用されて?場合?true を返します?
068             * インラインタグにつ?は false が設定されます?
069             *
070             * @return 概要ドキュメン??ションの場合? true、そ?な??合? false を返しま?
071             */
072            public boolean inOverview() {
073                    return true;
074            }
075    
076            /**
077             * こ?タグレ?がパ?ージドキュメン??ションで
078             * 使用されて?場合?true を返します?
079             * インラインタグにつ?は false が設定されます?
080             *
081             * @return パッケージドキュメン??ションの場合? true、そ?な??合? false を返しま?
082             */
083            public boolean inPackage() {
084                    return true;
085            }
086    
087            /**
088             * こ?タグレ?がタイプドキュメン??ションで
089             * 使用されて?場合?true を返します?
090             * インラインタグにつ?は false が設定されます?
091             *
092             * @return タイプドキュメン??ションの場合? true、そ?な??合? false を返しま?
093             */
094            public boolean inType() {
095                    return true;
096            }
097    
098            /**
099             * こ?タグレ?がインラインタグで
100             * 使用されて?場合?true を返します?
101             * そうでな??合につ?は false が設定されます?
102             *
103             * @return インラインタグの場合? true、そ?な??合? false を返しま?
104             */
105            public boolean isInlineTag() {
106                    return false;
107            }
108    
109            /**
110             * こ?タグレ?がインラインタグで {@link XXXX YYYY} を??るよ?
111             * 用意された、カスタ?ソ?です?
112             *
113             * @og.rev 5.1.9.0 (2010/08/01) 新規追?
114             *
115             * @param       in      オリジナルの??
116             *
117             * @return      インラインタグの link を??た結果の??
118             */
119            protected String link( final String in ) {
120                    if( in == null ) { return ""; }
121                    int index = in.indexOf( "{@link" );
122                    if( index < 0 ) { return in; }
123    
124                    StringBuilder rtn = new StringBuilder();
125                    int start = 0;
126                    while( index >= 0 ) {
127                            int end = in.indexOf( '}',index );
128    
129                            // {@ より前方の??を追?
130                            if( index > 0 ) { rtn.append( in.substring( start,index ) ); }
131    
132                            // {@link XXXX YY} の XXXX YY部?処?
133                            String val = in.substring( index+7,end );
134                            if( val != null ) {
135                                    int sp = val.indexOf( ' ' );
136                                    String xxx = val.substring( 0,sp ).trim();      // 前半?アドレス変換
137                                    String yyy = val.substring( sp ).trim();        // 後半?ラベル
138                                    String zzz = xxx.replace( '.','/' );
139                                    rtn.append( "<a href=\"../../../../" ).append( zzz ).append( ".html\" " )
140                                            .append( "title=\"" ).append( xxx ).append( "\">" )
141                                            .append( yyy ).append( "</a>" );
142                            }
143    
144                            start = end+1 ;
145                            index = in.indexOf( "{@",start );
146                    }
147                    rtn.append( in.substring( start ) );
148    
149                    return rtn.toString();
150            }
151    }