/**
* Gone To Get Music Info
* Copyright (C) 2010 Joao Eduardo Luis, Tiago Melo
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
package pt.gtg.musicinfo.lastfm.xml;
import java.util.List;
import java.util.Vector;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import pt.gtg.musicinfo.data.DataEntry;
import pt.gtg.musicinfo.data.TrackDataEntry;
public class TracksXMLHandler
extends LastfmXMLHandler
{
private List<DataEntry> tracks;
private TrackDataEntry trackDataSet = null;
// private String position = "";
public List<DataEntry> getParsedData()
{
return this.tracks;
}
protected void init()
{
this.tracks = new Vector<DataEntry>();
this.trackDataSet = new TrackDataEntry();
}
@Override
protected void startElementExtra(String namespaceURI, String localName,
String qName, Attributes attrs)
throws SAXException
{
if (localName.equals("track")) {
trackDataSet = new TrackDataEntry();
}
}
@Override
protected void endElementExtra(String namespaceURI, String localName,
String qName)
{
if (localName.equals("track")) {
tracks.add(trackDataSet);
}
}
/** Gets be called on the following structure:
* <tag>characters</tag> */
public void characters(char ch[], int start, int length) {
String text = new String(ch, start, length);
if(position.compareTo(".lfm.playlist.trackList.track.title")==0){
trackDataSet.setName(text);
} else if(position.compareTo(".lfm.playlist.trackList.track.duration")==0){
trackDataSet.setDuration(text);
}
}
}
|