    001    // Copyright 2007, 2008, 2011 The Apache Software Foundation
    002    //
    003    // Licensed under the Apache License, Version 2.0 (the "License");
    004    // you may not use this file except in compliance with the License.
    005    // You may obtain a copy of the License at
    006    //
    007    // http://www.apache.org/licenses/LICENSE-2.0
    008    //
    009    // Unless required by applicable law or agreed to in writing, software
    010    // distributed under the License is distributed on an "AS IS" BASIS,
    011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    012    // See the License for the specific language governing permissions and
    013    // limitations under the License.
    014
    015    package org.apache.tapestry5.javadoc;
    016
    017    import java.io.IOException;
    018    import java.io.Writer;
    019    import java.util.regex.Pattern;
    020
    021    import com.sun.javadoc.FieldDoc;
    022    import com.sun.javadoc.SeeTag;
    023    import com.sun.javadoc.Tag;
    024
    025    public class ParameterDescription
    026    {
    027        public final FieldDoc field;
    028
    029        public final String name;
    030
    031        public final String type;
    032
    033        public final String defaultValue;
    034
    035        public final String defaultPrefix;
    036
    037        public final boolean required;
    038
    039        public final boolean allowNull;
    040
    041        public final boolean cache;
    042
    043        public final String since;
    044
    045        public final boolean deprecated;
    046
    047        private static final Pattern STRIPPER = Pattern.compile("(<.*?>|&.*?;)", Pattern.DOTALL);
    048
    049        public ParameterDescription(FieldDoc fieldDoc, String name, String type, String defaultValue, String defaultPrefix,
    050                boolean required, boolean allowNull, boolean cache, String since, boolean deprecated)
    051        {
    052            this.field = fieldDoc;
    053            this.name = name;
    054            this.type = type;
    055            this.defaultValue = defaultValue;
    056            this.defaultPrefix = defaultPrefix;
    057            this.required = required;
    058            this.allowNull = allowNull;
    059            this.cache = cache;
    060            this.since = since;
    061            this.deprecated = deprecated;
    062        }
    063
    064        public void writeDescription(Writer writer) throws IOException
    065        {
    066            StringBuilder builder = new StringBuilder();
    067
    068            for (Tag tag : field.inlineTags())
    069            {
    070                if (tag.name().equals("Text"))
    071                {
    072                    builder.append(tag.text());
    073                    continue;
    074                }
    075
    076                if (tag.name().equals("@link"))
    077                {
    078                    SeeTag seeTag = (SeeTag) tag;
    079
    080                    String label = seeTag.label();
    081                    if (label != null && !label.equals(""))
    082                    {
    083                        builder.append(label);
    084                        continue;
    085                    }
    086
    087                    if (seeTag.referencedClassName() != null)
    088                        builder.append(seeTag.referencedClassName());
    089
    090                    if (seeTag.referencedMemberName() != null)
    091                    {
    092                        builder.append("#");
    093                        builder.append(seeTag.referencedMemberName());
    094                    }
    095                }
    096            }
    097
    098            String text = builder.toString();
    099
    100            // Fix it up a little.
    101
    102            // Remove any simple open or close tags found in the text, as well as any XML entities.
    103
    104            String stripped = STRIPPER.matcher(text).replaceAll("");
    105
    106            writer.write(stripped);
    107        }
    108    }