Android Open Source - AndroIUT Marks 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  w w.  j a va2s . c o m
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;

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

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

/**
 * Adaptateur permettant de lire le fichier XML renvoyer par le serveur et de le convertir en 
 * un tableau associatif sous forme : mati?re => Liste de notes 
 * @author Morgan Funtowicz
 *
 */
public class MarksAdapter extends XmlAdapter<HashMap<String, ArrayList<Mark>>> {

  private static final String DATA_FIELD = "data";
  private static final String MARK_DATA_FIELD = "mark";
  private static final String MARK_FIELD = "note";
  private static final String SUBJECT_FIELD = "matiere";
  private static final String COEF_FIELD = "coefficient";
  private static final String DAY_FIELD = "jour";
  private static final String INFO_FIELD = "info";
  
  
  /**
   * Voir {@link XmlAdapter}
   */
  @SuppressWarnings("unchecked")
  @Override
  public HashMap<String, ArrayList<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<Mark>> values = new HashMap<String, ArrayList<Mark>>();
    
    parser.require(XmlPullParser.START_TAG, null, DATA_FIELD);
    
    while(parser.next() != XmlPullParser.END_TAG){
      if (parser.getEventType() != XmlPullParser.START_TAG) {
              continue;
          }
      Mark m = readEntry(parser);
      if(values.containsKey(m.getDiscipline())){
        values.get(m.getDiscipline()).add(m);
      }else{
        
        ArrayList<Mark> list = new ArrayList<Mark>();
        list.add(m);
        values.put(m.getDiscipline(), list);
      }
    }
    
    return values;
  }
  
  /**
   * Lit une entr?e "mark" 
   * @param parser Le parser contenant l'InputStream
   * @return La note lue depuis le flux {@link Mark}
   * @throws XmlPullParserException Lors de la lecture
   * @throws IOException Lors d'un probl?me de lecture
   */
  private Mark readEntry(XmlPullParser parser) throws XmlPullParserException, IOException{
    Mark mark = null;
    String date ="";
    String discipline="";
    String note="";
    String title=""; 
    String coef="";
    
    parser.require(XmlPullParser.START_TAG, null, MARK_DATA_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(MARK_FIELD)){
         note = readMark(parser);
      }else if(name.equals(COEF_FIELD)){
         coef = readCoef(parser);
      }else if(name.equals(DAY_FIELD)){
         date =readDate(parser);
      }else if(name.equals(INFO_FIELD)){
        title = readInfo(parser);
      }else {
              skip(parser);
          }
    }
    
    mark = new Mark(date, discipline, note, title, coef);
    return mark;
  }
  
  /**
   * Permet de sauter certaines lignes d'un XML
   * @param parser Le parser content l'InputStream
   * @throws XmlPullParserException Lors de la lecture
   * @throws IOException Lors d'un probl?me de lecture
   */
  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 le champ contenant la mati?re dans le noeud "mark"
   * @param parser Le parser contenant l'InputStream
   * @return Le texte du noeud
   * @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 le champ contenant la note dans le noeud "mark"
   * @param parser Le parser contenant l'InputStream
   * @return Le texte du noeud
   * @throws XmlPullParserException
   * @throws IOException
   */
  private String readMark(XmlPullParser parser) throws XmlPullParserException, IOException{
    parser.require(XmlPullParser.START_TAG, null, MARK_FIELD);
    String mark = readText(parser);
      parser.require(XmlPullParser.END_TAG, null, MARK_FIELD);
      
      return mark;
  }
  
  /**
   * Lit le champ contenant le coefficient dans le noeud "mark"
   * @param parser Le parser contenant l'InputStream
   * @return Le texte du noeud
   * @throws XmlPullParserException
   * @throws IOException
   */
  private String readCoef(XmlPullParser parser) throws XmlPullParserException, IOException{
    parser.require(XmlPullParser.START_TAG, null, COEF_FIELD);
    String coef = readText(parser);
      parser.require(XmlPullParser.END_TAG, null, COEF_FIELD);
      
      return coef;
  }
  
  /**
   * Lit le champ contenant la date dans le noeud "mark"
   * @param parser Le parser contenant l'InputStream
   * @return Le texte du noeud
   * @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;
  }
  
  /**
   * Lit le champ contenant les informations ? propos de l'examen dans le noeud "mark"
   * @param parser
   * @return
   * @throws XmlPullParserException
   * @throws IOException
   */
  private String readInfo(XmlPullParser parser) throws XmlPullParserException, IOException{
    parser.require(XmlPullParser.START_TAG, null, INFO_FIELD);
    String info = readText(parser);
      parser.require(XmlPullParser.END_TAG, null, INFO_FIELD);
      
      return info;
  }

}




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