Android Open Source - TumblifeForAndroid T L Post Parser






From Project

Back to project page TumblifeForAndroid.

License

The source code is released under:

GNU General Public License

If you think the Android project TumblifeForAndroid 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 jp.mitukiii.tumblife.parser;
//from   www .j a  v a2  s  .c  o  m
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import jp.mitukiii.tumblife.model.TLPost;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

public class TLPostParser extends TLParser
{
  public TLPostParser(InputStream input)
    throws XmlPullParserException
  {
    super(input);
  }

  public List<TLPost> parse()
    throws NumberFormatException, XmlPullParserException, IOException
  {
    List<TLPost> posts = new ArrayList<TLPost>(50);
    TLPost post = null;
    for (int e = parser.getEventType(); e != XmlPullParser.END_DOCUMENT; e = parser.next()) {
      String tag = parser.getName();
      if (e == XmlPullParser.START_TAG) {
        if ("post".equals(tag)) {
          post = new TLPost();
          post.setId(Long.valueOf(parser.getAttributeValue(NAME_SPACE, "id")));
          post.setUrl(parser.getAttributeValue(NAME_SPACE, "url"));
          post.setUrlWithSlug(parser.getAttributeValue(NAME_SPACE, "url-with-slug"));
          post.setType(parser.getAttributeValue(NAME_SPACE, "type"));
          post.setDateGmt(parser.getAttributeValue(NAME_SPACE, "date-gmt"));
          post.setDate(parser.getAttributeValue(NAME_SPACE, "date"));
          post.setUnixTimestamp(Integer.valueOf(parser.getAttributeValue(NAME_SPACE, "unix-timestamp")));
          post.setFormat(parser.getAttributeValue(NAME_SPACE, "format"));
          post.setReblogKey(parser.getAttributeValue(NAME_SPACE, "reblog-key"));
          post.setSlug(parser.getAttributeValue(NAME_SPACE, "slug"));
          String noteCount = parser.getAttributeValue(NAME_SPACE, "note-count");
          if (noteCount == null || noteCount.length() == 0) {
            post.setNoteCount(0);
          } else {
            post.setNoteCount(Integer.valueOf(noteCount));
          }
          post.setRebloggedFromUrl(parser.getAttributeValue(NAME_SPACE, "reblogged-from-url"));
          post.setRebloggedFromName(parser.getAttributeValue(NAME_SPACE, "reblogged-from-name"));
          post.setRebloggedFromTitle(parser.getAttributeValue(NAME_SPACE, "reblogged-from-title"));
        } else if ("tumblelog".equals(tag)) {
          post.setTumblelogTitle(parser.getAttributeValue(NAME_SPACE, "title"));
          post.setTumblelogName(parser.getAttributeValue(NAME_SPACE, "name"));
          post.setTumblelogUrl(parser.getAttributeValue(NAME_SPACE, "url"));
          post.setTumblelogTimezone(parser.getAttributeValue(NAME_SPACE, "timezone"));
        } else if ("tag".equals(tag)) {
          post.setTag(parser.nextText());
        } else if ("quote-text".equals(tag)) {
          post.setQuoteText(parser.nextText());
        } else if ("quote-source".equals(tag)) {
          post.setQuoteSource(parser.nextText());
        } else if ("photo-caption".equals(tag)) {
          post.setPhotoCaption(parser.nextText());
        } else if ("photo-link-url".equals(tag)) {
          post.setPhotoLinkUrl(parser.nextText());
        } else if ("photo-url".equals(tag)) {
          String maxWidth = parser.getAttributeValue(NAME_SPACE, "max-width");
          if ("1280".equals(maxWidth)) {
            post.setPhotoUrlMaxWidth1280(parser.nextText());
          } else if ("500".equals(maxWidth)) {
            post.setPhotoUrlMaxWidth500(parser.nextText());
          } else if ("400".equals(maxWidth)) {
            post.setPhotoUrlMaxWidth400(parser.nextText());
          } else if ("250".equals(maxWidth)) {
            post.setPhotoUrlMaxWidth250(parser.nextText());
          } else if ("100".equals(maxWidth)) {
            post.setPhotoUrlMaxWidth100(parser.nextText());
          } else if ("75".equals(maxWidth)) {
            post.setPhotoUrlMaxWidth75(parser.nextText());
          } 
        } else if ("link-text".equals(tag)) {
          post.setLinkText(parser.nextText());
        } else if ("link-url".equals(tag)) {
          post.setLinkUrl(parser.nextText());
        } else if ("link-description".equals(tag)) {
          post.setLinkDescription(parser.nextText());
        } else if ("conversation-title".equals(tag)) {
          post.setConversationTitle(parser.nextText());
        } else if ("conversation-text".equals(tag)) {
          post.setConversationText(parser.nextText());
        } else if ("line".equals(tag)) {
          String beforeText = post.getConversation();
          if (beforeText == null) {
            beforeText = "";
          }
          post.setConversation(beforeText + "<p>" + parser.getAttributeValue(NAME_SPACE, "label") + parser.nextText() + "</p>");
        } else if ("video-caption".equals(tag)) {
          post.setVideoCaption(parser.nextText());
        } else if ("video-source".equals(tag)) {
          try {
            post.setVideoSource(parser.nextText());
          } catch (XmlPullParserException exception) {
            // Raise error if contains meta info of video by XML.
          }
        } else if ("video-player".equals(tag)) {
          post.setVideoPlayer(parser.nextText());
        } else if ("audio-caption".equals(tag)) {
          post.setAudioCaption(parser.nextText());
        } else if ("audio-player".equals(tag)) {
          post.setAudioPlayer(parser.nextText());
        } else if ("download-url".equals(tag)) {
          post.setDownloadUrl(parser.nextText());
        } else if ("regular-title".equals(tag)) {
          post.setRegularTitle(parser.nextText());
        } else if ("regular-body".equals(tag)) {
          post.setRegularBody(parser.nextText());
        }
      } else if (e == XmlPullParser.END_TAG) {
        if ("post".equals(tag)) {
          posts.add(post);
        }
      }
    }
    return posts;
  }

}




