Class RemoteStore
- java.lang.Object
-
- org.springframework.extensions.webscripts.AbstractStore
-
- org.springframework.extensions.webscripts.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classRemoteStore.RemoteStoreScriptLoaderRemote Store implementation of a Script Loader
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_APIstatic java.lang.StringDEFAULT_ENDPOINT_ID-
Fields inherited from class org.springframework.extensions.webscripts.AbstractStore
DESC_PATH_PATTERN
-
-
Constructor Summary
Constructors Constructor Description RemoteStore()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.StringbuildUri(java.lang.String uri)protected ResponsecallDelete(java.lang.String uri)Perform a DELETE call to the given URI.protected ResponsecallGet(java.lang.String uri)Perform a GET call to the given URI.protected ResponsecallPost(java.lang.String uri, java.io.InputStream in)Perform a POST call to the given URI with the supplied input.voidcreateDocument(java.lang.String documentPath, java.lang.String content)Creates a document.voidcreateDocuments(java.util.List<org.springframework.extensions.surf.util.Pair<java.lang.String,org.dom4j.Document>> pathContents)Creates multiple XML documents at the specified paths.booleanexists()Determines whether the store actually existsjava.lang.String[]getAllDocumentPaths()Gets the paths of all documents in this storejava.lang.StringgetApi()Gets the api.java.lang.StringgetBasePath()Gets the base path of the storeprotected ConnectorgetConnector()Get a Connector for access to the endpoint.ConnectorProvidergetConnectorProvider()ConnectorServicegetConnectorService()Gets the connector service.java.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.StringgetEndpoint()Gets the endpoint.java.lang.String[]getScriptDocumentPaths(WebScript script)Gets the paths of all implementation files for a given Web ScriptScriptLoadergetScriptLoader()Gets the script loader for this storejava.lang.StringgetStoreId()Gets the store id.java.lang.StringgetStorePath()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.TemplateLoadergetTemplateLoader()Gets the template loader for this storejava.lang.StringgetWebappId()Gets the store's web application id binding This is meaningful for WCM Web Project stores.java.lang.StringgetWebappPathPrefix()booleanhasDocument(java.lang.String documentPath)Determines if the document exists.voidinit()Initialise Store (called once)booleanisSecure()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.voidsetApi(java.lang.String api)voidsetConnectorProvider(ConnectorProvider connectorProvider)Sets the connector providervoidsetConnectorService(ConnectorService service)voidsetEndpoint(java.lang.String endpoint)voidsetPath(java.lang.String path)Sets the base path to send to the remote storevoidsetStoreId(java.lang.String storeId)Allows for specification of default or fallback store id to use when binding to a remote store.voidsetWebappId(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.voidsetWebappPathPrefix(java.lang.String webappPathPrefix)voidupdateDocument(java.lang.String documentPath, java.lang.String content)Updates an existing document.-
Methods inherited from class org.springframework.extensions.webscripts.AbstractStore
getDocumentPaths, getPreviewContext, isReadOnly, setPreviewContextProvider, setReadOnly
-
-
-
-
Field Detail
-
DEFAULT_API
public static final java.lang.String DEFAULT_API
- See Also:
- Constant Field Values
-
DEFAULT_ENDPOINT_ID
public static final java.lang.String DEFAULT_ENDPOINT_ID
- See Also:
- Constant Field Values
-
-
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:StoreInitialise Store (called once)
-
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.- Returns:
- true if this store is considered secure
-
exists
public boolean exists()
Description copied from interface:StoreDetermines whether the store actually exists- Returns:
- true => it does exist
-
hasDocument
public boolean hasDocument(java.lang.String documentPath) throws java.io.IOExceptionDescription copied from interface:StoreDetermines 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.IOExceptionDescription copied from interface:StoreGets 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.IOExceptionDescription copied from interface:StoreUpdates an existing document.- 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.- 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.IOExceptionDescription copied from interface:StoreCreates a document.- Parameters:
documentPath- document pathcontent- 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.IOExceptionDescription copied from interface:StoreCreates multiple XML documents at the specified paths.- Specified by:
createDocumentsin interfaceStore- Overrides:
createDocumentsin classAbstractStore- 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.IOExceptionDescription copied from interface:StoreGets 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:StoreGets 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:StoreGets the paths of given document pattern within given path/sub-paths in this store- Parameters:
path- start pathincludeSubPaths- if true, include sub-pathsdocumentPattern- document name, allows wildcards, eg. *.ftl or my*.ftl- Returns:
- array of document paths
-
getDescriptionDocumentPaths
public java.lang.String[] getDescriptionDocumentPaths()
Description copied from interface:StoreGets 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:StoreGets 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:StoreGets the script loader for this store- Returns:
- script loader
-
getTemplateLoader
public freemarker.cache.TemplateLoader getTemplateLoader()
Description copied from interface:StoreGets the template loader for this store- Returns:
- template loader
-
getBasePath
public java.lang.String getBasePath()
Description copied from interface:StoreGets 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
-
-