Android Open Source - tracks-android Task Xml Handler






From Project

Back to project page tracks-android.

License

The source code is released under:

Copyright (c) 2010 Adam Wolfe Gordon <awg@xvx.ca> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to...

If you think the Android project tracks-android 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 ca.xvx.tracks;
//  w  w w .j a v a2s . c o  m
import android.util.Log;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;

public class TaskXmlHandler extends DefaultHandler {
  private static final String TAG = "TaskXmlHandler";
  
  private int _id;
  private String _description;
  private String _notes;
  private TodoContext _context;
  private Project _project;
  private Date _due;
  private Date _showFrom;
  private boolean _err;

  private final StringBuffer _text;
  private static final DateFormat DATEFORM = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");

  public TaskXmlHandler() {
    super();
    Task.clear();
    _text = new StringBuffer();
  }
  
  @Override
  public void startElement(String uri, String localName, String qName, Attributes attributes) {
    if(qName.equals("todo")) {
      _id = -1;
      _description = null;
      _notes = null;
      _context = null;
      _project = null;
      _due = null;
      _showFrom = null;
      _err = false;
    }
    _text.setLength(0);
  }

  @Override
  public void endElement(String uri, String localName, String qName) {
    if(qName.equals("todo")) {
      if(!_err) {
        try {
          new Task(_id, _description, _notes, _context, _project, _due, _showFrom);
        } catch(DuplicateTaskException e) {
          Log.w(TAG, "Tried to add the same task twice, id: " + String.valueOf(_id), e);
        }
      }
    } else if(qName.equals("id")) {
      _id = Integer.valueOf(_text.toString());
    } else if(qName.equals("description")) {
      _description = _text.toString();
    } else if(qName.equals("notes")) {
      _notes = _text.toString();
    } else if(qName.equals("context-id")) {
      _context = TodoContext.getContext(Integer.parseInt(_text.toString()));
      if(_context == null) {
        _err = true;
      }
    } else if(qName.equals("project-id")) {
      if(_text.length() > 0) {
        _project = Project.getProject(Integer.parseInt(_text.toString()));
      }
    } else if(qName.equals("due") && _text.length() > 0) {
      try {
        _due = DATEFORM.parse(_text.toString());
      } catch(ParseException e) {
        Log.w(TAG, "Unexpected date format: " + _text.toString(), e);
      }
    } else if(qName.equals("show-from") && _text.length() > 0) {
      try {
        _showFrom = DATEFORM.parse(_text.toString());
      } catch(ParseException e) {
        Log.w(TAG, "Unexpected date format: " + _text.toString(), e);
      }
    }
  }

  @Override
  public void characters(char[] ch, int start, int length) {
    _text.append(ch, start, length);
  }
}




Java Source Code List

ca.xvx.tracks.ContextEditorActivity.java
ca.xvx.tracks.ContextXmlHandler.java
ca.xvx.tracks.DuplicateContextException.java
ca.xvx.tracks.DuplicateProjectException.java
ca.xvx.tracks.DuplicateTaskException.java
ca.xvx.tracks.ProjectEditorActivity.java
ca.xvx.tracks.ProjectXmlHandler.java
ca.xvx.tracks.Project.java
ca.xvx.tracks.SettingsActivity.java
ca.xvx.tracks.TaskEditorActivity.java
ca.xvx.tracks.TaskListActivity.java
ca.xvx.tracks.TaskListAdapter.java
ca.xvx.tracks.TaskListItem.java
ca.xvx.tracks.TaskXmlHandler.java
ca.xvx.tracks.Task.java
ca.xvx.tracks.TodoContext.java
ca.xvx.tracks.TracksAction.java
ca.xvx.tracks.TracksCommunicator.java
ca.xvx.tracks.preferences.PreferenceConstants.java
ca.xvx.tracks.preferences.PreferenceUtils.java
ca.xvx.tracks.util.HttpConnection.java