org.owasp.webscarab.model
Class FileSystemStore

java.lang.Object
  extended by org.owasp.webscarab.model.FileSystemStore
All Implemented Interfaces:
SiteModelStore

public class FileSystemStore
extends java.lang.Object
implements SiteModelStore

Author:
rdawes

Constructor Summary
FileSystemStore(java.io.File dir)
          Creates a new instance of FileSystemStore
 
Method Summary
 int addConversation(ConversationID id, java.util.Date when, Request request, Response response)
          adds a new conversation
 boolean addConversationProperty(ConversationID id, java.lang.String property, java.lang.String value)
          adds a new value to the list of values for the specified property and conversation
 boolean addCookie(Cookie cookie)
          adds a new cookie to the store
 void addUrl(HttpUrl url)
          adds an entry for the specified URL, so that subsequent calls to isKnownUrl will return true.
 boolean addUrlProperty(HttpUrl url, java.lang.String property, java.lang.String value)
          adds a new value to the list of values for the specified property and url
 void flush()
          forces the store implementation to ensure that all external representations are in a consistent state
 HttpUrl getChildAt(HttpUrl url, int index)
          returns the specified child of the URL passed.
 int getChildCount(HttpUrl url)
          returns the number of URL's that are children of the URL passed.
 ConversationID getConversationAt(HttpUrl url, int index)
          returns the ID of the conversation at position index in the list of conversations related to the supplied url.
 int getConversationCount(HttpUrl url)
          returns the number of conversations related to the url supplied
 java.lang.String[] getConversationProperties(ConversationID id, java.lang.String property)
          returns an array of strings containing the values that have been set for the specified conversation property
 java.lang.String getCookieAt(int index)
          returns a key which represents a cookie in the jar, basically "domain/path name"
 Cookie getCookieAt(java.lang.String key, int index)
          returns the cookie containing the value indicated by the key and index parameters
 int getCookieCount()
          returns the number of unique cookie names in the jar
 int getCookieCount(java.lang.String key)
          returns the number of different cookie values that have been observed for the particular cookie key
 Cookie getCurrentCookie(java.lang.String key)
          returns the most recent cookie indicated by the key parameters
 int getIndexOf(HttpUrl url)
           
 int getIndexOfConversation(HttpUrl url, ConversationID id)
          Conversations are sorted according to the natural ordering of their conversationID.
 int getIndexOfCookie(Cookie cookie)
          returns the index of the provided cookie in the list of values
 int getIndexOfCookie(java.lang.String key, Cookie cookie)
          returns the index of the provided cookie in the list of values
 Request getRequest(ConversationID id)
          Reads the requested Request class from long-term storage.
 Response getResponse(ConversationID id)
          Reads the desired Response class from long-term storage.
 java.lang.String[] getUrlProperties(HttpUrl url, java.lang.String property)
          returns an array of strings containing the values that have been set for the specified url property
static boolean isExistingSession(java.io.File dir)
           
 boolean isKnownUrl(HttpUrl url)
          returns true if the url is already existing in the store, false otherwise
 boolean removeCookie(Cookie cookie)
          removes a cookie from the store
 void setConversationProperty(ConversationID id, java.lang.String property, java.lang.String value)
          sets a value for a property, for a specific conversation
 void setRequest(ConversationID id, Request request)
          associates the specified request with the provided conversation id
 void setResponse(ConversationID id, Response response)
          associates the response with the specified conversation id
 void setUrlProperty(HttpUrl url, java.lang.String property, java.lang.String value)
          sets a value for a property, for a specific URL
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileSystemStore

public FileSystemStore(java.io.File dir)
                throws StoreException
Creates a new instance of FileSystemStore

Throws:
StoreException
Method Detail

isExistingSession

public static boolean isExistingSession(java.io.File dir)

addConversation

public int addConversation(ConversationID id,
                           java.util.Date when,
                           Request request,
                           Response response)
adds a new conversation

