src/share/classes/com/sun/tools/doclets/formats/html/LinkFactoryImpl.java

Tue, 09 Oct 2012 19:10:00 -0700

author
jjg
date
Tue, 09 Oct 2012 19:10:00 -0700
changeset 1357
c75be5bc5283
parent 958
734144b6b22f
child 1358
fc123bdeddb8
permissions
-rw-r--r--

8000663: clean up langtools imports
Reviewed-by: darcy

     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  */
    26 package com.sun.tools.doclets.formats.html;
    28 import com.sun.javadoc.*;
    29 import com.sun.tools.doclets.internal.toolkit.*;
    30 import com.sun.tools.doclets.internal.toolkit.util.*;
    31 import com.sun.tools.doclets.internal.toolkit.util.links.*;
    33 /**
    34  * A factory that returns a link given the information about it.
    35  *
    36  * @author Jamie Ho
    37  * @since 1.5
    38  */
    39 public class LinkFactoryImpl extends LinkFactory {
    41     private HtmlDocletWriter m_writer;
    43     public LinkFactoryImpl(HtmlDocletWriter writer) {
    44         m_writer = writer;
    45     }
    47     /**
    48      * {@inheritDoc}
    49      */
    50     protected LinkOutput getOutputInstance() {
    51         return new LinkOutputImpl();
    52     }
    54     /**
    55      * {@inheritDoc}
    56      */
    57     protected LinkOutput getClassLink(LinkInfo linkInfo) {
    58         LinkInfoImpl classLinkInfo = (LinkInfoImpl) linkInfo;
    59         boolean noLabel = linkInfo.label == null || linkInfo.label.length() == 0;
    60         ClassDoc classDoc = classLinkInfo.classDoc;
    61         //Create a tool tip if we are linking to a class or interface.  Don't
    62         //create one if we are linking to a member.
    63         String title =
    64             (classLinkInfo.where == null || classLinkInfo.where.length() == 0) ?
    65                 getClassToolTip(classDoc,
    66                     classLinkInfo.type != null &&
    67                     !classDoc.qualifiedTypeName().equals(classLinkInfo.type.qualifiedTypeName())) :
    68             "";
    69         StringBuffer label = new StringBuffer(
    70             classLinkInfo.getClassLinkLabel(m_writer.configuration));
    71         classLinkInfo.displayLength += label.length();
    72         Configuration configuration = ConfigurationImpl.getInstance();
    73         LinkOutputImpl linkOutput = new LinkOutputImpl();
    74         if (classDoc.isIncluded()) {
    75             if (configuration.isGeneratedDoc(classDoc)) {
    76                 String filename = pathString(classLinkInfo);
    77                 if (linkInfo.linkToSelf ||
    78                                 !(linkInfo.classDoc.name() + ".html").equals(m_writer.filename)) {
    79                         linkOutput.append(m_writer.getHyperLinkString(filename,
    80                             classLinkInfo.where, label.toString(),
    81                             classLinkInfo.isStrong, classLinkInfo.styleName,
    82                             title, classLinkInfo.target));
    83                         if (noLabel && !classLinkInfo.excludeTypeParameterLinks) {
    84                             linkOutput.append(getTypeParameterLinks(linkInfo).toString());
    85                         }
    86                         return linkOutput;
    87                 }
    88             }
    89         } else {
    90             String crossLink = m_writer.getCrossClassLink(
    91                 classDoc.qualifiedName(), classLinkInfo.where,
    92                 label.toString(), classLinkInfo.isStrong, classLinkInfo.styleName,
    93                 true);
    94             if (crossLink != null) {
    95                 linkOutput.append(crossLink);
    96                 if (noLabel && !classLinkInfo.excludeTypeParameterLinks) {
    97                     linkOutput.append(getTypeParameterLinks(linkInfo).toString());
    98                 }
    99                 return linkOutput;
   100             }
   101         }
   102         // Can't link so just write label.
   103         linkOutput.append(label.toString());
   104         if (noLabel && !classLinkInfo.excludeTypeParameterLinks) {
   105             linkOutput.append(getTypeParameterLinks(linkInfo).toString());
   106         }
   107         return linkOutput;
   108     }
   110     /**
   111      * {@inheritDoc}
   112      */
   113     protected LinkOutput getTypeParameterLink(LinkInfo linkInfo,
   114         Type typeParam) {
   115         LinkInfoImpl typeLinkInfo = new LinkInfoImpl(linkInfo.getContext(),
   116             typeParam);
   117         typeLinkInfo.excludeTypeBounds = linkInfo.excludeTypeBounds;
   118         typeLinkInfo.excludeTypeParameterLinks = linkInfo.excludeTypeParameterLinks;
   119         typeLinkInfo.linkToSelf = linkInfo.linkToSelf;
   120         LinkOutput output = getLinkOutput(typeLinkInfo);
   121         ((LinkInfoImpl) linkInfo).displayLength += typeLinkInfo.displayLength;
   122         return output;
   123     }
   125     /**
   126      * Given a class, return the appropriate tool tip.
   127      *
   128      * @param classDoc the class to get the tool tip for.
   129      * @return the tool tip for the appropriate class.
   130      */
   131     private String getClassToolTip(ClassDoc classDoc, boolean isTypeLink) {
   132         Configuration configuration = ConfigurationImpl.getInstance();
   133         if (isTypeLink) {
   134             return configuration.getText("doclet.Href_Type_Param_Title",
   135             classDoc.name());
   136         } else if (classDoc.isInterface()){
   137             return configuration.getText("doclet.Href_Interface_Title",
   138                 Util.getPackageName(classDoc.containingPackage()));
   139         } else if (classDoc.isAnnotationType()) {
   140             return configuration.getText("doclet.Href_Annotation_Title",
   141                 Util.getPackageName(classDoc.containingPackage()));
   142         } else if (classDoc.isEnum()) {
   143             return configuration.getText("doclet.Href_Enum_Title",
   144                 Util.getPackageName(classDoc.containingPackage()));
   145         } else {
   146             return configuration.getText("doclet.Href_Class_Title",
   147                 Util.getPackageName(classDoc.containingPackage()));
   148         }
   149     }
   151     /**
   152      * Return path to the given file name in the given package. So if the name
   153      * passed is "Object.html" and the name of the package is "java.lang", and
   154      * if the relative path is "../.." then returned string will be
   155      * "../../java/lang/Object.html"
   156      *
   157      * @param linkInfo the information about the link.
   158      * @param fileName the file name, to which path string is.
   159      */
   160     private String pathString(LinkInfoImpl linkInfo) {
   161         if (linkInfo.context == LinkInfoImpl.PACKAGE_FRAME) {
   162             //Not really necessary to do this but we want to be consistent
   163             //with 1.4.2 output.
   164             return linkInfo.classDoc.name() + ".html";
   165         }
   166         StringBuffer buf = new StringBuffer(m_writer.relativePath);
   167         buf.append(DirectoryManager.getPathToPackage(
   168             linkInfo.classDoc.containingPackage(),
   169             linkInfo.classDoc.name() + ".html"));
   170         return buf.toString();
   171     }
   172 }

mercurial