/** * Registers all the drivers known to the program. */ private void autoRegister() { // This will classload them all and they will register themselves. Class<? extends BookDriver>[] types = PluginUtil.getImplementors(BookDriver.class); log.debug("begin auto-registering {} drivers:", Integer.toString(types.length)); for (int i = 0; i < types.length; i++) { // job.setProgress(Msg.JOB_DRIVER.toString() + // ClassUtils.getShortClassName(types[i])); try { Method driverInstance = types[i].getMethod("instance", new Class[0]); BookDriver driver = (BookDriver) driverInstance.invoke(null, new Object[0]); // types[i].newInstance(); registerDriver(driver); } catch (NoSuchMethodException e) { Reporter.informUser(Books.class, e); } catch (IllegalArgumentException e) { Reporter.informUser(Books.class, e); } catch (IllegalAccessException e) { Reporter.informUser(Books.class, e); } catch (InvocationTargetException e) { Reporter.informUser(Books.class, e); } catch (BookException e) { Reporter.informUser(Books.class, e); } } }
Reporter.addReporterListener(new ReporterListener() { @Override public void reportException(final ReporterEvent ev) {
/** * Something has happened. We need to tell the user or someone. * * @param source * The cause of the message, a Component if possible. * @param message * The message to pass to the user */ public static void informUser(Object source, String message) { LOGGER.debug(message); fireCapture(new ReporterEvent(source, message)); }
public void run() { Log.i(TAG, "Starting generic download thread - file:"+target.getName()); try { // Delete the file, if present if (target.exists()) { Log.d(TAG, "deleting file"); target.delete(); } try { downloadFile(source, target, description); } catch (Exception e) { Reporter.informUser(this, "IO Error creating index"); throw new RuntimeException("IO Error downloading index", e); } Log.i(TAG, "Finished index download thread"); } catch (Exception e) { Log.e(TAG, "Error downloading index", e); Reporter.informUser(this, "Error downloading index"); } } };
/** * Something has gone wrong. We need to tell the user or someone, but we can * carry on. In general having caught an exception and passed it to * Reporter.informUser(), you should not throw another Exception. Called to * fire a commandEntered event to all the Listeners * * @param source * The cause of the problem, a Component if possible. * @param prob * The Exception that was thrown */ public static void informUser(Object source, Throwable prob) { Class<?> cat = (source != null) ? source.getClass() : Reporter.class; Logger templog = LoggerFactory.getLogger(cat); templog.warn(prob.getMessage(), prob); fireCapture(new ReporterEvent(source, prob)); }
/** * Determine the last modified date of this WebResource. * <p> * Note that the http client may read the entire file. * </p> * * @return the last mod date of the file */ public long getLastModified() { HttpRequestBase method = new HttpHead(uri); HttpResponse response = null; try { // Execute the method. response = client.execute(method); StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() == HttpStatus.SC_OK) { return getHeaderAsDate(response, "Last-Modified"); } String reason = response.getStatusLine().getReasonPhrase(); // TRANSLATOR: Common error condition: {0} is a placeholder for the // URL of what could not be found. Reporter.informUser(this, JSMsg.gettext("Unable to find: {0}", reason + ':' + uri.getPath())); } catch (IOException e) { return new Date().getTime(); } return new Date().getTime(); }
/** * Something has gone wrong. We need to tell the user or someone, but we can * carry on. In general having caught an exception and passed it to * Reporter.informUser(), you should not throw another Exception. Called to * fire a commandEntered event to all the Listeners * * @param source * The cause of the problem, a Component if possible. * @param prob * The Exception that was thrown */ public static void informUser(Object source, LucidException prob) { Class<?> cat = (source != null) ? source.getClass() : Reporter.class; Logger templog = LoggerFactory.getLogger(cat); templog.warn(prob.getMessage(), prob); fireCapture(new ReporterEvent(source, prob)); }
/** * Determine the size of this WebResource. * <p> * Note that the http client may read the entire file to determine this. * </p> * * @return the size of the file */ public int getSize() { HttpRequestBase method = new HttpHead(uri); HttpResponse response = null; try { // Execute the method. response = client.execute(method); StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() == HttpStatus.SC_OK) { return getHeaderAsInt(response, "Content-Length"); } String reason = response.getStatusLine().getReasonPhrase(); // TRANSLATOR: Common error condition: {0} is a placeholder for the // URL of what could not be found. Reporter.informUser(this, JSMsg.gettext("Unable to find: {0}", reason + ':' + uri.getPath())); } catch (IOException e) { return 0; } return 0; }
/** * Something has gone wrong. We need to tell the user or someone, but we can * carry on. In general having caught an exception and passed it to * Reporter.informUser(), you should not throw another Exception. Called to * fire a commandEntered event to all the Listeners * * @param source * The cause of the problem, a Component if possible. * @param prob * The Exception that was thrown */ public static void informUser(Object source, LucidRuntimeException prob) { Class<?> cat = (source != null) ? source.getClass() : Reporter.class; Logger templog = LoggerFactory.getLogger(cat); templog.warn(prob.getMessage(), prob); fireCapture(new ReporterEvent(source, prob)); }
path = getExpandedDataPath(); } catch (BookException e) { Reporter.informUser(this, e); return; Reporter.informUser(this, new BookException(JSMsg.gettext("Error reading {0}", idxFile.getAbsolutePath()))); return; Reporter.informUser(this, new BookException(JSMsg.gettext("Error reading {0}", datFile.getAbsolutePath()))); return;
public void downloadIndex(final Installer installer, final Book book) { try { BookIndexer bookIndexer = new BookIndexer(book); // Delete the index, if present // At the moment, JSword will not re-install. Later it will, if the // remote version is greater. if (bookIndexer.isIndexed()) { Log.d(TAG, "deleting index"); bookIndexer.deleteIndex(); } try { org.crosswire.jsword.util.IndexDownloader.downloadIndex(book, installer); } catch (IOException e) { Reporter.informUser(this, "IO Error creating index"); throw new RuntimeException("IO Error downloading index", e); } Log.i(TAG, "Finished index download thread"); } catch (Exception e) { Log.e(TAG, "Error downloading index", e); Reporter.informUser(this, "Error downloading index"); } } }
path = SwordUtil.getExpandedDataPath(bookMetaData); } catch (BookException e) { Reporter.informUser(this, e); return; Reporter.informUser(this, new BookException(JSMsg.gettext("Error reading {0}", bdtFile.getAbsolutePath()))); return;
/** * Convert a String to a Map, without type checking * * @param data * the thing to convert * @return the converted data */ public static PropertyMap string2Map(String data) { PropertyMap commands = new PropertyMap(); String[] parts = StringUtil.split(data, " "); String entry = ""; for (int i = 0; i < parts.length; i++) { try { entry = parts[i]; int pos = entry.indexOf('='); String key = entry.substring(0, pos); String value = entry.substring(pos + 1); Class<?> clazz = ClassUtil.forName(value); if (clazz.isAssignableFrom(Object.class)) { assert false; } else { commands.put(key, value); } } catch (ClassNotFoundException ex) { log.warn("Invalid config file entry: {} System message: {}", entry, ex.getMessage()); Reporter.informUser(Convert.class, ex); } } return commands; }
path = SwordUtil.getExpandedDataPath(bookMetaData); } catch (BookException e) { Reporter.informUser(this, e); return; Reporter.informUser(this, new BookException(JSMsg.gettext("Error reading {0}", zdtFile.getAbsolutePath()))); return; Reporter.informUser(this, new BookException(JSMsg.gettext("Error reading {0}", zdtFile.getAbsolutePath()))); return;
Reporter.informUser(this, e); Reporter.informUser(this, ex);
/** * Handle AWT exceptions * * @param ex the exception to handle */ public void handle(Throwable ex) { // Only allow one to be reported every so often. // This interval control was needed because AWT exceptions // were causing recursive AWT exceptions // and way too many dialogs were being thrown up on the screen. if (gate.open()) { // TRANSLATOR: Very frequent error condition: The program has encountered a severe problem and it is likely that the program is unusable. Reporter.informUser(this, new LucidException(JSMsg.gettext("Unexpected internal problem. You may need to restart."), ex)); } }
path = SwordUtil.getExpandedDataPath(bookMetaData); } catch (BookException e) { Reporter.informUser(this, e); throw e; Reporter.informUser(this, new BookException(JSMsg.gettext("Error reading {0}", idxFile.getAbsolutePath()))); Reporter.informUser(this, prob); throw prob;
public void scheduleIndexCreation(final Book book) { book.setIndexStatus(IndexStatus.SCHEDULED); IndexStatus finalStatus = IndexStatus.UNDONE; try { URI storage = getStorageArea(book); Index index = new LuceneIndex(book, storage, this.policy); //todo update Installed IndexVersion for newly created index // todo implement: Installed.Index.Version.Book.XXX value add/update in metadata file after creation, use value getLatestIndexVersion(book) // We were successful if the directory exists. if (NetUtil.getAsFile(storage).exists()) { finalStatus = IndexStatus.DONE; INDEXES.put(book, index); //update IndexVersion InstalledIndex.instance().storeLatestVersionAsInstalledIndexMetadata(book); } } catch (IOException e) { Reporter.informUser(LuceneIndexManager.this, e); } catch (BookException e) { Reporter.informUser(LuceneIndexManager.this, e); } finally { book.setIndexStatus(finalStatus); } }
Reporter.informUser(this, prob); throw prob;
Reporter.informUser(this, new ConfigException(JSOtherMsg.lookupText("Failed to set option: {0}", choice.getFullPath()), ex));