1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/LinkFactoryImpl.java Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,175 @@ 1.4 +/* 1.5 + * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Sun designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Sun in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.26 + * have any questions. 1.27 + */ 1.28 + 1.29 +package com.sun.tools.doclets.formats.html; 1.30 + 1.31 +import com.sun.tools.doclets.internal.toolkit.util.links.*; 1.32 +import com.sun.javadoc.*; 1.33 +import com.sun.tools.doclets.internal.toolkit.*; 1.34 +import com.sun.tools.doclets.internal.toolkit.util.*; 1.35 + 1.36 +/** 1.37 + * A factory that returns a link given the information about it. 1.38 + * 1.39 + * @author Jamie Ho 1.40 + * @since 1.5 1.41 + */ 1.42 +public class LinkFactoryImpl extends LinkFactory { 1.43 + 1.44 + private HtmlDocletWriter m_writer; 1.45 + 1.46 + public LinkFactoryImpl(HtmlDocletWriter writer) { 1.47 + m_writer = writer; 1.48 + } 1.49 + 1.50 + /** 1.51 + * {@inheritDoc} 1.52 + */ 1.53 + protected LinkOutput getOutputInstance() { 1.54 + return new LinkOutputImpl(); 1.55 + } 1.56 + 1.57 + /** 1.58 + * {@inheritDoc} 1.59 + */ 1.60 + protected LinkOutput getClassLink(LinkInfo linkInfo) { 1.61 + LinkInfoImpl classLinkInfo = (LinkInfoImpl) linkInfo; 1.62 + boolean noLabel = linkInfo.label == null || linkInfo.label.length() == 0; 1.63 + ClassDoc classDoc = classLinkInfo.classDoc; 1.64 + //Create a tool tip if we are linking to a class or interface. Don't 1.65 + //create one if we are linking to a member. 1.66 + String title = 1.67 + (classLinkInfo.where == null || classLinkInfo.where.length() == 0) ? 1.68 + getClassToolTip(classDoc, 1.69 + classLinkInfo.type != null && 1.70 + !classDoc.qualifiedTypeName().equals(classLinkInfo.type.qualifiedTypeName())) : 1.71 + ""; 1.72 + StringBuffer label = new StringBuffer( 1.73 + classLinkInfo.getClassLinkLabel(m_writer.configuration)); 1.74 + classLinkInfo.displayLength += label.length(); 1.75 + if (noLabel && classLinkInfo.excludeTypeParameterLinks) { 1.76 + label.append(getTypeParameterLinks(linkInfo).toString()); 1.77 + } 1.78 + Configuration configuration = ConfigurationImpl.getInstance(); 1.79 + LinkOutputImpl linkOutput = new LinkOutputImpl(); 1.80 + if (classDoc.isIncluded()) { 1.81 + if (configuration.isGeneratedDoc(classDoc)) { 1.82 + String filename = pathString(classLinkInfo); 1.83 + if (linkInfo.linkToSelf || 1.84 + !(linkInfo.classDoc.name() + ".html").equals(m_writer.filename)) { 1.85 + linkOutput.append(m_writer.getHyperLink(filename, 1.86 + classLinkInfo.where, label.toString(), 1.87 + classLinkInfo.isBold, classLinkInfo.styleName, 1.88 + title, classLinkInfo.target)); 1.89 + if (noLabel && !classLinkInfo.excludeTypeParameterLinks) { 1.90 + linkOutput.append(getTypeParameterLinks(linkInfo).toString()); 1.91 + } 1.92 + return linkOutput; 1.93 + } 1.94 + } 1.95 + } else { 1.96 + String crossLink = m_writer.getCrossClassLink( 1.97 + classDoc.qualifiedName(), classLinkInfo.where, 1.98 + label.toString(), classLinkInfo.isBold, classLinkInfo.styleName, 1.99 + true); 1.100 + if (crossLink != null) { 1.101 + linkOutput.append(crossLink); 1.102 + if (noLabel && !classLinkInfo.excludeTypeParameterLinks) { 1.103 + linkOutput.append(getTypeParameterLinks(linkInfo).toString()); 1.104 + } 1.105 + return linkOutput; 1.106 + } 1.107 + } 1.108 + // Can't link so just write label. 1.109 + linkOutput.append(label.toString()); 1.110 + if (noLabel && !classLinkInfo.excludeTypeParameterLinks) { 1.111 + linkOutput.append(getTypeParameterLinks(linkInfo).toString()); 1.112 + } 1.113 + return linkOutput; 1.114 + } 1.115 + 1.116 + /** 1.117 + * {@inheritDoc} 1.118 + */ 1.119 + protected LinkOutput getTypeParameterLink(LinkInfo linkInfo, 1.120 + Type typeParam) { 1.121 + LinkInfoImpl typeLinkInfo = new LinkInfoImpl(linkInfo.getContext(), 1.122 + typeParam); 1.123 + typeLinkInfo.excludeTypeBounds = linkInfo.excludeTypeBounds; 1.124 + typeLinkInfo.excludeTypeParameterLinks = linkInfo.excludeTypeParameterLinks; 1.125 + typeLinkInfo.linkToSelf = linkInfo.linkToSelf; 1.126 + LinkOutput output = getLinkOutput(typeLinkInfo); 1.127 + ((LinkInfoImpl) linkInfo).displayLength += typeLinkInfo.displayLength; 1.128 + return output; 1.129 + } 1.130 + 1.131 + /** 1.132 + * Given a class, return the appropriate tool tip. 1.133 + * 1.134 + * @param classDoc the class to get the tool tip for. 1.135 + * @return the tool tip for the appropriate class. 1.136 + */ 1.137 + private String getClassToolTip(ClassDoc classDoc, boolean isTypeLink) { 1.138 + Configuration configuration = ConfigurationImpl.getInstance(); 1.139 + if (isTypeLink) { 1.140 + return configuration.getText("doclet.Href_Type_Param_Title", 1.141 + classDoc.name()); 1.142 + } else if (classDoc.isInterface()){ 1.143 + return configuration.getText("doclet.Href_Interface_Title", 1.144 + Util.getPackageName(classDoc.containingPackage())); 1.145 + } else if (classDoc.isAnnotationType()) { 1.146 + return configuration.getText("doclet.Href_Annotation_Title", 1.147 + Util.getPackageName(classDoc.containingPackage())); 1.148 + } else if (classDoc.isEnum()) { 1.149 + return configuration.getText("doclet.Href_Enum_Title", 1.150 + Util.getPackageName(classDoc.containingPackage())); 1.151 + } else { 1.152 + return configuration.getText("doclet.Href_Class_Title", 1.153 + Util.getPackageName(classDoc.containingPackage())); 1.154 + } 1.155 + } 1.156 + 1.157 + /** 1.158 + * Return path to the given file name in the given package. So if the name 1.159 + * passed is "Object.html" and the name of the package is "java.lang", and 1.160 + * if the relative path is "../.." then returned string will be 1.161 + * "../../java/lang/Object.html" 1.162 + * 1.163 + * @param linkInfo the information about the link. 1.164 + * @param fileName the file name, to which path string is. 1.165 + */ 1.166 + private String pathString(LinkInfoImpl linkInfo) { 1.167 + if (linkInfo.context == LinkInfoImpl.PACKAGE_FRAME) { 1.168 + //Not really necessary to do this but we want to be consistent 1.169 + //with 1.4.2 output. 1.170 + return linkInfo.classDoc.name() + ".html"; 1.171 + } 1.172 + StringBuffer buf = new StringBuffer(m_writer.relativePath); 1.173 + buf.append(DirectoryManager.getPathToPackage( 1.174 + linkInfo.classDoc.containingPackage(), 1.175 + linkInfo.classDoc.name() + ".html")); 1.176 + return buf.toString(); 1.177 + } 1.178 +}