Exemplo 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;
 }
Exemplo n.º 2
0
 // Override
 public boolean startElementHandler(String tag, ZLStringMap attributes) {
   if ((tag == "subgenre") || (tag == "genre-alt")) {
     final String id = attributes.getValue("value");
     if (id != null) {
       myGenreIds.add(id);
     }
   } else if (tag == "root-descr") {
     if (myLanguage == attributes.getValue("lang")) {
       myCategoryTag = Tag.getTag(null, attributes.getValue("genre-title"));
     }
   } else if (tag == "genre-descr") {
     if (myLanguage == attributes.getValue("lang")) {
       mySubCategoryTag = Tag.getTag(myCategoryTag, attributes.getValue("title"));
     }
   }
   return false;
 }
Exemplo n.º 3
0
 @Override
 public boolean startElementHandler(String tag, ZLStringMap attributes) {
   tag = tag.toLowerCase().intern();
   switch (myReadState) {
     case READ_NONE:
       if (tag == TAG_NAVMAP) {
         myReadState = READ_MAP;
       }
       break;
     case READ_MAP:
       if (tag == TAG_NAVPOINT) {
         final String order = attributes.getValue(ATTRIBUTE_PLAYORDER);
         final int index = (order != null) ? atoi(order) : myPlayIndex++;
         myPointStack.add(new NavPoint(index, myPointStack.size()));
         myReadState = READ_POINT;
       }
       break;
     case READ_POINT:
       if (tag == TAG_NAVPOINT) {
         final String order = attributes.getValue(ATTRIBUTE_PLAYORDER);
         final int index = (order != null) ? atoi(order) : myPlayIndex++;
         myPointStack.add(new NavPoint(index, myPointStack.size()));
       } else if (tag == TAG_NAVLABEL) {
         myReadState = READ_LABEL;
       } else if (tag == TAG_CONTENT) {
         final int size = myPointStack.size();
         if (size > 0) {
           myPointStack.get(size - 1).ContentHRef =
               ZLArchiveEntryFile.normalizeEntryName(
                   myLocalPathPrefix + MiscUtil.decodeHtmlReference(attributes.getValue("src")));
         }
       }
       break;
     case READ_LABEL:
       if (TAG_TEXT == tag) {
         myReadState = READ_TEXT;
       }
       break;
     case READ_TEXT:
       break;
   }
   return false;
 }
Exemplo n.º 4
0
 @Override
 public boolean startElementHandler(String tag, ZLStringMap xmlattributes, String[] tagStack) {
   tag = tag.toLowerCase();
   if (myOPFSchemePrefix != null && tag.startsWith(myOPFSchemePrefix)) {
     tag = tag.substring(myOPFSchemePrefix.length());
   }
   tag = tag.intern();
   if (MANIFEST == tag) {
     myState = READ_MANIFEST;
   } else if (SPINE == tag) {
     myNCXTOCFileName = myIdToHref.get(xmlattributes.getValue("toc"));
     myState = READ_SPINE;
   } else if (GUIDE == tag) {
     myState = READ_GUIDE;
   } else if (TOUR == tag) {
     myState = READ_TOUR;
   } else if (myState == READ_MANIFEST && ITEM == tag) {
     final String id = xmlattributes.getValue("id");
     String href = xmlattributes.getValue("href");
     if ((id != null) && (href != null)) {
       href = MiscUtil.decodeHtmlReference(href);
       myIdToHref.put(id, href);
     }
   } else if (myState == READ_SPINE && ITEMREF == tag) {
     final String id = xmlattributes.getValue("idref");
     if (id != null) {
       final String fileName = myIdToHref.get(id);
       if (fileName != null) {
         myHtmlFileNames.add(fileName);
       }
     }
   } else if (myState == READ_GUIDE && REFERENCE == tag) {
     final String type = xmlattributes.getValue("type");
     final String title = xmlattributes.getValue("title");
     String href = xmlattributes.getValue("href");
     if (href != null) {
       href = MiscUtil.decodeHtmlReference(href);
       if (title != null) {
         myGuideTOC.add(new Reference(title, href));
       }
       if (COVER.equals(type)) {
         final ZLFile imageFile = ZLFile.createFileByPath(myFilePrefix + href);
         myCoverFileName = imageFile.getPath();
         final String imageName = imageFile.getLongName();
         final ZLFileImage image = XHTMLImageFinder.getCoverImage(imageFile);
         if (image != null) {
           myModelReader.setMainTextModel();
           myModelReader.addImageReference(imageName, (short) 0, true);
           myModelReader.addImage(imageName, image);
           myModelReader.insertEndOfSectionParagraph();
         }
       } else if (COVER_IMAGE.equals(type)) {
         final ZLFile imageFile = ZLFile.createFileByPath(myFilePrefix + href);
         myCoverFileName = imageFile.getPath();
         final String imageName = imageFile.getLongName();
         myModelReader.setMainTextModel();
         myModelReader.addImageReference(imageName, (short) 0, true);
         myModelReader.addImage(imageName, new ZLFileImage(MimeType.IMAGE_AUTO, imageFile));
         myModelReader.insertEndOfSectionParagraph();
       }
     }
   } else if (myState == READ_TOUR && SITE == tag) {
     final String title = xmlattributes.getValue("title");
     String href = xmlattributes.getValue("href");
     if ((title != null) && (href != null)) {
       href = MiscUtil.decodeHtmlReference(href);
       myTourTOC.add(new Reference(title, href));
     }
   }
   return false;
 }