Java Source Code List

jp.mitukiii.tumblife.App.java
jp.mitukiii.tumblife.HardkeySetting.java
jp.mitukiii.tumblife.KeyCodeMap.java
jp.mitukiii.tumblife.Main.java
jp.mitukiii.tumblife.Setting.java
jp.mitukiii.tumblife.exeption.TLAuthenticationFailureException.java
jp.mitukiii.tumblife.exeption.TLFailureException.java
jp.mitukiii.tumblife.exeption.TLParserException.java
jp.mitukiii.tumblife.exeption.TLSDCardNotFoundException.java
jp.mitukiii.tumblife.model.TLModel.java
jp.mitukiii.tumblife.model.TLPost.java
jp.mitukiii.tumblife.model.TLSetting.java
jp.mitukiii.tumblife.model.TLTumblelog.java
jp.mitukiii.tumblife.model.TLUser.java
jp.mitukiii.tumblife.parser.TLParser.java
jp.mitukiii.tumblife.parser.TLPostParser.java
jp.mitukiii.tumblife.parser.TLUserParser.java
jp.mitukiii.tumblife.tumblr.TLDashboardDelegate.java
jp.mitukiii.tumblife.tumblr.TLDashboardInterface.java
jp.mitukiii.tumblife.tumblr.TLDashboard.java
jp.mitukiii.tumblife.ui.TLWebViewClientDelegate.java
jp.mitukiii.tumblife.ui.TLWebViewClient.java
jp.mitukiii.tumblife.util.TLBrowser.java
jp.mitukiii.tumblife.util.TLConnection.java
jp.mitukiii.tumblife.util.TLExplorer.java
jp.mitukiii.tumblife.util.TLLog.java
jp.mitukiii.tumblife.util.TLPostFactory.java