ArtistAlbumsXMLHandler.java :  » App » gone-to-get » pt » gtg » musicinfo » lastfm » xml » Android Open Source

Android Open Source » App » gone to get 
gone to get » pt » gtg » musicinfo » lastfm » xml » ArtistAlbumsXMLHandler.java
/**
 * 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.ArtistAlbumDataEntry;
import pt.gtg.musicinfo.data.DataEntry;



public class ArtistAlbumsXMLHandler extends LastfmXMLHandler
{

  private List<DataEntry> albums;
  private ArtistAlbumDataEntry albumDataSet = null;
//  private String position = "";
  private String artist = "";

  @Override
  protected void init()
  {
    this.albums = new Vector<DataEntry>();
  }

  public List<DataEntry> getParsedData() 
  {
    return this.albums;
  }
  
  @Override
  protected void startElementExtra(String namespaceURI, String localName,
    String qName, Attributes attrs)
    throws SAXException
  {
    if (localName.equals("album")) {
      albumDataSet = new ArtistAlbumDataEntry();
      albumDataSet.setArtistName(artist);
    }
    if (localName.equals("image")) {
      position = position.concat("." + attrs.getValue("size")); 
    }
    if (localName.equals("topalbums")) {
      artist = attrs.getValue("artist"); 
    }
  }
  
  @Override
  protected void endElementExtra(String namespaceURI, String localName,
    String qName)
  {
    if (localName.equals("album")) {
      albums.add(albumDataSet);
    }
  }

  /** 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.topalbums.album.name")==0){
      albumDataSet.setAlbumName(text);
    } else if(position.compareTo(".lfm.topalbums.album.mbid")==0){
      albumDataSet.setMbid(text);
    } else if(position.compareTo(".lfm.artist.image.small")==0){
      albumDataSet.setImage_small(text);
    } else if(position.compareTo(".lfm.artist.image.medium")==0){
      albumDataSet.setImage_medium(text);
    } else if(position.compareTo(".lfm.artist.image.large")==0){
      albumDataSet.setImage_large(text);
    } else if(position.compareTo(".lfm.artist.image.extralarge")==0){
      albumDataSet.setImage_extralarge(text);
    } 
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.