Android Open Source - SELP2013 Courses Xml Parser






From Project

Back to project page SELP2013.

License

The source code is released under:

License ======= This work is licensed under the BSD 2-clause license as follows. # BSD 2-clause license Copyright (c) 2013, Sky Welch All rights reserved. Redistribution and use in source and ...

If you think the Android project SELP2013 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 uk.co.skywelch.selp2013;
//from w  ww.j  a  v a  2 s.c o m
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import android.util.Xml;

public class CoursesXmlParser {
  private static final String ns = null;

  public ArrayList<Course> parse(InputStream in) throws XmlPullParserException, IOException {
    try {
      XmlPullParser parser = Xml.newPullParser();
      parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
      parser.setInput(in, null);
      parser.nextTag();
      return readFeed(parser);
    } finally {
      in.close();
    }
  }

  private ArrayList<Course> readFeed(XmlPullParser parser) throws XmlPullParserException,
      IOException {
    ArrayList<Course> entries = new ArrayList<Course>();

    parser.require(XmlPullParser.START_TAG, ns, "list");
    while (parser.next() != XmlPullParser.END_TAG) {
      if (parser.getEventType() != XmlPullParser.START_TAG) {
        continue;
      }
      String name = parser.getName();

      if (name.equals("course")) {
        entries.add(readEntry(parser));
      } else {
        XMLUtilities.skip(parser);
      }
    }
    return entries;
  }

  // Parses the contents of a course
  private Course readEntry(XmlPullParser parser) throws XmlPullParserException, IOException {
    parser.require(XmlPullParser.START_TAG, ns, "course");

    String url = null;
    String name = null;
    String drps = null;
    String euclid = null;
    String acronym = null;

    Boolean ai = null;
    Boolean cg = null;
    Boolean cs = null;
    Boolean se = null;

    Integer level = null;
    Integer points = null;
    Integer year = null;

    String deliveryperiod = null;
    String lecturer = null;

    // Run through each tag and update our Course with values if they exist
    while (parser.next() != XmlPullParser.END_TAG) {
      if (parser.getEventType() != XmlPullParser.START_TAG) {
        continue;
      }
      String tag = parser.getName();
      if (tag.equals("url")) {
        url = XMLUtilities.readString(parser, ns, "url");
      } else if (tag.equals("name")) {
        name = XMLUtilities.readString(parser, ns, "name");
      } else if (tag.equals("drps")) {
        drps = XMLUtilities.readString(parser, ns, "drps");
      } else if (tag.equals("euclid")) {
        euclid = XMLUtilities.readString(parser, ns, "euclid");
      } else if (tag.equals("acronym")) {
        acronym = XMLUtilities.readString(parser, ns, "acronym");
      } else if (tag.equals("ai")) {
        ai = XMLUtilities.readString(parser, ns, "ai").equals("AI");
      } else if (tag.equals("cg")) {
        cg = XMLUtilities.readString(parser, ns, "cg").equals("CG");
      } else if (tag.equals("cs")) {
        cs = XMLUtilities.readString(parser, ns, "cs").equals("CS");
      } else if (tag.equals("se")) {
        se = XMLUtilities.readString(parser, ns, "se").equals("SE");
      } else if (tag.equals("level")) {
        level = XMLUtilities.readInteger(parser, ns, "level");
      } else if (tag.equals("points")) {
        points = XMLUtilities.readInteger(parser, ns, "points");
      } else if (tag.equals("year")) {
        year = XMLUtilities.readInteger(parser, ns, "year");
      } else if (tag.equals("deliveryperiod")) {
        deliveryperiod = XMLUtilities.readString(parser, ns, "deliveryperiod");
      } else if (tag.equals("lecturer")) {
        lecturer = XMLUtilities.readString(parser, ns, "lecturer");
      } else {
        XMLUtilities.skip(parser);
      }
    }

    return new Course(url, name, drps, euclid, acronym, ai, cg, cs, se, level, points, year,
        deliveryperiod, lecturer);
  }
}




Java Source Code List

uk.co.skywelch.selp2013.AboutActivity.java
uk.co.skywelch.selp2013.CourseInformationActivity.java
uk.co.skywelch.selp2013.CourseListActivity.java
uk.co.skywelch.selp2013.CourseListAdapter.java
uk.co.skywelch.selp2013.Course.java
uk.co.skywelch.selp2013.CoursesParseTask.java
uk.co.skywelch.selp2013.CoursesXmlParser.java
uk.co.skywelch.selp2013.DrawerListAdapter.java
uk.co.skywelch.selp2013.FileDownloader.java
uk.co.skywelch.selp2013.HourMinute.java
uk.co.skywelch.selp2013.Lecture.java
uk.co.skywelch.selp2013.ListItem.java
uk.co.skywelch.selp2013.ListSection.java
uk.co.skywelch.selp2013.StringListItem.java
uk.co.skywelch.selp2013.TimetableActivity.java
uk.co.skywelch.selp2013.TimetableFragment.java
uk.co.skywelch.selp2013.TimetableListAdapter.java
uk.co.skywelch.selp2013.TimetableParseTask.java
uk.co.skywelch.selp2013.TimetableXmlParser.java
uk.co.skywelch.selp2013.VenueInformationActivity.java
uk.co.skywelch.selp2013.Venue.java
uk.co.skywelch.selp2013.VenuesParseTask.java
uk.co.skywelch.selp2013.VenuesXmlParser.java
uk.co.skywelch.selp2013.XMLUtilities.java