@Override
 public boolean endElementHandler(String ns, String tag, String bufferContent) {
   switch (myState) {
     default:
       return super.endElementHandler(ns, tag, bufferContent);
     case FEL_PRICE:
       if (ns == XMLNamespaces.Opds && tag == TAG_PRICE) {
         if (bufferContent != null && myPriceCurrency != null) {
           getOPDSLink().Prices.add(new Money(bufferContent, myPriceCurrency));
           myPriceCurrency = null;
         }
         myState = FE_LINK;
       }
       return false;
     case FEL_FORMAT:
       if (ns == XMLNamespaces.DublinCoreTerms && tag == DC_TAG_FORMAT) {
         if (bufferContent != null) {
           getOPDSLink().Formats.add(bufferContent.intern());
         }
         myState = FE_LINK;
       }
       return false;
     case FEC_HACK_SPAN:
       // FIXME: HACK
       myFormattedBuffer.appendText(bufferContent);
       myFormattedBuffer.appendEndTag(tag);
       myFormattedBuffer.appendText("<br/>");
       if (bufferContent != null) {
         getOPDSEntry().addAttribute(KEY_PRICE, bufferContent.intern());
       }
       myState = FE_CONTENT;
       return false;
     case FE_DC_LANGUAGE:
       if (ns == XMLNamespaces.DublinCoreTerms && tag == DC_TAG_LANGUAGE) {
         // FIXME:language can be lost:buffer will be truncated, if there are extension tags inside
         // the <dc:language> tag
         getOPDSEntry().DCLanguage = bufferContent;
         myState = F_ENTRY;
       }
       return false;
     case FE_DC_ISSUED:
       if (ns == XMLNamespaces.DublinCoreTerms && tag == DC_TAG_ISSUED) {
         // FIXME:issued can be lost:buffer will be truncated, if there are extension tags inside
         // the <dc:issued> tag
         if (ATOMDateConstruct.parse(bufferContent, myDCIssued)) {
           getOPDSEntry().DCIssued = myDCIssued;
         }
         myDCIssued = null;
         myState = F_ENTRY;
       }
       return false;
     case FE_DC_PUBLISHER:
       if (ns == XMLNamespaces.DublinCoreTerms && tag == DC_TAG_PUBLISHER) {
         // FIXME:publisher can be lost:buffer will be truncated, if there are extension tags
         // inside the <dc:publisher> tag
         getOPDSEntry().DCPublisher = bufferContent;
         myState = F_ENTRY;
       }
       return false;
     case FE_CALIBRE_SERIES:
       if (ns == XMLNamespaces.CalibreMetadata && tag == CALIBRE_TAG_SERIES) {
         getOPDSEntry().SeriesTitle = bufferContent;
         myState = F_ENTRY;
       }
       return false;
     case FE_CALIBRE_SERIES_INDEX:
       if (ns == XMLNamespaces.CalibreMetadata && tag == CALIBRE_TAG_SERIES_INDEX) {
         if (bufferContent != null) {
           try {
             getOPDSEntry().SeriesIndex = Float.parseFloat(bufferContent);
           } catch (NumberFormatException ex) {
           }
         }
         myState = F_ENTRY;
       }
       return false;
     case OPENSEARCH_TOTALRESULTS:
       if (ns == XMLNamespaces.OpenSearch && tag == OPENSEARCH_TAG_TOTALRESULTS) {
         if (getOPDSFeed() != null && bufferContent != null) {
           try {
             getOPDSFeed().OpensearchTotalResults = Integer.parseInt(bufferContent);
           } catch (NumberFormatException ex) {
           }
         }
         myState = FEED;
       }
       return false;
     case OPENSEARCH_ITEMSPERPAGE:
       if (ns == XMLNamespaces.OpenSearch && tag == OPENSEARCH_TAG_ITEMSPERPAGE) {
         if (getOPDSFeed() != null && bufferContent != null) {
           try {
             getOPDSFeed().OpensearchItemsPerPage = Integer.parseInt(bufferContent);
           } catch (NumberFormatException ex) {
           }
         }
         myState = FEED;
       }
       return false;
     case OPENSEARCH_STARTINDEX:
       if (ns == XMLNamespaces.OpenSearch && tag == OPENSEARCH_TAG_STARTINDEX) {
         if (getOPDSFeed() != null && bufferContent != null) {
           try {
             getOPDSFeed().OpensearchStartIndex = Integer.parseInt(bufferContent);
           } catch (NumberFormatException ex) {
           }
         }
         myState = FEED;
       }
       return false;
     case FBREADER_VIEW:
       if (ns == XMLNamespaces.FBReaderCatalogMetadata && tag == FBREADER_TAG_VIEW) {
         if (getOPDSFeed() != null) {
           getOPDSFeed().ViewType = bufferContent;
         }
         myState = FEED;
       }
       return false;
   }
 }
