org.springframework.extensions.webscripts
Class LocalFileSystemStore

java.lang.Object
  extended by org.springframework.extensions.webscripts.AbstractStore
      extended by org.springframework.extensions.webscripts.LocalFileSystemStore
All Implemented Interfaces:
Store, org.springframework.web.context.ServletContextAware
Direct Known Subclasses:
WebApplicationStore

public class LocalFileSystemStore
extends AbstractStore
implements org.springframework.web.context.ServletContextAware

Simple implementation of a local store file system. This is extremely light weight and is used as a base case for comparing other store performance vs. the local file system.

Author:
muzquiano

Nested Class Summary
protected  class LocalFileSystemStore.LocalFileSystemStoreScriptLoader
          Local File System Store implementation of a Script Loader
 
Constructor Summary
LocalFileSystemStore()
           
 
Method Summary
 void createDocument(String documentPath, String content)
          Creates a document.
 boolean exists()
          Determines whether the store actually exists
protected  void gatherAbsolutePaths(String absPath, List<String> list)
           
 String[] getAllDocumentPaths()
          Gets the paths of all documents in this store
 String getBasePath()
          Gets the base path of the store
 String[] getDescriptionDocumentPaths()
          Gets the paths of all Web Script description documents in this store
 InputStream getDocument(String documentPath)
          Gets a document
 String[] getDocumentPaths(String path, boolean includedSubPaths, String documentPattern)
          Gets the paths of given document pattern within given path/sub-paths in this store
protected  String[] getDocumentPathsByRegEx(String path, String regexPattern, boolean traverseChildren)
          Performs a pattern filter look up using a regex and starting from a given path.
 String getPath()
           
 String getRealPath(String path)
          Helper function for converting a web application path to a real system path.
 String getRoot()
           
protected  File getRootDir()
           
 String[] getScriptDocumentPaths(WebScript script)
          Gets the paths of all implementation files for a given Web Script
 ScriptLoader getScriptLoader()
          Gets the script loader for this store
 javax.servlet.ServletContext getServletContext()
           
 freemarker.cache.TemplateLoader getTemplateLoader()
          Gets the template loader for this store
 boolean hasDocument(String documentPath)
          Determines if the document exists.
 void init()
          Initialise Store (called once)
 boolean isSecure()
          Returns true if this store is considered secure - i.e.
 long lastModified(String documentPath)
          Gets the last modified timestamp for the document.
 boolean removeDocument(String documentPath)
          Removes an existing document.
 void setPath(String path)
           
 void setRoot(String root)
           
 void setServletContext(javax.servlet.ServletContext servletContext)
           
protected  String toAbsolutePath(String documentPath)
          Returns the absolute path relative to the root of the store given a particular document path.
 void updateDocument(String documentPath, String content)
          Updates an existing document.
 
Methods inherited from class org.springframework.extensions.webscripts.AbstractStore
getDocumentPaths, getPreviewContext, setPreviewContextProvider
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocalFileSystemStore

public LocalFileSystemStore()
Method Detail

setServletContext

public void setServletContext(javax.servlet.ServletContext servletContext)
Specified by:
setServletContext in interface org.springframework.web.context.ServletContextAware

getServletContext

public javax.servlet.ServletContext getServletContext()

getRootDir

protected File getRootDir()

setRoot

public void setRoot(String root)
Parameters:
root - the root path

getRoot

public String getRoot()

setPath

public void setPath(String path)
Parameters:
path - the relative path to set

getPath

public String getPath()

init

public void init()
Description copied from interface: Store
Initialise Store (called once)

Specified by:
init in interface Store

isSecure

public boolean isSecure()
Description copied from interface: Store
Returns true if this store is considered secure - i.e. on the app-server classpath. Scripts in secure stores can be run under the identity of a declared user (via the runas attribute) rather than the authenticated user.

Specified by:
isSecure in interface Store
Returns:
true if this store is considered secure

exists

public boolean exists()
Description copied from interface: Store
Determines whether the store actually exists

Specified by:
exists in interface Store
Returns:
true => it does exist

hasDocument

public boolean hasDocument(String documentPath)
Description copied from interface: Store
Determines if the document exists.

Specified by:
hasDocument in interface Store
Parameters:
documentPath - document path
Returns:
true => exists, false => does not exist

