org.springframework.extensions.webscripts
Class JarStore

java.lang.Object
  extended by org.springframework.extensions.webscripts.AbstractStore
      extended by org.springframework.extensions.webscripts.JarStore
All Implemented Interfaces:
org.springframework.context.ApplicationContextAware, Store, org.springframework.web.context.ServletContextAware

public class JarStore
extends AbstractStore
implements Store, org.springframework.web.context.ServletContextAware, org.springframework.context.ApplicationContextAware

Read only store implementation that can be mounted against a JAR file. Works against the contents of the JAR file beginning at a specified path. This is used to prepackage assets into JAR files for ease of build and distribution into external web applications (via Maven). As with any Store, the interface methods deal principally with document paths. Document paths are assumed to be relative to the root path. In this case, all of the JAR file entries under the root path are considered to be Store contents. The paths to these jar entries are determined by combining the root path with the document path. An example of a relative path: org/alfresco/web/example/template.ftl An example of an absolute path: META-INF/org/alfresco/web/example/template.ftl Where the root path is "META-INF/"

Author:
muzquiano

Field Summary
protected  org.springframework.context.ApplicationContext applicationContext
           
protected  List<String> documents
           
protected  boolean exists
           
static String JAR_PROTOCOL
           
protected  String jarAutoDiscoveryClassPath
           
protected  String jarPath
           
protected  boolean mustExist
           
protected  String rootPath
           
protected  javax.servlet.ServletContext servletContext
           
 
Constructor Summary
JarStore()
           
 
Method Summary
 void createDocument(String documentPath, String content)
          Creates a document.
 boolean exists()
          Determines whether the store actually exists
 String[] getAllDocumentPaths()
          Gets the paths of all documents in this store
 org.springframework.context.ApplicationContext getApplicationContext()
          Gets the application context.
 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 includeSubPaths, String documentPattern)
          Gets the paths of given document pattern within given path/sub-paths in this store
 String getJarAutoDiscoveryClassPath()
          Gets the jar auto discovery class path.
protected  JarFile getJarFile()
          Gets the jar file.
 String getJarPath()
          Gets the jar path.
 String getRootPath()
          Gets the root path.
 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
 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 setAllowedResourcePaths(List<String> allowedResourcePaths)
          Sets the allowed resource paths.
 void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
          Sets the application context.
 void setJarAutoDiscoveryClassPath(String jarAutoDiscoveryClassPath)
          Sets the jar auto discovery path.
 void setJarPath(String jarPath)
          Sets the jar path.
 void setMustExist(boolean mustExist)
          Sets whether the class path must exist If it must exist, but it doesn't exist, an exception is thrown on initialisation of the store
 void setRootPath(String rootPath)
          Sets the root path
 void setServletContext(javax.servlet.ServletContext servletContext)
           
protected  String toAbsolutePath(String relativePath)
          To absolute path.
protected  String toRelativePath(String fullPath)
          To relative path.
 String toString()
           
 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, wait, wait, wait
 
Methods inherited from interface org.springframework.extensions.webscripts.Store
getDocumentPaths
 

Field Detail

JAR_PROTOCOL

public static final String JAR_PROTOCOL
See Also:
Constant Field Values

mustExist

protected boolean mustExist

exists

protected boolean exists

rootPath

protected String rootPath

jarPath

protected String jarPath

jarAutoDiscoveryClassPath

protected String jarAutoDiscoveryClassPath

documents

protected List<String> documents

servletContext

protected javax.servlet.ServletContext servletContext

applicationContext

protected org.springframework.context.ApplicationContext applicationContext
Constructor Detail

JarStore

public JarStore()
Method Detail

setAllowedResourcePaths

public void setAllowedResourcePaths(List<String> allowedResourcePaths)
Sets the allowed resource paths.

Parameters:
allowedResourcePaths - the new allowed resource paths

setServletContext

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

setApplicationContext

public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
Sets the application context.

Specified by:
setApplicationContext in interface org.springframework.context.ApplicationContextAware
Parameters:
applicationContext - the new application context

getApplicationContext

public org.springframework.context.ApplicationContext getApplicationContext()
Gets the application context.

Returns:
the application context

setJarAutoDiscoveryClassPath

public void setJarAutoDiscoveryClassPath(String jarAutoDiscoveryClassPath)
Sets the jar auto discovery path.

Parameters:
jarAutoDiscoveryPath - the new jar auto discovery path

getJarAutoDiscoveryClassPath

public String getJarAutoDiscoveryClassPath()
Gets the jar auto discovery class path.

Returns:
the jar auto discovery class path

setJarPath

public void setJarPath(String jarPath)
Sets the jar path.

Parameters:
jarPath - the new jar path

getJarPath

public String getJarPath()
Gets the jar path.

Returns:
the jar path

setRootPath

public void setRootPath(String rootPath)
Sets the root path

Parameters:
rootPath - the new root path

getRootPath

public String getRootPath()
Gets the root path.

Returns:
the root path

toRelativePath

protected String toRelativePath(String fullPath)
To relative path.

Parameters:
fullPath - the full path
Returns:
the string

toAbsolutePath

protected String toAbsolutePath(String relativePath)
To absolute path.

Parameters:
relativePath - the relative path
Returns:
the string

setMustExist

public void setMustExist(boolean mustExist)
Sets whether the class path must exist If it must exist, but it doesn't exist, an exception is thrown on initialisation of the store

Parameters:
mustExist -

getJarFile

protected JarFile getJarFile()
Gets the jar file.

Returns:
the jar file

init

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

Specified by:
init in interface Store

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

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

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

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

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

getDocumentPaths

public String[] getDocumentPaths(String path,
                                 boolean includeSubPaths,
                                 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
includeSubPaths - if true, include sub-paths
documentPattern - document name, allows wildcards, eg. *.ftl or my*.ftl
Returns:
array of document paths

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

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

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

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

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

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

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

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2009 SpringSource, Inc. All Rights Reserved.