void readFile(ZLFile file) throws BookReadingException {
   myLocalPathPrefix = MiscUtil.archiveEntryName(MiscUtil.htmlDirectoryPrefix(file));
   try {
     read(file);
   } catch (IOException e) {
     throw new BookReadingException(e, file);
   }
 }
Beispiel #2
0
  boolean readBook(ZLFile file) {
    myFilePrefix = MiscUtil.htmlDirectoryPrefix(file);

    myIdToHref.clear();
    myHtmlFileNames.clear();
    myParagraphIndexList.clear();
    myNCXTOCFileName = null;
    myTourTOC.clear();
    myGuideTOC.clear();
    myState = READ_NONE;

    if (!read(file)) {
      return false;
    }

    myModelReader.setMainTextModel();
    myModelReader.pushKind(FBTextKind.REGULAR);

    int count = 0;
    for (String name : myHtmlFileNames) {
      final ZLFile xhtmlFile = ZLFile.createFileByPath(myFilePrefix + name);
      if (xhtmlFile == null) {
        // NPE fix: null for bad attributes in .opf XML file
        return false;
      }
      if (count++ == 0 && xhtmlFile.getPath().equals(myCoverFileName)) {
        continue;
      }
      final XHTMLReader reader = new XHTMLReader(myModelReader, myFileNumbers);
      final String referenceName =
          reader.getFileAlias(MiscUtil.archiveEntryName(xhtmlFile.getPath()));

      myModelReader.addHyperlinkLabel(referenceName);
      myParagraphIndexList.add(myModelReader.Model.BookTextModel.getParagraphsNumber());
      myTOCLabels.put(referenceName, myModelReader.Model.BookTextModel.getParagraphsNumber());
      reader.readFile(xhtmlFile, referenceName + '#');
      myModelReader.insertEndOfSectionParagraph();
    }

    final FBReaderApp fbreader = (FBReaderApp) ZLApplication.Instance();
    //		fbreader.setTOCLabels(myTOCLabels);
    fbreader.setParagraphIndexList(myParagraphIndexList);
    fbreader.setHtmlFileNames(myHtmlFileNames, myFilePrefix, myCoverFileName);
    generateTOC();

    return true;
  }
Beispiel #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;
 }
 protected void doAtStart(XHTMLReader reader, ZLStringMap xmlattributes) {
   String fileName = reader.getAttributeValue(xmlattributes, myNamespace, myNameAttribute);
   if (fileName != null) {
     fileName = MiscUtil.decodeHtmlReference(fileName);
     final ZLFile imageFile = ZLFile.createFileByPath(reader.myPathPrefix + fileName);
     if (imageFile != null) {
       final BookReader modelReader = reader.getModelReader();
       boolean flag = modelReader.paragraphIsOpen() && !modelReader.paragraphIsNonEmpty();
       if (flag) {
         modelReader.endParagraph();
       }
       final String imageName = imageFile.getLongName();
       modelReader.addImageReference(imageName, (short) 0);
       modelReader.addImage(imageName, new ZLFileImage(MimeTypes.MIME_IMAGE_AUTO, imageFile));
       if (flag) {
         modelReader.beginParagraph();
       }
     }
   }
 }
  @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;
  }
Beispiel #6
0
 boolean readFile(String filePath) {
   final ZLFile file = ZLFile.createFileByPath(filePath);
   myLocalPathPrefix = MiscUtil.archiveEntryName(MiscUtil.htmlDirectoryPrefix(file));
   return read(file);
 }
 ZLFileImage readImage(ZLFile file) {
   myXHTMLPathPrefix = MiscUtil.htmlDirectoryPrefix(file);
   myImage = null;
   readQuietly(file);
   return myImage;
 }
Beispiel #8
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;
 }