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