示例#2
0
  public boolean endElementHandler(String ns, String tag, String bufferContent) {
    boolean interruptReading = false;
    switch (myState) {
      case START:
        break;
      case FEED:
        if (ns == XMLNamespaces.Atom && tag == TAG_FEED) {
          if (myFeed != null) {
            interruptReading = myFeedHandler.processFeedMetadata(myFeed, false);
          }
          myFeed = null;
          myFeedHandler.processFeedEnd();
          myState = START;
        }
        break;
      case F_ENTRY:
        if (ns == XMLNamespaces.Atom && tag == TAG_ENTRY) {
          if (myEntry != null) {
            interruptReading = myFeedHandler.processFeedEntry(myEntry);
          }
          myEntry = null;
          myState = FEED;
        }
        break;
      case F_ID:
        if (ns == XMLNamespaces.Atom && tag == TAG_ID) {
          // FIXME:uri can be lost:buffer will be truncated, if there are extension tags inside the
          // <id> tag
          if (bufferContent != null && myFeed != null) {
            myId.Uri = bufferContent;
            myFeed.Id = myId;
          }
          myId = null;
          myState = FEED;
        }
        break;
      case F_ICON:
        if (ns == XMLNamespaces.Atom && tag == TAG_ICON) {
          // FIXME:uri can be lost:buffer will be truncated, if there are extension tags inside the
          // <id> tag
          if (bufferContent != null && myFeed != null) {
            myIcon.Uri = bufferContent;
            myFeed.Icon = myIcon;
          }
          myIcon = null;
          myState = FEED;
        }
        break;
      case F_LINK:
        if (ns == XMLNamespaces.Atom && tag == TAG_LINK) {
          if (myFeed != null) {
            myFeed.Links.add(myLink);
          }
          myLink = null;
          myState = FEED;
        }
        break;
      case F_CATEGORY:
        if (ns == XMLNamespaces.Atom && tag == TAG_CATEGORY) {
          if (myFeed != null) {
            myFeed.Categories.add(myCategory);
          }
          myCategory = null;
          myState = FEED;
        }
        break;
      case F_TITLE:
        myFormattedBuffer.appendText(bufferContent);
        if (ns == XMLNamespaces.Atom && tag == TAG_TITLE) {
          // TODO:implement ATOMTextConstruct & ATOMTitle
          final CharSequence title = myFormattedBuffer.getText();
          if (myFeed != null) {
            myFeed.Title = title;
          }
          myState = FEED;
        } else {
          myFormattedBuffer.appendEndTag(tag);
        }
        break;
      case F_SUBTITLE:
        myFormattedBuffer.appendText(bufferContent);
        if (ns == XMLNamespaces.Atom && tag == TAG_SUBTITLE) {
          // TODO:implement ATOMTextConstruct & ATOMSubtitle
          final CharSequence subtitle = myFormattedBuffer.getText();
          if (myFeed != null) {
            myFeed.Subtitle = subtitle;
          }
          myState = FEED;
        } else {
          myFormattedBuffer.appendEndTag(tag);
        }
        break;
      case F_UPDATED:
        if (ns == XMLNamespaces.Atom && tag == TAG_UPDATED) {
          // FIXME:uri can be lost:buffer will be truncated, if there are extension tags inside the
          // <id> tag
          if (ATOMDateConstruct.parse(bufferContent, myUpdated) && myFeed != null) {
            myFeed.Updated = myUpdated;
          }
          myUpdated = null;
          myState = FEED;
        }
        break;
      case F_AUTHOR:
        if (ns == XMLNamespaces.Atom && tag == TAG_AUTHOR) {
          if (myFeed != null && myAuthor.Name != null) {
            myFeed.Authors.add(myAuthor);
          }
          myAuthor = null;
          myState = FEED;
        }
        break;
      case FA_NAME:
        if (ns == XMLNamespaces.Atom && tag == TAG_NAME) {
          myAuthor.Name = bufferContent;
          myState = F_AUTHOR;
        }
        break;
      case FEA_NAME:
        if (ns == XMLNamespaces.Atom && tag == TAG_NAME) {
          myAuthor.Name = bufferContent;
          myState = FE_AUTHOR;
        }
        break;
      case FA_URI:
        if (ns == XMLNamespaces.Atom && tag == TAG_URI) {
          myAuthor.Uri = bufferContent;
          myState = F_AUTHOR;
        }
        break;
      case FEA_URI:
        if (ns == XMLNamespaces.Atom && tag == TAG_URI) {
          myAuthor.Uri = bufferContent;
          myState = FE_AUTHOR;
        }
        break;
      case FA_EMAIL:
        if (ns == XMLNamespaces.Atom && tag == TAG_EMAIL) {
          myAuthor.Email = bufferContent;
          myState = F_AUTHOR;
        }
        break;
      case FEA_EMAIL:
        if (ns == XMLNamespaces.Atom && tag == TAG_EMAIL) {
          myAuthor.Email = bufferContent;
          myState = FE_AUTHOR;
        }
        break;
      case FE_AUTHOR:
        if (ns == XMLNamespaces.Atom && tag == TAG_AUTHOR) {
          if (myAuthor.Name != null) {
            myEntry.Authors.add(myAuthor);
          }
          myAuthor = null;
          myState = F_ENTRY;
        }
        break;
      case FE_ID:
        if (ns == XMLNamespaces.Atom && tag == TAG_ID) {
          // FIXME:uri can be lost:buffer will be truncated, if there are extension tags inside the
          // <id> tag
          if (bufferContent != null) {
            myId.Uri = bufferContent;
            myEntry.Id = myId;
          }
          myId = null;
          myState = F_ENTRY;
        }
        break;
      case FE_CATEGORY:
        if (ns == XMLNamespaces.Atom && tag == TAG_CATEGORY) {
          myEntry.Categories.add(myCategory);
          myCategory = null;
          myState = F_ENTRY;
        }
        break;
      case FE_LINK:
        if (ns == XMLNamespaces.Atom && tag == TAG_LINK) {
          myEntry.Links.add(myLink);
          myLink = null;
          myState = F_ENTRY;
        }
        break;
      case FE_PUBLISHED:
        if (ns == XMLNamespaces.Atom && tag == TAG_PUBLISHED) {
          // FIXME:uri can be lost:buffer will be truncated, if there are extension tags inside the
          // <id> tag
          if (ATOMDateConstruct.parse(bufferContent, myPublished)) {
            myEntry.Published = myPublished;
          }
          myPublished = null;
          myState = F_ENTRY;
        }
        break;
      case FE_SUMMARY:
        myFormattedBuffer.appendText(bufferContent);
        if (ns == XMLNamespaces.Atom && tag == TAG_SUMMARY) {
          // TODO:implement ATOMTextConstruct & ATOMSummary
          myEntry.Summary = myFormattedBuffer.getText();
          myState = F_ENTRY;
        } else {
          myFormattedBuffer.appendEndTag(tag);
        }
        break;
      case FE_CONTENT:
        myFormattedBuffer.appendText(bufferContent);
        if (ns == XMLNamespaces.Atom && tag == TAG_CONTENT) {
          // TODO:implement ATOMContent
          myEntry.Content = myFormattedBuffer.getText();
          myState = F_ENTRY;
        } else {
          myFormattedBuffer.appendEndTag(tag);
        }
        break;
      case FE_TITLE:
        myFormattedBuffer.appendText(bufferContent);
        if (ns == XMLNamespaces.Atom && tag == TAG_TITLE) {
          // TODO:implement ATOMTextConstruct & ATOMTitle
          myEntry.Title = myFormattedBuffer.getText();
          myState = F_ENTRY;
        } else {
          myFormattedBuffer.appendEndTag(tag);
        }
        break;
      case FE_UPDATED:
        if (ns == XMLNamespaces.Atom && tag == TAG_UPDATED) {
          // FIXME:uri can be lost:buffer will be truncated, if there are extension tags inside the
          // <id> tag
          try {
            if (ATOMDateConstruct.parse(bufferContent, myUpdated)) {
              myEntry.Updated = myUpdated;
            }
          } catch (Exception e) {
            // this ATOMDateConstruct.parse() throws OOB exception time to time
          }
          myUpdated = null;
          myState = F_ENTRY;
        }
        break;
    }

    return interruptReading;
  }