Android Open Source - wxalert Rss Handler






From Project

Back to project page wxalert.

License

The source code is released under:

Apache License

If you think the Android project wxalert listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.creatuity.wxalert;
import java.util.ArrayList;
import java.util.List;
//from  w ww .ja va  2  s.c o m
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import static com.creatuity.wxalert.BaseFeedParser.*;

public class RssHandler extends DefaultHandler{
  private List<Message> messages;
  private Message currentMessage;
  private StringBuilder builder;
  
  public List<Message> getMessages(){
    return this.messages;
  }
  @Override
  public void characters(char[] ch, int start, int length)
      throws SAXException {
    super.characters(ch, start, length);
    builder.append(ch, start, length);
  }

  @Override
  public void endElement(String uri, String localName, String name)
      throws SAXException {
    super.endElement(uri, localName, name);
    if (this.currentMessage != null){
      if (localName.equalsIgnoreCase(TITLE)){
        currentMessage.setTitle(builder.toString());
      } else if (localName.equalsIgnoreCase(LINK)){
        currentMessage.setLink(builder.toString());
      } else if (localName.equalsIgnoreCase(DESCRIPTION)){
        currentMessage.setDescription(builder.toString());
      } else if (localName.equalsIgnoreCase(PUB_DATE)){
        currentMessage.setDate(builder.toString());
      } else if (localName.equalsIgnoreCase(ITEM)){
        messages.add(currentMessage);
      }
      builder.setLength(0);  
    }
  }

  @Override
  public void startDocument() throws SAXException {
    super.startDocument();
    messages = new ArrayList<Message>();
    builder = new StringBuilder();
  }

  @Override
  public void startElement(String uri, String localName, String name,
      Attributes attributes) throws SAXException {
    super.startElement(uri, localName, name, attributes);
    if (localName.equalsIgnoreCase(ITEM)){
      this.currentMessage = new Message();
    }
  }
}




Java Source Code List

com.creatuity.wxalert.Alert.java
com.creatuity.wxalert.AndroidSaxFeedParser.java
com.creatuity.wxalert.BaseFeedParser.java
com.creatuity.wxalert.DomFeedParser.java
com.creatuity.wxalert.FeedParserFactory.java
com.creatuity.wxalert.FeedParser.java
com.creatuity.wxalert.MessageList.java
com.creatuity.wxalert.Message.java
com.creatuity.wxalert.ParserType.java
com.creatuity.wxalert.RssHandler.java
com.creatuity.wxalert.SaxFeedParser.java
com.creatuity.wxalert.WeatherAlert.java
com.creatuity.wxalert.XmlPullFeedParser.java