/** * Gets the class name minus the package name from a <code>Class</code>. * * @param cls * the class to get the short name for, must not be * <code>null</code> * @return the class name without the package name * @throws IllegalArgumentException * if the class is <code>null</code> */ public static String getShortClassName(Class<?> cls) { if (cls == null) { throw new IllegalArgumentException("The class must not be null"); } return getShortClassName(cls.getName()); }
/** * Gets the class name minus the package name for an <code>Object</code>. * * @param object * the class to get the short name for, may be null * @param valueIfNull * the value to return if null * @return the class name of the object without the package name, or the * null value */ public static String getShortClassName(Object object, String valueIfNull) { if (object == null) { return valueIfNull; } return getShortClassName(object.getClass().getName()); }
/** * Get and load a properties file from the writable area or if that fails * from the classpath (where a default ought to be stored) * * @param <T> the type of the resource * @param clazz * The name of the desired resource * @return The found and loaded properties file * @throws IOException * if the resource can not be loaded */ public static <T> PropertyMap getProperties(Class<T> clazz) throws IOException { return getProperties(clazz, ClassUtil.getShortClassName(clazz)); }
private ResourceBundle getLocalisedResources() { Class<? extends MsgBase> implementingClass = getClass(); String className = implementingClass.getName(); String shortClassName = ClassUtil.getShortClassName(className); Locale currentUserLocale = LocaleProviderManager.getLocale(); Map<String, ResourceBundle> localisedResourceMap = getLazyLocalisedResourceMap(currentUserLocale); ResourceBundle resourceBundle = localisedResourceMap.get(className); if (resourceBundle == null) { resourceBundle = getResourceBundleForClass(implementingClass, className, shortClassName, currentUserLocale, localisedResourceMap); } // if for some reason, we are still looking at a null, then we can only do our best, which is to return the English Locale. if (resourceBundle == null) { resourceBundle = getResourceBundleForClass(implementingClass, className, shortClassName, Locale.ENGLISH, localisedResourceMap); } //if we're still looking at a null, there is definitely nothing else we can do, so throw an exception if (resourceBundle == null) { log.error("Missing resources: Locale={} class={}", currentUserLocale, className); throw new MissingResourceException("Unable to find the language resources.", className, shortClassName); } return resourceBundle; }
public void updateOsisStack(Book book, Key key, LinkedList<Content> stack) { if (stack.isEmpty()) { DataPolice.report(book, key, "Ignoring end tag without corresponding start tag: " + getName()); return; } Object pop = stack.removeFirst(); if (!(pop instanceof Element)) { DataPolice.report(book, key, "expected to pop a Note, but found " + ClassUtil.getShortClassName(pop.getClass())); return; } Element note = (Element) pop; if (note.getContentSize() < 1) { Content top = stack.get(0); if (top instanceof Element) { Element ele = (Element) top; ele.removeContent(note); } } } }
/** * Get and load a plugin file by looking it up as a resource. * * @param <T> the implementor's type * @param clazz * The name of the desired resource * @return The found and loaded plugin file * @throws IOException * if the resource can not be loaded * @throws MissingResourceException * if the resource can not be found */ public static <T> PropertyMap getPlugin(Class<T> clazz) throws IOException { String subject = ClassUtil.getShortClassName(clazz); try { String lookup = subject + PluginUtil.EXTENSION_PLUGIN; InputStream in = ResourceUtil.getResourceAsStream(clazz, lookup); PropertyMap prop = new PropertyMap(); prop.load(in); return prop; } catch (MissingResourceException e) { return new PropertyMap(); } }
String shortClassName = ClassUtil.getShortClassName(className); ResourceBundle resources = ResourceBundle.getBundle(shortClassName, locale, CWClassLoader.instance(BibleNames.class));