Search in sources :

Example 31 with StepInternalException

use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.

the class AbstractClasspathBasedModuleLoader method parseMultipleCsvFiles.

/**
 * parses multiple files held in a index.txt file
 */
private void parseMultipleCsvFiles() {
    // read files one by one
    final String directory = this.resourcePath.substring(0, this.resourcePath.lastIndexOf('/') + 1);
    final InputStream stream = ModuleLoader.class.getResourceAsStream(this.resourcePath);
    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new InputStreamReader(stream));
        String line = null;
        while ((line = reader.readLine()) != null) {
            if (!line.startsWith("--")) {
                parseSingleFile(directory + line);
            }
        }
    } catch (final IOException e) {
        throw new StepInternalException("Unable to read index.txt file", e);
    } finally {
        closeQuietly(reader);
    }
}
Also used : StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException)

Example 32 with StepInternalException

use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.

the class AbstractClasspathBasedModuleLoader method calculateSkipLines.

/**
 * Calculates the number of lines to be skipped
 * @param resourcePath the path to the resource
 * @return
 */
private int calculateSkipLines(final String resourcePath) {
    BufferedReader reader = null;
    try {
        int skipLines = 0;
        reader = new BufferedReader(new InputStreamReader(ModuleLoader.class.getResourceAsStream(resourcePath)));
        String line;
        while ((line = reader.readLine()) != null && line.length() != 0 && line.charAt(0) == '#') {
            LOG.trace("Skipping line...");
            skipLines++;
        }
        return skipLines;
    } catch (IOException ex) {
        throw new StepInternalException("Failed to skip lines", ex);
    } finally {
        IOUtils.closeQuietly(reader);
    }
}
Also used : ModuleLoader(com.tyndalehouse.step.core.data.create.ModuleLoader) StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException)

Example 33 with StepInternalException

use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.

the class Loader method init.

/**
 * Creates the table and loads the initial data set
 */
public void init() {
    if (this.inProgress) {
        return;
    }
    this.totalProgress = 0;
    try {
        this.inProgress = true;
        listenInJobs();
        if (!Boolean.getBoolean("step.skipBookInstallation")) {
            // remove any internet loader, because we are running locally first...
            // THIS LINE IS ABSOLUTELY CRITICAL AS IT DISABLES HTTP INSTALLER ON AN APPLICATION-WIDE LEVEL
            this.jswordModule.setOffline(true);
            // attempt to reload the installer list. This ensures we have all the versions in the available bibles
            // that we need
            this.jswordModule.reloadInstallers();
            final List<Book> availableModules = this.jswordModule.getAllModules(-1, BookCategory.BIBLE, BookCategory.COMMENTARY);
            final String[] initials = new String[availableModules.size()];
            // This may put too much stress on smaller systems, since indexing for all modules in
            // package
            // would result as happening at the same times
            this.totalItems += availableModules.size() * 2;
            for (int ii = 0; ii < availableModules.size(); ii++) {
                final Book b = availableModules.get(ii);
                installAndIndex(b.getInitials());
                initials[ii] = b.getInitials();
            }
            this.jswordModule.waitForIndexes(initials);
        }
        // now we can load the data
        loadData();
        this.complete = true;
        appManager.setAndSaveAppVersion(runningAppVersion);
    } catch (Exception ex) {
        // wrap it into an internal exception so that we get some logging.
        throw new StepInternalException(ex.getMessage(), ex);
    } finally {
        if (workListener != null) {
            JobManager.removeWorkListener(workListener);
        }
        this.jswordModule.setOffline(false);
        this.inProgress = false;
    }
}
Also used : StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) Book(org.crosswire.jsword.book.Book) ProvisionException(com.google.inject.ProvisionException) StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException)

Example 34 with StepInternalException

use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.

the class HeadwordLineBasedLoader method parseFile.

@Override
protected void parseFile(final Reader reader, int skipLines) {
    final BufferedReader bufferedReader = new BufferedReader(reader);
    String line = null;
    try {
        while ((line = bufferedReader.readLine()) != null) {
            parseLine(line);
        }
    } catch (final IOException e) {
        throw new StepInternalException("Unable to read a line from the source file ", e);
    }
    // save last article
    this.writer.save();
    LOGGER.info("Loaded [{}] entries.", this.count);
}
Also used : StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 35 with StepInternalException

use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.

the class AnalyzedPrefixSearchQueryParser method getPrefixQuery.

@Override
protected org.apache.lucene.search.Query getPrefixQuery(final String field, final String termStr) throws ParseException {
    TokenStream source;
    final Analyzer analyzer = super.getAnalyzer();
    try {
        source = analyzer.reusableTokenStream(field, new StringReader(termStr));
        source.reset();
        final BooleanQuery query = new BooleanQuery();
        // now need to consume the stream
        while (source.incrementToken()) {
            final TermAttribute attribute = source.getAttribute(TermAttribute.class);
            final String prefixTerm = attribute.term();
            if (prefixTerm.length() != 0) {
                final org.apache.lucene.search.Query prefixQuery = super.getPrefixQuery(field, prefixTerm);
                query.add(prefixQuery, Occur.SHOULD);
            }
        }
        return query;
    } catch (final IOException e) {
        throw new StepInternalException("Unable to make a prefix query", e);
    }
}
Also used : BooleanQuery(org.apache.lucene.search.BooleanQuery) TokenStream(org.apache.lucene.analysis.TokenStream) StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) StringReader(java.io.StringReader) TermAttribute(org.apache.lucene.analysis.tokenattributes.TermAttribute) IOException(java.io.IOException) Analyzer(org.apache.lucene.analysis.Analyzer)

Aggregations

StepInternalException (com.tyndalehouse.step.core.exceptions.StepInternalException)62 IOException (java.io.IOException)25 Book (org.crosswire.jsword.book.Book)9 Key (org.crosswire.jsword.passage.Key)7 EntityDoc (com.tyndalehouse.step.core.data.EntityDoc)5 OsisWrapper (com.tyndalehouse.step.core.models.OsisWrapper)4 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 ParseException (org.apache.lucene.queryParser.ParseException)4 BookException (org.crosswire.jsword.book.BookException)4 Versification (org.crosswire.jsword.versification.Versification)4 LocalisedException (com.tyndalehouse.step.core.exceptions.LocalisedException)3 TranslatedException (com.tyndalehouse.step.core.exceptions.TranslatedException)3 KeyWrapper (com.tyndalehouse.step.core.models.KeyWrapper)3 FileInputStream (java.io.FileInputStream)3 TransformingSAXEventProvider (org.crosswire.common.xml.TransformingSAXEventProvider)3 XMLUtil.writeToString (org.crosswire.common.xml.XMLUtil.writeToString)3 NoSuchKeyException (org.crosswire.jsword.passage.NoSuchKeyException)3 BibleBook (org.crosswire.jsword.versification.BibleBook)3 AllResultsCollector (com.tyndalehouse.step.core.data.AllResultsCollector)2