Android Open Source - AndroIUT Absences Adapter






From Project

Back to project page AndroIUT.

License

The source code is released under:

GNU General Public License

If you think the Android project AndroIUT 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.iutdijon.androiut2.util.adapters;
//  w  ww .  j ava2 s  . c o  m
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;

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

import com.iutdijon.androiut2.schooling.data.Absence;
import com.iutdijon.androiut2.schooling.data.Mark;

/**
 * Permet de r?cup?rer les informations sur les absences ? partir du XML renvoyer sur le serveur
 * @author Morgan Funtowicz
 *
 */
public class AbsencesAdapter extends XmlAdapter<HashMap<String, Set<Mark>>> {
  
  private static final String DATA_FIELD = "data";
  private static final String ABSENCE_FIELD = "absence";
  private static final String SUBJECT_FIELD = "matiere";
  private static final String DAY_FIELD = "jour";
  private static final String DURATION_FIELD = "duree";
  private static final String HOUR_FIELD = "heure";

  @SuppressWarnings("unchecked")
  @Override
  public HashMap<String, Set<Mark>> parse(InputStream data) throws Exception {
    parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
    parser.setInput(data, null);
    parser.nextTag();
    
    return readFeed(parser);
  }

  @SuppressWarnings("rawtypes")
  @Override
  protected HashMap readFeed(XmlPullParser parser) throws XmlPullParserException, IOException {
    HashMap<String, ArrayList<Absence>> values = new HashMap<String, ArrayList<Absence>>();
    
    parser.require(XmlPullParser.START_TAG, null, DATA_FIELD);
    
    while(parser.next() != XmlPullParser.END_TAG){
      if (parser.getEventType() != XmlPullParser.START_TAG) {
              continue;
          }
      Absence a = readEntry(parser);
      if(values.containsKey(a.getDate())){
        values.get(a.getDate()).add(a);
      }else{
        
        ArrayList<Absence> list = new ArrayList<Absence>();
        list.add(a);
        values.put(a.getDate(), list);
      }
    }
    
    return values;
  }
  
  private Absence readEntry(XmlPullParser parser) throws XmlPullParserException, IOException{
    Absence a = null;
    String date ="";
    String discipline="";
    String hour=""; 
    String duration="";
    
    parser.require(XmlPullParser.START_TAG, null, ABSENCE_FIELD);
    while(parser.next() != XmlPullParser.END_TAG){
      
      if (parser.getEventType() != XmlPullParser.START_TAG) {
              continue;
          }
      String name = parser.getName();
      if(name.equals(SUBJECT_FIELD)){
        discipline = readDiscipline(parser);
      }else if(name.equals(HOUR_FIELD)){
         hour = readHour(parser);
      }else if(name.equals(DURATION_FIELD)){
         duration = readDuration(parser);
      }else if(name.equals(DAY_FIELD)){
         date = readDate(parser);
      }else {
              skip(parser);
          }
    }
    
    a = new Absence(date, discipline, hour, duration);
    return a;
  }
  
  /**
   * Permet d'ignorer certains noeuds du XML
   * @param parser Le parser utilis? pour lire le fichier XML
   * @throws XmlPullParserException 
   * @throws IOException
   */
  private void skip(XmlPullParser parser) throws XmlPullParserException, IOException {
      if (parser.getEventType() != XmlPullParser.START_TAG) {
          throw new IllegalStateException();
      }
      int depth = 1;
      while (depth != 0) {
          switch (parser.next()) {
          case XmlPullParser.END_TAG:
              depth--;
              break;
          case XmlPullParser.START_TAG:
              depth++;
              break;
          }
      }
   }

  /**
   * Lit une discipline dans le XML
   * @param parser Le parser utilis? pour lire le fichier XML
   * @return La valeur de la discipline
   * @throws XmlPullParserException
   * @throws IOException
   */
  private String readDiscipline(XmlPullParser parser) throws XmlPullParserException, IOException{
    
    parser.require(XmlPullParser.START_TAG, null, SUBJECT_FIELD);
    String discipline = readText(parser);
      parser.require(XmlPullParser.END_TAG, null, SUBJECT_FIELD);
      
      return discipline;
  }
  
  /**
   * Lit l'heure dans le XML
   * @param parser Le parser utilis? pour lire le fichier XML
   * @return La valeur de l'heure
   * @throws XmlPullParserException
   * @throws IOException
   */
  private String readHour(XmlPullParser parser) throws XmlPullParserException, IOException{
    parser.require(XmlPullParser.START_TAG, null, HOUR_FIELD);
    String mark = readText(parser);
      parser.require(XmlPullParser.END_TAG, null, HOUR_FIELD);
      
      return mark;
  }
  
  /**
   * Lit une dur?e dans le XML
   * @param parser Le parser utilis? pour lire le fichier XML
   * @return La valeur de la dur?e
   * @throws XmlPullParserException
   * @throws IOException
   */
  private String readDuration(XmlPullParser parser) throws XmlPullParserException, IOException{
    parser.require(XmlPullParser.START_TAG, null, DURATION_FIELD);
    String coef = readText(parser);
      parser.require(XmlPullParser.END_TAG, null, DURATION_FIELD);
      
      return coef;
  }
  
