Class RemoteStore

  • All Implemented Interfaces:
    Store

    public class RemoteStore
    extends AbstractStore
    Store implementation that queries and retrieves documents from a remote HTTP endpoint.

    The endpoint is assumed to support a WebScript Remote Store implementation (such as AVMRemoteStore) that mirrors the required Store API.

    Author:
    Kevin Roast
    • Constructor Summary

      Constructors 
      Constructor Description
      RemoteStore()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.lang.String buildUri​(java.lang.String uri)  
      protected Response callDelete​(java.lang.String uri)
      Perform a DELETE call to the given URI.
      protected Response callGet​(java.lang.String uri)
      Perform a GET call to the given URI.
      protected Response callPost​(java.lang.String uri, java.io.InputStream in)
      Perform a POST call to the given URI with the supplied input.
      void createDocument​(java.lang.String documentPath, java.lang.String content)
      Creates a document.
      void createDocuments​(java.util.List<org.springframework.extensions.surf.util.Pair<java.lang.String,​org.dom4j.Document>> pathContents)
      Creates multiple XML documents at the specified paths.
      boolean exists()
      Determines whether the store actually exists
      java.lang.String[] getAllDocumentPaths()
      Gets the paths of all documents in this store
      java.lang.String getApi()
      Gets the api.
      java.lang.String getBasePath()
      Gets the base path of the store
      protected Connector getConnector()
      Get a Connector for access to the endpoint.
      ConnectorProvider getConnectorProvider()  
      ConnectorService getConnectorService()
      Gets the connector service.
      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 getEndpoint()
      Gets the endpoint.
      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
      java.lang.String getStoreId()
      Gets the store id.
      java.lang.String getStorePath()
      Store path calculation If we have a store context, then we can check to see if a base path should be inserted ahead of the path that we believe we're directing to.
      freemarker.cache.TemplateLoader getTemplateLoader()
      Gets the template loader for this store
      java.lang.String getWebappId()
      Gets the store's web application id binding This is meaningful for WCM Web Project stores.
      java.lang.String getWebappPathPrefix()  
      boolean hasDocument​(java.lang.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​(java.lang.String documentPath)
      Gets the last modified timestamp for the document.
      boolean removeDocument​(java.lang.String documentPath)
      Removes an existing document.
      void setApi​(java.lang.String api)  
      void setConnectorProvider​(ConnectorProvider connectorProvider)
      Sets the connector provider
      void setConnectorService​(ConnectorService service)  
      void setEndpoint​(java.lang.String endpoint)  
      void setPath​(java.lang.String path)
      Sets the base path to send to the remote store
      void setStoreId​(java.lang.String storeId)
      Allows for specification of default or fallback store id to use when binding to a remote store.
      void setWebappId​(java.lang.String webappId)
      Sets the store's web application id to bind to within the designated store This is meaningful for WCM Web Project stores.
      void setWebappPathPrefix​(java.lang.String webappPathPrefix)  
      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, toString, wait, wait, wait
    • Constructor Detail

      • RemoteStore

        public RemoteStore()
    • Method Detail

      • setConnectorService

        public void setConnectorService​(ConnectorService service)
        Parameters:
        service - The ConnectorService bean
      • getConnectorService

        public ConnectorService getConnectorService()
        Gets the connector service.
        Returns:
        the connector service
      • setConnectorProvider

        public void setConnectorProvider​(ConnectorProvider connectorProvider)
        Sets the connector provider
      • getConnectorProvider

        public ConnectorProvider getConnectorProvider()
        Returns:
        the connector provider
      • setApi

        public void setApi​(java.lang.String api)
        Parameters:
        api - the WebScript API path to set for the remote store i.e. "/remotestore"
      • getApi

        public java.lang.String getApi()
        Gets the api.
        Returns:
        the api
      • setPath

        public void setPath​(java.lang.String path)
        Sets the base path to send to the remote store
        Parameters:
        path - String
      • setEndpoint

        public void setEndpoint​(java.lang.String endpoint)
        Parameters:
        endpoint - the endpoint ID to use when calling the remote API
      • getEndpoint

        public java.lang.String getEndpoint()
        Gets the endpoint.
        Returns:
        the endpoint
      • setWebappId

        public void setWebappId​(java.lang.String webappId)
        Sets the store's web application id to bind to within the designated store This is meaningful for WCM Web Project stores.
        Parameters:
        webappId - String
      • getWebappPathPrefix

        public java.lang.String getWebappPathPrefix()
      • setWebappPathPrefix

        public void setWebappPathPrefix​(java.lang.String webappPathPrefix)
      • getWebappId

        public java.lang.String getWebappId()
        Gets the store's web application id binding This is meaningful for WCM Web Project stores.
        Returns:
        String
      • setStoreId

        public void setStoreId​(java.lang.String storeId)
        Allows for specification of default or fallback store id to use when binding to a remote store. This can be overridden by providing an implementation of a RemoteStoreContextProvider in the Spring Bean configuration.
        Parameters:
        storeId - the default store id
      • getStoreId

        public java.lang.String getStoreId()
        Gets the store id.
        Returns:
        the store id
      • getStorePath

        public java.lang.String getStorePath()
        Store path calculation If we have a store context, then we can check to see if a base path should be inserted ahead of the path that we believe we're directing to. Use case - consider writing a file /alfresco/site-data/components/component.xml If we're writing to sitestore, then the file is stored relative to the store root. In the case of a WCM web project, however, we may want to persist to one of several web applications. If we have a webappId (retrieved from the context), then we prepend: /WEB-INF/classes The new location is: /WEB-INF/classes/alfresco/site-data/components/component.xml This allows us to operate against both straight up AVM stores as well as WCM Web Project AVM stores.
        Returns:
        String
      • init

        public void init()
        Description copied from interface: Store
        Initialise Store (called once)
      • 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.
        Returns:
        true if this store is considered secure
      • exists

        public boolean exists()
        Description copied from interface: Store
        Determines whether the store actually exists
        Returns:
        true => it does exist
      • hasDocument

        public boolean hasDocument​(java.lang.String documentPath)
                            throws java.io.IOException
        Description copied from interface: Store
        Determines if the document exists.
        Parameters:
        documentPath - document path
        Returns:
        true => exists, false => does not exist
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • 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.
        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
      • 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.
        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.
        Parameters:
        documentPath - document path
        Returns:
        whether the operation succeeded
        Throws:
        java.io.IOException - if the document does not exist or the remove fails
      • createDocument

        public void createDocument​(java.lang.String documentPath,
                                   java.lang.String content)
                            throws java.io.IOException
        Description copied from interface: Store
        Creates a document.
        Parameters:
        documentPath - document path
        content - content of the document to write
        Throws:
        java.io.IOException - if the document already exists or the create fails
      • createDocuments

        public void createDocuments​(java.util.List<org.springframework.extensions.surf.util.Pair<java.lang.String,​org.dom4j.Document>> pathContents)
                             throws java.io.IOException
        Description copied from interface: Store
        Creates multiple XML documents at the specified paths.
        Specified by:
        createDocuments in interface Store
        Overrides:
        createDocuments in class AbstractStore
        Parameters:
        pathContents - list of path, document pairs
        Throws:
        java.io.IOException - if a document already exists or a create fails
      • 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.
        Parameters:
        documentPath - document path
        Returns:
        input stream onto document
        Throws:
        java.io.IOException - if the document does not exist in the store
      • getAllDocumentPaths

        public java.lang.String[] getAllDocumentPaths()
        Description copied from interface: Store
        Gets the paths of all documents in this store
        Returns:
        array of all document paths
      • getDocumentPaths

        public java.lang.String[] getDocumentPaths​(java.lang.String path,
                                                   boolean includeSubPaths,
                                                   java.lang.String documentPattern)
        Description copied from interface: Store
        Gets the paths of given document pattern within given path/sub-paths in this 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
      • getDescriptionDocumentPaths

        public java.lang.String[] getDescriptionDocumentPaths()
        Description copied from interface: Store
        Gets the paths of all Web Script description documents in this store
        Returns:
        array of description document paths
      • getScriptDocumentPaths

        public java.lang.String[] getScriptDocumentPaths​(WebScript script)
        Description copied from interface: Store
        Gets the paths of all implementation files for a given Web Script
        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
        Returns:
        script loader
      • getTemplateLoader

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

        public java.lang.String getBasePath()
        Description copied from interface: Store
        Gets the base path of the store
        Returns:
        base path
      • buildUri

        protected java.lang.String buildUri​(java.lang.String uri)
      • callPost

        protected Response callPost​(java.lang.String uri,
                                    java.io.InputStream in)
        Perform a POST call to the given URI with the supplied input.
      • callGet

        protected Response callGet​(java.lang.String uri)
        Perform a GET call to the given URI.
      • callDelete

        protected Response callDelete​(java.lang.String uri)
        Perform a DELETE call to the given URI.
      • getConnector

        protected Connector getConnector()
                                  throws ConnectorProviderException
        Get a Connector for access to the endpoint. If a connector has been bound to the current thread then use it, else retrieve a transient connector instance from the ConnectorService.
        Returns:
        Connector
        Throws:
        ConnectorProviderException