/* * (non-Javadoc) * * @see java.text.DateFormat#getDateInstance(int) */ public static DateFormatter getSimpleDateInstance(String format) { DateFormatter fmt = new DateFormatter(); boolean oops = false; try { fmt.formatterClass = ClassUtil.forName("com.ibm.icu.text.SimpleDateFormat"); fmt.formatter = ReflectionUtil.construct("com.ibm.icu.text.SimpleDateFormat", format); } catch (NoSuchMethodException e) { oops = true; } catch (IllegalAccessException e) { oops = true; } catch (InvocationTargetException e) { oops = true; } catch (ClassNotFoundException e) { oops = true; } catch (InstantiationException e) { oops = true; } if (oops) { fmt.formatterClass = SimpleDateFormat.class; fmt.formatter = new SimpleDateFormat(format); } return fmt; }
/* * (non-Javadoc) * * @see java.text.DateFormat#getDateInstance(int) */ public static DateFormatter getDateInstance(int format) { DateFormatter fmt = new DateFormatter(); boolean oops = false; try { fmt.formatterClass = ClassUtil.forName("com.ibm.icu.text.DateFormat"); // To call a method taking a type of int, the type has to match but // the object has to be wrapped Class<?>[] instanceTypes = {int.class}; Object[] instanceParams = {Integer.valueOf(format)}; fmt.formatter = ReflectionUtil.invoke( fmt.formatterClass, fmt.formatterClass, "getDateInstance", instanceParams, instanceTypes); } catch (NoSuchMethodException e) { oops = true; } catch (IllegalAccessException e) { oops = true; } catch (InvocationTargetException e) { oops = true; } catch (ClassNotFoundException e) { oops = true; } if (oops) { fmt.formatterClass = DateFormat.class; fmt.formatter = DateFormat.getDateInstance(format); } return fmt; }
/** * Get the Class that owns the function * * @param level Number of calling function */ public Class getClass(int level) { try { return ClassUtil.forName(classNames[level]); } catch (ClassNotFoundException ex) { assert false : ex; return null; } }
/* * (non-Javadoc) * * @see * org.crosswire.common.config.AbstractReflectedChoice#convertToObject(java * .lang.String) */ @Override public Object convertToObject(String orig) { try { return ClassUtil.forName(orig); } catch (ClassNotFoundException ex) { log.warn("Class not found: " + orig, ex); return null; } }
/** * Load up the resources for Bible book and section names, and cache the upper and lower * versions of them. */ private void initialize() { int ntCount = 0; int otCount = 0; int ncCount = 0; BibleBook[] bibleBooks = BibleBook.values(); for (BibleBook book : bibleBooks) { int ordinal = book.ordinal(); if (ordinal > BibleBook.INTRO_OT.ordinal() && ordinal < BibleBook.INTRO_NT.ordinal()) { ++ntCount; } else if (ordinal > BibleBook.INTRO_NT.ordinal() && ordinal <= BibleBook.REV.ordinal()) { ++otCount; } else { ++ncCount; } } // Create the book name maps books = new LinkedHashMap<BibleBook, BookName>(ntCount + otCount + ncCount); String className = BibleNames.class.getName(); String shortClassName = ClassUtil.getShortClassName(className); ResourceBundle resources = ResourceBundle.getBundle( shortClassName, locale, CWClassLoader.instance(BibleNames.class)); fullNT = new HashMap<String, BookName>(ntCount); shortNT = new HashMap<String, BookName>(ntCount); altNT = new HashMap<String, BookName>(ntCount); for (int i = BibleBook.MATT.ordinal(); i <= BibleBook.REV.ordinal(); ++i) { BibleBook book = bibleBooks[i]; store(resources, book, fullNT, shortNT, altNT); } fullOT = new HashMap<String, BookName>(otCount); shortOT = new HashMap<String, BookName>(otCount); altOT = new HashMap<String, BookName>(otCount); for (int i = BibleBook.GEN.ordinal(); i <= BibleBook.MAL.ordinal(); ++i) { BibleBook book = bibleBooks[i]; store(resources, book, fullOT, shortOT, altOT); } fullNC = new HashMap<String, BookName>(ncCount); shortNC = new HashMap<String, BookName>(ncCount); altNC = new HashMap<String, BookName>(ncCount); store(resources, BibleBook.INTRO_BIBLE, fullNC, shortNC, altNC); store(resources, BibleBook.INTRO_OT, fullNC, shortNC, altNC); store(resources, BibleBook.INTRO_NT, fullNC, shortNC, altNC); for (int i = BibleBook.REV.ordinal() + 1; i < bibleBooks.length; ++i) { BibleBook book = bibleBooks[i]; store(resources, book, fullNC, shortNC, altNC); } }
/** * 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 clazz The name of the desired resource * @return The found and loaded properties file * @throws IOException if the resource can not be loaded * @throws MissingResourceException if the resource can not be found */ public static Properties getProperties(Class clazz) throws IOException { return getProperties(clazz, ClassUtil.getShortClassName(clazz)); }