org.lyra.LastDotFm
Class Demarcation

java.lang.Object
  extended by org.lyra.LastDotFm.Demarcation

public class Demarcation
extends java.lang.Object

Wraps the Sender class with XML parsing in order to hide much of the complexity associated with integration of the Last.fm service with Lyra itself. All of the details are hidden in the individual methods.

For example:

Parser query = Parser.getInstance(Logger, Global, Lang); string token = query.getToken();

Since:
1.0.1
Version:
1.0.5, %Revision, 174%, %LastChangedDate, 27/10/12 3:33PM%
Author:
Martin Foster
See Also:
Sender

Field Summary
private static java.lang.String CLASS
           
private  java.util.Map<java.lang.String,java.lang.String> Global
           
private  java.util.Map<java.lang.String,java.lang.String> Lang
           
private  Ledger Logger
           
private static Demarcation OnesSelf
           
private  Sender Request
           
private  javax.xml.xpath.XPath Search
           
 
Constructor Summary
private Demarcation(Ledger logger, java.util.Map<java.lang.String,java.lang.String> global, java.util.Map<java.lang.String,java.lang.String> lang)
          Base constructor for class.
 
Method Summary
 java.util.Map<java.lang.String,java.lang.String> extracAuthSession(java.lang.String token)
          Fetch a session key for a user.
 java.lang.String extracAuthToken()
          Fetch an unauthorised request token for an API account.
 java.lang.String extractAlbumInfo_Art(java.lang.String album, java.lang.String artist)
          Captures the album covert art used based on an album name and artist name combination.
 java.util.Map<java.lang.String,java.lang.Object> extractAlbumInfo(java.lang.String album, java.lang.String artist, java.lang.String lcode)
          Captures the album covert art used based on an album name and artist name combination.
 java.lang.String extractArtistInfo_Art(java.lang.String artist)
          Captures the artist photograph used as an alternate to album art covers when they cannot be found.
 java.util.Map<java.lang.String,java.lang.Object> extractArtistInfo(java.lang.String artist, java.lang.String lcode)
          Captures the album covert art used based on an album name and artist name combination.
static Demarcation getInstance(Ledger logger, java.util.Map<java.lang.String,java.lang.String> global, java.util.Map<java.lang.String,java.lang.String> lang)
          This integration is a bit different then many of the others.
private  java.util.Map<java.lang.String,java.lang.String> getMultiple(java.lang.String search, java.util.Map<java.lang.String,java.lang.String> params)
          Extracts all of the elements from a node and transfers it into a map in order to pass multi-value elements over.
private  java.lang.String getSingle(java.lang.String search, java.util.Map<java.lang.String,java.lang.String> params)
          Hides the recurring code that tends to exist when making single element searches.
private  org.xml.sax.InputSource getSource(java.lang.String reply)
          XPath has an aversion to dealing with a string based document.
private  java.lang.String getString(java.lang.String encoded)
          Some of the strings will contain elements which are encoded in order to avoid conflicts with the XML document.
private  boolean isParsableToInt(java.lang.String number)
          Here we attempt to determine if there is an actual number to be dealt with.
private  java.lang.String isProperTrack(java.lang.String trackno)
          Track numbers are more complicated elements as they sometimes come in a different format.
 void transmitPlaylistCreate(java.util.List<java.util.Map<java.lang.String,java.lang.String>> playlist, java.lang.String identifier)
          Creates a playlist and passes on all of the associated songs to the Last.fm service.
 void transmitTrackScrobble(java.lang.Long start, java.lang.String track, java.lang.String artist, java.lang.String album, java.lang.String trackno, java.lang.String duration)
          This is the second component that is to be sent when a track has reached a certain point.
 void transmitTrackScrobble(java.lang.String track, java.lang.String artist, java.lang.String album, java.lang.String trackno, java.lang.String duration)
          This is the second component that is to be sent when a track has reached a certain point.
 void transmitUpdateNowPlaying(java.lang.String track, java.lang.String artist, java.lang.String album, java.lang.String trackno, java.lang.String duration)
          Sends off a notice that a certain track is being played on our Last.fm integrated client.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

Logger

private Ledger Logger

Global

private java.util.Map<java.lang.String,java.lang.String> Global

Lang

private java.util.Map<java.lang.String,java.lang.String> Lang

Request

private Sender Request

Search

private javax.xml.xpath.XPath Search

OnesSelf

private static Demarcation OnesSelf

CLASS

private static final java.lang.String CLASS
See Also:
Constant Field Values
Constructor Detail

Demarcation

private Demarcation(Ledger logger,
                    java.util.Map<java.lang.String,java.lang.String> global,
                    java.util.Map<java.lang.String,java.lang.String> lang)
Base constructor for class.

Parameters:
logger - Ledger instance for logging.
global - Global settings map.
lang - Language dependent map.
Method Detail

getInstance

public static Demarcation getInstance(Ledger logger,
                                      java.util.Map<java.lang.String,java.lang.String> global,
                                      java.util.Map<java.lang.String,java.lang.String> lang)
This integration is a bit different then many of the others. Completely optional it may never be used, or it may be employed at multiple locations this will permit us to only have one instance instead of many.

Parameters:
logger - Ledger instance for logging.
global - Global settings map.
lang - Language dependent map.
Returns:
org.lyra.LastDotFm.Parser

getSource

private org.xml.sax.InputSource getSource(java.lang.String reply)
XPath has an aversion to dealing with a string based document. This can be a problem when that is the way we get information from the service.

