Esempio n. 1
0
  boolean readMetaInfo() {
    myEncoding = null;
    myLanguage = null;
    myTitle = null;
    myAuthors = null;
    myTags = null;
    mySeriesInfo = null;

    myIsSaved = false;

    final FormatPlugin plugin = PluginCollection.Instance().getPlugin(File);
    if (plugin == null || !plugin.readMetaInfo(this)) {
      return false;
    }
    if (myTitle == null || myTitle.length() == 0) {
      final String fileName = File.getShortName();
      final int index = fileName.lastIndexOf('.');
      setTitle(index > 0 ? fileName.substring(0, index) : fileName);
    }
    final String demoPathPrefix =
        Paths.BooksDirectoryOption().getValue()
            + java.io.File.separator
            + "Demos"
            + java.io.File.separator;
    if (File.getPath().startsWith(demoPathPrefix)) {
      final String demoTag = LibraryUtil.resource().getResource("demo").getValue();
      setTitle(getTitle() + " (" + demoTag + ")");
      addTag(demoTag);
    }
    return true;
  }
Esempio n. 2
0
 @Override
 public void characterDataHandler(char[] ch, int start, int length) {
   // TODO + length -- remove
   final String text = new String(ch).substring(start, start + length);
   if (myReadTitle) {
     myBook.setTitle(myBook.getTitle() + text);
   }
 }
 @Override
 protected void reloadBook(Book book) {
   final Cursor cursor =
       myDatabase.rawQuery(
           "SELECT title,encoding,language FROM Books WHERE book_id = " + book.getId(), null);
   if (cursor.moveToNext()) {
     book.setTitle(cursor.getString(0));
     book.setEncoding(cursor.getString(1));
     book.setLanguage(cursor.getString(2));
   }
   cursor.close();
 }
 @Override
 protected void setValue(String value) {
   super.setValue(value);
   myBook.setTitle(value);
 }
Esempio n. 5
0
 @Override
 public void readMetaInfo(Book book) throws BookReadingException {
   InputStream stream = null;
   try {
     stream = book.File.getInputStream();
     final PdbHeader header = new PdbHeader(stream);
     PdbUtil.skip(stream, header.Offsets[0] + 16 - header.length());
     if (PdbUtil.readInt(stream) != 0x4D4F4249) /* "MOBI" */ {
       throw new BookReadingException("unsupportedFileFormat", book.File);
     }
     final int length = (int) PdbUtil.readInt(stream);
     PdbUtil.skip(stream, 4);
     final int encodingCode = (int) PdbUtil.readInt(stream);
     final Encoding encoding = supportedEncodings().getEncoding(encodingCode);
     final String encodingName = encoding != null ? encoding.Name : "utf-8";
     book.setEncoding(encodingName);
     PdbUtil.skip(stream, 52);
     final int fullNameOffset = (int) PdbUtil.readInt(stream);
     final int fullNameLength = (int) PdbUtil.readInt(stream);
     final int languageCode = (int) PdbUtil.readInt(stream);
     book.setLanguage(
         ZLLanguageUtil.languageByIntCode(languageCode & 0xFF, (languageCode >> 8) & 0xFF));
     PdbUtil.skip(stream, 32);
     int offset = 132;
     if ((PdbUtil.readInt(stream) & 0x40) != 0) {
       PdbUtil.skip(stream, length - 116);
       offset = length + 20;
       if (PdbUtil.readInt(stream) == 0x45585448) /* "EXTH" */ {
         PdbUtil.skip(stream, 4);
         final int recordsNumber = (int) PdbUtil.readInt(stream);
         offset += 8;
         for (int i = 0; i < recordsNumber; ++i) {
           final int type = (int) PdbUtil.readInt(stream);
           final int size = (int) PdbUtil.readInt(stream);
           offset += size;
           if (size <= 8) {
             continue;
           }
           switch (type) {
             default:
               PdbUtil.skip(stream, size - 8);
               break;
             case 100:
               {
                 final byte[] buffer = new byte[size - 8];
                 stream.read(buffer);
                 String author = new String(buffer, encodingName);
                 final int index = author.indexOf(',');
                 if (index != -1) {
                   author =
                       author.substring(index + 1).trim()
                           + ' '
                           + author.substring(0, index).trim();
                 } else {
                   author = author.trim();
                 }
                 book.addAuthor(author);
                 break;
               }
             case 105:
               {
                 final byte[] buffer = new byte[size - 8];
                 stream.read(buffer);
                 book.addTag(new String(buffer, encodingName));
                 break;
               }
           }
         }
       }
     }
     PdbUtil.skip(stream, fullNameOffset - offset);
     final byte[] titleBuffer = new byte[fullNameLength];
     stream.read(titleBuffer);
     book.setTitle(new String(titleBuffer, encodingName));
   } catch (IOException e) {
     throw new BookReadingException(e, book.File);
   } finally {
     if (stream != null) {
       try {
         stream.close();
       } catch (IOException e) {
       }
     }
   }
 }
