CatNiP -test sprint-4-interim
catnip
IMSLPQueryHelper Class Reference

#import <IMSLPQueryHelper.h>

List of all members.

Public Member Functions

(id) - initWithCategory:intoArray:
(void) - startCategoryFetch
(id) - initWithTitle:
(void) - startPageFetch
(void) - startDownload

Static Public Member Functions

(BOOL) + readIMSLPCategory:reportTo:withMethod:
(BOOL) + readIMSLPPage:composerName:reportTo:withMethod:
(BOOL) + readIMSLPFile:ofComposition:reportTo:withMethod:
(BOOL) + abortAllReads
(NSString *) + imslpAPIURL
(void) + setImslpAPIURL:
(NSString *) + imslpFetchURL
(void) + setImslpFetchURL:
(NSString *) + imslpFileURL
(void) + setImslpFileURL:

Properties

NSString * categoryName
NSString * composerName
NSMutableArray * targetArray
NSString * pageTitle
BOOL working
SEL targetMethod
id targetObject
BOOL stopRequested
IMSLPCompositionDatathisComposition

Detailed Description

IMSLPQueryHelper.m

A combination of factory methods and helper object instance methods which facilitate the reading of data from the Internet Music Score Library Project, a MediaWiki site containing music scores.

The query helper objects currently utilize three different types of query objects to fetch data from IMSLP. MediaWikiCategoryQuery instances are used to fetch category (XML) data from IMSLP (ie. lists of composers and lists of compositions by composer). MediaWikiPageQuery instances are used to fetch information from a single composition (ie. the list of music scores). Finally MediaWikiDownload instances are used to fetch an actual music score file.

The implementation of the query procedure is currently slightly ugly. IMSLPQueryHelper is not subclassed into different types depending on the helper object type separately, but instead has different initialization methods and different work start methods for different types of tasks. This is an "action point" for later refactoring.

Created by Antti V J Niemela, tkol on 5/30/11. Copyright 2011 University of Helsinki. All rights reserved.


Member Function Documentation

+ (BOOL) abortAllReads

Signals the need to abort all currently ongoing IMSLP read operations.

All currently ongoing IMSLP read operations will be sent a setStopRequested message, which will cause them to stop reading after their current parse is over. The data generated by the parse will not be added to the specified mutable data types.

+ (NSString *) imslpAPIURL

Static method returning the current IMSLP API url

Returns:
The current URL used to connect to the IMSLP API
+ (NSString *) imslpFetchURL

Static method returning the current IMSLP page fetch URL

Returns:
The current URL used to connect to the IMSLP API
+ (NSString *) imslpFileURL

Static method returning the current IMSLP file download URL.

Used to set the IMSLP file download URL (this time WITH the '?' GET parameter start character, if required). The filename is appended to this URL.

Returns:
The current URL used to connect to the IMSLP API
- (id) initWithCategory: (NSString*)  category
intoArray: (NSMutableArray *)  mutableArray 

init... method for the IMSLPQueryHelper worker object. Not to be called directly!

This method initializes a worker category read object used by IMSLPQueryHelper. It is not intended to be used directly, instantiation and initialization should happen through the static class methods.

Parameters:
categoryThe category to read
mutableArrayThe NSMutableArray that will receive the read category contents.
- (id) initWithTitle: (NSString*)  pTitle

init... method for the IMSLPQueryHelper worker object. Not to be called directly!

This method initializes a worker page or file read object used by IMSLPQueryHelper. It is not intended to be used directly, instantiation and initialization should happen through the static class methods.

Parameters:
pTitleThe page title or filename for the target of this operation.
+ (BOOL) readIMSLPCategory: (NSString *)  categoryName
reportTo: (id)  targetObj
withMethod: (SEL)  targetMethod 

Begin reading a category from IMSLP, writing the results into an array and report progress to the defined target object and method

The static method begins an automatic read/XML parse process which reads the named category into a private NSMutableArray. Once the read process is completed, it will send a copy of the array as a parameter to the given object and method. The helper currently does not report errors in any way other than using NSLog, so consider that a Feature To Be Added!

Remember that categories always start with "Category:" querying the compositions of "Bach, Johann Sebastian" is done with the categoryName "Category:Bach, Johann Sebastian". You need to prepend "Category:" yourself, the helper won't do it for you!

