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

Sun, 24 Feb 2013 11:36:58 -0800

author
jjg
date
Sun, 24 Feb 2013 11:36:58 -0800
changeset 1606
ccbe7ffdd867
parent 1362
c46e0c9940d6
child 1742
7af0fa419a2b
permissions
-rw-r--r--

7112427: The doclet needs to be able to generate JavaFX documentation.
Reviewed-by: jjg
Contributed-by: jan.valenta@oracle.com

     1 /*
     2  * Copyright (c) 2003, 2012, Oracle and/or its affiliates. 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.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * 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  *  <p><b>This is NOT part of any supported API.
    42  *  If you write code that depends on this, you do so at your own risk.
    43  *  This code and its internal interfaces are subject to change or
    44  *  deletion without notice.</b>
    45  *
    46  * @author Scott Seligman
    47  * @since 1.5
    48  */
    50 public class LiteralTaglet implements Taglet {
    52     private static final String NAME = "literal";
    54     public static void register(Map<String,Taglet> map) {
    55            map.remove(NAME);
    56            map.put(NAME, new LiteralTaglet());
    57     }
    59     public String getName() {
    60         return NAME;
    61     }
    63     public String toString(Tag tag) {
    64         return textToString(tag.text());
    65     }
    67     public String toString(Tag[] tags) { return null; }
    69     public boolean inField() { return false; }
    71     public boolean inConstructor() { return false; }
    73     public boolean inMethod() { return false; }
    75     public boolean inOverview() { return false; }
    77     public boolean inPackage() { return false; }
    79     public boolean inType() { return false; }
    81     public boolean isInlineTag() { return true; }
    83     /*
    84      * Replace occurrences of the following characters:  < > &
    85      */
    86     protected static String textToString(String text) {
    87            StringBuilder buf = new StringBuilder();
    88            for (int i = 0; i < text.length(); i++) {
    89                char c = text.charAt(i);
    90                switch (c) {
    91                    case '<':
    92                           buf.append("&lt;");
    93                           break;
    94                    case '>':
    95                           buf.append("&gt;");
    96                           break;
    97                    case '&':
    98                           buf.append("&amp;");
    99                           break;
   100                    default:
   101                           buf.append(c);
   102                }
   103            }
   104            return buf.toString();
   105     }
   106 }

mercurial