Esempio n. 6
0
 public HtmlMetaInfoReader(Book book) {
   myBook = book;
   myBook.setTitle("");
 }
Esempio n. 7
0
 public FB2MetaInfoReader(Book book) {
   myBook = book;
   myBook.setTitle(null);
   myBook.setLanguage(null);
 }
Esempio n. 8
0
 @Override
 public boolean endElementHandler(String tag) {
   switch (FB2Tag.getTagByName(tag)) {
     case FB2Tag.TITLE_INFO:
       myReadState = READ_NOTHING;
       break;
     case FB2Tag.BOOK_TITLE:
       if (myReadState == READ_TITLE) {
         myBook.setTitle(myBuffer.toString().trim());
         myReadState = READ_SOMETHING;
       }
       break;
     case FB2Tag.GENRE:
       if (myReadState == READ_GENRE) {
         final String genre = myBuffer.toString().trim();
         if (genre.length() > 0) {
           final ArrayList<Tag> tags = FB2TagManager.humanReadableTags(genre);
           if (tags != null) {
             for (Tag t : tags) {
               myBook.addTag(t);
             }
           } else {
             myBook.addTag(genre);
           }
         }
         myReadState = READ_SOMETHING;
       }
       break;
     case FB2Tag.AUTHOR:
       if (myReadState == READ_AUTHOR) {
         myAuthorNames[0] = myAuthorNames[0].trim();
         myAuthorNames[1] = myAuthorNames[1].trim();
         myAuthorNames[2] = myAuthorNames[2].trim();
         String fullName = myAuthorNames[0];
         if (fullName.length() != 0 && myAuthorNames[1].length() != 0) {
           fullName += ' ';
         }
         fullName += myAuthorNames[1];
         if (fullName.length() != 0 && myAuthorNames[2].length() != 0) {
           fullName += ' ';
         }
         fullName += myAuthorNames[2];
         myBook.addAuthor(fullName, myAuthorNames[2]);
         myAuthorNames[0] = "";
         myAuthorNames[1] = "";
         myAuthorNames[2] = "";
         myReadState = READ_SOMETHING;
       }
       break;
     case FB2Tag.LANG:
       if (myReadState == READ_LANGUAGE) {
         myBook.setLanguage(myBuffer.toString().trim());
         myReadState = READ_SOMETHING;
       }
       break;
     case FB2Tag.FIRST_NAME:
       if (myReadState == READ_AUTHOR_NAME_0) {
         myReadState = READ_AUTHOR;
       }
       break;
     case FB2Tag.MIDDLE_NAME:
       if (myReadState == READ_AUTHOR_NAME_1) {
         myReadState = READ_AUTHOR;
       }
       break;
     case FB2Tag.LAST_NAME:
       if (myReadState == READ_AUTHOR_NAME_2) {
         myReadState = READ_AUTHOR;
       }
       break;
     default:
       break;
   }
   myBuffer.delete(0, myBuffer.length());
   return false;
 }