gw.gosudoc.com.sun.tools.javadoc.main.DocLocale Maven / Gradle / Ivy
Show all versions of gosu-doc Show documentation
/*
* This file is a shadowed version of the older javadoc codebase on which gosudoc is based; borrowed from jdk 9.
*/
package gw.gosudoc.com.sun.tools.javadoc.main;
import java.text.BreakIterator;
import java.text.Collator;
import java.util.Locale;
/**
* This class holds the information about locales.
*
* This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own risk.
* This code and its internal interfaces are subject to change or
* deletion without notice.
*
* @since 1.4
* @author Robert Field
*/
@Deprecated
class DocLocale {
/**
* The locale name will be set by Main, if option is provided on the
* command line.
*/
final String localeName;
/**
* The locale to be used. If user doesn't provide this,
* then set it to default locale value.
*/
final Locale locale;
/**
* The collator for this application. This is to take care of Locale
* Specific or Natural Language Text sorting.
*/
final Collator collator;
/**
* Enclosing DocEnv
*/
private final DocEnv docenv;
/**
* Sentence instance from the BreakIterator.
*/
private final BreakIterator sentenceBreaker;
/**
* True is we should use BreakIterator
* to compute first sentence.
*/
private boolean useBreakIterator = false;
/**
* The HTML sentence terminators.
*/
static final String[] sentenceTerminators =
{
"
", "
", "", "",
"", "", "", "",
"
", "", "", "", "",
"", "
", "", "
"
};
/**
* Constructor
*/
DocLocale( DocEnv docenv, String localeName, boolean useBreakIterator) {
this.docenv = docenv;
this.localeName = localeName;
this.useBreakIterator = useBreakIterator;
locale = getLocale();
if (locale == null) {
docenv.exit();
} else {
Locale.setDefault(locale); // NOTE: updating global state
}
collator = Collator.getInstance(locale);
sentenceBreaker = BreakIterator.getSentenceInstance(locale);
}
/**
* Get the locale if specified on the command line
* else return null and if locale option is not used
* then return default locale.
*/
private Locale getLocale() {
Locale userlocale = null;
if (localeName.length() > 0) {
int firstuscore = localeName.indexOf('_');
int seconduscore = -1;
String language = null;
String country = null;
String variant = null;
if (firstuscore == 2) {
language = localeName.substring(0, firstuscore);
seconduscore = localeName.indexOf('_', firstuscore + 1);
if (seconduscore > 0) {
if (seconduscore != firstuscore + 3 ||
localeName.length() <= seconduscore + 1) {
docenv.error(null, "main.malformed_locale_name", localeName);
return null;
}
country = localeName.substring(firstuscore + 1,
seconduscore);
variant = localeName.substring(seconduscore + 1);
} else if (localeName.length() == firstuscore + 3) {
country = localeName.substring(firstuscore + 1);
} else {
docenv.error(null, "main.malformed_locale_name", localeName);
return null;
}
} else if (firstuscore == -1 && localeName.length() == 2) {
language = localeName;
} else {
docenv.error(null, "main.malformed_locale_name", localeName);
return null;
}
userlocale = searchLocale(language, country, variant);
if (userlocale == null) {
docenv.error(null, "main.illegal_locale_name", localeName);
return null;
} else {
return userlocale;
}
} else {
return Locale.getDefault();
}
}
/**
* Search the locale for specified language, specified country and
* specified variant.
*/
private Locale searchLocale(String language, String country,
String variant) {
for (Locale loc : Locale.getAvailableLocales()) {
if (loc.getLanguage().equals(language) &&
(country == null || loc.getCountry().equals(country)) &&
(variant == null || loc.getVariant().equals(variant))) {
return loc;
}
}
return null;
}
String localeSpecificFirstSentence( DocImpl doc, String s) {
if (s == null || s.length() == 0) {
return "";
}
int index = s.indexOf("-->");
if(s.trim().startsWith("