Esempio n. 1
0
  /** Perform a test read on a single key */
  private static void readKey(Book book, Key key, int[] stats) {
    try {
      String orig;
      try {
        orig = book.getRawText(key);
      } catch (BookException ex) {
        log.warn(
            "Failed to read: {}({}):{}", book.getInitials(), key.getOsisID(), ex.getMessage(), ex);
        return;
      }

      Matcher matcher = null;
      if (orig.indexOf("passage=\"") != -1) {
        matcher = thmlPassagePattern.matcher(orig);
      } else if (orig.indexOf("osisRef=\"") != -1) {
        matcher = osisPassagePattern.matcher(orig);
      } else if (orig.indexOf("<RX>") != -1) {
        matcher = gbfPassagePattern.matcher(orig);
      }

      if (matcher != null) {
        while (matcher.find()) {
          String rawRef = matcher.group(2);
          stats[0]++;
          String message = book.getInitials() + ':' + key.getOsisRef() + '/' + rawRef;
          /*
                             try {
                                 Key ref = book.getKey(rawRef);
                                 message += '/' + ref.getOsisRef();
                             } catch (NoSuchKeyException e) {
                                 message += '!' + e.getMessage();
                                 stats[1]++;
                             }
          */

          out.println(message);
        }
      }

    } catch (Throwable ex) {
      log.error("Unexpected error reading: {} ({})", book.getInitials(), key.getName(), ex);
    }
  }
Esempio n. 2
0
  /**
   * Books like Josephus have hierarchical chapters. Only the current chapter should be returned,
   * not child chapters.
   *
   * @throws Exception
   */
  @Test
  public void testHierarchicalBook() throws Exception {
    Book josephus = Books.installed().getBook("Josephus");
    String section1Text = "THOSE who undertake to write histories";
    if (josephus != null) {
      // navigate down to the Preface
      Key theAntiquitiesOfTheJewsKey = josephus.getGlobalKeyList().get(1);
      Key prefaceKey = theAntiquitiesOfTheJewsKey.get(0);
      String prefaceText = josephus.getRawText(prefaceKey);
      Assert.assertFalse("Child keys returned in raw text", prefaceText.contains(section1Text));

      // Now attempt to parse a key but get the problem is that all child text is returned too
      BookData bookData = new BookData(josephus, prefaceKey);
      final Element osisFragment = bookData.getOsisFragment();

      final XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat());
      String prefaceXml = xmlOutputter.outputString(osisFragment);
      Assert.assertFalse("Child keys returned in xml", prefaceXml.contains(section1Text));
    }
  }