/** * Get a list of the supported translations */ private void loadSupportedTranslations() { if (translations == null) { try { URL index = ResourceUtil.getResource(Translations.class, "translations.txt"); translations = NetUtil.listByIndexFile(NetUtil.toURI(index)); } catch (IOException ex) { translations = new String[0]; } } }
/** * Get a list of the available readings sets * * @return all the installed reading sets */ public String[] getInstalledReadingsSets() { try { URL index = ResourceUtil.getResource(ReadingsBookDriver.class, "readings.txt"); return NetUtil.listByIndexFile(NetUtil.toURI(index), new ReadingsFilter()); } catch (IOException ex) { return new String[0]; } }
@Override public SAXEventProvider convert(SAXEventProvider xmlsep) throws TransformerException { try { URL xslurl = ResourceUtil.getResource(style); TransformingSAXEventProvider tsep = new TransformingSAXEventProvider(NetUtil.toURI(xslurl), xmlsep); // We used to do: // tsep.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); // however for various reasons, now we don't but nothing seems to be // broken ... return tsep; } catch (MissingResourceException ex) { throw new TransformerException(ex); } }
/** * Get an array of the available style names for a given subject. Different * subjects are available for different contexts. For example - for * insertion into a web page we might want to use a set that had complex * HTML, or IE/NS specific HTML, where as a JFC HTMLDocument needs simpler * HTML - and special tags like the starting <HTML> tags. * <p> * If the protocol of the URL of the current directory is not file then we * can't use File.list to get the contents of the directory. This will * happen if this is being run as an applet. When we start doing that then * we will need to think up something smarter here. Until then we just * return a zero length array. * * @return An array of available style names */ public String[] getStyles() { try { URL index = ResourceUtil.getResource(NetUtil.INDEX_FILE); return NetUtil.listByIndexFile(NetUtil.toURI(index), new XSLTFilter()); } catch (IOException ex) { return new String[0]; } }
/** * An example of how to do a search and then get text for each range of * verses. * * @throws BookException * @throws SAXException */ void searchAndShow() throws BookException, SAXException { Book bible = Books.installed().getBook(BIBLE_NAME); // Search for words like Melchezedik Key key = bible.find("melchesidec~"); // Here is an example of how to iterate over the ranges and get the text // for each. // The key's iterator would have iterated over verses. // The following shows how to use a stylesheet of your own choosing String path = "org/crosswire/jsword/xml/html5.xsl"; URL xslurl = ResourceUtil.getResource(path); // Make ranges break on chapter Iterator<VerseRange> rangeIter = ((Passage) key).rangeIterator(RestrictionType.CHAPTER); // boundaries. while (rangeIter.hasNext()) { Key range = rangeIter.next(); BookData data = new BookData(bible, range); SAXEventProvider osissep = data.getSAXEventProvider(); SAXEventProvider htmlsep = new TransformingSAXEventProvider(NetUtil.toURI(xslurl), osissep); String text = XMLUtil.writeToString(htmlsep); System.out.println("The html text of " + range.getName() + " is " + text); } }