src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/LiteralTaglet.java

Thu, 02 Oct 2008 19:58:40 -0700

author
xdono
date
Thu, 02 Oct 2008 19:58:40 -0700
changeset 117
24a47c3062fe
parent 74
5a9172b251dd
child 554
9d9f26857129
permissions
-rw-r--r--

6754988: Update copyright year
Summary: Update for files that have been modified starting July 2008
Reviewed-by: ohair, tbell

     1 /*
     2  * Copyright 2003-2008 Sun Microsystems, Inc.  All Rights Reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Sun designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Sun in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
    23  * have any questions.
    24  */
    25 package com.sun.tools.doclets.internal.toolkit.taglets;
    27 import java.util.Map;
    28 import com.sun.javadoc.Tag;
    29 import com.sun.tools.doclets.Taglet;
    32 /**
    33  * An inline Taglet used to denote literal text.
    34  * The enclosed text is interpreted as not containing HTML markup or
    35  * nested javadoc tags.
    36  * For example, the text:
    37  * <blockquote>  {@code {@literal a<B>c}}  </blockquote>
    38  * displays as:
    39  * <blockquote>  {@literal a<B>c}  </blockquote>
    40  *
    41  * @author Scott Seligman
    42  * @since 1.5
    43  */
    45 public class LiteralTaglet implements Taglet {
    47     private static final String NAME = "literal";
    49     public static void register(Map<String,Taglet> map) {
    50            map.remove(NAME);
    51            map.put(NAME, new LiteralTaglet());
    52     }
    54     public String getName() {
    55         return NAME;
    56     }
    58     public String toString(Tag tag) {
    59         return textToString(tag.text());
    60     }
    62     public String toString(Tag[] tags) { return null; }
    64     public boolean inField() { return false; }
    66     public boolean inConstructor() { return false; }
    68     public boolean inMethod() { return false; }
    70     public boolean inOverview() { return false; }
    72     public boolean inPackage() { return false; }
    74     public boolean inType() { return false; }
    76     public boolean isInlineTag() { return true; }
    78     /*
    79      * Replace occurrences of the following characters:  < > &
    80      */
    81     protected static String textToString(String text) {
    82            StringBuffer buf = new StringBuffer();
    83            for (int i = 0; i < text.length(); i++) {
    84                char c = text.charAt(i);
    85                switch (c) {
    86                    case '<':
    87                           buf.append("&lt;");
    88                           break;
    89                    case '>':
    90                           buf.append("&gt;");
    91                           break;
    92                    case '&':
    93                           buf.append("&amp;");
    94                           break;
    95                    default:
    96                           buf.append(c);
    97                }
    98            }
    99            return buf.toString();
   100     }
   101 }

mercurial