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

Tue, 28 Dec 2010 15:54:52 -0800

author
ohair
date
Tue, 28 Dec 2010 15:54:52 -0800
changeset 798
4868a36f6fd8
parent 766
90af8d87741f
child 958
734144b6b22f
permissions
-rw-r--r--

6962318: Update copyright year
Reviewed-by: xdono

     1 /*
     2  * Copyright (c) 2003, 2010, 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.tools.doclets.internal.toolkit.util.links.*;
    29 import com.sun.javadoc.*;
    30 import com.sun.tools.doclets.internal.toolkit.*;
    31 import com.sun.tools.doclets.internal.toolkit.util.*;
    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         if (noLabel && classLinkInfo.excludeTypeParameterLinks) {
    73             label.append(getTypeParameterLinks(linkInfo).toString());
    74         }
    75         Configuration configuration = ConfigurationImpl.getInstance();
    76         LinkOutputImpl linkOutput = new LinkOutputImpl();
    77         if (classDoc.isIncluded()) {
    78             if (configuration.isGeneratedDoc(classDoc)) {
    79                 String filename = pathString(classLinkInfo);
    80                 if (linkInfo.linkToSelf ||
    81                                 !(linkInfo.classDoc.name() + ".html").equals(m_writer.filename)) {
    82                         linkOutput.append(m_writer.getHyperLinkString(filename,
    83                             classLinkInfo.where, label.toString(),
    84                             classLinkInfo.isStrong, classLinkInfo.styleName,
    85                             title, classLinkInfo.target));
    86                         if (noLabel && !classLinkInfo.excludeTypeParameterLinks) {
    87                             linkOutput.append(getTypeParameterLinks(linkInfo).toString());
    88                         }
    89                         return linkOutput;
    90                 }
    91             }
    92         } else {
    93             String crossLink = m_writer.getCrossClassLink(
    94                 classDoc.qualifiedName(), classLinkInfo.where,
    95                 label.toString(), classLinkInfo.isStrong, classLinkInfo.styleName,
    96                 true);
    97             if (crossLink != null) {
    98                 linkOutput.append(crossLink);
    99                 if (noLabel && !classLinkInfo.excludeTypeParameterLinks) {
   100                     linkOutput.append(getTypeParameterLinks(linkInfo).toString());
   101                 }
   102                 return linkOutput;
   103             }
   104         }
   105         // Can't link so just write label.
   106         linkOutput.append(label.toString());
   107         if (noLabel && !classLinkInfo.excludeTypeParameterLinks) {
   108             linkOutput.append(getTypeParameterLinks(linkInfo).toString());
   109         }
   110         return linkOutput;
   111     }
   113     /**
   114      * {@inheritDoc}
   115      */
   116     protected LinkOutput getTypeParameterLink(LinkInfo linkInfo,
   117         Type typeParam) {
   118         LinkInfoImpl typeLinkInfo = new LinkInfoImpl(linkInfo.getContext(),
   119             typeParam);
   120         typeLinkInfo.excludeTypeBounds = linkInfo.excludeTypeBounds;
   121         typeLinkInfo.excludeTypeParameterLinks = linkInfo.excludeTypeParameterLinks;
   122         typeLinkInfo.linkToSelf = linkInfo.linkToSelf;
   123         LinkOutput output = getLinkOutput(typeLinkInfo);
   124         ((LinkInfoImpl) linkInfo).displayLength += typeLinkInfo.displayLength;
   125         return output;
   126     }
   128     /**
   129      * Given a class, return the appropriate tool tip.
   130      *
   131      * @param classDoc the class to get the tool tip for.
   132      * @return the tool tip for the appropriate class.
   133      */
   134     private String getClassToolTip(ClassDoc classDoc, boolean isTypeLink) {
   135         Configuration configuration = ConfigurationImpl.getInstance();
   136         if (isTypeLink) {
   137             return configuration.getText("doclet.Href_Type_Param_Title",
   138             classDoc.name());
   139         } else if (classDoc.isInterface()){
   140             return configuration.getText("doclet.Href_Interface_Title",
   141                 Util.getPackageName(classDoc.containingPackage()));
   142         } else if (classDoc.isAnnotationType()) {
   143             return configuration.getText("doclet.Href_Annotation_Title",
   144                 Util.getPackageName(classDoc.containingPackage()));
   145         } else if (classDoc.isEnum()) {
   146             return configuration.getText("doclet.Href_Enum_Title",
   147                 Util.getPackageName(classDoc.containingPackage()));
   148         } else {
   149             return configuration.getText("doclet.Href_Class_Title",
   150                 Util.getPackageName(classDoc.containingPackage()));
   151         }
   152     }
   154     /**
   155      * Return path to the given file name in the given package. So if the name
   156      * passed is "Object.html" and the name of the package is "java.lang", and
   157      * if the relative path is "../.." then returned string will be
   158      * "../../java/lang/Object.html"
   159      *
   160      * @param linkInfo the information about the link.
   161      * @param fileName the file name, to which path string is.
   162      */
   163     private String pathString(LinkInfoImpl linkInfo) {
   164         if (linkInfo.context == LinkInfoImpl.PACKAGE_FRAME) {
   165             //Not really necessary to do this but we want to be consistent
   166             //with 1.4.2 output.
   167             return linkInfo.classDoc.name() + ".html";
   168         }
   169         StringBuffer buf = new StringBuffer(m_writer.relativePath);
   170         buf.append(DirectoryManager.getPathToPackage(
   171             linkInfo.classDoc.containingPackage(),
   172             linkInfo.classDoc.name() + ".html"));
   173         return buf.toString();
   174     }
   175 }

mercurial