jacquard 1.12.0 by The Web Engineering Factory and Toolworks

uk.co.weft.amazon
Class AmazonDescriptor

java.lang.Object
  extended byuk.co.weft.amazon.AmazonDescriptor
All Implemented Interfaces:
DataStoreDescriptor

public class AmazonDescriptor
extends java.lang.Object
implements DataStoreDescriptor

An interface to Amazon Web Services, implemented as a DataStoreDescriptor


Field Summary
protected  java.lang.String accessKeyId
          the amazon access key - you must have one to use match operations, and, furthermore, it must be your own
static java.lang.String ACCESSKEYTOKEN
          As of AWS 4.0, you need an access key instead of an associates_id
static java.lang.String AMAZON_HOST_TOKEN
          the token on which I will seek my amazon host in the configuration
static java.lang.String AMAZON_SHOP_TOKEN
          the token on which I will seek my amazon shop in the configuration
protected  java.lang.String amazonHost
          the hostname of the amazon data server we will use
protected  java.lang.String amazonShop
          the hostname of the amazon shop we will use
static java.lang.String ASSOCIATES_ID_TOKEN
          Deprecated. obsoleted by AWS v4
protected  java.lang.String associatesId
          Deprecated. obsoleted by AWS v4
protected  boolean debug
          Whether or not I'm in debug mode
static java.lang.String DEBUGCONFIGTOKEN
          A token on which I shall seek in my config whether or not to enter debugging mode
static java.lang.String DEFAULTSEARCHINDEX
          Which indexes are availale varies from Amazon store to Amazon store, unfortunately, but 'Books' is always available
static java.lang.String DETAILS_TAG
          Deprecated. obsoleted by AWS v4
protected  java.lang.String developerId
          tha amazon developer ID I will use
static java.lang.String ERROR_MSG_TAG
          Tags used in Amazon's XML: the 'ErrorMsg' (title) tag
static java.lang.String ISBN_TOKEN
          The token on which I will seek the isbn to look up in the context.
static java.lang.String ITEM_TAG
          Tags used in Amazon's XML: the 'Item' tag
static java.lang.String KEYFN
          It's becoming a convention in Jacquard that the keyfield of a store can be found on the KEYFN class constant.
