Ejemplo n.º 1
0
 @Override
 public boolean startElementHandler(String tagName, ZLStringMap attributes) {
   switch (FB2Tag.getTagByName(tagName)) {
     case FB2Tag.BODY:
       return true;
     case FB2Tag.TITLE_INFO:
       myReadState = READ_SOMETHING;
       break;
     case FB2Tag.BOOK_TITLE:
       if (myReadState == READ_SOMETHING) {
         myReadState = READ_TITLE;
       }
       break;
     case FB2Tag.GENRE:
       if (myReadState == READ_SOMETHING) {
         myReadState = READ_GENRE;
       }
       break;
     case FB2Tag.AUTHOR:
       if (myReadState == READ_SOMETHING) {
         myReadState = READ_AUTHOR;
       }
       break;
     case FB2Tag.LANG:
       if (myReadState == READ_SOMETHING) {
         myReadState = READ_LANGUAGE;
       }
       break;
     case FB2Tag.FIRST_NAME:
       if (myReadState == READ_AUTHOR) {
         myReadState = READ_AUTHOR_NAME_0;
       }
       break;
     case FB2Tag.MIDDLE_NAME:
       if (myReadState == READ_AUTHOR) {
         myReadState = READ_AUTHOR_NAME_1;
       }
       break;
     case FB2Tag.LAST_NAME:
       if (myReadState == READ_AUTHOR) {
         myReadState = READ_AUTHOR_NAME_2;
       }
       break;
     case FB2Tag.SEQUENCE:
       if (myReadState == READ_SOMETHING) {
         String name = attributes.getValue("name");
         if (name != null) {
           name.trim();
           if (name.length() != 0) {
             myBook.setSeriesInfo(name, attributes.getValue("number"));
           }
         }
       }
       break;
   }
   return false;
 }
Ejemplo n.º 2
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;
 }