Specified by:
addConversation in interface SiteModelStore
Parameters:
id - the id of the new conversation
when - the date the conversation was created
request - the request to add
response - the response to add

setConversationProperty

public void setConversationProperty(ConversationID id,
                                    java.lang.String property,
                                    java.lang.String value)
sets a value for a property, for a specific conversation

Specified by:
setConversationProperty in interface SiteModelStore
Parameters:
id - the conversation ID
property - the name of the property
value - the value to set

addConversationProperty

public boolean addConversationProperty(ConversationID id,
                                       java.lang.String property,
                                       java.lang.String value)
adds a new value to the list of values for the specified property and conversation

Specified by:
addConversationProperty in interface SiteModelStore
Parameters:
id - the conversation id
property - the name of the property
value - the value to add

getConversationProperties

public java.lang.String[] getConversationProperties(ConversationID id,
                                                    java.lang.String property)
returns an array of strings containing the values that have been set for the specified conversation property

Specified by:
getConversationProperties in interface SiteModelStore
Parameters:
id - the conversation id
property - the name of the property
Returns:
the property values

addUrl

public void addUrl(HttpUrl url)
adds an entry for the specified URL, so that subsequent calls to isKnownUrl will return true.

Specified by:
addUrl in interface SiteModelStore
Parameters:
url - the url to add

isKnownUrl

public boolean isKnownUrl(HttpUrl url)
returns true if the url is already existing in the store, false otherwise

Specified by:
isKnownUrl in interface SiteModelStore
Parameters:
url - the url to test
Returns:
true if the url is already known, false otherwise

setUrlProperty

public void setUrlProperty(HttpUrl url,
                           java.lang.String property,
                           java.lang.String value)
sets a value for a property, for a specific URL

Specified by:
setUrlProperty in interface SiteModelStore
Parameters:
url - the url
property - the name of the property
value - the value to set

addUrlProperty

public boolean addUrlProperty(HttpUrl url,
                              java.lang.String property,
                              java.lang.String value)
adds a new value to the list of values for the specified property and url

Specified by:
addUrlProperty in interface SiteModelStore
Parameters:
url - the url
property - the name of the property
value - the value to add

getUrlProperties

public java.lang.String[] getUrlProperties(HttpUrl url,
                                           java.lang.String property)
returns an array of strings containing the values that have been set for the specified url property

Specified by:
getUrlProperties in interface SiteModelStore
Parameters:
url - the url
property - the name of the property
Returns:
the property values

getChildCount

public int getChildCount(HttpUrl url)
returns the number of URL's that are children of the URL passed.

Specified by:
getChildCount in interface SiteModelStore
Parameters:
url - the url
Returns:
the number of children of the supplied url.

getChildAt

public HttpUrl getChildAt(HttpUrl url,
                          int index)
returns the specified child of the URL passed.

Specified by:
getChildAt in interface SiteModelStore
Parameters:
url - the url
index - the index
Returns:
the child at position index.

getIndexOf

public int getIndexOf(HttpUrl url)
Specified by:
getIndexOf in interface SiteModelStore

getConversationCount

public int getConversationCount(HttpUrl url)
returns the number of conversations related to the url supplied

Specified by:
getConversationCount in interface SiteModelStore
Parameters:
url - the url in question, or null for all conversations
Returns:
the number of conversations related to the supplied URL

getConversationAt

public ConversationID getConversationAt(HttpUrl url,
                                        int index)
returns the ID of the conversation at position index in the list of conversations related to the supplied url. If url is null, returns the position in the total list of conversations.

Specified by:
getConversationAt in interface SiteModelStore
Parameters:
url - the url to use as a filter, or null for none
index - the position in the list
Returns:
the conversation id

getIndexOfConversation

public int getIndexOfConversation(HttpUrl url,
                                  ConversationID id)
Conversations are sorted according to the natural ordering of their conversationID. This method returns the position of the specified conversation in the list of conversations relating to the specified URL. If the URL is null, returns the position of the conversation in the overall list of conversations.

