KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > content > ContentStore


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.content;
18
19 import java.util.Date JavaDoc;
20 import java.util.Set JavaDoc;
21
22 import org.alfresco.service.cmr.repository.ContentIOException;
23 import org.alfresco.service.cmr.repository.ContentReader;
24 import org.alfresco.service.cmr.repository.ContentStreamListener;
25 import org.alfresco.service.cmr.repository.ContentWriter;
26
27 /**
28  * Provides low-level retrieval of content
29  * {@link org.alfresco.service.cmr.repository.ContentReader readers} and
30  * {@link org.alfresco.service.cmr.repository.ContentWriter writers}.
31  * <p>
32  * Implementations of this interface should be soley responsible for
33  * providing persistence and retrieval of the content against a
34  * <code>content URL</code>.
35  * <p>
36  * The URL format is <b>store://year/month/day/GUID.bin</b> <br>
37  * <ul>
38  * <li> <b>store://</b>: prefix identifying an Alfresco content stores
39  * regardless of the persistence mechanism. </li>
40  * <li> <b>year</b>: year </li>
41  * <li> <b>month</b>: 1-based month of the year </li>
42  * <li> <b>day</b>: 1-based day of the month </li>
43  * <li> <b>GUID</b>: A unique identifier </li>
44  * </ul>
45  * The old <b>file://</b> prefix must still be supported - and functionality
46  * around this can be found in the {@link org.alfresco.repo.content.AbstractContentStore}
47  * implementation.
48  *
49  * @author Derek Hulley
50  */

51 public interface ContentStore
52 {
53     /** <b>store://</b> is the new prefix for all content URLs */
54     public static final String JavaDoc STORE_PROTOCOL = "store://";
55     
56     /**
57      * Check for the existence of content in the store.
58      * <p>
59      * The implementation of this may be more efficient than first getting a
60      * reader to {@link ContentReader#exists() check for existence}, although
61      * that check should also be performed.
62      *
63      * @param contentUrl the path to the content
64      * @return Returns true if the content exists.
65      * @throws ContentIOException
66      *
67      * @see ContentReader#exists()
68      */

69     public boolean exists(String JavaDoc contentUrl) throws ContentIOException;
70     
71     /**
72      * Get the accessor with which to read from the content
73      * at the given URL. The reader is <b>stateful</b> and
74      * can <b>only be used once</b>.
75      *
76      * @param contentUrl the path to where the content is located
77      * @return Returns a read-only content accessor for the given URL. There may
78      * be no content at the given URL, but the reader must still be returned.
79      * The reader may implement the {@link RandomAccessContent random access interface}.
80      * @throws ContentIOException
81      *
82      * @see #exists(String)
83      * @see ContentReader#exists()
84      */

85     public ContentReader getReader(String JavaDoc contentUrl) throws ContentIOException;
86     
87     /**
88      * Get an accessor with which to write content to a location
89      * within the store. The writer is <b>stateful</b> and can
90      * <b>only be used once</b>. The location may be specified but must, in that case,
91      * be a valid and unused URL.
92      * <p>
93      * By supplying a reader to existing content, the store implementation may
94      * enable {@link RandomAccessContent random access}. The store implementation
95      * can enable this by copying the existing content into the new location
96      * before supplying a writer onto the new content.
97      *
98      * @param existingContentReader a reader onto any existing content for which
99      * a writer is required - may be null
100      * @param newContentUrl an unused, valid URL to use - may be null.
101      * @return Returns a write-only content accessor, possibly implementing
102      * the {@link RandomAccessContent random access interface}
103      * @throws ContentIOException if completely new content storage could not be
104      * created
105      *
106      * @see ContentWriter#addListener(ContentStreamListener)
107      * @see ContentWriter#getContentUrl()
108      */

109     public ContentWriter getWriter(ContentReader existingContentReader, String JavaDoc newContentUrl) throws ContentIOException;
110
111     /**
112      * Get all URLs for the store, regardless of creation time.
113      *
114      * @see #getUrls(Date, Date)
115      */

116     public Set JavaDoc<String JavaDoc> getUrls() throws ContentIOException;
117
118     /**
119      * Get a set of all content URLs in the store. This indicates all content
120      * available for reads.
121      *
122      * @param createdAfter all URLs returned must have been created after this date. May be null.
123      * @param createdBefore all URLs returned must have been created before this date. May be null.
124      * @return Returns a complete set of the unique URLs of all available content
125      * in the store
126      * @throws ContentIOException
127      */

128     public Set JavaDoc<String JavaDoc> getUrls(Date JavaDoc createdAfter, Date JavaDoc createdBefore) throws ContentIOException;
129     
130     /**
131      * Deletes the content at the given URL.
132      * <p>
133      * A delete cannot be forced since it is much better to have the
134      * file remain longer than desired rather than deleted prematurely.
135      * The store implementation should safeguard files for certain
136      * minimum period, in which case all files younger than a certain
137      * age will not be deleted.
138      *
139      * @param contentUrl the URL of the content to delete
140      * @return Return true if the content was deleted (either by this or
141      * another operation), otherwise false
142      * @throws ContentIOException
143      */

144     public boolean delete(String JavaDoc contentUrl) throws ContentIOException;
145 }
146
Popular Tags