本文整理汇总了Java中sun.util.locale.LocaleSyntaxException类的典型用法代码示例。如果您正苦于以下问题:Java LocaleSyntaxException类的具体用法?Java LocaleSyntaxException怎么用?Java LocaleSyntaxException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LocaleSyntaxException类属于sun.util.locale包,在下文中一共展示了LocaleSyntaxException类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readObject
import sun.util.locale.LocaleSyntaxException; //导入依赖的package包/类
/**
* Deserializes this <code>Locale</code>.
* @param in the <code>ObjectInputStream</code> to read
* @throws IOException
* @throws ClassNotFoundException
* @throws IllformedLocaleException
* @since 1.7
*/
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
ObjectInputStream.GetField fields = in.readFields();
String language = (String)fields.get("language", "");
String script = (String)fields.get("script", "");
String country = (String)fields.get("country", "");
String variant = (String)fields.get("variant", "");
String extStr = (String)fields.get("extensions", "");
baseLocale = BaseLocale.getInstance(convertOldISOCodes(language), script, country, variant);
if (extStr.length() > 0) {
try {
InternalLocaleBuilder bldr = new InternalLocaleBuilder();
bldr.setExtensions(extStr);
localeExtensions = bldr.getLocaleExtensions();
} catch (LocaleSyntaxException e) {
throw new IllformedLocaleException(e.getMessage());
}
} else {
localeExtensions = null;
}
}
示例2: readObject
import sun.util.locale.LocaleSyntaxException; //导入依赖的package包/类
/**
* Deserializes this <code>Locale</code>.
* @param in the <code>ObjectInputStream</code> to read
* @throws IOException
* @throws ClassNotFoundException
* @throws IllformdLocaleException
* @since 1.7
*/
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
ObjectInputStream.GetField fields = in.readFields();
String language = (String)fields.get("language", "");
String script = (String)fields.get("script", "");
String country = (String)fields.get("country", "");
String variant = (String)fields.get("variant", "");
String extStr = (String)fields.get("extensions", "");
baseLocale = BaseLocale.getInstance(convertOldISOCodes(language), script, country, variant);
if (extStr.length() > 0) {
try {
InternalLocaleBuilder bldr = new InternalLocaleBuilder();
bldr.setExtensions(extStr);
localeExtensions = bldr.getLocaleExtensions();
} catch (LocaleSyntaxException e) {
throw new IllformedLocaleException(e.getMessage());
}
} else {
localeExtensions = null;
}
}
示例3: setLocale
import sun.util.locale.LocaleSyntaxException; //导入依赖的package包/类
/**
* Resets the <code>Builder</code> to match the provided
* <code>locale</code>. Existing state is discarded.
*
* <p>All fields of the locale must be well-formed, see {@link Locale}.
*
* <p>Locales with any ill-formed fields cause
* <code>IllformedLocaleException</code> to be thrown, except for the
* following three cases which are accepted for compatibility
* reasons:<ul>
* <li>Locale("ja", "JP", "JP") is treated as "ja-JP-u-ca-japanese"
* <li>Locale("th", "TH", "TH") is treated as "th-TH-u-nu-thai"
* <li>Locale("no", "NO", "NY") is treated as "nn-NO"</ul>
*
* @param locale the locale
* @return This builder.
* @throws IllformedLocaleException if <code>locale</code> has
* any ill-formed fields.
* @throws NullPointerException if <code>locale</code> is null.
*/
public Builder setLocale(Locale locale) {
try {
localeBuilder.setLocale(locale.baseLocale, locale.localeExtensions);
} catch (LocaleSyntaxException e) {
throw new IllformedLocaleException(e.getMessage(), e.getErrorIndex());
}
return this;
}
示例4: setLanguage
import sun.util.locale.LocaleSyntaxException; //导入依赖的package包/类
/**
* Sets the language. If <code>language</code> is the empty string or
* null, the language in this <code>Builder</code> is removed. Otherwise,
* the language must be <a href="./Locale.html#def_language">well-formed</a>
* or an exception is thrown.
*
* <p>The typical language value is a two or three-letter language
* code as defined in ISO639.
*
* @param language the language
* @return This builder.
* @throws IllformedLocaleException if <code>language</code> is ill-formed
*/
public Builder setLanguage(String language) {
try {
localeBuilder.setLanguage(language);
} catch (LocaleSyntaxException e) {
throw new IllformedLocaleException(e.getMessage(), e.getErrorIndex());
}
return this;
}
示例5: setScript
import sun.util.locale.LocaleSyntaxException; //导入依赖的package包/类
/**
* Sets the script. If <code>script</code> is null or the empty string,
* the script in this <code>Builder</code> is removed.
* Otherwise, the script must be <a href="./Locale.html#def_script">well-formed</a> or an
* exception is thrown.
*
* <p>The typical script value is a four-letter script code as defined by ISO 15924.
*
* @param script the script
* @return This builder.
* @throws IllformedLocaleException if <code>script</code> is ill-formed
*/
public Builder setScript(String script) {
try {
localeBuilder.setScript(script);
} catch (LocaleSyntaxException e) {
throw new IllformedLocaleException(e.getMessage(), e.getErrorIndex());
}
return this;
}
示例6: setRegion
import sun.util.locale.LocaleSyntaxException; //导入依赖的package包/类
/**
* Sets the region. If region is null or the empty string, the region
* in this <code>Builder</code> is removed. Otherwise,
* the region must be <a href="./Locale.html#def_region">well-formed</a> or an
* exception is thrown.
*
* <p>The typical region value is a two-letter ISO 3166 code or a
* three-digit UN M.49 area code.
*
* <p>The country value in the <code>Locale</code> created by the
* <code>Builder</code> is always normalized to upper case.
*
* @param region the region
* @return This builder.
* @throws IllformedLocaleException if <code>region</code> is ill-formed
*/
public Builder setRegion(String region) {
try {
localeBuilder.setRegion(region);
} catch (LocaleSyntaxException e) {
throw new IllformedLocaleException(e.getMessage(), e.getErrorIndex());
}
return this;
}
示例7: setVariant
import sun.util.locale.LocaleSyntaxException; //导入依赖的package包/类
/**
* Sets the variant. If variant is null or the empty string, the
* variant in this <code>Builder</code> is removed. Otherwise, it
* must consist of one or more <a href="./Locale.html#def_variant">well-formed</a>
* subtags, or an exception is thrown.
*
* <p><b>Note:</b> This method checks if <code>variant</code>
* satisfies the IETF BCP 47 variant subtag's syntax requirements,
* and normalizes the value to lowercase letters. However,
* the <code>Locale</code> class does not impose any syntactic
* restriction on variant, and the variant value in
* <code>Locale</code> is case sensitive. To set such a variant,
* use a Locale constructor.
*
* @param variant the variant
* @return This builder.
* @throws IllformedLocaleException if <code>variant</code> is ill-formed
*/
public Builder setVariant(String variant) {
try {
localeBuilder.setVariant(variant);
} catch (LocaleSyntaxException e) {
throw new IllformedLocaleException(e.getMessage(), e.getErrorIndex());
}
return this;
}
示例8: setExtension
import sun.util.locale.LocaleSyntaxException; //导入依赖的package包/类
/**
* Sets the extension for the given key. If the value is null or the
* empty string, the extension is removed. Otherwise, the extension
* must be <a href="./Locale.html#def_extensions">well-formed</a> or an exception
* is thrown.
*
* <p><b>Note:</b> The key {@link Locale#UNICODE_LOCALE_EXTENSION
* UNICODE_LOCALE_EXTENSION} ('u') is used for the Unicode locale extension.
* Setting a value for this key replaces any existing Unicode locale key/type
* pairs with those defined in the extension.
*
* <p><b>Note:</b> The key {@link Locale#PRIVATE_USE_EXTENSION
* PRIVATE_USE_EXTENSION} ('x') is used for the private use code. To be
* well-formed, the value for this key needs only to have subtags of one to
* eight alphanumeric characters, not two to eight as in the general case.
*
* @param key the extension key
* @param value the extension value
* @return This builder.
* @throws IllformedLocaleException if <code>key</code> is illegal
* or <code>value</code> is ill-formed
* @see #setUnicodeLocaleKeyword(String, String)
*/
public Builder setExtension(char key, String value) {
try {
localeBuilder.setExtension(key, value);
} catch (LocaleSyntaxException e) {
throw new IllformedLocaleException(e.getMessage(), e.getErrorIndex());
}
return this;
}
示例9: setUnicodeLocaleKeyword
import sun.util.locale.LocaleSyntaxException; //导入依赖的package包/类
/**
* Sets the Unicode locale keyword type for the given key. If the type
* is null, the Unicode keyword is removed. Otherwise, the key must be
* non-null and both key and type must be <a
* href="./Locale.html#def_locale_extension">well-formed</a> or an exception
* is thrown.
*
* <p>Keys and types are converted to lower case.
*
* <p><b>Note</b>:Setting the 'u' extension via {@link #setExtension}
* replaces all Unicode locale keywords with those defined in the
* extension.
*
* @param key the Unicode locale key
* @param type the Unicode locale type
* @return This builder.
* @throws IllformedLocaleException if <code>key</code> or <code>type</code>
* is ill-formed
* @throws NullPointerException if <code>key</code> is null
* @see #setExtension(char, String)
*/
public Builder setUnicodeLocaleKeyword(String key, String type) {
try {
localeBuilder.setUnicodeLocaleKeyword(key, type);
} catch (LocaleSyntaxException e) {
throw new IllformedLocaleException(e.getMessage(), e.getErrorIndex());
}
return this;
}
示例10: addUnicodeLocaleAttribute
import sun.util.locale.LocaleSyntaxException; //导入依赖的package包/类
/**
* Adds a unicode locale attribute, if not already present, otherwise
* has no effect. The attribute must not be null and must be <a
* href="./Locale.html#def_locale_extension">well-formed</a> or an exception
* is thrown.
*
* @param attribute the attribute
* @return This builder.
* @throws NullPointerException if <code>attribute</code> is null
* @throws IllformedLocaleException if <code>attribute</code> is ill-formed
* @see #setExtension(char, String)
*/
public Builder addUnicodeLocaleAttribute(String attribute) {
try {
localeBuilder.addUnicodeLocaleAttribute(attribute);
} catch (LocaleSyntaxException e) {
throw new IllformedLocaleException(e.getMessage(), e.getErrorIndex());
}
return this;
}
示例11: removeUnicodeLocaleAttribute
import sun.util.locale.LocaleSyntaxException; //导入依赖的package包/类
/**
* Removes a unicode locale attribute, if present, otherwise has no
* effect. The attribute must not be null and must be <a
* href="./Locale.html#def_locale_extension">well-formed</a> or an exception
* is thrown.
*
* <p>Attribute comparision for removal is case-insensitive.
*
* @param attribute the attribute
* @return This builder.
* @throws NullPointerException if <code>attribute</code> is null
* @throws IllformedLocaleException if <code>attribute</code> is ill-formed
* @see #setExtension(char, String)
*/
public Builder removeUnicodeLocaleAttribute(String attribute) {
try {
localeBuilder.removeUnicodeLocaleAttribute(attribute);
} catch (LocaleSyntaxException e) {
throw new IllformedLocaleException(e.getMessage(), e.getErrorIndex());
}
return this;
}