lastModified

public long lastModified(String documentPath)
                  throws IOException
Description copied from interface: Store
Gets the last modified timestamp for the document.

Specified by:
lastModified in interface Store
Parameters:
documentPath - document path to an existing document
Returns:
last modified timestamp
Throws:
IOException - if the document does not exist in the store

updateDocument

public void updateDocument(String documentPath,
                           String content)
                    throws IOException
Description copied from interface: Store
Updates an existing document.

Specified by:
updateDocument in interface Store
Parameters:
documentPath - document path
content - content to update the document with
Throws:
IOException - if the document does not exist or the update fails

removeDocument

public boolean removeDocument(String documentPath)
                       throws IOException
Description copied from interface: Store
Removes an existing document.

Specified by:
removeDocument in interface Store
Parameters:
documentPath - document path
Returns:
whether the operation succeeded
Throws:
IOException - if the document does not exist or the remove fails

createDocument

public void createDocument(String documentPath,
                           String content)
                    throws IOException
Description copied from interface: Store
Creates a document.

Specified by:
createDocument in interface Store
Parameters:
documentPath - document path
content - content of the document to write
Throws:
IOException - if the document already exists or the create fails

getDocument

public InputStream getDocument(String documentPath)
                        throws IOException
Description copied from interface: Store
Gets a document

Specified by:
getDocument in interface Store
Parameters:
documentPath - document path
Returns:
input stream onto document
Throws:
IOException - if the document does not exist in the store

getAllDocumentPaths

public String[] getAllDocumentPaths()
Description copied from interface: Store
Gets the paths of all documents in this store

Specified by:
getAllDocumentPaths in interface Store
Returns:
array of all document paths

getDocumentPaths

public String[] getDocumentPaths(String path,
                                 boolean includedSubPaths,
                                 String documentPattern)
Description copied from interface: Store
Gets the paths of given document pattern within given path/sub-paths in this store

Specified by:
getDocumentPaths in interface Store
Parameters:
path - start path
includedSubPaths - if true, include sub-paths
documentPattern - document name, allows wildcards, eg. *.ftl or my*.ftl
Returns:
array of document paths

getDocumentPathsByRegEx

protected String[] getDocumentPathsByRegEx(String path,
                                           String regexPattern,
                                           boolean traverseChildren)
Performs a pattern filter look up using a regex and starting from a given path. Returns an array of valid document paths

Parameters:
path -
regexPattern -
traverseChildren -
Returns:
document paths

getDescriptionDocumentPaths

public String[] getDescriptionDocumentPaths()
Description copied from interface: Store
Gets the paths of all Web Script description documents in this store

Specified by:
getDescriptionDocumentPaths in interface Store
Returns:
array of description document paths

getScriptDocumentPaths

public String[] getScriptDocumentPaths(WebScript script)
Description copied from interface: Store
Gets the paths of all implementation files for a given Web Script

Specified by:
getScriptDocumentPaths in interface Store
Parameters:
script - web script
Returns:
array of implementation document paths

getScriptLoader

public ScriptLoader getScriptLoader()
Description copied from interface: Store
Gets the script loader for this store

Specified by:
getScriptLoader in interface Store
Returns:
script loader

getTemplateLoader

public freemarker.cache.TemplateLoader getTemplateLoader()
Description copied from interface: Store
Gets the template loader for this store

Specified by:
getTemplateLoader in interface Store
Returns:
template loader

getBasePath

public String getBasePath()
Description copied from interface: Store
Gets the base path of the store

Specified by:
getBasePath in interface Store
Returns:
base path

getRealPath

public String getRealPath(String path)
Helper function for converting a web application path to a real system path. The input path might be /products/product.xml and the generated real path would be the full system path to the file in the servlet container's web application. For example, d:/tomcat/webapps/surf/products/product.xml

Parameters:
path - the relative path
Returns:
the system path

toAbsolutePath

protected String toAbsolutePath(String documentPath)
Returns the absolute path relative to the root of the store given a particular document path.

Parameters:
documentPath -
Returns:

gatherAbsolutePaths

protected void gatherAbsolutePaths(String absPath,
                                   List<String> list)


Copyright © 2009 SpringSource, Inc. All Rights Reserved.