View Javadoc

1   /**
2    * Copyright (C) 2005-2009 Alfresco Software Limited.
3    *
4    * This file is part of the Spring Surf Extension project.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *  http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.springframework.extensions.webscripts;
20  
21  import java.io.IOException;
22  import java.io.InputStream;
23  
24  import org.springframework.extensions.surf.exception.ConnectorProviderException;
25  import org.springframework.extensions.webscripts.connector.Response;
26  import org.springframework.extensions.webscripts.connector.ResponseStatus;
27  
28  import freemarker.cache.TemplateLoader;
29  
30  
31  /**
32   * Store for holding Web Script Definitions and Implementations
33   *
34   * @author davidc
35   */
36  public interface Store
37  {
38  	/**
39  	 * Initialise Store (called once)
40  	 */
41  	public void init();
42  
43      /**
44       * Determines whether the store actually exists
45       *
46       * @return  true => it does exist
47       */
48      public boolean exists();
49  
50      /**
51       * Gets the base path of the store
52       *
53       * @return base path
54       */
55      public String getBasePath();
56  
57      /**
58       * Returns true if this store is considered secure - i.e. on the app-server classpath. Scripts in secure stores can
59       * be run under the identity of a declared user (via the runas attribute) rather than the authenticated user.
60       *
61       * @return true if this store is considered secure
62       */
63      public boolean isSecure();
64  
65      /**
66       * Gets the paths of given document pattern within given path/sub-paths in this store
67       *
68       * @param path             start path
69       * @param includeSubPaths  if true, include sub-paths
70       * @param documentPattern  document name, allows wildcards, eg. *.ftl or my*.ftl
71       * @return  array of document paths
72       */
73      public String[] getDocumentPaths(String path, boolean includeSubPaths, String documentPattern) throws IOException;
74  
75      /**
76       * Gets the paths matching a given file path pattern in this store.
77       *
78       * @param path             start path
79       * @param filePathPattern  file path pattern string, allows wildcards, eg. *.ftl or my*.ftl or *\/a\/*.xml
80       * @return  array of document paths
81       */
82      public String[] getDocumentPaths(String path, String filePathPattern) throws IOException;
83  
84      /**
85       * Gets the paths of all Web Script description documents in this store
86       *
87       * @return array of description document paths
88       */
89      public String[] getDescriptionDocumentPaths() throws IOException;
90  
91      /**
92       * Gets the paths of all implementation files for a given Web Script
93       *
94       * @param script  web script
95       * @return  array of implementation document paths
96       */
97      public String[] getScriptDocumentPaths(WebScript script) throws IOException;
98  
99      /**
100      * Gets the paths of all documents in this store
101      *
102      * @return array of all document paths
103      */
104     public String[] getAllDocumentPaths();
105 
106     /**
107      * Gets the last modified timestamp for the document.
108      *
109      * @param documentPath  document path to an existing document
110      * @return  last modified timestamp
111      *
112      * @throws IOException if the document does not exist in the store
113      */
114     public long lastModified(String documentPath)
115         throws IOException;
116 
117     /**
118      * Determines if the document exists.
119      * 
120      * @param documentPath
121      *            document path
122      * @return true => exists, false => does not exist
123      * @throws IOException
124      *             Signals that an I/O exception has occurred.
125      */
126     public boolean hasDocument(String documentPath)
127         throws IOException;
128 
129     /**
130      * Gets a document
131      *
132      * @param documentPath  document path
133      * @return  input stream onto document
134      *
135      * @throws IOException if the document does not exist in the store
136      */
137     public InputStream getDocument(String documentPath)
138         throws IOException;
139 
140     /**
141      * Creates a document.
142      *
143      * @param documentPath  document path
144      * @param content       content of the document to write
145      *
146      * @throws IOException if the document already exists or the create fails
147      */
148     public void createDocument(String documentPath, String content)
149         throws IOException;
150 
151     /**
152      * Updates an existing document.
153      *
154      * @param documentPath  document path
155      * @param content       content to update the document with
156      *
157      * @throws IOException if the document does not exist or the update fails
158      */
159     public void updateDocument(String documentPath, String content)
160         throws IOException;
161 
162     /**
163      * Removes an existing document.
164      *
165      * @param documentPath  document path
166      * @return  whether the operation succeeded
167      *
168      * @throws IOException if the document does not exist or the remove fails
169      */
170     public boolean removeDocument(String documentPath)
171         throws IOException;
172 
173     /**
174      * Gets the template loader for this store
175      *
176      * @return  template loader
177      */
178     public TemplateLoader getTemplateLoader();
179 
180     /**
181      * Gets the script loader for this store
182      *
183      * @return  script loader
184      */
185     public ScriptLoader getScriptLoader();
186 }