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.pages;
020
021import java.util.Collection;
022import java.util.List;
023
024import org.apache.wiki.WikiEngine;
025import org.apache.wiki.WikiPage;
026import org.apache.wiki.api.exceptions.ProviderException;
027import org.apache.wiki.event.WikiEvent;
028import org.apache.wiki.event.WikiEventListener;
029import org.apache.wiki.providers.WikiPageProvider;
030
031
032public interface PageManager extends WikiEventListener {
033
034    /** The property value for setting the current page provider.  Value is {@value}. */
035    String PROP_PAGEPROVIDER = "jspwiki.pageProvider";
036    /** The property value for setting the cache on/off.  Value is {@value}. */
037    String PROP_USECACHE = "jspwiki.usePageCache";
038    /** The property value for setting the amount of time before the page locks expire. Value is {@value}. */
039    String PROP_LOCKEXPIRY = "jspwiki.lockExpiryTime";
040
041    /**
042     * Returns the page provider currently in use.
043     *
044     * @return A WikiPageProvider instance.
045     */
046    WikiPageProvider getProvider();
047
048    /**
049     * Returns all pages in some random order.  If you need just the page names,
050     * please see {@link org.apache.wiki.ReferenceManager#findCreated() ReferenceManager#findCreated()}, which is probably a lot
051     * faster.  This method may cause repository access.
052     *
053     * @return A Collection of WikiPage objects.
054     * @throws ProviderException If the backend has problems.
055     */
056    Collection<WikiPage> getAllPages() throws ProviderException;
057
058    /**
059     * Fetches the page text from the repository.  This method also does some sanity checks,
060     * like checking for the pageName validity, etc.  Also, if the page repository has been
061     * modified externally, it is smart enough to handle such occurrences.
062     *
063     * @param pageName The name of the page to fetch.
064     * @param version  The version to find
065     * @return The page content as a raw string
066     * @throws ProviderException If the backend has issues.
067     */
068    String getPageText(String pageName, int version) throws ProviderException;
069
070    /**
071     * Returns the WikiEngine to which this PageManager belongs to.
072     *
073     * @return The WikiEngine object.
074     */
075    WikiEngine getEngine();
076
077    /**
078     * Puts the page text into the repository.  Note that this method does NOT update
079     * JSPWiki internal data structures, and therefore you should always use WikiEngine.saveText()
080     *
081     * @param page    Page to save
082     * @param content Wikimarkup to save
083     * @throws ProviderException If something goes wrong in the saving phase
084     */
085    void putPageText(WikiPage page, String content) throws ProviderException;
086
087    /**
088     * Locks page for editing.  Note, however, that the PageManager
089     * will in no way prevent you from actually editing this page;
090     * the lock is just for information.
091     *
092     * @param page WikiPage to lock
093     * @param user Username to use for locking
094     * @return null, if page could not be locked.
095     */
096    PageLock lockPage(WikiPage page, String user);
097
098    /**
099     * Marks a page free to be written again.  If there has not been a lock, will fail quietly.
100     *
101     * @param lock A lock acquired in lockPage().  Safe to be null.
102     */
103    void unlockPage(PageLock lock);
104
105    /**
106     * Returns the current lock owner of a page.  If the page is not
107     * locked, will return null.
108     *
109     * @param page The page to check the lock for
110     * @return Current lock, or null, if there is no lock
111     */
112    PageLock getCurrentLock(WikiPage page);
113
114    /**
115     * Returns a list of currently applicable locks.  Note that by the time you get the list,
116     * the locks may have already expired, so use this only for informational purposes.
117     *
118     * @return List of PageLock objects, detailing the locks.  If no locks exist, returns
119     *         an empty list.
120     * @since 2.0.22.
121     */
122    List<PageLock> getActiveLocks();
123
124    /**
125     * Finds a WikiPage object describing a particular page and version.
126     *
127     * @param pageName The name of the page
128     * @param version  A version number
129     * @return A WikiPage object, or null, if the page does not exist
130     * @throws ProviderException If there is something wrong with the page
131     *                           name or the repository
132     */
133    WikiPage getPageInfo(String pageName, int version) throws ProviderException;
134
135    /**
136     * Gets a version history of page.  Each element in the returned List is a WikiPage.
137     *
138     * @param pageName The name of the page to fetch history for
139     * @return If the page does not exist, returns null, otherwise a List of WikiPages.
140     * @throws ProviderException If the repository fails.
141     */
142    List<WikiPage> getVersionHistory(String pageName) throws ProviderException;
143
144    /**
145     * Returns a human-readable description of the current provider.
146     *
147     * @return A human-readable description.
148     */
149    String getProviderDescription();
150
151    /**
152     * Returns the total count of all pages in the repository. This
153     * method is equivalent of calling getAllPages().size(), but
154     * it swallows the ProviderException and returns -1 instead of
155     * any problems.
156     *
157     * @return The number of pages, or -1, if there is an error.
158     */
159    int getTotalPageCount();
160
161    /**
162     * Returns true, if the page exists (any version).
163     *
164     * @param pageName Name of the page.
165     * @return A boolean value describing the existence of a page
166     * @throws ProviderException If the backend fails or the name is illegal.
167     */
168    boolean pageExists(String pageName) throws ProviderException;
169
170    /**
171     * Checks for existence of a specific page and version.
172     *
173     * @param pageName Name of the page
174     * @param version  The version to check
175     * @return <code>true</code> if the page exists, <code>false</code> otherwise
176     * @throws ProviderException If backend fails or name is illegal
177     * @since 2.3.29
178     */
179    boolean pageExists(String pageName, int version) throws ProviderException;
180
181    /**
182     * Deletes only a specific version of a WikiPage.
183     *
184     * @param page The page to delete.
185     * @throws ProviderException if the page fails
186     */
187    void deleteVersion(WikiPage page) throws ProviderException;
188
189    /**
190     * Deletes an entire page, all versions, all traces.
191     *
192     * @param page The WikiPage to delete
193     * @throws ProviderException If the repository operation fails
194     */
195    void deletePage(WikiPage page) throws ProviderException;
196
197    /**
198     * Listens for {@link org.apache.wiki.event.WikiSecurityEvent#PROFILE_NAME_CHANGED}
199     * events. If a user profile's name changes, each page ACL is inspected. If an entry contains
200     * a name that has changed, it is replaced with the new one. No events are emitted
201     * as a consequence of this method, because the page contents are still the same; it is
202     * only the representations of the names within the ACL that are changing.
203     *
204     * @param event The event
205     */
206    void actionPerformed(WikiEvent event);
207
208    /**
209     * Returns the configured {@link PageSorter}.
210     * 
211     * @return the configured {@link PageSorter}.
212     */
213    PageSorter getPageSorter();
214
215}