Example #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;
 }
 // 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;
 }
Example #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;
 }
 private static int intValue(ZLStringMap attributes, String name, int defaultValue) {
   int i = defaultValue;
   String value = attributes.getValue(name);
   if (value != null) {
     try {
       i = Integer.parseInt(value);
     } catch (NumberFormatException e) {
     }
   }
   return i;
 }
  @Override
  public boolean startElementHandler(String tag, ZLStringMap attributes) {
    tag = tag.toLowerCase();
    String href = null;
    if ("img".equals(tag)) {
      href = attributes.getValue("src");
    } else if ("image".equals(tag)) {
      href = getAttributeValue(attributes, XMLNamespaces.XLink, "href");
    }

    if (href != null) {
      myImage =
          new ZLFileImage(
              MimeType.IMAGE_AUTO,
              ZLFile.createFileByPath(myXHTMLPathPrefix + MiscUtil.decodeHtmlReference(href)));
      return true;
    }

    return false;
  }
    public boolean startElementHandler(String tag, ZLStringMap attributes) {
      final String BASE = "base";
      final String STYLE = "style";

      if (BASE.equals(tag)) {
        myCollection.myBaseStyle =
            new ZLTextBaseStyle(attributes.getValue("family"), intValue(attributes, "fontSize", 0));
      } else if (STYLE.equals(tag)) {
        String idString = attributes.getValue("id");
        String name = attributes.getValue("name");
        if ((idString != null) && (name != null)) {
          byte id = Byte.parseByte(idString);
          ZLTextStyleDecoration decoration;

          int fontSizeDelta = intValue(attributes, "fontSizeDelta", 0);
          int bold = b3Value(attributes, "bold");
          int italic = b3Value(attributes, "italic");
          int underline = b3Value(attributes, "underline");
          int verticalShift = intValue(attributes, "vShift", 0);
          int allowHyphenations = b3Value(attributes, "allowHyphenations");

          if (booleanValue(attributes, "partial")) {
            decoration =
                new ZLTextStyleDecoration(
                    name, fontSizeDelta, bold, italic, underline, verticalShift, allowHyphenations);
          } else {
            int spaceBefore = intValue(attributes, "spaceBefore", 0);
            int spaceAfter = intValue(attributes, "spaceAfter", 0);
            int leftIndent = intValue(attributes, "leftIndent", 0);
            int rightIndent = intValue(attributes, "rightIndent", 0);
            int firstLineIndentDelta = intValue(attributes, "firstLineIndentDelta", 0);

            byte alignment = ZLTextAlignmentType.ALIGN_UNDEFINED;
            String alignmentString = attributes.getValue("alignment");
            if (alignmentString != null) {
              if (alignmentString.equals("left")) {
                alignment = ZLTextAlignmentType.ALIGN_LEFT;
              } else if (alignmentString.equals("right")) {
                alignment = ZLTextAlignmentType.ALIGN_RIGHT;
              } else if (alignmentString.equals("center")) {
                alignment = ZLTextAlignmentType.ALIGN_CENTER;
              } else if (alignmentString.equals("justify")) {
                alignment = ZLTextAlignmentType.ALIGN_JUSTIFY;
              }
            }
            final int lineSpacePercent = intValue(attributes, "lineSpacingPercent", -1);

            decoration =
                new ZLTextFullStyleDecoration(
                    name,
                    fontSizeDelta,
                    bold,
                    italic,
                    underline,
                    spaceBefore,
                    spaceAfter,
                    leftIndent,
                    rightIndent,
                    firstLineIndentDelta,
                    verticalShift,
                    alignment,
                    lineSpacePercent,
                    allowHyphenations);
          }

          String fontFamily = attributes.getValue("family");
          if (fontFamily != null) {
            decoration.FontFamilyOption.setValue(fontFamily);
          }

          myCollection.myDecorationMap[id & 0xFF] = decoration;
        }
      }
      return false;
    }
 private static int b3Value(ZLStringMap attributes, String name) {
   return ZLBoolean3.getByString(attributes.getValue(name));
 }
 private static boolean booleanValue(ZLStringMap attributes, String name) {
   return "true".equals(attributes.getValue(name));
 }
 @Override
 public boolean startElementHandler(
     String ns, String tag, ZLStringMap attributes, String bufferContent) {
   switch (myState) {
     case FEED:
       if (ns == XMLNamespaces.OpenSearch) {
         if (tag == OPENSEARCH_TAG_TOTALRESULTS) {
           myState = OPENSEARCH_TOTALRESULTS;
         } else if (tag == OPENSEARCH_TAG_ITEMSPERPAGE) {
           myState = OPENSEARCH_ITEMSPERPAGE;
         } else if (tag == OPENSEARCH_TAG_STARTINDEX) {
           myState = OPENSEARCH_STARTINDEX;
         }
         return false;
       } else if (ns == XMLNamespaces.FBReaderCatalogMetadata) {
         if (tag == FBREADER_TAG_VIEW) {
           myState = FBREADER_VIEW;
         }
       } else {
         return super.startElementHandler(ns, tag, attributes, bufferContent);
       }
     case F_ENTRY:
       if (ns == XMLNamespaces.DublinCoreTerms) {
         if (tag == DC_TAG_LANGUAGE) {
           myState = FE_DC_LANGUAGE;
         } else if (tag == DC_TAG_ISSUED) {
           myDCIssued = new DCDate(attributes);
           myState = FE_DC_ISSUED;
         } else if (tag == DC_TAG_PUBLISHER) {
           myState = FE_DC_PUBLISHER;
         }
         return false;
       } else if (ns == XMLNamespaces.CalibreMetadata) {
         if (tag == CALIBRE_TAG_SERIES) {
           myState = FE_CALIBRE_SERIES;
         } else if (tag == CALIBRE_TAG_SERIES_INDEX) {
           myState = FE_CALIBRE_SERIES_INDEX;
         }
         return false;
       } else {
         return super.startElementHandler(ns, tag, attributes, bufferContent);
       }
     case FE_LINK:
       if (ns == XMLNamespaces.Opds && tag == TAG_PRICE) {
         myPriceCurrency = attributes.getValue("currencycode");
         myState = FEL_PRICE;
         return false;
       }
       if (ns == XMLNamespaces.DublinCoreTerms && tag == DC_TAG_FORMAT) {
         myState = FEL_FORMAT;
         return false;
       } else {
         return super.startElementHandler(ns, tag, attributes, bufferContent);
       }
     case FE_CONTENT:
       super.startElementHandler(ns, tag, attributes, bufferContent);
       // FIXME: HACK: html handling must be implemeted neatly
       if (tag == TAG_HACK_SPAN || attributes.getValue("class") == "price") {
         myState = FEC_HACK_SPAN;
       }
       return false;
     default:
       return super.startElementHandler(ns, tag, attributes, bufferContent);
   }
 }
Example #10
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;
 }
Example #11
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;
  }