Class 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 class  ClassPathStore.ClassPathTemplateLoader
      Class 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 path
      protected class  ClassPathStore.ClassPathTemplateSource
      Template Source - loads from a Class Path Store
    • Constructor Summary

      Constructors 
      Constructor Description
      ClassPathStore()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void createDocument​(java.lang.String documentPath, java.lang.String content)
      Creates a document.
      static java.lang.String createPath​(java.lang.String path, java.lang.String relativePath)
      Helper method for creating fully qualified paths
      boolean exists()
      Determines whether the store actually exists
      protected static java.net.URL extractJarFileURL​(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 store
      java.lang.String getBasePath()
      Gets the base path of the store
      java.lang.String[] getDescriptionDocumentPaths()
      Gets the paths of all Web Script description documents in this store
      java.io.InputStream getDocument​(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 store
      java.lang.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​(java.lang.String documentPath)
      Determines if the document exists.
      void init()
      Initialise Store (called once)
      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".
      boolean isReadOnly()
      Whether the store is in read-only mode
      boolean isSecure()
      Returns true if this store is considered secure - i.e.
      long lastModified​(java.lang.String documentPath)
      Gets the last modified timestamp for the document.
      boolean removeDocument​(java.lang.String documentPath)
      Removes an existing document.
      void setApplicationContext​(org.springframework.context.ApplicationContext applicationContext)  
      void setClassPath​(java.lang.String classPath)
      Sets the class 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
      java.lang.String toString()  
      void updateDocument​(java.lang.String documentPath, java.lang.String content)
      Updates an existing document.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 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
      • 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
    • Constructor Detail

      • ClassPathStore

        public ClassPathStore()
    • 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:
        setApplicationContext in interface org.springframework.context.ApplicationContextAware
        Throws:
        org.springframework.beans.BeansException
      • 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 java.lang.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 java.lang.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 java.lang.String[] getDocumentPaths​(java.lang.String path,
                                                   boolean includeSubPaths,
                                                   java.lang.String documentPattern)
                                            throws java.io.IOException
        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
        Throws:
        java.io.IOException
      • getDescriptionDocumentPaths

        public java.lang.String[] getDescriptionDocumentPaths()
                                                       throws java.io.IOException
        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
        Throws:
        java.io.IOException
      • getScriptDocumentPaths

        public java.lang.String[] getScriptDocumentPaths​(WebScript script)
                                                  throws java.io.IOException
        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
        Throws:
        java.io.IOException
      • lastModified

        public long lastModified​(java.lang.String documentPath)
                          throws java.io.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:
        java.io.IOException - if the document does not exist in the store
      • hasDocument

        public boolean hasDocument​(java.lang.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 java.io.InputStream getDocument​(java.lang.String documentPath)
                                        throws java.io.IOException
        Description copied from interface: Store
        Gets a document. Note a raw InputStream to the content is returned and must be closed by the accessing method.
        Specified by:
        getDocument in interface Store
        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.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:
        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.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:
        java.io.IOException - if the document does not exist or the update fails
      • removeDocument

        public boolean removeDocument​(java.lang.String documentPath)
                               throws java.io.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:
        java.io.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
      • createPath

        public static java.lang.String createPath​(java.lang.String path,
                                                  java.lang.String relativePath)
        Helper method for creating fully qualified paths
        Parameters:
        path - String
        relativePath - String
        Returns:
        full qualified path
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.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.MalformedURLException
        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).
        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