Android Open Source - whohasmystuff X M L Content Handler






From Project

Back to project page whohasmystuff.

License

The source code is released under:

GNU General Public License

If you think the Android project whohasmystuff 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 de.freewarepoint.whohasmystuff.database;
//ww  w .j  a  v a2  s. c o  m
import android.net.Uri;
import de.freewarepoint.whohasmystuff.LentObject;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;

public class XMLContentHandler extends DefaultHandler {

    public int databaseVersion;
    public List<LentObject> lentObjects;

    @Override
    public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
        super.startElement(uri, localName, qName, attributes);

        if ("DatabaseBackup".equals(localName)) {
            lentObjects = new LinkedList<LentObject>();
            parseDatabaseBackupAttributes(attributes);
        }
        else if ("LentObject".equals(localName)) {
            parseLentObjectAttributes(attributes);
        }
    }

    private void parseDatabaseBackupAttributes(Attributes attributes) {
        for (int i = 0; i < attributes.getLength(); i++) {
            String name = attributes.getLocalName(i);
            if ("version".equals(name)) {
                databaseVersion = Integer.parseInt(attributes.getValue(i));
            }
        }
    }

    private void parseLentObjectAttributes(Attributes attributes) {

        LentObject lentObject = new LentObject();

        for (int i = 0; i < attributes.getLength(); i++) {
            String name = attributes.getLocalName(i);
            if ("description".equals(name)) {
                lentObject.description = attributes.getValue(i);
            }
            else if ("type".equals(name)) {
                lentObject.type = Integer.parseInt(attributes.getValue(i));
            }
            else if ("date".equals(name)) {
                lentObject.date = new Date(Long.parseLong(attributes.getValue(i)));
            }
            else if ("modificationDate".equals(name)) {
                lentObject.modificationDate = new Date(Long.parseLong(attributes.getValue(i)));
            }
            else if ("personName".equals(name)) {
                lentObject.personName = attributes.getValue(i);
            }
            else if ("personKey".equals(name)) {
                lentObject.personKey = attributes.getValue(i);
            }
            else if ("returned".equals(name)) {
                lentObject.returned = (Integer.parseInt(attributes.getValue(i)) == 1);
            }
            else if ("calendarEvent".equals(name)) {
                lentObject.calendarEventURI = Uri.parse(attributes.getValue(i));
            }
        }

        if (databaseVersion < 4) {
            lentObject.modificationDate = lentObject.date;
        }

        lentObjects.add(lentObject);

    }


}




Java Source Code List

de.freewarepoint.whohasmystuff.AbstractListFragment.java
de.freewarepoint.whohasmystuff.AddObject.java
de.freewarepoint.whohasmystuff.DatePickerFragment.java
de.freewarepoint.whohasmystuff.LentObject.java
de.freewarepoint.whohasmystuff.ListLentObjects.java
de.freewarepoint.whohasmystuff.MainActivity.java
de.freewarepoint.whohasmystuff.ShowHistory.java
de.freewarepoint.whohasmystuff.database.DatabaseHelper.java
de.freewarepoint.whohasmystuff.database.OpenLendDbAdapter.java
de.freewarepoint.whohasmystuff.database.XMLContentHandler.java