Parameters:
categoryNameThe *full name* of the category to be read from IMSLP
targetObjThe object which will receive progress reports (and error messages later)
targetMethodA selector describing the method which will be called to report progress (signature: (void)name:(id)msg, where msg is nil when a category has been partially read and a NSArray containing the category results when the read has completed. Later on it might also be a NSError* describing any error encountered.
Returns:
YES if the read process started, NO if it didn't (eg. because the named category is already actively being read).
+ (BOOL) readIMSLPFile: (NSString *)  fileName
ofComposition: (IMSLPCompositionData*)  theCompo
reportTo: (id)  targetObj
withMethod: (SEL)  targetMethod 

A factory method for downloading a file from IMSLP to local storage.

Starts an asynchronous reading process which will download the given composition score file from IMSLP to local storage. Once completed succesfully, the given object will be called in the given method with parameters describing both the local storage path of the file and the original filename.

Parameters:
fileNameThe IMSLP music score to download
reportToObject which should receive the download completion message
targetMethodMethod to call after downloading is complete. The signature for the method should be -(void)loadReport:(id)filePath :(id)originalFileName . Both parameters are NSString* objects.
Returns:
YES if the read was started, NO otherwise
+ (BOOL) readIMSLPPage: (NSString *)  pageName
composerName: (NSString *)  cName
reportTo: (id)  targetObj
withMethod: (SEL)  targetMethod 

Read a IMSLP (composition) wiki page parsing composition music scores into an IMSLPCompositionData object and report it to the object and method given.

The operation will be done asynchronously, and the factory method will return immediately with a value telling whether the read operation was started or not. Read operations against compositions which are already ongoing will not be started.

Parameters:
pageNameThe full composition name as reported by IMSLP
composerNameThe composer name (as reported by IMSLP, except without the "Category:" bit)
reportToThe object which should receive the read composition data
withMethodThe method which should be called to receive the data. The method should have a signature of -(void)name:(id)imslpObject, the imslpObject will be of type IMSLPCompositionData.
Returns:
YES if the read operation was started, NO otherwise.
+ (void) setImslpAPIURL: (NSString*)  newUrl

Static method to set the IMSLP API URL. Copies the given string.

Used to set the IMSLP full API URL (without the '?' signifying GET parameter list start), eg. [IMSLPQueryHelper setImslpAPIURL:"http://www.imslp.org/api.php"];

Parameters:
newUrlThe new URL pointing to the IMSLP API
+ (void) setImslpFetchURL: (NSString*)  newUrl

Static method to set the ISMLP page fetch URL. Copies the given string.

Used to set the ISMLP page fetch URL (without the '?' signifying GET parameter list start). eg. [IMSLPQueryHelper setImslpFetchURL:"http://www.imslp.org/index.php"];

Parameters:
newUrlThe new URL pointing to the ISMLP page display service
+ (void) setImslpFileURL: (NSString*)  newUrl

Static method to set the IMSLP file download URL. Copies the given string.

Parameters:
newUrlThe new URL pointing to the IMSLP file download service
- (void) startCategoryFetch

Starts the category query encapsulated by this worker object.

Builds a MediaWikiCategoryQuery object and starts the query.

- (void) startDownload

The starting point method for file download work. Requires that the pageTitle property, targetObject property and targetMethod property are set for succesful completion.

- (void) startPageFetch

Starts the page (composition data) read operation. Requires that the pageTitle, composerName, targetObject and targetMethod properties are set for the work to complete succesfully.


Property Documentation

- (NSString*) categoryName [read, write, copy]
- (NSString*) composerName [read, write, copy]
- (NSString*) pageTitle [read, write, copy]
- (BOOL) stopRequested [read, write, assign]
- (NSMutableArray*) targetArray [read, write, retain]
- (SEL) targetMethod [read, write, assign]

The method signature describing to which method in the target object the helper should send progress reports to. targetMethod must have a signature someMethod:(id)

- (id) targetObject [read, write, retain]

The target object which shall receive progress reports by calling the specified targetMethod

- (IMSLPCompositionData*) thisComposition [read, write, retain]
- (BOOL) working [read, write, assign]

The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Properties Defines