  /**
   * Lit une date dans le XML
   * @param parser Le parser utilis? pour lire le fichier XML
   * @return La valeur de la date
   * @throws XmlPullParserException
   * @throws IOException
   */
  private String readDate(XmlPullParser parser) throws XmlPullParserException, IOException{
    parser.require(XmlPullParser.START_TAG, null, DAY_FIELD);
    String date = readText(parser);
      parser.require(XmlPullParser.END_TAG, null, DAY_FIELD);
      
      return date;
  }

}




Java Source Code List

.ADEResourcesDataTree.java
com.iutdijon.androiut2.ade.activities.ADEActivity.java
com.iutdijon.androiut2.ade.activities.ADEListResourcesChooser.java
com.iutdijon.androiut2.ade.activities.OnImageDownloadedCallback.java
com.iutdijon.androiut2.ade.service.ADEICalendarDownloader.java
com.iutdijon.androiut2.ftp.activities.FTPActivity.java
com.iutdijon.androiut2.ftp.adapters.FTPFileListAdapter.java
com.iutdijon.androiut2.ftp.data.FTPCommandResult.java
com.iutdijon.androiut2.ftp.data.FTPCommandWrapper.java
com.iutdijon.androiut2.ftp.data.FTPCommand.java
com.iutdijon.androiut2.ftp.services.FTPDownloadMonitor.java
com.iutdijon.androiut2.ftp.services.FTPServiceCall.java
com.iutdijon.androiut2.ftp.services.ProgressDownload.java
com.iutdijon.androiut2.global.AndroIUTApplication.java
com.iutdijon.androiut2.iut.activities.HomeActivity.java
com.iutdijon.androiut2.iut.activities.LoginActivity.java
com.iutdijon.androiut2.iut.data.Credential.java
com.iutdijon.androiut2.iut.data.UserFactory.java
com.iutdijon.androiut2.iut.data.account.StudentAccount.java
com.iutdijon.androiut2.iut.data.account.TeacherAccount.java
com.iutdijon.androiut2.iut.data.account.UserAccount.java
com.iutdijon.androiut2.iut.services.IUTLoginServiceCall.java
com.iutdijon.androiut2.mail.activities.MailActivity.java
com.iutdijon.androiut2.mail.activities.MailReaderActivity.java
com.iutdijon.androiut2.mail.adapters.MailDisplayAdapter.java
com.iutdijon.androiut2.mail.adapters.MailsListAdapter.java
com.iutdijon.androiut2.mail.services.EmailUtils.java
com.iutdijon.androiut2.mail.services.MailReader.java
com.iutdijon.androiut2.mail.services.MailService.java
com.iutdijon.androiut2.schooling.activities.SchoolingActivity.java
com.iutdijon.androiut2.schooling.activities.SchoolingTabActivity.java
com.iutdijon.androiut2.schooling.adapters.SectionedAdapter.java
com.iutdijon.androiut2.schooling.data.Absence.java
com.iutdijon.androiut2.schooling.data.Mark.java
com.iutdijon.androiut2.schooling.data.SchoolingData.java
com.iutdijon.androiut2.schooling.service.SchoolingDataServiceCall.java
com.iutdijon.androiut2.util.AndroIUTLogger.java
com.iutdijon.androiut2.util.IOUtils.java
com.iutdijon.androiut2.util.PreferencesManager.java
com.iutdijon.androiut2.util.UIUtil.java
com.iutdijon.androiut2.util.adapters.AbsencesAdapter.java
com.iutdijon.androiut2.util.adapters.BitmapAdapter.java
com.iutdijon.androiut2.util.adapters.CalendarAdapter.java
com.iutdijon.androiut2.util.adapters.IAdapter.java
com.iutdijon.androiut2.util.adapters.MarksAdapter.java
com.iutdijon.androiut2.util.adapters.UserAdapter.java
com.iutdijon.androiut2.util.adapters.XmlAdapter.java
com.iutdijon.androiut2.util.bridge.BridgeFinder.java
com.iutdijon.androiut2.util.loaders.AndroIUTHTTPConnection.java
com.iutdijon.androiut2.util.loaders.AsyncServiceCall.java
com.iutdijon.androiut2.util.loaders.BitmapDownloaderTask.java
com.iutdijon.androiut2.util.loaders.GetAsyncServiceCall.java
com.iutdijon.androiut2.util.loaders.ImageDownloader.java
com.iutdijon.androiut2.util.loaders.PostAsyncServiceCall.java
com.iutdijon.androiut2.util.observers.Observable.java
com.iutdijon.androiut2.util.observers.Observer.java
com.iutdijon.androiut2.util.security.SecureCenter.java
com.iutdijon.androiut2.util.view.ImageZoomView.java
com.iutdijon.androiut2.util.zoom.AspectQuotient.java
com.iutdijon.androiut2.util.zoom.DynamicZoomControl.java
com.iutdijon.androiut2.util.zoom.LongPressZoomListener.java
com.iutdijon.androiut2.util.zoom.PinchZoomListener.java
com.iutdijon.androiut2.util.zoom.SimpleZoomListener.java
com.iutdijon.androiut2.util.zoom.ZoomState.java
com.iutdijon.androiut2.util.zoom.util.Dynamics.java
com.iutdijon.androiut2.util.zoom.util.SpringDynamics.java