Exemplo n.º 1
0
 public boolean startElementHandler(
     String ns, String tag, ZLStringMap attributes, String bufferContent) {
   switch (myState) {
     case START:
       if (testTag(TAG_RSS, tag, ns, null)) {
         myState = RSS;
       }
       break;
     case RSS:
       if (testTag(TAG_CHANNEL, tag, ns, null)) {
         myState = CHANNEL;
       }
       break;
     case CHANNEL:
       if (testTag(TAG_TITLE, tag, ns, null)) {
         myState = C_TITLE;
       }
       if (testTag(TAG_LINK, tag, ns, null)) {
         myState = C_LINK;
       }
       if (testTag(TAG_ITEM, tag, ns, null)) {
         myItem = myFeedHandler.createEntry(attributes);
         myState = ITEM;
       }
       break;
     case ITEM:
       if (testTag(TAG_TITLE, tag, ns, null)) {
         myAuthor = new RSSAuthor(attributes);
         myState = TITLE;
       }
       if (testTag(TAG_LINK, tag, ns, null)) {
         myState = LINK;
       }
       if (testTag(TAG_DESCRIPTION, tag, ns, null)) {
         myState = DESCRIPTION;
       }
       if (testTag(TAG_CATEGORY, tag, ns, null)) {
         myState = CATEGORY;
       }
       if (testTag(TAG_GUID, tag, ns, null)) {
         myId = new ATOMId();
         myState = GUID;
       }
       if (testTag(TAG_PUBDATE, tag, ns, null)) {
         myState = PUBDATE;
       }
   }
   return false;
 }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
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;
  }
Exemplo n.º 4
0
  public boolean startElementHandler(
      final String ns, final String tag, final ZLStringMap attributes, final String bufferContent) {
    boolean interruptReading = false;
    switch (myState) {
      case START:
        if (ns == XMLNamespaces.Atom && tag == TAG_FEED) {
          myFeedHandler.processFeedStart();
          myFeed = myFeedHandler.createFeed(attributes);
          myState = FEED;
          myFeedMetadataProcessed = false;
        }
        break;
      case FEED:
        if (ns == XMLNamespaces.Atom) {
          if (tag == TAG_AUTHOR) {
            myAuthor = new ATOMAuthor(attributes);
            myState = F_AUTHOR;
          } else if (tag == TAG_ID) {
            myId = new ATOMId(attributes);
            myState = F_ID;
          } else if (tag == TAG_ICON) {
            myIcon = new ATOMIcon(attributes);
            myState = F_ICON;
          } else if (tag == TAG_LINK) {
            myLink = myFeedHandler.createLink(attributes); // TODO
            myState = F_LINK;
          } else if (tag == TAG_CATEGORY) {
            myCategory = new ATOMCategory(attributes);
            myState = F_CATEGORY;
          } else if (tag == TAG_TITLE) {
            // myTitle = new ATOMTitle(attributes); // TODO:implement ATOMTextConstruct & ATOMTitle
            setFormattingType(attributes.getValue("type"));
            myState = F_TITLE;
          } else if (tag == TAG_SUBTITLE) {
            // mySubtitle = new ATOMTitle(attributes); // TODO:implement ATOMTextConstruct &
            // ATOMSubtitle
            setFormattingType(attributes.getValue("type"));
            myState = F_SUBTITLE;
          } else if (tag == TAG_UPDATED) {
            myUpdated = new ATOMUpdated(attributes);
            myState = F_UPDATED;
          } else if (tag == TAG_ENTRY) {
            myEntry = myFeedHandler.createEntry(attributes);
            myState = F_ENTRY;
            // Process feed metadata just before first feed entry
            if (myFeed != null && !myFeedMetadataProcessed) {
              interruptReading = myFeedHandler.processFeedMetadata(myFeed, true);
              myFeedMetadataProcessed = true;
            }
          }
        }
        break;
      case F_ENTRY:
        if (ns == XMLNamespaces.Atom) {
          if (tag == TAG_AUTHOR) {
            myAuthor = new ATOMAuthor(attributes);
            myState = FE_AUTHOR;
          } else if (tag == TAG_ID) {
            myId = new ATOMId(attributes);
            myState = FE_ID;
          } else if (tag == TAG_CATEGORY) {
            myCategory = new ATOMCategory(attributes);
            myState = FE_CATEGORY;
          } else if (tag == TAG_LINK) {
            myLink = myFeedHandler.createLink(attributes); // TODO
            myState = FE_LINK;
          } else if (tag == TAG_PUBLISHED) {
            myPublished = new ATOMPublished(attributes);
            myState = FE_PUBLISHED;
          } else if (tag == TAG_SUMMARY) {
            // mySummary = new ATOMSummary(attributes); // TODO:implement ATOMTextConstruct &
            // ATOMSummary
            setFormattingType(attributes.getValue("type"));
            myState = FE_SUMMARY;
          } else if (tag == TAG_CONTENT) {
            // myConent = new ATOMContent(attributes); // TODO:implement ATOMContent
            setFormattingType(attributes.getValue("type"));
            myState = FE_CONTENT;
          } else if (tag == TAG_TITLE) {
            // myTitle = new ATOMTitle(attributes); // TODO:implement ATOMTextConstruct & ATOMTitle
            setFormattingType(attributes.getValue("type"));
            myState = FE_TITLE;
          } else if (tag == TAG_UPDATED) {
            myUpdated = new ATOMUpdated(attributes);
            myState = FE_UPDATED;
          }
        }
        break;
      case F_AUTHOR:
        if (ns == XMLNamespaces.Atom) {
          if (tag == TAG_NAME) {
            myState = FA_NAME;
          } else if (tag == TAG_URI) {
            myState = FA_URI;
          } else if (tag == TAG_EMAIL) {
            myState = FA_EMAIL;
          }
        }
        break;
      case FE_AUTHOR:
        if (ns == XMLNamespaces.Atom) {
          if (tag == TAG_NAME) {
            myState = FEA_NAME;
          } else if (tag == TAG_URI) {
            myState = FEA_URI;
          } else if (tag == TAG_EMAIL) {
            myState = FEA_EMAIL;
          }
        }
        break;
      case FE_CONTENT:
      case FE_SUMMARY:
      case FE_TITLE:
      case F_TITLE:
      case F_SUBTITLE:
        myFormattedBuffer.appendText(bufferContent);
        myFormattedBuffer.appendStartTag(tag, attributes);
        break;
      default:
        break;
    }

    return interruptReading;
  }