use of java.util.MissingResourceException in project jdk8u_jdk by JetBrains.
the class DateFormatProviderImpl method getInstance.
private DateFormat getInstance(int dateStyle, int timeStyle, Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
SimpleDateFormat sdf = new SimpleDateFormat("", locale);
Calendar cal = sdf.getCalendar();
try {
String pattern = LocaleProviderAdapter.forType(type).getLocaleResources(locale).getDateTimePattern(timeStyle, dateStyle, cal);
sdf.applyPattern(pattern);
} catch (MissingResourceException mre) {
// Specify the fallback pattern
sdf.applyPattern("M/d/yy h:mm a");
}
return sdf;
}
use of java.util.MissingResourceException in project jdk8u_jdk by JetBrains.
the class RuleBasedBreakIterator method readFile.
protected byte[] readFile(final String datafile) throws IOException, MissingResourceException {
BufferedInputStream is;
try {
is = AccessController.doPrivileged(new PrivilegedExceptionAction<BufferedInputStream>() {
@Override
public BufferedInputStream run() throws Exception {
return new BufferedInputStream(getClass().getResourceAsStream("/sun/text/resources/" + datafile));
}
});
} catch (PrivilegedActionException e) {
throw new InternalError(e.toString(), e);
}
int offset = 0;
/* First, read magic, version, and header_info. */
int len = LABEL_LENGTH + 5;
byte[] buf = new byte[len];
if (is.read(buf) != len) {
throw new MissingResourceException("Wrong header length", datafile, "");
}
/* Validate the magic number. */
for (int i = 0; i < LABEL_LENGTH; i++, offset++) {
if (buf[offset] != LABEL[offset]) {
throw new MissingResourceException("Wrong magic number", datafile, "");
}
}
/* Validate the version number. */
if (buf[offset] != supportedVersion) {
throw new MissingResourceException("Unsupported version(" + buf[offset] + ")", datafile, "");
}
/* Read data: totalDataSize + 8(for checksum) */
len = getInt(buf, ++offset);
buf = new byte[len];
if (is.read(buf) != len) {
throw new MissingResourceException("Wrong data length", datafile, "");
}
is.close();
return buf;
}
use of java.util.MissingResourceException in project jdk8u_jdk by JetBrains.
the class CodePointIM method main.
// Actually, the main method is not required for InputMethod.
// The following method is added just to tell users that their use is
// not correct and encourage their reading README.txt.
public static void main(String[] args) {
try {
ResourceBundle resource = ResourceBundle.getBundle("resources.codepoint", Locale.getDefault());
System.err.println(resource.getString("warning"));
} catch (MissingResourceException e) {
System.err.println(e.toString());
}
System.exit(1);
}
use of java.util.MissingResourceException in project jdk8u_jdk by JetBrains.
the class ImageWriter method processWarningOccurred.
/**
* Broadcasts a localized warning message to all registered
* <code>IIOWriteWarningListener</code>s by calling their
* <code>warningOccurred</code> method with a string taken
* from a <code>ResourceBundle</code>. Subclasses may use this
* method as a convenience.
*
* @param imageIndex the index of the image on which the warning
* occurred.
* @param baseName the base name of a set of
* <code>ResourceBundle</code>s containing localized warning
* messages.
* @param keyword the keyword used to index the warning message
* within the set of <code>ResourceBundle</code>s.
*
* @exception IllegalArgumentException if <code>baseName</code>
* is <code>null</code>.
* @exception IllegalArgumentException if <code>keyword</code>
* is <code>null</code>.
* @exception IllegalArgumentException if no appropriate
* <code>ResourceBundle</code> may be located.
* @exception IllegalArgumentException if the named resource is
* not found in the located <code>ResourceBundle</code>.
* @exception IllegalArgumentException if the object retrieved
* from the <code>ResourceBundle</code> is not a
* <code>String</code>.
*/
protected void processWarningOccurred(int imageIndex, String baseName, String keyword) {
if (warningListeners == null) {
return;
}
if (baseName == null) {
throw new IllegalArgumentException("baseName == null!");
}
if (keyword == null) {
throw new IllegalArgumentException("keyword == null!");
}
int numListeners = warningListeners.size();
for (int i = 0; i < numListeners; i++) {
IIOWriteWarningListener listener = (IIOWriteWarningListener) warningListeners.get(i);
Locale locale = (Locale) warningLocales.get(i);
if (locale == null) {
locale = Locale.getDefault();
}
/**
* If an applet supplies an implementation of ImageWriter and
* resource bundles, then the resource bundle will need to be
* accessed via the applet class loader. So first try the context
* class loader to locate the resource bundle.
* If that throws MissingResourceException, then try the
* system class loader.
*/
ClassLoader loader = (ClassLoader) java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {
public Object run() {
return Thread.currentThread().getContextClassLoader();
}
});
ResourceBundle bundle = null;
try {
bundle = ResourceBundle.getBundle(baseName, locale, loader);
} catch (MissingResourceException mre) {
try {
bundle = ResourceBundle.getBundle(baseName, locale);
} catch (MissingResourceException mre1) {
throw new IllegalArgumentException("Bundle not found!");
}
}
String warning = null;
try {
warning = bundle.getString(keyword);
} catch (ClassCastException cce) {
throw new IllegalArgumentException("Resource is not a String!");
} catch (MissingResourceException mre) {
throw new IllegalArgumentException("Resource is missing!");
}
listener.warningOccurred(this, imageIndex, warning);
}
}
use of java.util.MissingResourceException in project uPortal by Jasig.
the class XmlChannelPublishingDefinitionDao method loadChannelPublishingDefinition.
private PortletPublishingDefinition loadChannelPublishingDefinition(int channelTypeId) {
// if the CPD is not already in the cache, determine the CPD URI
final String cpdUri;
if (channelTypeId >= 0) {
final IPortletType type = this.portletTypeRegistry.getPortletType(channelTypeId);
if (type == null) {
throw new IllegalArgumentException("No ChannelType registered with id: " + channelTypeId);
}
cpdUri = type.getCpdUri();
} else {
throw new IllegalArgumentException("No ChannelType registered with id: " + channelTypeId);
}
// read and parse the CPD
final PortletPublishingDefinition def;
final Resource cpdResource = this.resourceLoader.getResource("classpath:" + cpdUri);
if (!cpdResource.exists()) {
throw new MissingResourceException("Failed to find CPD '" + cpdUri + "' for channel type " + channelTypeId, this.getClass().getName(), cpdUri);
}
final InputStream cpdStream;
try {
cpdStream = cpdResource.getInputStream();
} catch (IOException e) {
throw new MissingResourceException("Failed to load CPD '" + cpdUri + "' for channel type " + channelTypeId, this.getClass().getName(), cpdUri);
}
try {
def = (PortletPublishingDefinition) this.unmarshaller.unmarshal(cpdStream);
final List<Step> sharedParameters = this.getSharedParameters();
def.getSteps().addAll(sharedParameters);
// add the CPD to the cache and return it
this.cpdCache.put(channelTypeId, def);
return def;
} catch (JAXBException e) {
} finally {
IOUtils.closeQuietly(cpdStream);
}
return null;
}
Aggregations