示例#1
0
 @Override
 public boolean endElementHandler(String tag) {
   tag = tag.toLowerCase().intern();
   switch (myReadState) {
     case READ_NONE:
       break;
     case READ_MAP:
       if (TAG_NAVMAP == tag) {
         myReadState = READ_NONE;
       }
       break;
     case READ_POINT:
       if (TAG_NAVPOINT == tag) {
         NavPoint last = myPointStack.get(myPointStack.size() - 1);
         if (last.Text.length() == 0) {
           last.Text = "...";
         }
         myNavigationMap.put(last.Order, last);
         myPointStack.remove(myPointStack.size() - 1);
         myReadState = (myPointStack.isEmpty()) ? READ_MAP : READ_POINT;
       }
     case READ_LABEL:
       if (TAG_NAVLABEL == tag) {
         myReadState = READ_POINT;
       }
       break;
     case READ_TEXT:
       if (TAG_TEXT == tag) {
         myReadState = READ_LABEL;
       }
       break;
   }
   return false;
 }
示例#2
0
 private BookModel.Label getTOCLabel(String id) {
   final int index = id.indexOf('#');
   final String path = (index >= 0) ? id.substring(0, index) : id;
   Integer num = myFileNumbers.get(path);
   if (num == null) {
     return null;
   }
   if (index == -1) {
     final Integer para = myTOCLabels.get(num.toString());
     if (para == null) {
       return null;
     }
     return new BookModel.Label(null, para);
   }
   return myModelReader.Model.getLabel(num + id.substring(index));
 }
示例#3
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;
  }