Пример #1
0
 public boolean endElementHandler(String ns, String tag, String bufferContent) {
   switch (myState) {
     case START:
       break;
     case RSS:
       if (testTag(TAG_RSS, tag, ns, null)) {
         myState = START;
       }
       break;
     case CHANNEL:
       if (testTag(TAG_CHANNEL, tag, ns, null)) {
         myState = RSS;
       }
       break;
     case C_TITLE:
       if (testTag(TAG_TITLE, tag, ns, null)) {
         myState = CHANNEL;
       }
       break;
     case C_LINK:
       if (testTag(TAG_LINK, tag, ns, null)) {
         myState = CHANNEL;
       }
       break;
     case ITEM:
       if (testTag(TAG_ITEM, tag, ns, null)) {
         myFeedHandler.processFeedEntry(myItem);
         myState = CHANNEL;
       }
     case TITLE:
       if (testTag(TAG_TITLE, tag, ns, null)) {
         parseTitle(bufferContent);
         myState = ITEM;
       }
       break;
     case GUID:
       if (testTag(TAG_GUID, tag, ns, null)) {
         if (myId != null) {
           myId.Uri = bufferContent;
           myItem.Id = myId;
           myId = null;
         }
         myState = ITEM;
       }
       break;
     case DESCRIPTION:
       if (testTag(TAG_DESCRIPTION, tag, ns, null)) {
         myFormattedBuffer.reset(FormattedBuffer.Type.Html);
         myFormattedBuffer.appendText(makeFormat(bufferContent));
         myItem.Summary = myFormattedBuffer.getText();
         myState = ITEM;
       }
       break;
     case CATEGORY:
       if (testTag(TAG_CATEGORY, tag, ns, null)) {
         String[] tokens = bufferContent.split(", ");
         for (String str : tokens) {
           ZLStringMap source = new ZLStringMap();
           source.put(RSSCategory.LABEL, str);
           myCategory = new RSSCategory(source);
           if (myCategory != null) {
             myItem.Categories.push(myCategory);
           }
           myCategory = null;
         }
         myState = ITEM;
       }
       break;
     case PUBDATE:
       if (testTag(TAG_PUBDATE, tag, ns, null)) {
         myState = ITEM;
       }
       break;
     case LINK:
       if (testTag(TAG_LINK, tag, ns, null)) {
         myState = ITEM;
       }
       break;
   }
   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;
  }