コード例 #1
0
 private String toBibtex(Book book) throws IllegalArgumentException, IllegalAccessException {
   String result = "@Book {";
   String tabs;
   Class<? extends Object> obj = book.getClass();
   Field[] fields = obj.getDeclaredFields();
   for (Field field : fields) {
     field.setAccessible(true);
     if (field.getName().equals("tags")) {
       continue;
     }
     boolean ehto = (field.get(book) != null && !field.get(book).toString().isEmpty());
     if (ehto && field.getName().equals("citation")) {
       result += book.getCitation() + "\n";
       continue;
     }
     if (ehto) {
       if (field.getName().length() < 8) {
         tabs = "\t\t\t";
       } else {
         tabs = "\t\t";
       }
       result += String.format("%s%s=\t\t\"%s\",\n", field.getName(), tabs, field.get(book));
     }
   }
   int ind = result.lastIndexOf(",");
   result = new StringBuilder(result).replace(ind, ind + 1, "").toString();
   result += "}";
   result = aakkosetBibtexMuotoon(result);
   return result;
 }
コード例 #2
0
 public void addTag(Long bookId, Tag tag) {
   Book book = getBook(bookId);
   book.getTags().add(tag);
   addBook(book);
 }