Android Open Source - UTHPortal-Android-Gradle General Ann Parser






From Project

Back to project page UTHPortal-Android-Gradle.

License

The source code is released under:

MIT License

If you think the Android project UTHPortal-Android-Gradle 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.uth.uthportal.buffers;
//  ww  w .  j ava  2s  .c  om
import android.util.Log;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.uth.uthportal.collections.GeneralAnnouncement;

/**
 * Parser for the general department announcements.
 * @author George T. Gougoudis
 *
 */
public class GeneralAnnParser {
  public  Boolean wasSuccessful=true;//stays true if not changed
  public String errorMessage;
  
  public List<GeneralAnnouncement> parseGeneralAnnouncements(String JSONBuffer){
    JSONObject jObj;
    try {
      jObj = new JSONObject(JSONBuffer);
      JSONArray announcements = jObj.getJSONArray("entries");
      
      //Initialize list
      List<GeneralAnnouncement> generalAnnouncements = new ArrayList<GeneralAnnouncement>();
      for (int i=0; i < announcements.length(); i++){
        JSONObject announcement = announcements.getJSONObject(i);//get current object
        
        Date date = parseDateString( announcement.getString("date") );
        String title = announcement.getString("title");
        String link = announcement.getString("link");
        String html = announcement.getString("html");

                if (date == null)
                    return null;
        generalAnnouncements.add(new GeneralAnnouncement(title, link, date, html));
      }
      return generalAnnouncements;
      
    } catch (JSONException e) {
            wasSuccessful = false;
            errorMessage = e.getMessage();
            Log.e("e.gap.parseGeneralAnnouncements:", errorMessage);
    } catch (NullPointerException e) {
            wasSuccessful = false;
            errorMessage = e.getMessage();
            Log.e("e.gap.parseGeneralAnnouncements:", errorMessage);
        }

        return null;
  }

  private Date parseDateString(String dateStr){
    //function to parse IsoDate
    SimpleDateFormat  format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); 
    Date result;
    try {  
        result = format.parse(dateStr);     
    } catch (ParseException e) {
            wasSuccessful = false;
            errorMessage = e.getMessage();
            Log.e("e.gap.parseDateString",errorMessage);
            return null;
    }
    return result;
  }
}




Java Source Code List

com.uth.uthportal.AboutScreen.java
com.uth.uthportal.CoursesFragment.java
com.uth.uthportal.DepartmentFragment.java
com.uth.uthportal.FoodFragment.java
com.uth.uthportal.MainScreen.java
com.uth.uthportal.SettingsScreen.java
com.uth.uthportal.adapter.AdapterManager.java
com.uth.uthportal.adapter.AdapterProvider.java
com.uth.uthportal.adapter.ExpandableListAdapter.java
com.uth.uthportal.adapter.SettingsAdapter.java
com.uth.uthportal.adapter.TabsPagerAdapter.java
com.uth.uthportal.buffers.AvailableCoursesParser.java
com.uth.uthportal.buffers.CoursesParser.java
com.uth.uthportal.buffers.FileOperation.java
com.uth.uthportal.buffers.FoodParser.java
com.uth.uthportal.buffers.GeneralAnnParser.java
com.uth.uthportal.buffers.SettingsManager.java
com.uth.uthportal.collections.AnnItem.java
com.uth.uthportal.collections.Announcements.java
com.uth.uthportal.collections.AvailableCourse.java
com.uth.uthportal.collections.CourseInfo.java
com.uth.uthportal.collections.Course.java
com.uth.uthportal.collections.DayMenu.java
com.uth.uthportal.collections.DefaultIntervals.java
com.uth.uthportal.collections.Dish.java
com.uth.uthportal.collections.Food.java
com.uth.uthportal.collections.GeneralAnnouncement.java
com.uth.uthportal.collections.Settings.java
com.uth.uthportal.network.ApiLinks.java
com.uth.uthportal.network.AppRater.java
com.uth.uthportal.network.AsyncJSONDownloader.java
com.uth.uthportal.network.JSONDownloader.java
com.uth.uthportal.service.DataSyncService.java
com.uth.uthportal.util.SystemUiHiderBase.java
com.uth.uthportal.util.SystemUiHiderHoneycomb.java
com.uth.uthportal.util.SystemUiHider.java