}
public static void fromXMLElement(XMLElement playlistElement, Store store, Playlist playlist) throws DespotifyException {
/* Get "change" element. */
XMLElement changeElement = playlistElement.getChild("next-change").getChild("change");
/* Set author. */
playlist.author = changeElement.getChildText("user");
/* Set name. */
playlist.name = changeElement.getChild("ops").getChildText("name");
/* Get items (comma separated list). */
if (changeElement.getChild("ops").hasChild("add")) {
String items = changeElement.getChild("ops").getChild("add").getChildText("items");
if (playlist.tracks == null) {
playlist.tracks = new ArrayList<Track>();
}
/* Add track items. */
int position = 0;
String[] split = items.split(",");
List<Track> tracks = new ArrayList<Track>(split.length);
for (String trackData : split) {
trackData = trackData.trim();
final String trackHexUUID;
if (trackData.length() != 34) {
if (SpotifyURI.isHex(trackData)) {
// not sure why playlist UUID is send sometimes. notice it is lacking UUID prefix byte
if (!trackData.equals(playlist.getId())) {
throw new DespotifyException("32 byte hex UUID does not equal the playlist UUID!");
}
continue;
} else {
throw new RuntimeException(trackData + " is not a valid 32 byte hex UUID!");
}
} else if (trackData.length() == 34) {
trackHexUUID = trackData.substring(0, 32);
if (!"01".equals(trackData.substring(32, 34))) {
throw new DespotifyException("Expected hex UUID type suffix 01, got " + trackData.substring(32, 34));
}
} else {
throw new RuntimeException("track UUID was not 16+1 or 16 byte!");
}
Track track = store.getTrack(trackHexUUID);
tracks.add(track);
position++; // todo perhaps we should use this to syncronize any discrepancy
}
playlist.setTracks(tracks);
}
/* Get "version" element. */
XMLElement versionElement = playlistElement.getChild("next-change").getChild("version");
/* Split version string into parts. */
String[] parts = versionElement.getText().split(",", 4);
/* Set values. */
String[] versionTagValues = versionElement.getText().split(",", 4);
playlist.setRevision(Long.parseLong(versionTagValues[0]));
playlist.setChecksum(Long.parseLong(versionTagValues[2]));
playlist.collaborative = (Integer.parseInt(parts[3]) == 1);