Class ClassPathStore
- java.lang.Object
-
- org.springframework.extensions.webscripts.AbstractStore
-
- org.springframework.extensions.webscripts.ClassPathStore
-
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.context.ApplicationContextAware,Store
public class ClassPathStore extends AbstractStore implements org.springframework.context.ApplicationContextAware, Store
ClassPath based Web Script Store- Author:
- davidc, kevinr, muzquiano
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classClassPathStore.ClassPathTemplateLoaderClass Path Store implementation of a Template Loader Retrieves templates either from classes in the class path or classes inside of JAR files within the class pathprotected classClassPathStore.ClassPathTemplateSourceTemplate Source - loads from a Class Path Store
-
Field Summary
Fields Modifier and Type Field Description protected org.springframework.context.ApplicationContextapplicationContextprotected java.lang.StringclassPathprotected booleanexistsprotected booleanmustExistprotected ClassPathStoreResourceResolverresolverprotected java.lang.String[]storeDirsprotected static java.lang.StringVFSFILE_URL_PREFIXprotected static java.lang.StringVFSJAR_URL_SEPARATORprotected static java.lang.StringVFSWAR_CLASSES_URL_SEPARATORprotected static java.lang.StringVFSWAR_URL_SEPARATORprotected static java.lang.StringVFSZIP_URL_PREFIX-
Fields inherited from class org.springframework.extensions.webscripts.AbstractStore
DESC_PATH_PATTERN
-
-
Constructor Summary
Constructors Constructor Description ClassPathStore()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcreateDocument(java.lang.String documentPath, java.lang.String content)Creates a document.static java.lang.StringcreatePath(java.lang.String path, java.lang.String relativePath)Helper method for creating fully qualified pathsbooleanexists()Determines whether the store actually existsprotected static java.net.URLextractJarFileURL(java.net.URL jarUrl)Extract the URL for the actual jar file from the given URL (which may point to a resource in a jar file or to a jar file itself).java.lang.String[]getAllDocumentPaths()Gets the paths of all documents in this storejava.lang.StringgetBasePath()Gets the base path of the storejava.lang.String[]getDescriptionDocumentPaths()Gets the paths of all Web Script description documents in this storejava.io.InputStreamgetDocument(java.lang.String documentPath)Gets a document.java.lang.String[]getDocumentPaths(java.lang.String path, boolean includeSubPaths, java.lang.String documentPattern)Gets the paths of given document pattern within given path/sub-paths in this storejava.lang.String[]getScriptDocumentPaths(WebScript script)Gets the paths of all implementation files for a given Web ScriptScriptLoadergetScriptLoader()Gets the script loader for this storefreemarker.cache.TemplateLoadergetTemplateLoader()Gets the template loader for this storebooleanhasDocument(java.lang.String documentPath)Determines if the document exists.voidinit()Initialise Store (called once)protected static booleanisJarURL(java.net.URL url)Determine whether the given URL points to a resource in a jar file, that is, has protocol "jar", "zip", "vfszip", "wsjar" or "code-source".booleanisReadOnly()Whether the store is in read-only modebooleanisSecure()Returns true if this store is considered secure - i.e.longlastModified(java.lang.String documentPath)Gets the last modified timestamp for the document.booleanremoveDocument(java.lang.String documentPath)Removes an existing document.voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext)voidsetClassPath(java.lang.String classPath)Sets the class pathvoidsetMustExist(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 storejava.lang.StringtoString()voidupdateDocument(java.lang.String documentPath, java.lang.String content)Updates an existing document.-
Methods inherited from class org.springframework.extensions.webscripts.AbstractStore
createDocuments, getDocumentPaths, getPreviewContext, setPreviewContextProvider, setReadOnly
-
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
createDocuments, getDocumentPaths
-
-
-
-
Field Detail
-
VFSFILE_URL_PREFIX
protected static final java.lang.String VFSFILE_URL_PREFIX
- See Also:
- Constant Field Values
-
VFSZIP_URL_PREFIX
protected static final java.lang.String VFSZIP_URL_PREFIX
- See Also:
- Constant Field Values
-
VFSJAR_URL_SEPARATOR
protected static final java.lang.String VFSJAR_URL_SEPARATOR
- See Also:
- Constant Field Values
-
VFSWAR_URL_SEPARATOR
protected static final java.lang.String VFSWAR_URL_SEPARATOR
- See Also:
- Constant Field Values
-
VFSWAR_CLASSES_URL_SEPARATOR
protected static final java.lang.String VFSWAR_CLASSES_URL_SEPARATOR
- See Also:
- Constant Field Values
-
resolver
protected ClassPathStoreResourceResolver resolver
-
storeDirs
protected java.lang.String[] storeDirs
-
applicationContext
protected org.springframework.context.ApplicationContext applicationContext
-
classPath
protected java.lang.String classPath
-
mustExist
protected boolean mustExist
-
exists
protected boolean exists
-
-
Method Detail
-
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- boolean
-
setClassPath
public void setClassPath(java.lang.String classPath)
Sets the class path- Parameters:
classPath- classpath
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException- Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Throws:
org.springframework.beans.BeansException
-
init
public void init()
Description copied from interface:StoreInitialise Store (called once)
-
exists
public boolean exists()
Description copied from interface:StoreDetermines whether the store actually exists
-
getBasePath
public java.lang.String getBasePath()
Description copied from interface:StoreGets the base path of the store- Specified by:
getBasePathin interfaceStore- Returns:
- base path
-
isSecure
public boolean isSecure()
Description copied from interface:StoreReturns 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.
-
isReadOnly
public boolean isReadOnly()
Description copied from class:AbstractStoreWhether the store is in read-only mode- Specified by:
isReadOnlyin interfaceStore- Overrides:
isReadOnlyin classAbstractStore- Returns:
- boolean
-
getAllDocumentPaths
public java.lang.String[] getAllDocumentPaths()
Description copied from interface:StoreGets the paths of all documents in this store- Specified by:
getAllDocumentPathsin interfaceStore- Returns:
- array of all document paths
-
getDocumentPaths
public java.lang.String[] getDocumentPaths(java.lang.String path, boolean includeSubPaths, java.lang.String documentPattern) throws java.io.IOExceptionDescription copied from interface:StoreGets the paths of given document pattern within given path/sub-paths in this store- Specified by:
getDocumentPathsin interfaceStore- Parameters:
path- start pathincludeSubPaths- if true, include sub-pathsdocumentPattern- document name, allows wildcards, eg. *.ftl or my*.ftl- Returns:
- array of document paths
- Throws:
java.io.IOException
-
getDescriptionDocumentPaths
public java.lang.String[] getDescriptionDocumentPaths() throws java.io.IOExceptionDescription copied from interface:StoreGets the paths of all Web Script description documents in this store- Specified by:
getDescriptionDocumentPathsin interfaceStore- Returns:
- array of description document paths
- Throws:
java.io.IOException
-
getScriptDocumentPaths
public java.lang.String[] getScriptDocumentPaths(WebScript script) throws java.io.IOException
Description copied from interface:StoreGets the paths of all implementation files for a given Web Script- Specified by:
getScriptDocumentPathsin interfaceStore- Parameters:
script- web script- Returns:
- array of implementation document paths
- Throws:
java.io.IOException
-
lastModified
public long lastModified(java.lang.String documentPath) throws java.io.IOExceptionDescription copied from interface:StoreGets the last modified timestamp for the document.- Specified by:
lastModifiedin interfaceStore- Parameters:
documentPath- document path to an existing document- Returns:
- last modified timestamp
- Throws:
java.io.IOException- if the document does not exist in the store
-
hasDocument
public boolean hasDocument(java.lang.String documentPath)
Description copied from interface:StoreDetermines if the document exists.- Specified by:
hasDocumentin interfaceStore- Parameters:
documentPath- document path- Returns:
- true => exists, false => does not exist
-
getDocument
public java.io.InputStream getDocument(java.lang.String documentPath) throws java.io.IOExceptionDescription copied from interface:StoreGets a document. Note a raw InputStream to the content is returned and must be closed by the accessing method.- Specified by:
getDocumentin interfaceStore- Parameters:
documentPath- document path- Returns:
- input stream onto document
- Throws:
java.io.IOException- if the document does not exist in the store
-
createDocument
public void createDocument(java.lang.String documentPath, java.lang.String content) throws java.io.IOExceptionDescription copied from interface:StoreCreates a document.- Specified by:
createDocumentin interfaceStore- Parameters:
documentPath- document pathcontent- content of the document to write- Throws:
java.io.IOException- if the document already exists or the create fails
-
updateDocument
public void updateDocument(java.lang.String documentPath, java.lang.String content) throws java.io.IOExceptionDescription copied from interface:StoreUpdates an existing document.- Specified by:
updateDocumentin interfaceStore- Parameters:
documentPath- document pathcontent- content to update the document with- Throws:
java.io.IOException- if the document does not exist or the update fails
-
removeDocument
public boolean removeDocument(java.lang.String documentPath) throws java.io.IOExceptionDescription copied from interface:StoreRemoves an existing document.- Specified by:
removeDocumentin interfaceStore- Parameters:
documentPath- document path- Returns:
- whether the operation succeeded
- Throws:
java.io.IOException- if the document does not exist or the remove fails
-
getTemplateLoader
public freemarker.cache.TemplateLoader getTemplateLoader()
Description copied from interface:StoreGets the template loader for this store- Specified by:
getTemplateLoaderin interfaceStore- Returns:
- template loader
-
getScriptLoader
public ScriptLoader getScriptLoader()
Description copied from interface:StoreGets the script loader for this store- Specified by:
getScriptLoaderin interfaceStore- Returns:
- script loader
-
createPath
public static java.lang.String createPath(java.lang.String path, java.lang.String relativePath)Helper method for creating fully qualified paths- Parameters:
path- StringrelativePath- String- Returns:
- full qualified path
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
isJarURL
protected static boolean isJarURL(java.net.URL url)
Determine whether the given URL points to a resource in a jar file, that is, has protocol "jar", "zip", "vfszip", "wsjar" or "code-source"."zip" and "wsjar" and "vfszip" are used by BEA WebLogic Server and IBM WebSphere and JBoss, respectively, but can be treated like jar files. The same applies to "code-source" URLs on Oracle OC4J, provided that the path contains a jar separator.
- Parameters:
url- the URL to check- Returns:
- whether the URL has been identified as a JAR URL
-
extractJarFileURL
protected static java.net.URL extractJarFileURL(java.net.URL jarUrl) throws java.net.MalformedURLExceptionExtract the URL for the actual jar file from the given URL (which may point to a resource in a jar file or to a jar file itself).- Parameters:
jarUrl- the original URL- Returns:
- the URL for the actual jar file
- Throws:
java.net.MalformedURLException- if no valid jar file URL could be extracted
-
-