protected  java.lang.String mode
          my default mode (over-ridden by the value of MODE_TOKEN in the fetch or match context
static java.lang.String MODE_HEAVY
          Deprecated. obsoleted by AWS v4
static java.lang.String MODE_LIGHT
          Deprecated. obsoleted by AWS v4
static java.lang.String MODE_TOKEN
          Deprecated. obsoleted by AWS v4
static java.lang.String PRODUCT_NAME_TAG
          Tags used in Amazon's XML: the 'ProductName' (title) tag
static java.lang.String SEARCHAUTHORTOKEN
          Amazon Web Services has a number of simple search tokens; this is the author field
static java.lang.String SEARCHINDEXTOKEN
          Amazon Web Services have a number of indexes to search
static java.lang.String SEARCHKEYWORDSTOKEN
          Amazon Web Services has a number of simple search tokens; this is the keywords field
static java.lang.String SEARCHTITLETOKEN
          Amazon Web Services has a number of simple search tokens; this is the title field
static java.lang.String SEARCHTOKENPREFIX
          To avoid namespace clashes, we'll prefix the Amazon search tokens in the context with a prefix
static java.lang.String SHOPPING_URL_TOKEN
          the token on which I will store the 'shopping URL' in the returned context
 
Constructor Summary
AmazonDescriptor(Context config)
          initialise me with the data values in this context
 
Method Summary
 java.net.URL composeShoppingURL(java.lang.String isbn)
          compose a suitable 'shopping' URL for this ISBN
 void drop(Context c, java.lang.Object key)
          can't do this; perhaps later could but that requires understanding Amazon's inventory system
 int fetch(Context context)
          fetch details of the item whose ISBN/ASIN is passed as key; results return in the context
 int fetch(Context context, java.lang.Object key)
          fetch details of the item whose ISBN/ASIN is passed as key; results return in the context
static void main(java.lang.String[] args)
          Test harness only - don't expect this to be useful in practice
 Contexts match(Context c)
          Fetch all the records from the data store described by this descriptor, which match the values contained in this context
 Contexts match(Context context, boolean exact)
          return all items in Amazon which match the criteria.
static java.lang.String normaliseISBN(java.lang.String isbn)
          Clean up this ISBN into the format that Amazon prefers - i.e.
protected  Context parseItemRecord(Node item)
          parse an Item node returned by Amazon Web Services and return it as a context
 java.lang.Object store(Context c)
          can't do this; perhaps later could but that requires understanding Amazon's inventory system
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SEARCHTOKENPREFIX

public static final java.lang.String SEARCHTOKENPREFIX
To avoid namespace clashes, we'll prefix the Amazon search tokens in the context with a prefix

See Also:
Constant Field Values

SEARCHAUTHORTOKEN

public static final java.lang.String SEARCHAUTHORTOKEN
Amazon Web Services has a number of simple search tokens; this is the author field

See Also:
Constant Field Values

SEARCHTITLETOKEN

public static final java.lang.String SEARCHTITLETOKEN
Amazon Web Services has a number of simple search tokens; this is the title field

See Also:
Constant Field Values

SEARCHKEYWORDSTOKEN

public static final java.lang.String SEARCHKEYWORDSTOKEN
Amazon Web Services has a number of simple search tokens; this is the keywords field

See Also:
Constant Field Values

SEARCHINDEXTOKEN

public static final java.lang.String SEARCHINDEXTOKEN
Amazon Web Services have a number of indexes to search

See Also:
Constant Field Values

DEFAULTSEARCHINDEX

public static final java.lang.String DEFAULTSEARCHINDEX
Which indexes are availale varies from Amazon store to Amazon store, unfortunately, but 'Books' is always available

See Also:
Constant Field Values

MODE_LIGHT

public static final java.lang.String MODE_LIGHT
Deprecated. obsoleted by AWS v4

Amazon web services search results come in two formats: 'light' and 'heavy'

See Also:
Constant Field Values

MODE_HEAVY

public static final java.lang.String MODE_HEAVY
Deprecated. obsoleted by AWS v4

Amazon web services search results come in two formats: 'light' and 'heavy'

See Also:
Constant Field Values

MODE_TOKEN

public static final java.lang.String MODE_TOKEN
Deprecated. obsoleted by AWS v4

The token on which I will seek my default mode in the configuration, and my per-service mode in the context. Value must be one of 'light' or 'heavy'

See Also:
Constant Field Values

AMAZON_HOST_TOKEN

public static final java.lang.String AMAZON_HOST_TOKEN
the token on which I will seek my amazon host in the configuration

See Also:
Constant Field Values

AMAZON_SHOP_TOKEN

public static final java.lang.String AMAZON_SHOP_TOKEN
the token on which I will seek my amazon shop in the configuration

See Also:
Constant Field Values

SHOPPING_URL_TOKEN

public static final java.lang.String SHOPPING_URL_TOKEN
the token on which I will store the 'shopping URL' in the returned context

See Also:
Constant Field Values

ISBN_TOKEN

public static final java.lang.String ISBN_TOKEN
The token on which I will seek the isbn to look up in the context. ISBN is effectively the 'key field' in this store. Note that the value may be an ISBN or an ASIN code.

See Also:
Constant Field Values

KEYFN

public static final java.lang.String KEYFN
It's becoming a convention in Jacquard that the keyfield of a store can be found on the KEYFN class constant. Conventions are good.

See Also:
Constant Field Values

DETAILS_TAG

public static final java.lang.String DETAILS_TAG
Deprecated. obsoleted by AWS v4

Tags used in Amazon's XML: the 'Details' tag

See Also:
Constant Field Values

ITEM_TAG

public static final java.lang.String ITEM_TAG
Tags used in Amazon's XML: the 'Item' tag

See Also:
Constant Field Values

PRODUCT_NAME_TAG

public static final java.lang.String PRODUCT_NAME_TAG
Tags used in Amazon's XML: the 'ProductName' (title) tag

See Also:
Constant Field Values

ERROR_MSG_TAG

public static final java.lang.String ERROR_MSG_TAG
Tags used in Amazon's XML: the 'ErrorMsg' (title) tag

See Also:
Constant Field Values

ASSOCIATES_ID_TOKEN

public static final java.lang.String ASSOCIATES_ID_TOKEN
Deprecated. obsoleted by AWS v4

The token on which I will seek my amazon associates ID in the configuration

See Also:
Constant Field Values

ACCESSKEYTOKEN

public static final java.lang.String ACCESSKEYTOKEN
As of AWS 4.0, you need an access key instead of an associates_id

See Also:
Constant Field Values

DEBUGCONFIGTOKEN

public static final java.lang.String DEBUGCONFIGTOKEN
A token on which I shall seek in my config whether or not to enter debugging mode

See Also:
Constant Field Values

associatesId

protected java.lang.String associatesId
Deprecated. obsoleted by AWS v4

the amazon associates ID I will use (this one's my one, so if you don't over-ride it in the config (web.xml) I will get all the money!


developerId

protected final java.lang.String developerId
tha amazon developer ID I will use

See Also:
Constant Field Values

accessKeyId

protected java.lang.String accessKeyId
the amazon access key - you must have one to use match operations, and, furthermore, it must be your own


amazonHost

protected java.lang.String amazonHost
the hostname of the amazon data server we will use


amazonShop

protected java.lang.String amazonShop
the hostname of the amazon shop we will use


mode

protected java.lang.String mode
my default mode (over-ridden by the value of MODE_TOKEN in the fetch or match context


debug

protected boolean debug
Whether or not I'm in debug mode

Constructor Detail

AmazonDescriptor

public AmazonDescriptor(Context config)
                 throws DataStoreException
initialise me with the data values in this context

Parameters:
config - a context containing my configuration values
Method Detail

composeShoppingURL

public java.net.URL composeShoppingURL(java.lang.String isbn)
                                throws java.net.MalformedURLException
compose a suitable 'shopping' URL for this ISBN

Parameters:
isbn - an ISBN number, not necessarily normalised
Returns:
the URL.
Throws:
java.net.MalformedURLException

drop

public void drop(Context c,
                 java.lang.Object key)
          throws DataStoreException
can't do this; perhaps later could but that requires understanding Amazon's inventory system

Specified by:
drop in interface DataStoreDescriptor
Throws:
DataStoreException

fetch

public int fetch(Context context)
          throws DataStoreException
fetch details of the item whose ISBN/ASIN is passed as key; results return in the context

Parameters:
context - the context in which this search is performed
Returns:
the number of possible matches found (ideally 1).
Throws:
DataStoreException

fetch

public int fetch(Context context,
                 java.lang.Object key)
          throws DataStoreException
fetch details of the item whose ISBN/ASIN is passed as key; results return in the context

Specified by:
fetch in interface DataStoreDescriptor
Parameters:
context - the context in which this search is performed
key - an object which when rendered as a string using toString() is a valid ISBN or ASIN code.
Returns:
the number of possible matches found (ideally 1).
Throws:
DataStoreException

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Test harness only - don't expect this to be useful in practice

Parameters:
args - only one understood - amazon_associates_id
Throws:
java.lang.Exception

normaliseISBN

public static java.lang.String normaliseISBN(java.lang.String isbn)
Clean up this ISBN into the format that Amazon prefers - i.e. letters and digits only

Parameters:
isbn - the unclean isbn
Returns:
the cleaned isbn

match

public Contexts match(Context c)
               throws DataStoreException
Deprecated. use match( Context,boolean)

Description copied from interface: DataStoreDescriptor
Fetch all the records from the data store described by this descriptor, which match the values contained in this context

Specified by:
match in interface DataStoreDescriptor
Throws:
DataStoreException

match

public Contexts match(Context context,
                      boolean exact)
               throws DataStoreException
return all items in Amazon which match the criteria. Potentially useful; not yet implemented.

Specified by:
match in interface DataStoreDescriptor
Parameters:
context - the context to match
exact - whether or not an exact match is required - i.e. whether or not to allow fuzzy matching of strings.
Throws:
DataStoreException

store

public java.lang.Object store(Context c)
                       throws DataStoreException
can't do this; perhaps later could but that requires understanding Amazon's inventory system

Specified by:
store in interface DataStoreDescriptor
Throws:
DataStoreException

parseItemRecord

protected Context parseItemRecord(Node item)
parse an Item node returned by Amazon Web Services and return it as a context

Parameters:
item - the node to parse
Returns:
a context containing data taken from that node

jacquard 1.12.0 by The Web Engineering Factory and Toolworks