001/*
002 * (C) Copyright 2006-2007 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Nuxeo - initial API and implementation
018 *
019 * $Id: JOOoConvertPluginImpl.java 18651 2007-05-13 20:28:53Z sfermigier $
020 */
021
022package org.nuxeo.ecm.platform.ui.web.api;
023
024import java.util.List;
025
026import org.nuxeo.ecm.core.api.CoreSession;
027import org.nuxeo.ecm.core.api.DocumentModel;
028import org.nuxeo.ecm.core.api.DocumentModelList;
029import org.nuxeo.ecm.core.api.DocumentRef;
030import org.nuxeo.ecm.core.api.VersionModel;
031import org.nuxeo.ecm.platform.ui.web.pathelements.PathElement;
032import org.nuxeo.ecm.platform.util.RepositoryLocation;
033
034/**
035 * Stateful Seam component.
036 * <ul>
037 * <li>manages the navigation context variables
038 * <li>outjects them for compatibility
039 * <li>provides getters and setters for navigation context variables (ie : hide what Seam scope is used for that)
040 * <li>provides basic navigation features by leveraging Core API + Distributed cache + internal cache
041 * </ul>
042 * This Seam component should ideally serve only DocumentModel, lists of DMs and Trees of DMs: no UI related structure.
043 */
044public interface NavigationContext {
045
046    /**
047     * Callback for component initialization.
048     */
049    void init();
050
051    /**
052     * @return current repository location or null if no server is connected
053     */
054    RepositoryLocation getCurrentServerLocation();
055
056    /**
057     * @return current selected repository location or null
058     * @deprecated use getCurrentServerLocation instead
059     */
060    @Deprecated
061    RepositoryLocation getSelectedServerLocation();
062
063    /**
064     * Current Domain, <strong>if user has read permission on it</strong>. Use
065     *
066     * @link{getCurrentDomainPath if you are in a situation where it is not guaranteed that the user has read permission
067     *                            on the domain.
068     * @return the current domain.
069     */
070    DocumentModel getCurrentDomain();
071
072    /**
073     * Finds the path to current domain.
074     * <p>
075     * This method tries hard to always returns an answer: the path to current domain is deduced from the path of
076     * current document (assuming that it would be the first element of this path).
077     * <p>
078     * If current document is null, the same logic is applied to the first document found amongst all documents user has
079     * access to.
080     */
081    String getCurrentDomainPath();
082
083    void setCurrentDomain(DocumentModel currentDomain);
084
085    /**
086     * Current Document other than Domain or Workspace.
087     */
088    DocumentModel getCurrentDocument();
089
090    /**
091     * Returns the currentSuperSpace (Section, Workspace...). Uses SuperSpace facet for that.
092     */
093    DocumentModel getCurrentSuperSpace();
094
095    void setCurrentDocument(DocumentModel documentModel);
096
097    /**
098     * This is used for documents about to be created, which are not yet persisted thus not all their fields might be
099     * valid (like its reference).
100     */
101    DocumentModel getChangeableDocument();
102
103    void setChangeableDocument(DocumentModel changeableDocument);
104
105    /**
106     * Saves the current copy of the document to server.
107     */
108    void saveCurrentDocument();
109
110    List<PathElement> getCurrentPathList();
111
112    /**
113     * Returns a list of the DocumentsModels (to build the BreadCrumb for example).
114     */
115    DocumentModelList getCurrentPath();
116
117    /**
118     * @return the URL that can be used to refer the current document from outside current context
119     */
120    String getCurrentDocumentUrl();
121
122    /**
123     * @return the URL that can be used to refer the current document from outside current context
124     */
125    String getCurrentDocumentFullUrl();
126
127    /**
128     * Updates the current document in the (session) context and resets the other common structures (breadcrumbs, etc).
129     *
130     * @param doc DocumentModel that will be set as current document
131     */
132    void updateDocumentContext(DocumentModel doc);
133
134    /**
135     * Resets all context variables.
136     */
137    void resetCurrentContext();
138
139    /**
140     * Performs context updates and returns the view associated with the document and action passed.
141     *
142     * @return document view associated with the result
143     */
144    String getActionResult(DocumentModel doc, UserAction action);
145
146    /**
147     * go to the root server, the root document or to the dashboard if the latest document are not accessible.
148     */
149    String goHome();
150
151    String goBack();
152
153    /**
154     * Updates the context and returns the view for the given document id.
155     */
156    String navigateToId(String documentId);
157
158    /**
159     * Updates the context and returns the view for the given document ref.
160     */
161    String navigateToRef(DocumentRef docRef);
162
163    /**
164     * Updates the context with given document and returns its default view.
165     * <p>
166     * The default view is configured on the UI document type definition.
167     */
168    String navigateToDocument(DocumentModel doc);
169
170    /**
171     * Initializes the context for the given doc and returns its given view.
172     * <p>
173     * If view is not found, use default view.
174     *
175     * @param doc
176     * @param viewId for the document as defined in its type
177     * @return navigation view for the document
178     */
179    String navigateToDocument(DocumentModel doc, String viewId);
180
181    /**
182     * Initializes the context for the given doc and returns its given view.
183     * <p>
184     * If view is not found, use default view set on the UI document type. This is an alias to
185     * <code>navigateToDocument(DocumentModel doc, String viewId)</code>, to resolve ambiguity when method is invoked by
186     * an EL expression.
187     *
188     * @param doc
189     * @param viewId for the document as defined in its type
190     * @return navigation view for the document
191     */
192    String navigateToDocumentWithView(DocumentModel doc, String viewId);
193
194    /**
195     * Initializes the context for the given refs and returns the default view for the doc.
196     */
197    String navigateTo(RepositoryLocation serverLocation, DocumentRef docRef);
198
199    /**
200     * Initializes the context for the given refs and returns the default view for the doc.
201     */
202    String navigateToURL(String documentUrl);
203
204    /**
205     * Initializes the context for the given refs and returns the default view for the doc.
206     * <p>
207     * Takes parameter String docRef from the Request.
208     */
209    String navigateToURL();
210
211    // --- do not call these methods directly
212    // --- they are listeners - called by Seam
213    void selectionChanged();
214
215    /**
216     * Switch to a new server location by updating the context and updating to the CoreSession (aka the
217     * 'documentManager' Seam component).
218     *
219     * @param serverLocation new server location to connect to
220     */
221    void setCurrentServerLocation(RepositoryLocation serverLocation);
222
223    /**
224     * Returns the current documentManager if any or create a new session to the currently selected repository location.
225     */
226    CoreSession getOrCreateDocumentManager();
227
228    String navigateToDocument(DocumentModel docModel, VersionModel versionModel);
229
230    /**
231     * Gets the currentDocument and puts it in Page context.
232     */
233    DocumentModel factoryCurrentDocument();
234
235    /**
236     * Gets the currentDomain and puts it in Page context.
237     */
238    DocumentModel factoryCurrentDomain();
239
240    /**
241     * Gets the currentWorkspace and puts it in Page context.
242     */
243    DocumentModel factoryCurrentWorkspace();
244
245    /**
246     * Gets the currentSuperSpace and puts it in Page context.
247     */
248    DocumentModel factoryCurrentSuperSpace();
249
250    /**
251     * Gets the currentContentRootWorkspace and puts it in Page context.
252     */
253    DocumentModel factoryCurrentContentRoot();
254
255    /**
256     * Gets the current ServerLocation and puts it in Page Context.
257     */
258    RepositoryLocation factoryCurrentServerLocation();
259
260    /**
261     * Gets current document for edition.
262     */
263    DocumentModel factoryChangeableDocument();
264
265    /**
266     * Gets the current Content Root (Workspaces, Sections, Templates...).
267     */
268    DocumentModel getCurrentContentRoot();
269
270    /**
271     * Gets the current Workspace.
272     */
273    DocumentModel getCurrentWorkspace();
274
275    /**
276     * Sets the current ContentRoot.
277     */
278    void setCurrentContentRoot(DocumentModel currentContentRoot);
279
280    /**
281     * Will trigger reloading of current document data from the server.
282     */
283    void invalidateCurrentDocument();
284
285}