40303
|
1 |
/*
|
|
2 |
* Copyright (c) 1998, 2016, 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 |
*/
|
|
25 |
|
|
26 |
package jdk.javadoc.internal.doclets.formats.html;
|
|
27 |
|
|
28 |
import java.util.regex.Matcher;
|
|
29 |
import java.util.regex.Pattern;
|
|
30 |
|
|
31 |
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
|
|
32 |
import jdk.javadoc.internal.doclets.formats.html.markup.FixedStringContent;
|
|
33 |
import jdk.javadoc.internal.doclets.formats.html.markup.RawHtml;
|
|
34 |
import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
|
|
35 |
import jdk.javadoc.internal.doclets.toolkit.Content;
|
|
36 |
import jdk.javadoc.internal.doclets.toolkit.Resources;
|
|
37 |
import jdk.javadoc.internal.doclets.toolkit.util.DocletConstants;
|
|
38 |
|
|
39 |
/**
|
|
40 |
* Constants and factory methods for common fragments of content
|
|
41 |
* used by HtmlDoclet. The string content of these fragments is
|
|
42 |
* generally obtained from the {@link Resources resources} found
|
|
43 |
* in the doclet's configuration.
|
|
44 |
*
|
|
45 |
* @implNote
|
|
46 |
* Many constants are made available in this class, so that they are
|
|
47 |
* only created once per doclet-instance, instead of once per generated page.
|
|
48 |
*/
|
|
49 |
public class Contents {
|
|
50 |
public static final Content SPACE = RawHtml.nbsp;
|
|
51 |
|
|
52 |
public final Content allClassesLabel;
|
|
53 |
public final Content allImplementedInterfacesLabel;
|
|
54 |
public final Content allModulesLabel;
|
|
55 |
public final Content allPackagesLabel;
|
|
56 |
public final Content allSuperinterfacesLabel;
|
|
57 |
public final Content also;
|
|
58 |
public final Content annotateTypeOptionalMemberSummaryLabel;
|
|
59 |
public final Content annotateTypeRequiredMemberSummaryLabel;
|
|
60 |
public final Content annotationType;
|
|
61 |
public final Content annotationTypeDetailsLabel;
|
|
62 |
public final Content annotationTypeMemberDetail;
|
|
63 |
public final Content annotationTypes;
|
|
64 |
public final Content classLabel;
|
|
65 |
public final Content classes;
|
|
66 |
public final Content constantsSummaryTitle;
|
|
67 |
public final Content constructorDetailsLabel;
|
|
68 |
public final Content constructorSummaryLabel;
|
|
69 |
public final Content constructors;
|
|
70 |
public final Content contentsHeading;
|
|
71 |
public final Content defaultPackageLabel;
|
|
72 |
public final Content default_;
|
|
73 |
public final Content deprecatedAPI;
|
|
74 |
public final Content deprecatedLabel;
|
|
75 |
public final Content deprecatedPhrase;
|
|
76 |
public final Content descfrmClassLabel;
|
|
77 |
public final Content descfrmInterfaceLabel;
|
|
78 |
public final Content descriptionLabel;
|
|
79 |
public final Content detailLabel;
|
|
80 |
public final Content enclosingClassLabel;
|
|
81 |
public final Content enclosingInterfaceLabel;
|
|
82 |
public final Content enumConstantDetailLabel;
|
|
83 |
public final Content enumConstantSummary;
|
|
84 |
public final Content enum_;
|
|
85 |
public final Content enums;
|
|
86 |
public final Content errors;
|
|
87 |
public final Content exceptions;
|
|
88 |
public final Content fieldDetailsLabel;
|
|
89 |
public final Content fieldSummaryLabel;
|
|
90 |
public final Content fields;
|
|
91 |
public final Content framesLabel;
|
|
92 |
public final Content functionalInterface;
|
|
93 |
public final Content functionalInterfaceMessage;
|
|
94 |
public final Content helpLabel;
|
|
95 |
public final Content hierarchyForAllPackages;
|
|
96 |
public final Content implementation;
|
|
97 |
public final Content implementingClassesLabel;
|
|
98 |
public final Content inClass;
|
|
99 |
public final Content inInterface;
|
|
100 |
public final Content indexLabel;
|
|
101 |
public final Content interfaces;
|
|
102 |
public final Content interfacesItalic;
|
|
103 |
public final Content methodDetailLabel;
|
|
104 |
public final Content methodSummary;
|
|
105 |
public final Content methods;
|
|
106 |
public final Content moduleLabel;
|
|
107 |
public final Content moduleSubNavLabel;
|
|
108 |
public final Content modulesLabel;
|
|
109 |
public final Content navAnnotationTypeMember;
|
|
110 |
public final Content navAnnotationTypeOptionalMember;
|
|
111 |
public final Content navAnnotationTypeRequiredMember;
|
|
112 |
public final Content navConstructor;
|
|
113 |
public final Content navEnum;
|
|
114 |
public final Content navField;
|
|
115 |
public final Content navMethod;
|
|
116 |
public final Content navModuleDescription;
|
|
117 |
public final Content navModules;
|
|
118 |
public final Content navNested;
|
|
119 |
public final Content navPackages;
|
|
120 |
public final Content navProperty;
|
|
121 |
public final Content navServices;
|
|
122 |
public final Content nestedClassSummary;
|
|
123 |
public final Content nextClassLabel;
|
|
124 |
public final Content nextLabel;
|
|
125 |
public final Content nextLetter;
|
|
126 |
public final Content nextModuleLabel;
|
|
127 |
public final Content nextPackageLabel;
|
|
128 |
public final Content noFramesLabel;
|
|
129 |
public final Content noScriptMessage;
|
|
130 |
public final Content overridesLabel;
|
|
131 |
public final Content overviewLabel;
|
|
132 |
public final Content packageHierarchies;
|
|
133 |
public final Content packageLabel;
|
|
134 |
public final Content package_;
|
|
135 |
public final Content packagesLabel;
|
|
136 |
public final Content prevClassLabel;
|
|
137 |
public final Content prevLabel;
|
|
138 |
public final Content prevLetter;
|
|
139 |
public final Content prevModuleLabel;
|
|
140 |
public final Content prevPackageLabel;
|
|
141 |
public final Content properties;
|
|
142 |
public final Content propertyDetailsLabel;
|
|
143 |
public final Content propertySummary;
|
|
144 |
public final Content seeLabel;
|
|
145 |
public final Content serializedForm;
|
|
146 |
public final Content specifiedByLabel;
|
|
147 |
public final Content subclassesLabel;
|
|
148 |
public final Content subinterfacesLabel;
|
|
149 |
public final Content summaryLabel;
|
|
150 |
public final Content treeLabel;
|
|
151 |
public final Content useLabel;
|
|
152 |
|
|
153 |
private final Resources resources;
|
|
154 |
|
|
155 |
/**
|
|
156 |
* Creates a {@code Contents} object.
|
|
157 |
*
|
|
158 |
* @param configuration the configuration in which to find the
|
|
159 |
* resources used to look up resource keys, and other details.
|
|
160 |
*/
|
|
161 |
Contents(ConfigurationImpl configuration) {
|
|
162 |
this.resources = configuration.getResources();
|
|
163 |
|
|
164 |
allClassesLabel = getNonBreakContent("doclet.All_Classes");
|
|
165 |
allImplementedInterfacesLabel = getContent("doclet.All_Implemented_Interfaces");
|
|
166 |
allModulesLabel = getNonBreakContent("doclet.All_Modules");
|
|
167 |
allPackagesLabel = getNonBreakContent("doclet.All_Packages");
|
|
168 |
allSuperinterfacesLabel = getContent("doclet.All_Superinterfaces");
|
|
169 |
also = getContent("doclet.also");
|
|
170 |
annotateTypeOptionalMemberSummaryLabel = getContent("doclet.Annotation_Type_Optional_Member_Summary");
|
|
171 |
annotateTypeRequiredMemberSummaryLabel = getContent("doclet.Annotation_Type_Required_Member_Summary");
|
|
172 |
annotationType = getContent("doclet.AnnotationType");
|
|
173 |
annotationTypeDetailsLabel = getContent("doclet.Annotation_Type_Member_Detail");
|
|
174 |
annotationTypeMemberDetail = getContent("doclet.Annotation_Type_Member_Detail");
|
|
175 |
annotationTypes = getContent("doclet.AnnotationTypes");
|
|
176 |
classLabel = getContent("doclet.Class");
|
|
177 |
classes = getContent("doclet.Classes");
|
|
178 |
constantsSummaryTitle = getContent("doclet.Constants_Summary");
|
|
179 |
constructorDetailsLabel = getContent("doclet.Constructor_Detail");
|
|
180 |
constructorSummaryLabel = getContent("doclet.Constructor_Summary");
|
|
181 |
constructors = getContent("doclet.Constructors");
|
|
182 |
contentsHeading = getContent("doclet.Contents");
|
|
183 |
defaultPackageLabel = new StringContent(DocletConstants.DEFAULT_PACKAGE_NAME);
|
|
184 |
default_ = getContent("doclet.Default");
|
|
185 |
deprecatedAPI = getContent("doclet.Deprecated_API");
|
|
186 |
deprecatedLabel = getContent("doclet.navDeprecated");
|
|
187 |
deprecatedPhrase = getContent("doclet.Deprecated");
|
|
188 |
descfrmClassLabel = getContent("doclet.Description_From_Class");
|
|
189 |
descfrmInterfaceLabel = getContent("doclet.Description_From_Interface");
|
|
190 |
descriptionLabel = getContent("doclet.Description");
|
|
191 |
detailLabel = getContent("doclet.Detail");
|
|
192 |
enclosingClassLabel = getContent("doclet.Enclosing_Class");
|
|
193 |
enclosingInterfaceLabel = getContent("doclet.Enclosing_Interface");
|
|
194 |
enumConstantDetailLabel = getContent("doclet.Enum_Constant_Detail");
|
|
195 |
enumConstantSummary = getContent("doclet.Enum_Constant_Summary");
|
|
196 |
enum_ = getContent("doclet.Enum");
|
|
197 |
enums = getContent("doclet.Enums");
|
|
198 |
errors = getContent("doclet.Errors");
|
|
199 |
exceptions = getContent("doclet.Exceptions");
|
|
200 |
fieldDetailsLabel = getContent("doclet.Field_Detail");
|
|
201 |
fieldSummaryLabel = getContent("doclet.Field_Summary");
|
|
202 |
fields = getContent("doclet.Fields");
|
|
203 |
framesLabel = getContent("doclet.Frames");
|
|
204 |
functionalInterface = getContent("doclet.Functional_Interface");
|
|
205 |
functionalInterfaceMessage = getContent("doclet.Functional_Interface_Message");
|
|
206 |
helpLabel = getContent("doclet.Help");
|
|
207 |
hierarchyForAllPackages = getContent("doclet.Hierarchy_For_All_Packages");
|
|
208 |
implementation = getContent("doclet.Implementation");
|
|
209 |
implementingClassesLabel = getContent("doclet.Implementing_Classes");
|
|
210 |
inClass = getContent("doclet.in_class");
|
|
211 |
inInterface = getContent("doclet.in_interface");
|
|
212 |
indexLabel = getContent("doclet.Index");
|
|
213 |
interfaces = getContent("doclet.Interfaces");
|
|
214 |
interfacesItalic = getContent("doclet.Interfaces_Italic");
|
|
215 |
methodDetailLabel = getContent("doclet.Method_Detail");
|
|
216 |
methodSummary = getContent("doclet.Method_Summary");
|
|
217 |
methods = getContent("doclet.Methods");
|
|
218 |
moduleLabel = getContent("doclet.Module");
|
|
219 |
moduleSubNavLabel = getContent("doclet.Module_Sub_Nav");
|
|
220 |
modulesLabel = getContent("doclet.Modules");
|
|
221 |
navAnnotationTypeMember = getContent("doclet.navAnnotationTypeMember");
|
|
222 |
navAnnotationTypeOptionalMember = getContent("doclet.navAnnotationTypeOptionalMember");
|
|
223 |
navAnnotationTypeRequiredMember = getContent("doclet.navAnnotationTypeRequiredMember");
|
|
224 |
navConstructor = getContent("doclet.navConstructor");
|
|
225 |
navEnum = getContent("doclet.navEnum");
|
|
226 |
navField = getContent("doclet.navField");
|
|
227 |
navMethod = getContent("doclet.navMethod");
|
|
228 |
navModuleDescription = getContent("doclet.navModuleDescription");
|
|
229 |
navModules = getContent("doclet.navModules");
|
|
230 |
navNested = getContent("doclet.navNested");
|
|
231 |
navPackages = getContent("doclet.navPackages");
|
|
232 |
navProperty = getContent("doclet.navProperty");
|
|
233 |
navServices = getContent("doclet.navServices");
|
|
234 |
nestedClassSummary = getContent("doclet.Nested_Class_Summary");
|
|
235 |
nextClassLabel = getNonBreakContent("doclet.Next_Class");
|
|
236 |
nextLabel = getNonBreakContent("doclet.Next");
|
|
237 |
nextLetter = getContent("doclet.Next_Letter");
|
|
238 |
nextModuleLabel = getNonBreakContent("doclet.Next_Module");
|
|
239 |
nextPackageLabel = getNonBreakContent("doclet.Next_Package");
|
|
240 |
noFramesLabel = getNonBreakContent("doclet.No_Frames");
|
|
241 |
noScriptMessage = getContent("doclet.No_Script_Message");
|
|
242 |
overridesLabel = getContent("doclet.Overrides");
|
|
243 |
overviewLabel = getContent("doclet.Overview");
|
|
244 |
packageHierarchies = getContent("doclet.Package_Hierarchies");
|
|
245 |
packageLabel = getContent("doclet.Package");
|
|
246 |
package_ = getContent("doclet.package");
|
|
247 |
packagesLabel = getContent("doclet.Packages");
|
|
248 |
prevClassLabel = getNonBreakContent("doclet.Prev_Class");
|
|
249 |
prevLabel = getContent("doclet.Prev");
|
|
250 |
prevLetter = getContent("doclet.Prev_Letter");
|
|
251 |
prevModuleLabel = getNonBreakContent("doclet.Prev_Module");
|
|
252 |
prevPackageLabel = getNonBreakContent("doclet.Prev_Package");
|
|
253 |
properties = getContent("doclet.Properties");
|
|
254 |
propertyDetailsLabel = getContent("doclet.Property_Detail");
|
|
255 |
propertySummary = getContent("doclet.Property_Summary");
|
|
256 |
seeLabel = getContent("doclet.See");
|
|
257 |
serializedForm = getContent("doclet.Serialized_Form");
|
|
258 |
specifiedByLabel = getContent("doclet.Specified_By");
|
|
259 |
subclassesLabel = getContent("doclet.Subclasses");
|
|
260 |
subinterfacesLabel = getContent("doclet.Subinterfaces");
|
|
261 |
summaryLabel = getContent("doclet.Summary");
|
|
262 |
treeLabel = getContent("doclet.Tree");
|
|
263 |
useLabel = getContent("doclet.navClassUse");
|
|
264 |
}
|
|
265 |
|
|
266 |
/**
|
|
267 |
* Gets a {@code Content} object, containing the string for
|
|
268 |
* a given key in the doclet's resources.
|
|
269 |
*
|
|
270 |
* @param key the key for the desired string
|
|
271 |
* @return a content tree for the string
|
|
272 |
*/
|
|
273 |
public Content getContent(String key) {
|
|
274 |
return new FixedStringContent(resources.getText(key));
|
|
275 |
}
|
|
276 |
|
|
277 |
/**
|
|
278 |
* Gets a {@code Content} object, containing the string for
|
|
279 |
* a given key in the doclet's resources, formatted with
|
|
280 |
* given arguments.
|
|
281 |
*
|
|
282 |
* @param key the key to look for in the configuration fil
|
|
283 |
* @param key the key for the desired string
|
|
284 |
* @param o0 string or content argument to be formatted into the result
|
|
285 |
* @return a content tree for the text
|
|
286 |
*/
|
|
287 |
public Content getContent(String key, Object o0) {
|
|
288 |
return getContent(key, o0, null, null);
|
|
289 |
}
|
|
290 |
|
|
291 |
/**
|
|
292 |
* Gets a {@code Content} object, containing the string for
|
|
293 |
* a given key in the doclet's resources, formatted with
|
|
294 |
* given arguments.
|
|
295 |
|
|
296 |
* @param key the key for the desired string
|
|
297 |
* @param o0 string or content argument to be formatted into the result
|
|
298 |
* @param o1 string or content argument to be formatted into the result
|
|
299 |
* @return a content tree for the text
|
|
300 |
*/
|
|
301 |
public Content getContent(String key, Object o0, Object o1) {
|
|
302 |
return getContent(key, o0, o1, null);
|
|
303 |
}
|
|
304 |
|
|
305 |
/**
|
|
306 |
* Gets a {@code Content} object, containing the string for
|
|
307 |
* a given key in the doclet's resources, formatted with
|
|
308 |
* given arguments.
|
|
309 |
*
|
|
310 |
* @param key the key for the desired string
|
|
311 |
* @param o0 string or content argument to be formatted into the result
|
|
312 |
* @param o1 string or content argument to be formatted into the result
|
|
313 |
* @param o2 string or content argument to be formatted into the result
|
|
314 |
* @return a content tree for the text
|
|
315 |
*/
|
|
316 |
public Content getContent(String key, Object o0, Object o1, Object o2) {
|
|
317 |
Content c = new ContentBuilder();
|
|
318 |
Pattern p = Pattern.compile("\\{([012])\\}");
|
|
319 |
String text = resources.getText(key); // TODO: cache
|
|
320 |
Matcher m = p.matcher(text);
|
|
321 |
int start = 0;
|
|
322 |
while (m.find(start)) {
|
|
323 |
c.addContent(text.substring(start, m.start()));
|
|
324 |
|
|
325 |
Object o = null;
|
|
326 |
switch (m.group(1).charAt(0)) {
|
|
327 |
case '0': o = o0; break;
|
|
328 |
case '1': o = o1; break;
|
|
329 |
case '2': o = o2; break;
|
|
330 |
}
|
|
331 |
|
|
332 |
if (o == null) {
|
|
333 |
c.addContent("{" + m.group(1) + "}");
|
|
334 |
} else if (o instanceof String) {
|
|
335 |
c.addContent((String) o);
|
|
336 |
} else if (o instanceof Content) {
|
|
337 |
c.addContent((Content) o);
|
|
338 |
}
|
|
339 |
|
|
340 |
start = m.end();
|
|
341 |
}
|
|
342 |
|
|
343 |
c.addContent(text.substring(start));
|
|
344 |
return c;
|
|
345 |
}
|
|
346 |
|
|
347 |
/**
|
|
348 |
* Gets a {@code Content} object, containing the string for
|
|
349 |
* a given key in the doclet's resources, substituting
|
|
350 |
* <code> </code> for any space characters found in
|
|
351 |
* the named resource string.
|
|
352 |
*
|
|
353 |
* @param key the key for the desired string
|
|
354 |
* @return a content tree for the string
|
|
355 |
*/
|
|
356 |
private Content getNonBreakContent(String key) {
|
|
357 |
String text = resources.getText(key); // TODO: cache
|
|
358 |
Content c = new ContentBuilder();
|
|
359 |
int start = 0;
|
|
360 |
int p;
|
|
361 |
while ((p = text.indexOf(" ", start)) != -1) {
|
|
362 |
c.addContent(text.substring(start, p));
|
|
363 |
c.addContent(RawHtml.nbsp);
|
|
364 |
start = p + 1;
|
|
365 |
}
|
|
366 |
c.addContent(text.substring(start));
|
|
367 |
return c; // TODO: should be made immutable
|
|
368 |
}
|
|
369 |
}
|