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

changeset 1
9a66ca7c79fa
child 74
5a9172b251dd
equal deleted inserted replaced
-1:000000000000 1:9a66ca7c79fa
1 /*
2 * Copyright 2003 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;
26
27 import java.util.Map;
28 import com.sun.javadoc.Tag;
29 import com.sun.tools.doclets.Taglet;
30
31
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 */
44
45 public class LiteralTaglet implements Taglet {
46
47 private static final String NAME = "literal";
48
49 public static void register(Map map) {
50 map.remove(NAME);
51 map.put(NAME, new LiteralTaglet());
52 }
53
54 public String getName() {
55 return NAME;
56 }
57
58 public String toString(Tag tag) {
59 return textToString(tag.text());
60 }
61
62 public String toString(Tag[] tags) { return null; }
63
64 public boolean inField() { return false; }
65
66 public boolean inConstructor() { return false; }
67
68 public boolean inMethod() { return false; }
69
70 public boolean inOverview() { return false; }
71
72 public boolean inPackage() { return false; }
73
74 public boolean inType() { return false; }
75
76 public boolean isInlineTag() { return true; }
77
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