001/* 
002    Licensed to the Apache Software Foundation (ASF) under one
003    or more contributor license agreements.  See the NOTICE file
004    distributed with this work for additional information
005    regarding copyright ownership.  The ASF licenses this file
006    to you under the Apache License, Version 2.0 (the
007    "License"); you may not use this file except in compliance
008    with the License.  You may obtain a copy of the License at
009
010       http://www.apache.org/licenses/LICENSE-2.0
011
012    Unless required by applicable law or agreed to in writing,
013    software distributed under the License is distributed on an
014    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015    KIND, either express or implied.  See the License for the
016    specific language governing permissions and limitations
017    under the License.  
018 */
019package org.apache.wiki.providers;
020
021import java.util.Collection;
022import java.util.Date;
023import java.util.List;
024
025import org.apache.wiki.WikiPage;
026import org.apache.wiki.WikiProvider;
027import org.apache.wiki.api.exceptions.ProviderException;
028import org.apache.wiki.search.QueryItem;
029import org.apache.wiki.search.SearchResult;
030
031
032/**
033 *  Each Wiki page provider should implement this interface.
034 *  <P>
035 *  You can build whatever page providers based on this, just
036 *  leave the unused methods do something useful.
037 *  <P>
038 *  WikiPageProvider uses Strings and ints to refer to pages.  This may
039 *  be a bit odd, since WikiAttachmentProviders all use Attachment
040 *  instead of name/version.  We will perhaps modify these in the
041 *  future.  In the mean time, name/version is quite sufficient.
042 *  <P>
043 *  FIXME: In reality we should have an AbstractWikiPageProvider,
044 *  which would provide intelligent backups for subclasses.
045 */
046public interface WikiPageProvider extends WikiProvider {
047
048    /**
049     *  Attempts to save the page text for page "page".  Note that the
050     *  provider creates a new version regardless of what the version
051     *  parameter of the WikiPage is.
052     *  
053     *  @param page The WikiPage to save
054     *  @param text The text to save.
055     *  @throws ProviderException If something goes wrong.
056     */
057    void putPageText( WikiPage page, String text ) throws ProviderException;
058
059    /**
060     *  Return true, if page exists.
061     *  
062     *  @param page The page name.
063     *  @return true, if the page exists; false otherwise.
064     */
065    boolean pageExists( String page );
066
067    /**
068     * Return true, if page with a particular version exists.
069     *
070     * @param page    The page name to check for
071     * @param version The version to check
072     * @return True, if page exists; false otherwise.
073     */
074
075    boolean pageExists(String page, int version);
076
077    /**
078     *  Finds pages based on the query.   Only applicable to providers
079     *  which implement the FastSearch interface.  Otherwise JSPWiki
080     *  will use its internal cache.
081     *  <p>
082     *  This method should really be a part of the FastSearch IF.
083     *  
084     *  @param query An array of QueryItems to match
085     *  @return A Collection of WikiPages.
086     */
087    Collection< SearchResult > findPages( QueryItem[] query );
088
089    /**
090     *  Returns info about the page.
091     *  
092     *  @return A filled WikiPage.
093     *  @param page The page name
094     *  @param version The version number
095     *  @throws ProviderException If something goes wrong.
096     */
097    WikiPage getPageInfo( String page, int version ) throws ProviderException;
098
099    /**
100     *  Returns all pages.  Each element in the returned
101     *  Collection should be a WikiPage.
102     *  
103     *  @return A collection of WikiPages
104     *  @throws ProviderException If something goes wrong.
105     */
106    Collection< WikiPage > getAllPages() throws ProviderException;
107
108    /**
109     *  Gets a list of recent changes.
110     *  
111     *  @param date The date to check from
112     *  @return A Collection of WikiPages
113     *  @since 1.6.4
114     */
115    Collection< WikiPage > getAllChangedSince( Date date );
116
117    /**
118     *  Gets the number of pages.
119     *  
120     *  @return The number of pages in the repository
121     *  @throws ProviderException If something goes wrong
122     *  @since 1.6.4
123     */
124    int getPageCount() throws ProviderException;
125
126    /**
127     *  Returns version history.  Each element should be
128     *  a WikiPage.
129     *
130     *  @param page The name of the page to get the history from.
131     *  @return A collection of WikiPages.
132     *  @throws ProviderException If something goes wrong.
133     */
134    List< WikiPage > getVersionHistory( String page ) throws ProviderException;
135
136    /**
137     *  Gets a specific version out of the repository.
138     *
139     *  @param page Name of the page to fetch.
140     *  @param version Version of the page to fetch.
141     *
142     *  @return The content of the page, or null, if the page does not exist.
143     *  @throws ProviderException If something goes wrong.
144     */
145    String getPageText( String page, int version ) throws ProviderException;
146
147    /**
148     *  Removes a specific version from the repository.  The implementations
149     *  should really do no more security checks, since that is the domain
150     *  of the PageManager.  Just delete it as efficiently as you can.
151     *
152     *  @since 2.0.17.
153     *
154     *  @param pageName Name of the page to be removed.
155     *  @param version  Version of the page to be removed.  May be LATEST_VERSION.
156     *
157     *  @throws ProviderException If the page cannot be removed for some reason.
158     */
159    void deleteVersion( String pageName, int version ) throws ProviderException;
160
161    /**
162     *  Removes an entire page from the repository.  The implementations
163     *  should really do no more security checks, since that is the domain
164     *  of the PageManager.  Just delete it as efficiently as you can.  You should also
165     *  delete any auxiliary files that belong to this page, IF they were created
166     *  by this provider.
167     *
168     *  <P>The reason why this is named differently from
169     *  deleteVersion() (logically, this method should be an
170     *  overloaded version) is that I want to be absolutely sure I
171     *  don't accidentally use the wrong method.  With overloading
172     *  something like that happens sometimes...
173     *
174     *  @since 2.0.17.
175     *
176     *  @param pageName Name of the page to be removed completely.
177     *
178     *  @throws ProviderException If the page could not be removed for some reason.
179     */
180    void deletePage( String pageName ) throws ProviderException;
181
182    /**
183     * Move a page
184     *
185     * @param from  Name of the page to move.
186     * @param to    New name of the page.
187     *
188     * @throws ProviderException If the page could not be moved for some reason.
189     */
190    void movePage(String from, String to) throws ProviderException;
191
192}