Mon, 25 Mar 2013 16:55:14 -0700
8010521: jdk8 l10n resource file translation update 2
Reviewed-by: naoto, yhuang
1 /*
2 * Copyright (c) 1997, 2013, 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;
28 import java.io.*;
29 import java.util.*;
31 import com.sun.javadoc.*;
32 import com.sun.tools.javac.sym.Profiles;
33 import com.sun.tools.javac.jvm.Profile;
34 import com.sun.tools.doclets.internal.toolkit.builders.BuilderFactory;
35 import com.sun.tools.doclets.internal.toolkit.taglets.*;
36 import com.sun.tools.doclets.internal.toolkit.util.*;
37 import javax.tools.JavaFileManager;
39 /**
40 * Configure the output based on the options. Doclets should sub-class
41 * Configuration, to configure and add their own options. This class contains
42 * all user options which are supported by the 1.1 doclet and the standard
43 * doclet.
44 *
45 * <p><b>This is NOT part of any supported API.
46 * If you write code that depends on this, you do so at your own risk.
47 * This code and its internal interfaces are subject to change or
48 * deletion without notice.</b>
49 *
50 * @author Robert Field.
51 * @author Atul Dambalkar.
52 * @author Jamie Ho
53 */
54 public abstract class Configuration {
56 /**
57 * Exception used to report a problem during setOptions.
58 */
59 public class Fault extends Exception {
60 private static final long serialVersionUID = 0;
62 Fault(String msg) {
63 super(msg);
64 }
66 Fault(String msg, Exception cause) {
67 super(msg, cause);
68 }
69 }
71 /**
72 * The factory for builders.
73 */
74 protected BuilderFactory builderFactory;
76 /**
77 * The taglet manager.
78 */
79 public TagletManager tagletManager;
81 /**
82 * The path to the builder XML input file.
83 */
84 public String builderXMLPath;
86 /**
87 * The default path to the builder XML.
88 */
89 private static final String DEFAULT_BUILDER_XML = "resources/doclet.xml";
91 /**
92 * The path to Taglets
93 */
94 public String tagletpath = "";
96 /**
97 * This is true if option "-serialwarn" is used. Defualt value is false to
98 * suppress excessive warnings about serial tag.
99 */
100 public boolean serialwarn = false;
102 /**
103 * The specified amount of space between tab stops.
104 */
105 public int sourcetab;
107 public String tabSpaces;
109 /**
110 * True if we should generate browsable sources.
111 */
112 public boolean linksource = false;
114 /**
115 * True if command line option "-nosince" is used. Default value is
116 * false.
117 */
118 public boolean nosince = false;
120 /**
121 * True if we should recursively copy the doc-file subdirectories
122 */
123 public boolean copydocfilesubdirs = false;
125 /**
126 * The META charset tag used for cross-platform viewing.
127 */
128 public String charset = "";
130 /**
131 * True if user wants to add member names as meta keywords.
132 * Set to false because meta keywords are ignored in general
133 * by most Internet search engines.
134 */
135 public boolean keywords = false;
137 /**
138 * The meta tag keywords instance.
139 */
140 public final MetaKeywords metakeywords = new MetaKeywords(this);
142 /**
143 * The list of doc-file subdirectories to exclude
144 */
145 protected Set<String> excludedDocFileDirs;
147 /**
148 * The list of qualifiers to exclude
149 */
150 protected Set<String> excludedQualifiers;
152 /**
153 * The Root of the generated Program Structure from the Doclet API.
154 */
155 public RootDoc root;
157 /**
158 * Destination directory name, in which doclet will generate the entire
159 * documentation. Default is current directory.
160 */
161 public String destDirName = "";
163 /**
164 * Destination directory name, in which doclet will copy the doc-files to.
165 */
166 public String docFileDestDirName = "";
168 /**
169 * Encoding for this document. Default is default encoding for this
170 * platform.
171 */
172 public String docencoding = null;
174 /**
175 * True if user wants to suppress descriptions and tags.
176 */
177 public boolean nocomment = false;
179 /**
180 * Encoding for this document. Default is default encoding for this
181 * platform.
182 */
183 public String encoding = null;
185 /**
186 * Generate author specific information for all the classes if @author
187 * tag is used in the doc comment and if -author option is used.
188 * <code>showauthor</code> is set to true if -author option is used.
189 * Default is don't show author information.
190 */
191 public boolean showauthor = false;
193 /**
194 * Generate documentation for JavaFX getters and setters automatically
195 * by copying it from the appropriate property definition.
196 */
197 public boolean javafx = false;
199 /**
200 * Generate version specific information for the all the classes
201 * if @version tag is used in the doc comment and if -version option is
202 * used. <code>showversion</code> is set to true if -version option is
203 * used.Default is don't show version information.
204 */
205 public boolean showversion = false;
207 /**
208 * Sourcepath from where to read the source files. Default is classpath.
209 *
210 */
211 public String sourcepath = "";
213 /**
214 * Argument for command line option "-Xprofilespath".
215 */
216 public String profilespath = "";
218 /**
219 * Generate profiles documentation if profilespath is set and valid profiles
220 * are present.
221 */
222 public boolean showProfiles = false;
224 /**
225 * Don't generate deprecated API information at all, if -nodeprecated
226 * option is used. <code>nodepracted</code> is set to true if
227 * -nodeprecated option is used. Default is generate deprected API
228 * information.
229 */
230 public boolean nodeprecated = false;
232 /**
233 * The catalog of classes specified on the command-line
234 */
235 public ClassDocCatalog classDocCatalog;
237 /**
238 * Message Retriever for the doclet, to retrieve message from the resource
239 * file for this Configuration, which is common for 1.1 and standard
240 * doclets.
241 *
242 * TODO: Make this private!!!
243 */
244 public MessageRetriever message = null;
246 /**
247 * True if user wants to suppress time stamp in output.
248 * Default is false.
249 */
250 public boolean notimestamp= false;
252 /**
253 * The package grouping instance.
254 */
255 public final Group group = new Group(this);
257 /**
258 * The tracker of external package links.
259 */
260 public final Extern extern = new Extern(this);
262 /**
263 * Return the build date for the doclet.
264 */
265 public abstract String getDocletSpecificBuildDate();
267 /**
268 * This method should be defined in all those doclets(configurations),
269 * which want to derive themselves from this Configuration. This method
270 * can be used to set its own command line options.
271 *
272 * @param options The array of option names and values.
273 * @throws DocletAbortException
274 */
275 public abstract void setSpecificDocletOptions(String[][] options) throws Fault;
277 /**
278 * Return the doclet specific {@link MessageRetriever}
279 * @return the doclet specific MessageRetriever.
280 */
281 public abstract MessageRetriever getDocletSpecificMsg();
283 /**
284 * A profiles object used to access profiles across various pages.
285 */
286 public Profiles profiles;
288 /**
289 * An map of the profiles to packages.
290 */
291 public Map<String,PackageDoc[]> profilePackages;
293 /**
294 * An array of the packages specified on the command-line merged
295 * with the array of packages that contain the classes specified on the
296 * command-line. The array is sorted.
297 */
298 public PackageDoc[] packages;
300 /**
301 * Constructor. Constructs the message retriever with resource file.
302 */
303 public Configuration() {
304 message =
305 new MessageRetriever(this,
306 "com.sun.tools.doclets.internal.toolkit.resources.doclets");
307 excludedDocFileDirs = new HashSet<String>();
308 excludedQualifiers = new HashSet<String>();
309 setTabWidth(DocletConstants.DEFAULT_TAB_STOP_LENGTH);
310 }
312 /**
313 * Return the builder factory for this doclet.
314 *
315 * @return the builder factory for this doclet.
316 */
317 public BuilderFactory getBuilderFactory() {
318 if (builderFactory == null) {
319 builderFactory = new BuilderFactory(this);
320 }
321 return builderFactory;
322 }
324 /**
325 * This method should be defined in all those doclets
326 * which want to inherit from this Configuration. This method
327 * should return the number of arguments to the command line
328 * option (including the option name). For example,
329 * -notimestamp is a single-argument option, so this method would
330 * return 1.
331 *
332 * @param option Command line option under consideration.
333 * @return number of arguments to option (including the
334 * option name). Zero return means option not known.
335 * Negative value means error occurred.
336 */
337 public int optionLength(String option) {
338 option = option.toLowerCase();
339 if (option.equals("-author") ||
340 option.equals("-docfilessubdirs") ||
341 option.equals("-javafx") ||
342 option.equals("-keywords") ||
343 option.equals("-linksource") ||
344 option.equals("-nocomment") ||
345 option.equals("-nodeprecated") ||
346 option.equals("-nosince") ||
347 option.equals("-notimestamp") ||
348 option.equals("-quiet") ||
349 option.equals("-xnodate") ||
350 option.equals("-version")) {
351 return 1;
352 } else if (option.equals("-d") ||
353 option.equals("-docencoding") ||
354 option.equals("-encoding") ||
355 option.equals("-excludedocfilessubdir") ||
356 option.equals("-link") ||
357 option.equals("-sourcetab") ||
358 option.equals("-noqualifier") ||
359 option.equals("-output") ||
360 option.equals("-sourcepath") ||
361 option.equals("-tag") ||
362 option.equals("-taglet") ||
363 option.equals("-tagletpath") ||
364 option.equals("-xprofilespath")) {
365 return 2;
366 } else if (option.equals("-group") ||
367 option.equals("-linkoffline")) {
368 return 3;
369 } else {
370 return -1; // indicate we don't know about it
371 }
372 }
374 /**
375 * Perform error checking on the given options.
376 *
377 * @param options the given options to check.
378 * @param reporter the reporter used to report errors.
379 */
380 public abstract boolean validOptions(String options[][],
381 DocErrorReporter reporter);
383 private void initProfiles() throws IOException {
384 profiles = Profiles.read(new File(profilespath));
385 // Generate profiles documentation only is profilespath is set and if
386 // profiles is not null and profiles count is 1 or more.
387 showProfiles = (!profilespath.isEmpty() && profiles != null &&
388 profiles.getProfileCount() > 0);
389 }
391 private void initProfilePackages() throws IOException {
392 profilePackages = new HashMap<String,PackageDoc[]>();
393 ArrayList<PackageDoc> results;
394 Map<String,PackageDoc> packageIndex = new HashMap<String,PackageDoc>();
395 for (int i = 0; i < packages.length; i++) {
396 PackageDoc pkg = packages[i];
397 packageIndex.put(pkg.name(), pkg);
398 }
399 for (int i = 1; i < profiles.getProfileCount(); i++) {
400 Set<String> profPkgs = profiles.getPackages(i);
401 results = new ArrayList<PackageDoc>();
402 for (String packageName : profPkgs) {
403 packageName = packageName.replace("/", ".");
404 PackageDoc profPkg = packageIndex.get(packageName);
405 if (profPkg != null) {
406 results.add(profPkg);
407 }
408 }
409 Collections.sort(results);
410 PackageDoc[] profilePkgs = results.toArray(new PackageDoc[]{});
411 profilePackages.put(Profile.lookup(i).name, profilePkgs);
412 }
413 }
415 private void initPackageArray() {
416 Set<PackageDoc> set = new HashSet<PackageDoc>(Arrays.asList(root.specifiedPackages()));
417 ClassDoc[] classes = root.specifiedClasses();
418 for (int i = 0; i < classes.length; i++) {
419 set.add(classes[i].containingPackage());
420 }
421 ArrayList<PackageDoc> results = new ArrayList<PackageDoc>(set);
422 Collections.sort(results);
423 packages = results.toArray(new PackageDoc[] {});
424 }
426 /**
427 * Set the command line options supported by this configuration.
428 *
429 * @param options the two dimensional array of options.
430 */
431 public void setOptions(String[][] options) throws Fault {
432 LinkedHashSet<String[]> customTagStrs = new LinkedHashSet<String[]>();
434 // Some options, specifically -link and -linkoffline, require that
435 // the output directory has already been created: so do that first.
436 for (int oi = 0; oi < options.length; ++oi) {
437 String[] os = options[oi];
438 String opt = os[0].toLowerCase();
439 if (opt.equals("-d")) {
440 destDirName = addTrailingFileSep(os[1]);
441 docFileDestDirName = destDirName;
442 ensureOutputDirExists();
443 break;
444 }
445 }
447 for (int oi = 0; oi < options.length; ++oi) {
448 String[] os = options[oi];
449 String opt = os[0].toLowerCase();
450 if (opt.equals("-docfilessubdirs")) {
451 copydocfilesubdirs = true;
452 } else if (opt.equals("-docencoding")) {
453 docencoding = os[1];
454 } else if (opt.equals("-encoding")) {
455 encoding = os[1];
456 } else if (opt.equals("-author")) {
457 showauthor = true;
458 } else if (opt.equals("-javafx")) {
459 javafx = true;
460 } else if (opt.equals("-nosince")) {
461 nosince = true;
462 } else if (opt.equals("-version")) {
463 showversion = true;
464 } else if (opt.equals("-nodeprecated")) {
465 nodeprecated = true;
466 } else if (opt.equals("-sourcepath")) {
467 sourcepath = os[1];
468 } else if (opt.equals("-classpath") &&
469 sourcepath.length() == 0) {
470 sourcepath = os[1];
471 } else if (opt.equals("-excludedocfilessubdir")) {
472 addToSet(excludedDocFileDirs, os[1]);
473 } else if (opt.equals("-noqualifier")) {
474 addToSet(excludedQualifiers, os[1]);
475 } else if (opt.equals("-linksource")) {
476 linksource = true;
477 } else if (opt.equals("-sourcetab")) {
478 linksource = true;
479 try {
480 setTabWidth(Integer.parseInt(os[1]));
481 } catch (NumberFormatException e) {
482 //Set to -1 so that warning will be printed
483 //to indicate what is valid argument.
484 sourcetab = -1;
485 }
486 if (sourcetab <= 0) {
487 message.warning("doclet.sourcetab_warning");
488 setTabWidth(DocletConstants.DEFAULT_TAB_STOP_LENGTH);
489 }
490 } else if (opt.equals("-notimestamp")) {
491 notimestamp = true;
492 } else if (opt.equals("-nocomment")) {
493 nocomment = true;
494 } else if (opt.equals("-tag") || opt.equals("-taglet")) {
495 customTagStrs.add(os);
496 } else if (opt.equals("-tagletpath")) {
497 tagletpath = os[1];
498 } else if (opt.equals("-xprofilespath")) {
499 profilespath = os[1];
500 } else if (opt.equals("-keywords")) {
501 keywords = true;
502 } else if (opt.equals("-serialwarn")) {
503 serialwarn = true;
504 } else if (opt.equals("-group")) {
505 group.checkPackageGroups(os[1], os[2]);
506 } else if (opt.equals("-link")) {
507 String url = os[1];
508 extern.link(url, url, root, false);
509 } else if (opt.equals("-linkoffline")) {
510 String url = os[1];
511 String pkglisturl = os[2];
512 extern.link(url, pkglisturl, root, true);
513 }
514 }
515 if (sourcepath.length() == 0) {
516 sourcepath = System.getProperty("env.class.path") == null ? "" :
517 System.getProperty("env.class.path");
518 }
519 if (docencoding == null) {
520 docencoding = encoding;
521 }
523 classDocCatalog = new ClassDocCatalog(root.specifiedClasses(), this);
524 initTagletManager(customTagStrs);
525 }
527 /**
528 * Set the command line options supported by this configuration.
529 *
530 * @throws DocletAbortException
531 */
532 public void setOptions() throws Fault {
533 initPackageArray();
534 setOptions(root.options());
535 if (!profilespath.isEmpty()) {
536 try {
537 initProfiles();
538 initProfilePackages();
539 } catch (Exception e) {
540 throw new DocletAbortException();
541 }
542 }
543 setSpecificDocletOptions(root.options());
544 }
546 private void ensureOutputDirExists() throws Fault {
547 DocFile destDir = DocFile.createFileForDirectory(this, destDirName);
548 if (!destDir.exists()) {
549 //Create the output directory (in case it doesn't exist yet)
550 root.printNotice(getText("doclet.dest_dir_create", destDirName));
551 destDir.mkdirs();
552 } else if (!destDir.isDirectory()) {
553 throw new Fault(getText(
554 "doclet.destination_directory_not_directory_0",
555 destDir.getPath()));
556 } else if (!destDir.canWrite()) {
557 throw new Fault(getText(
558 "doclet.destination_directory_not_writable_0",
559 destDir.getPath()));
560 }
561 }
564 /**
565 * Initialize the taglet manager. The strings to initialize the simple custom tags should
566 * be in the following format: "[tag name]:[location str]:[heading]".
567 * @param customTagStrs the set two dimensional arrays of strings. These arrays contain
568 * either -tag or -taglet arguments.
569 */
570 private void initTagletManager(Set<String[]> customTagStrs) {
571 tagletManager = tagletManager == null ?
572 new TagletManager(nosince, showversion, showauthor, javafx, message) :
573 tagletManager;
574 String[] args;
575 for (Iterator<String[]> it = customTagStrs.iterator(); it.hasNext(); ) {
576 args = it.next();
577 if (args[0].equals("-taglet")) {
578 tagletManager.addCustomTag(args[1], getFileManager(), tagletpath);
579 continue;
580 }
581 String[] tokens = tokenize(args[1],
582 TagletManager.SIMPLE_TAGLET_OPT_SEPARATOR, 3);
583 if (tokens.length == 1) {
584 String tagName = args[1];
585 if (tagletManager.isKnownCustomTag(tagName)) {
586 //reorder a standard tag
587 tagletManager.addNewSimpleCustomTag(tagName, null, "");
588 } else {
589 //Create a simple tag with the heading that has the same name as the tag.
590 StringBuilder heading = new StringBuilder(tagName + ":");
591 heading.setCharAt(0, Character.toUpperCase(tagName.charAt(0)));
592 tagletManager.addNewSimpleCustomTag(tagName, heading.toString(), "a");
593 }
594 } else if (tokens.length == 2) {
595 //Add simple taglet without heading, probably to excluding it in the output.
596 tagletManager.addNewSimpleCustomTag(tokens[0], tokens[1], "");
597 } else if (tokens.length >= 3) {
598 tagletManager.addNewSimpleCustomTag(tokens[0], tokens[2], tokens[1]);
599 } else {
600 message.error("doclet.Error_invalid_custom_tag_argument", args[1]);
601 }
602 }
603 }
605 /**
606 * Given a string, return an array of tokens. The separator can be escaped
607 * with the '\' character. The '\' character may also be escaped by the
608 * '\' character.
609 *
610 * @param s the string to tokenize.
611 * @param separator the separator char.
612 * @param maxTokens the maximum number of tokens returned. If the
613 * max is reached, the remaining part of s is appended
614 * to the end of the last token.
615 *
616 * @return an array of tokens.
617 */
618 private String[] tokenize(String s, char separator, int maxTokens) {
619 List<String> tokens = new ArrayList<String>();
620 StringBuilder token = new StringBuilder ();
621 boolean prevIsEscapeChar = false;
622 for (int i = 0; i < s.length(); i += Character.charCount(i)) {
623 int currentChar = s.codePointAt(i);
624 if (prevIsEscapeChar) {
625 // Case 1: escaped character
626 token.appendCodePoint(currentChar);
627 prevIsEscapeChar = false;
628 } else if (currentChar == separator && tokens.size() < maxTokens-1) {
629 // Case 2: separator
630 tokens.add(token.toString());
631 token = new StringBuilder();
632 } else if (currentChar == '\\') {
633 // Case 3: escape character
634 prevIsEscapeChar = true;
635 } else {
636 // Case 4: regular character
637 token.appendCodePoint(currentChar);
638 }
639 }
640 if (token.length() > 0) {
641 tokens.add(token.toString());
642 }
643 return tokens.toArray(new String[] {});
644 }
646 private void addToSet(Set<String> s, String str){
647 StringTokenizer st = new StringTokenizer(str, ":");
648 String current;
649 while(st.hasMoreTokens()){
650 current = st.nextToken();
651 s.add(current);
652 }
653 }
655 /**
656 * Add a trailing file separator, if not found. Remove superfluous
657 * file separators if any. Preserve the front double file separator for
658 * UNC paths.
659 *
660 * @param path Path under consideration.
661 * @return String Properly constructed path string.
662 */
663 public static String addTrailingFileSep(String path) {
664 String fs = System.getProperty("file.separator");
665 String dblfs = fs + fs;
666 int indexDblfs;
667 while ((indexDblfs = path.indexOf(dblfs, 1)) >= 0) {
668 path = path.substring(0, indexDblfs) +
669 path.substring(indexDblfs + fs.length());
670 }
671 if (!path.endsWith(fs))
672 path += fs;
673 return path;
674 }
676 /**
677 * This checks for the validity of the options used by the user.
678 * This works exactly like
679 * {@link com.sun.javadoc.Doclet#validOptions(String[][],
680 * DocErrorReporter)}. This will validate the options which are shared
681 * by our doclets. For example, this method will flag an error using
682 * the DocErrorReporter if user has used "-nohelp" and "-helpfile" option
683 * together.
684 *
685 * @param options options used on the command line.
686 * @param reporter used to report errors.
687 * @return true if all the options are valid.
688 */
689 public boolean generalValidOptions(String options[][],
690 DocErrorReporter reporter) {
691 boolean docencodingfound = false;
692 String encoding = "";
693 for (int oi = 0; oi < options.length; oi++) {
694 String[] os = options[oi];
695 String opt = os[0].toLowerCase();
696 if (opt.equals("-docencoding")) {
697 docencodingfound = true;
698 if (!checkOutputFileEncoding(os[1], reporter)) {
699 return false;
700 }
701 } else if (opt.equals("-encoding")) {
702 encoding = os[1];
703 }
704 }
705 if (!docencodingfound && encoding.length() > 0) {
706 if (!checkOutputFileEncoding(encoding, reporter)) {
707 return false;
708 }
709 }
710 return true;
711 }
713 /**
714 * Check the validity of the given Source or Output File encoding on this
715 * platform.
716 *
717 * @param docencoding output file encoding.
718 * @param reporter used to report errors.
719 */
720 private boolean checkOutputFileEncoding(String docencoding,
721 DocErrorReporter reporter) {
722 OutputStream ost= new ByteArrayOutputStream();
723 OutputStreamWriter osw = null;
724 try {
725 osw = new OutputStreamWriter(ost, docencoding);
726 } catch (UnsupportedEncodingException exc) {
727 reporter.printError(getText("doclet.Encoding_not_supported",
728 docencoding));
729 return false;
730 } finally {
731 try {
732 if (osw != null) {
733 osw.close();
734 }
735 } catch (IOException exc) {
736 }
737 }
738 return true;
739 }
741 /**
742 * Return true if the given doc-file subdirectory should be excluded and
743 * false otherwise.
744 * @param docfilesubdir the doc-files subdirectory to check.
745 */
746 public boolean shouldExcludeDocFileDir(String docfilesubdir){
747 if (excludedDocFileDirs.contains(docfilesubdir)) {
748 return true;
749 } else {
750 return false;
751 }
752 }
754 /**
755 * Return true if the given qualifier should be excluded and false otherwise.
756 * @param qualifier the qualifier to check.
757 */
758 public boolean shouldExcludeQualifier(String qualifier){
759 if (excludedQualifiers.contains("all") ||
760 excludedQualifiers.contains(qualifier) ||
761 excludedQualifiers.contains(qualifier + ".*")) {
762 return true;
763 } else {
764 int index = -1;
765 while ((index = qualifier.indexOf(".", index + 1)) != -1) {
766 if (excludedQualifiers.contains(qualifier.substring(0, index + 1) + "*")) {
767 return true;
768 }
769 }
770 return false;
771 }
772 }
774 /**
775 * Return the qualified name of the <code>ClassDoc</code> if it's qualifier is not excluded. Otherwise,
776 * return the unqualified <code>ClassDoc</code> name.
777 * @param cd the <code>ClassDoc</code> to check.
778 */
779 public String getClassName(ClassDoc cd) {
780 PackageDoc pd = cd.containingPackage();
781 if (pd != null && shouldExcludeQualifier(cd.containingPackage().name())) {
782 return cd.name();
783 } else {
784 return cd.qualifiedName();
785 }
786 }
788 public String getText(String key) {
789 try {
790 //Check the doclet specific properties file.
791 return getDocletSpecificMsg().getText(key);
792 } catch (Exception e) {
793 //Check the shared properties file.
794 return message.getText(key);
795 }
796 }
798 public String getText(String key, String a1) {
799 try {
800 //Check the doclet specific properties file.
801 return getDocletSpecificMsg().getText(key, a1);
802 } catch (Exception e) {
803 //Check the shared properties file.
804 return message.getText(key, a1);
805 }
806 }
808 public String getText(String key, String a1, String a2) {
809 try {
810 //Check the doclet specific properties file.
811 return getDocletSpecificMsg().getText(key, a1, a2);
812 } catch (Exception e) {
813 //Check the shared properties file.
814 return message.getText(key, a1, a2);
815 }
816 }
818 public String getText(String key, String a1, String a2, String a3) {
819 try {
820 //Check the doclet specific properties file.
821 return getDocletSpecificMsg().getText(key, a1, a2, a3);
822 } catch (Exception e) {
823 //Check the shared properties file.
824 return message.getText(key, a1, a2, a3);
825 }
826 }
828 /**
829 * Return true if the ClassDoc element is getting documented, depending upon
830 * -nodeprecated option and the deprecation information. Return true if
831 * -nodeprecated is not used. Return false if -nodeprecated is used and if
832 * either ClassDoc element is deprecated or the containing package is deprecated.
833 *
834 * @param cd the ClassDoc for which the page generation is checked
835 */
836 public boolean isGeneratedDoc(ClassDoc cd) {
837 if (!nodeprecated) {
838 return true;
839 }
840 return !(Util.isDeprecated(cd) || Util.isDeprecated(cd.containingPackage()));
841 }
843 /**
844 * Return the doclet specific instance of a writer factory.
845 * @return the {@link WriterFactory} for the doclet.
846 */
847 public abstract WriterFactory getWriterFactory();
849 /**
850 * Return the input stream to the builder XML.
851 *
852 * @return the input steam to the builder XML.
853 * @throws FileNotFoundException when the given XML file cannot be found.
854 */
855 public InputStream getBuilderXML() throws IOException {
856 return builderXMLPath == null ?
857 Configuration.class.getResourceAsStream(DEFAULT_BUILDER_XML) :
858 DocFile.createFileForInput(this, builderXMLPath).openInputStream();
859 }
861 /**
862 * Return the Locale for this document.
863 */
864 public abstract Locale getLocale();
866 /**
867 * Return the current file manager.
868 */
869 public abstract JavaFileManager getFileManager();
871 /**
872 * Return the comparator that will be used to sort member documentation.
873 * To no do any sorting, return null.
874 *
875 * @return the {@link java.util.Comparator} used to sort members.
876 */
877 public abstract Comparator<ProgramElementDoc> getMemberComparator();
879 private void setTabWidth(int n) {
880 sourcetab = n;
881 tabSpaces = String.format("%" + n + "s", "");
882 }
884 public abstract boolean showMessage(SourcePosition pos, String key);
885 }