コード例 #1
0
  public void fillBooks(FsModule module, BufferedReader bReader)
      throws FileAccessException, BooksDefinitionException, BookDefinitionException {
    String str, key, value;

    ArrayList<String> fullNames = new ArrayList<String>();
    ArrayList<String> pathNames = new ArrayList<String>();
    ArrayList<String> shortNames = new ArrayList<String>();
    ArrayList<Integer> chapterQty = new ArrayList<Integer>();
    int booksCount = 0;

    int pos;
    try {
      while ((str = bReader.readLine()) != null) {
        pos = str.indexOf("//");
        if (pos >= 0) str = str.substring(0, pos);

        int delimiterPos = str.indexOf("=");
        if (delimiterPos == -1) {
          continue;
        }

        key = str.substring(0, delimiterPos).trim().toLowerCase();
        delimiterPos++;
        value =
            delimiterPos >= str.length() ? "" : str.substring(delimiterPos, str.length()).trim();

        if (key.equals("pathname")) {
          pathNames.add(value);
        } else if (key.equals("fullname")) {
          fullNames.add(value);
        } else if (key.equals("shortname")) {
          shortNames.add(value.replaceAll("\\.", ""));
        } else if (key.equals("chapterqty")) {
          try {
            chapterQty.add(Integer.valueOf(value));
          } catch (NumberFormatException e) {
            chapterQty.add(0);
          }
        } else if (key.equals("bookqty")) {
          try {
            booksCount = Integer.valueOf(value);
          } catch (NumberFormatException e) {
          }
        }
      }

    } catch (IOException e) {
      String message = String.format("fillBooks(%1$s)", module.getDataSourceID(), e);
      Log.e(TAG, message, e);
      throw new FileAccessException(message);
    }

    if (booksCount == 0
        || pathNames.size() < booksCount
        || fullNames.size() < booksCount
        || shortNames.size() < booksCount
        || chapterQty.size() < booksCount) {
      String message =
          String.format(
              "Incorrect books definition in module %1$s: BookQty=%2$s, PathNameCount=%3$s, FullNameCount=%4$s, ShortNameCount=%5$s, ChapterQtyCount=%6$s",
              module.getDataSourceID(),
              booksCount,
              pathNames.size(),
              fullNames.size(),
              shortNames.size(),
              chapterQty.size());
      throw new BooksDefinitionException(
          message,
          module.getDataSourceID(),
          booksCount,
          pathNames.size(),
          fullNames.size(),
          shortNames.size(),
          chapterQty.size());
    }

    for (int i = 0; i < booksCount; i++) {
      if (pathNames.get(i).equals("")
          || fullNames.get(i).equals("")
          || shortNames.get(i).equals("")
          || chapterQty.get(i) == 0) {
        // Имя книги, путь к книге и кол-во глав должны быть обязательно указаны
        String message =
            String.format(
                "Incorrect attributes of book #%1$s in module %2$s: PathName=%3$s, FullName=%4$s, ShortName=%5$s, ChapterQty=%6$s",
                i,
                module.getDataSourceID(),
                pathNames.get(i),
                fullNames.get(i),
                shortNames.get(i),
                chapterQty.get(i));
        throw new BookDefinitionException(
            message,
            module.getDataSourceID(),
            i,
            pathNames.get(i),
            fullNames.get(i),
            shortNames.get(i),
            chapterQty.get(i));
      }
      FsBook book =
          new FsBook(
              module,
              fullNames.get(i),
              pathNames.get(i),
              (shortNames.size() > i ? shortNames.get(i) : ""),
              chapterQty.get(i));
      module.Books.put(book.getID(), book);
    }
  }
コード例 #2
0
  public void fillModule(FsModule module, BufferedReader bReader) throws FileAccessException {
    String str, HTMLFilter = "", key, value;

    int pos;
    try {
      while ((str = bReader.readLine()) != null) {
        pos = str.indexOf("//");
        if (pos >= 0) str = str.substring(0, pos);

        int delimiterPos = str.indexOf("=");
        if (delimiterPos == -1) {
          continue;
        }

        key = str.substring(0, delimiterPos).trim().toLowerCase();
        delimiterPos++;
        value =
            delimiterPos >= str.length() ? "" : str.substring(delimiterPos, str.length()).trim();

        if (key.equals("biblename")) {
          module.setName(value);
        } else if (key.equals("bibleshortname")) {
          module.ShortName = value.replaceAll("\\.", "");
        } else if (key.equals("chaptersign")) {
          module.ChapterSign = value.toLowerCase();
        } else if (key.equals("chapterzero")) {
          module.ChapterZero = value.toLowerCase().contains("y") ? true : false;
        } else if (key.equals("versesign")) {
          module.VerseSign = value.toLowerCase();
        } else if (key.equals("htmlfilter")) {
          HTMLFilter = value;
        } else if (key.equals("bible")) {
          module.isBible = value.toLowerCase().contains("y") ? true : false;
        } else if (key.equals("strongnumbers")) {
          module.containsStrong = value.toLowerCase().contains("y") ? true : false;
        }
      }

    } catch (IOException e) {
      String message = String.format("fillModule(%1$s)", module.getDataSourceID());
      Log.e(TAG, message, e);
      throw new FileAccessException(message);
    }

    String TagFilter[] = {
      "p", "b", "i", "em", "strong", "q", "big", "sub", "sup", "h1", "h2", "h3", "h4"
    };
    ArrayList<String> TagArray = new ArrayList<String>();
    for (String tag : TagFilter) {
      TagArray.add(tag);
    }

    if (!HTMLFilter.equals("")) {
      String[] words = HTMLFilter.replaceAll("\\W", " ").trim().split("\\s+");
      for (String word : words) {
        if (word.equals("") || TagArray.contains(word)) {
          continue;
        }
        TagArray.add(word);
      }
    }

    String separator = "";
    for (String tag : TagArray) {
      module.HtmlFilter +=
          separator
              + "("
              + tag
              + ")|(/"
              + tag
              + ")"
              + "|("
              + tag.toUpperCase()
              + ")|(/"
              + tag.toUpperCase()
              + ")";
      separator = "|";
    }

    module.setIsClosed(false);
  }