Parameters:
reply - String containing XML reply.
Returns:
Instance of InputSource.

getString

private java.lang.String getString(java.lang.String encoded)
Some of the strings will contain elements which are encoded in order to avoid conflicts with the XML document. This will make the string usable.

Parameters:
encoded - String encoded in XML document.
Returns:
String decoded from XML document.

isParsableToInt

private boolean isParsableToInt(java.lang.String number)
Here we attempt to determine if there is an actual number to be dealt with. If this is not the case, then we notify the caller of the bad number.

Parameters:
number - String containing a potential number.
Returns:
Boolean of result.

isProperTrack

private java.lang.String isProperTrack(java.lang.String trackno)
Track numbers are more complicated elements as they sometimes come in a different format. This will handle the actual guess work.

Parameters:
trackno - String containing a track number.
Returns:
String containing what we expect for track numbers or null.

getSingle

private java.lang.String getSingle(java.lang.String search,
                                   java.util.Map<java.lang.String,java.lang.String> params)
Hides the recurring code that tends to exist when making single element searches. All we do is pass on the Map in order to proceed.

Parameters:
search - String containing XPath search.
params - Map containing parameter string to pass on.
Returns:
String containing reply.

getMultiple

private java.util.Map<java.lang.String,java.lang.String> getMultiple(java.lang.String search,
                                                                     java.util.Map<java.lang.String,java.lang.String> params)
Extracts all of the elements from a node and transfers it into a map in order to pass multi-value elements over.

Parameters:
search - String containing XPath search.
params - Map containing parameter string to pass on.
Returns:
Map containing response.

extractAlbumInfo_Art

public java.lang.String extractAlbumInfo_Art(java.lang.String album,
                                             java.lang.String artist)
Captures the album covert art used based on an album name and artist name combination.

Parameters:
album - String containing album cover.
artist - String containing artist name.
Returns:
String containing link to the desired cover.

extractAlbumInfo

public java.util.Map<java.lang.String,java.lang.Object> extractAlbumInfo(java.lang.String album,
                                                                         java.lang.String artist,
                                                                         java.lang.String lcode)
Captures the album covert art used based on an album name and artist name combination.

Parameters:
album - String containing album cover.
artist - String containing artist name.
lcode - Two letter language code.
Returns:
Complex map containing consolidated results.

extractArtistInfo_Art

public java.lang.String extractArtistInfo_Art(java.lang.String artist)
Captures the artist photograph used as an alternate to album art covers when they cannot be found.

Parameters:
artist - String containing artist name.
Returns:
String containing link to the desired image.

extractArtistInfo

public java.util.Map<java.lang.String,java.lang.Object> extractArtistInfo(java.lang.String artist,
                                                                          java.lang.String lcode)
Captures the album covert art used based on an album name and artist name combination.

Parameters:
artist - String containing artist name.
lcode - Two letter language code.
Returns:
Complex map containing consolidated results.

extracAuthSession

public java.util.Map<java.lang.String,java.lang.String> extracAuthSession(java.lang.String token)
Fetch a session key for a user. The third step in the authentication process. See the authentication how-to for more information.

Parameters:
token - Generated token used to link session.
Returns:
Map containing session information.

extracAuthToken

public java.lang.String extracAuthToken()
Fetch an unauthorised request token for an API account. This is step 2 of the authentication process for desktop applications. Web applications do not need to use this service.

Returns:
String containing token.

transmitUpdateNowPlaying

public void transmitUpdateNowPlaying(java.lang.String track,
                                     java.lang.String artist,
                                     java.lang.String album,
                                     java.lang.String trackno,
                                     java.lang.String duration)
Sends off a notice that a certain track is being played on our Last.fm integrated client.

Parameters:
track - String with track title.
artist - String with artist name.
album - String with album name (optional).
trackno - String with track number (optional).
duration - String with duration in seconds (optional).

transmitTrackScrobble

public void transmitTrackScrobble(java.lang.Long start,
                                  java.lang.String track,
                                  java.lang.String artist,
                                  java.lang.String album,
                                  java.lang.String trackno,
                                  java.lang.String duration)
This is the second component that is to be sent when a track has reached a certain point. So we throw this in at the end of a song play in order to meet most of their terms.

Parameters:
start - Long value containing start time.
track - String with track title.
artist - String with artist name.
album - String with album name (optional).
trackno - String with track number (optional).
duration - String with duration in seconds (optional).

transmitTrackScrobble

public void transmitTrackScrobble(java.lang.String track,
                                  java.lang.String artist,
                                  java.lang.String album,
                                  java.lang.String trackno,
                                  java.lang.String duration)
This is the second component that is to be sent when a track has reached a certain point. So we throw this in at the end of a song play in order to meet most of their terms.

Parameters:
track - String with track title.
artist - String with artist name.
album - String with album name (optional).
trackno - String with track number (optional).
duration - String with duration in seconds (optional).

transmitPlaylistCreate

public void transmitPlaylistCreate(java.util.List<java.util.Map<java.lang.String,java.lang.String>> playlist,
                                   java.lang.String identifier)
Creates a playlist and passes on all of the associated songs to the Last.fm service. Since there is no inherent way to remove and modify lists, this is mostly considered a 'copy' command and not heavily integrated into Lyra.

Parameters:
playlist - A list of all songs in the playlist.
identifier - A string containing the identifier for the list.