package sonos;
import java.io.IOException;
import java.io.StringReader;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
import common.TrackMetaData;
public class XMLParser {
public synchronized static TrackMetaData parseTrackMetaData(String xml){
String title;
String album;
String duration; // not necessary?
String id; // id
String parentId; //parentID
String resource = "";
String streamContent;//<r:streamContent>
String albumArtUri;///upnp:albumArtURI>
String upnpClass;
String creator;
String albumArtist;//<r:albumArtist
String playDate;
int i = xml.indexOf("duration");
int k = 0;
// System.out.println(i+" "+k);
duration = xml.substring(i+12,i+17);
//System.out.println(duration);
i = xml.indexOf("id");
// System.out.println(i+" "+k);
if (i>-1)
id = xml.substring(i+4,i+6);
else
id="";
//System.out.println(id);
i = xml.indexOf("parentID");
// System.out.println(i+" "+k);
if (i>-1)
parentId = xml.substring(i+10,i+12);
else
parentId="";
//System.out.println(parentId);
i = xml.indexOf("<dc:title>");
k = xml.indexOf("</dc:title>");
// System.out.println(i+" "+k);
if (i>-1 && k>-1)
title = xml.substring(i+10, k);
else
title="";
//System.out.println(title);
i= xml.indexOf("<dc:creator>");
k = xml.indexOf("</dc:creator>");
// System.out.println(i+" "+k);
if (i>-1 && k>-1)
creator = xml.substring(i+12,k);
else
creator="";
//System.out.println(creator);
i= xml.indexOf("<upnp:album>");
k = xml.indexOf("</upnp:album>");
// System.out.println(i+" "+k);
if (i>-1 && k>-1)
album = xml.substring(i+12,k);
else
album="";
//System.out.println(album);
i= xml.indexOf("<upnp:class>");
k = xml.indexOf("</upnp:class>");
// System.out.println(i+" "+k);
if (i>-1 && k>-1)
upnpClass = xml.substring(i+12,k);
else
upnpClass="";
//System.out.println(upnpClass);
i= xml.indexOf("<r:albumArtist>");
k = xml.indexOf("</r:albumArtist");
// System.out.println(i+" "+k);
if (i>-1 && k>-1)
albumArtist = xml.substring(i+15,k);
else
albumArtist="";
//System.out.println(albumArtist);
i= xml.indexOf("<upnp:albumArtURI>");
k = xml.indexOf("</upnp:albumArtURI>");
// System.out.println(i+" "+k);
if (i!=-1 && k!=-1)
albumArtUri = xml.substring(i+18,k);
else
albumArtUri="";
//System.out.println(albumArtUri);
i= xml.indexOf("<r:streamContent>");
k = xml.indexOf("</r:streamContent>");
// System.out.println(i+" "+k);
if (i>-1 && k>-1)
streamContent = xml.substring(i+17,k);
else
streamContent="";
//System.out.println(streamContent);
playDate = "nodata";
TrackMetaData a = new TrackMetaData(id,parentId,resource,streamContent,albumArtUri,title,upnpClass,creator,album,albumArtist, playDate);
return a;
}
}