Exemplo n.º 5
0
  @Override
  public boolean startElementHandler(String tag, ZLStringMap attributes) {
    tag = tag.intern();

    final char[] bufferContentArray = myBuffer.toString().trim().toCharArray();
    final String bufferContent;
    if (bufferContentArray.length == 0) {
      bufferContent = null;
    } else {
      bufferContent = new String(bufferContentArray);
    }
    myBuffer.delete(0, myBuffer.length());

    switch (myState) {
      case START:
        if (TAG_CATALOG == tag) {
          myState = CATALOG;
        }
        break;
      case CATALOG:
        if (TAG_BOOK == tag) {
          myBookId = attributes.getValue("hub_id");
          myCover = attributes.getValue("cover_preview");

          myReferences.add(
              new BookReference(
                  "https://robot.litres.ru/pages/catalit_download_book/?art=" + myBookId,
                  BookReference.Format.FB2_ZIP,
                  BookReference.Type.DOWNLOAD_FULL_CONDITIONAL));
          myState = BOOK;
        }
        break;
      case BOOK:
        if (TAG_TEXT_DESCRIPTION == tag) {
          myState = BOOK_DESCRIPTION;
        }
        break;
      case BOOK_DESCRIPTION:
        if (TAG_HIDDEN == tag) {
          myState = HIDDEN;
        }
        break;
      case HIDDEN:
        if (TAG_TITLE_INFO == tag) {
          myState = TITLE_INFO;
        }
        break;
      case TITLE_INFO:
        if (TAG_GENRE == tag) {
          myState = GENRE;
        } else if (TAG_AUTHOR == tag) {
          myState = AUTHOR;
        } else if (TAG_BOOK_TITLE == tag) {
          myState = BOOK_TITLE;
        } else if (TAG_ANNOTATION == tag) {
          myHtmlToString.setupTextContent(MimeTypes.MIME_TEXT_XHTML);
          myState = ANNOTATION;
        } else if (TAG_DATE == tag) {
          myState = DATE;
        } else if (TAG_LANGUAGE == tag) {
          myState = LANGUAGE;
        } else if (TAG_SEQUENCE == tag) {
          mySeriesTitle = attributes.getValue("name");
          if (mySeriesTitle != null) {
            myIndexInSeries = 0;
            final String indexInSeries = attributes.getValue("number");
            if (indexInSeries != null) {
              try {
                myIndexInSeries = Integer.parseInt(indexInSeries);
              } catch (NumberFormatException e) {
              }
            }
          }
          // myState = SEQUENCE; // handled through attributes without state
        }
        break;
      case AUTHOR:
        if (TAG_FIRST_NAME == tag) {
          myState = FIRST_NAME;
        } else if (TAG_MIDDLE_NAME == tag) {
          myState = MIDDLE_NAME;
        } else if (TAG_LAST_NAME == tag) {
          myState = LAST_NAME;
        }
        break;
      case ANNOTATION:
        myHtmlToString.processTextContent(false, tag, attributes, bufferContent);
        break;
    }
    return false;
  }