src/share/classes/com/sun/tools/doclets/internal/toolkit/util/MetaKeywords.java

Tue, 25 May 2010 15:54:51 -0700

author
ohair
date
Tue, 25 May 2010 15:54:51 -0700
changeset 554
9d9f26857129
parent 140
22c4c1143a3a
child 1357
c75be5bc5283
permissions
-rw-r--r--

6943119: Rebrand source copyright notices
Reviewed-by: darcy

     1 /*
     2  * Copyright (c) 2002, 2008, 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.internal.toolkit.util;
    28 import com.sun.tools.doclets.internal.toolkit.*;
    29 import com.sun.javadoc.*;
    30 import java.util.*;
    32 /**
    33  * Provides methods for creating an array of class, method and
    34  * field names to be included as meta keywords in the HTML header
    35  * of class pages.  These keywords improve search results
    36  * on browsers that look for keywords.
    37  *
    38  * This code is not part of an API.
    39  * It is implementation that is subject to change.
    40  * Do not use it as an API
    41  *
    42  * @author Doug Kramer
    43  */
    44 public class MetaKeywords {
    46     /**
    47      * The global configuration information for this run.
    48      */
    49     private final Configuration configuration;
    51     /**
    52      * Constructor
    53      */
    54     public MetaKeywords(Configuration configuration) {
    55         this.configuration = configuration;
    56     }
    58     /**
    59      * Returns an array of strings where each element
    60      * is a class, method or field name.  This array is
    61      * used to create one meta keyword tag for each element.
    62      * Method parameter lists are converted to "()" and
    63      * overloads are combined.
    64      *
    65      * Constructors are not included because they have the same
    66      * name as the class, which is already included.
    67      * Nested class members are not included because their
    68      * definitions are on separate pages.
    69      */
    70     public String[] getMetaKeywords(ClassDoc classdoc) {
    71         ArrayList<String> results = new ArrayList<String>();
    73         // Add field and method keywords only if -keywords option is used
    74         if( configuration.keywords ) {
    75             results.addAll(getClassKeyword(classdoc));
    76             results.addAll(getMemberKeywords(classdoc.fields()));
    77             results.addAll(getMemberKeywords(classdoc.methods()));
    78         }
    79         return results.toArray(new String[]{});
    80     }
    82     /**
    83      * Get the current class for a meta tag keyword, as the first
    84      * and only element of an array list.
    85      */
    86     protected ArrayList<String> getClassKeyword(ClassDoc classdoc) {
    87         String cltypelower = classdoc.isInterface() ? "interface" : "class";
    88         ArrayList<String> metakeywords = new ArrayList<String>(1);
    89         metakeywords.add(classdoc.qualifiedName() + " " + cltypelower);
    90         return metakeywords;
    91     }
    93     /**
    94      * Get the package keywords.
    95      */
    96     public String[] getMetaKeywords(PackageDoc packageDoc) {
    97         if( configuration.keywords ) {
    98             String pkgName = Util.getPackageName(packageDoc);
    99             return new String[] { pkgName + " " + "package" };
   100         } else {
   101             return new String[] {};
   102         }
   103     }
   105     /**
   106      * Get the overview keywords.
   107      */
   108     public String[] getOverviewMetaKeywords(String title, String docTitle) {
   109         if( configuration.keywords ) {
   110             String windowOverview = configuration.getText(title);
   111             String[] metakeywords = { windowOverview };
   112             if (docTitle.length() > 0 ) {
   113                 metakeywords[0] += ", " + docTitle;
   114             }
   115             return metakeywords;
   116         } else {
   117             return new String[] {};
   118         }
   119     }
   121     /**
   122      * Get members for meta tag keywords as an array,
   123      * where each member name is a string element of the array.
   124      * The parameter lists are not included in the keywords;
   125      * therefore all overloaded methods are combined.<br>
   126      * Example: getValue(Object) is returned in array as getValue()
   127      *
   128      * @param memberdocs  array of MemberDoc objects to be added to keywords
   129      */
   130     protected ArrayList<String> getMemberKeywords(MemberDoc[] memberdocs) {
   131         ArrayList<String> results = new ArrayList<String>();
   132         String membername;
   133         for (int i=0; i < memberdocs.length; i++) {
   134             membername = memberdocs[i].name()
   135                              + (memberdocs[i].isMethod() ? "()" : "");
   136             if ( ! results.contains(membername) ) {
   137                 results.add(membername);
   138             }
   139         }
   140         return results;
   141     }
   142 }

mercurial