Android Open Source - UTHPortal-Android-Gradle Available Courses 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;
/*from  www. ja  v  a 2s .  c  o m*/
import android.util.Log;

import com.uth.uthportal.collections.AvailableCourse;
import com.uth.uthportal.collections.CourseInfo;

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

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Giorgos T. Gougoudis on 9/7/2014.
 * Available courses parser.
 */

public class AvailableCoursesParser {

    public  Boolean wasSuccessful=true;//stays true if not changed
    public String errorMessage;

    public AvailableCoursesParser(){
    }

    public List<AvailableCourse> parseAvailableCourses(String JSONBuffer){
        JSONArray jArr;
        List<AvailableCourse> availableCourseList = new ArrayList<AvailableCourse>();

        try {
            JSONObject jObj = new JSONObject(JSONBuffer);

            jArr= jObj.getJSONArray("children");
        } catch (JSONException e) {
            wasSuccessful = false;
            errorMessage = e.getMessage();
            Log.e("e.acp.AvailableCourses:",errorMessage);
            return null;
        }

        for(int i = 0; i < jArr.length(); i++){
            JSONObject avCourseObj;

            try{
                avCourseObj = jArr.getJSONObject(i);
                availableCourseList.add( parseAvailableCourse(avCourseObj));

            } catch(JSONException e){
                wasSuccessful = false;
                errorMessage = e.getMessage();
                Log.e("e.acp.AvailableCourses:",errorMessage);
                return null;
            } catch (NullPointerException e) {
                wasSuccessful = false;
                errorMessage = e.getMessage();
                Log.e("e.acp.AvailableCourses:",errorMessage);
                return null;
            }
        }

        return availableCourseList;
    }
    private AvailableCourse parseAvailableCourse(JSONObject avCourse){
        CourseInfo cInfo;
        String code;

        JSONObject cInfoObj;

        try{
            code = avCourse.getString("code");
            cInfoObj = avCourse.getJSONObject("info");
            cInfo = parseAvailCourseInfo(cInfoObj);
        }
        catch(JSONException e){
            wasSuccessful = false;
            errorMessage = e.getMessage();
            Log.e("e.acp.AvailableCourse:",errorMessage);
            return null;
        }

        if (cInfo == null)
            return null;
        return new AvailableCourse(code, cInfo, false);
    }

    private CourseInfo parseAvailCourseInfo(JSONObject cInfoObj){
        String name;
        String link;

        try{
            name = cInfoObj.getString("name");
            link = cInfoObj.getString("link");
        }
        catch(JSONException e){
            wasSuccessful = false;
            errorMessage = e.getMessage();
            Log.e("e.acp.AvailableCourseInfo:",errorMessage);
            return null;
        }

        return new CourseInfo(name, link);
    }

}




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