Specified by:
getIndexOfConversation in interface SiteModelStore
Parameters:
url - acts as a filter on the overall list of conversations
id - the conversation
Returns:
the position in the list, or the insertion point if it is not in the list

setRequest

public void setRequest(ConversationID id,
                       Request request)
associates the specified request with the provided conversation id

Specified by:
setRequest in interface SiteModelStore
Parameters:
id - the conversation id
request - the request

getRequest

public Request getRequest(ConversationID id)
Description copied from interface: SiteModelStore
Reads the requested Request class from long-term storage.

Specified by:
getRequest in interface SiteModelStore
Parameters:
id - The id of the specific Request
Returns:
the desired Request

setResponse

public void setResponse(ConversationID id,
                        Response response)
associates the response with the specified conversation id

Specified by:
setResponse in interface SiteModelStore
Parameters:
id - the conversation id
response - the response

getResponse

public Response getResponse(ConversationID id)
Description copied from interface: SiteModelStore
Reads the desired Response class from long-term storage.

Specified by:
getResponse in interface SiteModelStore
Parameters:
id - the id of the desired Response
Returns:
the desired Response

flush

public void flush()
           throws StoreException
Description copied from interface: SiteModelStore
forces the store implementation to ensure that all external representations are in a consistent state

Specified by:
flush in interface SiteModelStore
Throws:
StoreException - if there is any error writing the data

getCookieCount

public int getCookieCount()
Description copied from interface: SiteModelStore
returns the number of unique cookie names in the jar

Specified by:
getCookieCount in interface SiteModelStore
Returns:
the number of unique cookie names in the jar

getCookieCount

public int getCookieCount(java.lang.String key)
Description copied from interface: SiteModelStore
returns the number of different cookie values that have been observed for the particular cookie key

Specified by:
getCookieCount in interface SiteModelStore
Parameters:
key - the cookie key
Returns:
the number of cookies

getCookieAt

public java.lang.String getCookieAt(int index)
Description copied from interface: SiteModelStore
returns a key which represents a cookie in the jar, basically "domain/path name"

Specified by:
getCookieAt in interface SiteModelStore
Parameters:
index - the number of the cookie in the jar
Returns:
a key which represents a cookie in the jar, basically "domain/path name"

getCookieAt

public Cookie getCookieAt(java.lang.String key,
                          int index)
Description copied from interface: SiteModelStore
returns the cookie containing the value indicated by the key and index parameters

Specified by:
getCookieAt in interface SiteModelStore
Parameters:
key - the cookie key
index - the index. The higher the number, the more recent the cookie.
Returns:
the cookie

getCurrentCookie

public Cookie getCurrentCookie(java.lang.String key)
Description copied from interface: SiteModelStore
returns the most recent cookie indicated by the key parameters

Specified by:
getCurrentCookie in interface SiteModelStore
Parameters:
key - the cookie key
Returns:
the cookie

getIndexOfCookie

public int getIndexOfCookie(Cookie cookie)
Description copied from interface: SiteModelStore
returns the index of the provided cookie in the list of values

Specified by:
getIndexOfCookie in interface SiteModelStore
Parameters:
cookie - the cookie
Returns:
the index of the cookie

getIndexOfCookie

public int getIndexOfCookie(java.lang.String key,
                            Cookie cookie)
Description copied from interface: SiteModelStore
returns the index of the provided cookie in the list of values

Specified by:
getIndexOfCookie in interface SiteModelStore
Parameters:
key - the key
cookie - the cookie
Returns:
the index of the cookie

addCookie

public boolean addCookie(Cookie cookie)
adds a new cookie to the store

Specified by:
addCookie in interface SiteModelStore
Parameters:
cookie - the cookie to add
Returns:
true if the cookie did not previously exist in the store, false if it did.

removeCookie

public boolean removeCookie(Cookie cookie)
removes a cookie from the store

Specified by:
removeCookie in interface SiteModelStore
Parameters:
cookie - the cookie to remove
Returns:
true if the cookie was deleted, or false if it was not already in the store