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$
020 */
021
022package org.nuxeo.ecm.webapp.helpers;
023
024import org.apache.commons.logging.Log;
025import org.apache.commons.logging.LogFactory;
026import org.nuxeo.ecm.platform.types.Type;
027import org.nuxeo.ecm.platform.types.TypeView;
028
029/**
030 * Encapsulates the page handling logic. Based on a document type, computes what page should be displayed to the user.
031 *
032 * @author <a href="mailto:rcaraghin@nuxeo.com">Razvan Caraghin</a>
033 * @author <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a>
034 * @deprecated
035 */
036@Deprecated
037public class ApplicationControllerHelper {
038
039    protected static final String DEFAULT_VIEW = "view_documents";
040
041    protected static final String CREATE_VIEW = "create_document";
042
043    protected static final String EDIT_VIEW = "edit_document";
044
045    private static final Log log = LogFactory.getLog(ApplicationControllerHelper.class);
046
047    // Utility class.
048    private ApplicationControllerHelper() {
049    }
050
051    public static String getPageOnSelectedDocumentType(Type docType) {
052        String returnPage = null;
053        if (docType != null) {
054            String view = docType.getDefaultView();
055            if (view != null) {
056                returnPage = view;
057            } else {
058                returnPage = DEFAULT_VIEW;
059            }
060        }
061        log.debug("Return page -> " + returnPage);
062        return returnPage;
063    }
064
065    // Not used.
066    public static String getPageOnEditDocumentType(Type docType) {
067        String returnPage = null;
068        if (docType != null) {
069            String view = docType.getEditView();
070            if (view != null) {
071                returnPage = view;
072            } else {
073                returnPage = EDIT_VIEW;
074            }
075        }
076        log.debug("Return page -> " + returnPage);
077        return returnPage;
078    }
079
080    public static String getPageOnEditedDocumentType(Type docType) {
081        String returnPage = null;
082        if (docType != null) {
083            TypeView view = docType.getView("after-edit");
084            if (view == null) {
085                returnPage = getPageOnSelectedDocumentType(docType);
086            } else {
087                returnPage = view.getValue();
088            }
089        }
090        log.debug("Return page -> " + returnPage);
091        return returnPage;
092    }
093
094    public static String getPageOnCreateDocumentType(Type docType) {
095        String returnPage = null;
096        if (docType != null) {
097            String view = docType.getCreateView();
098            if (view != null) {
099                returnPage = view;
100            } else {
101                returnPage = CREATE_VIEW;
102            }
103        }
104        log.debug("Return page -> " + returnPage);
105        return returnPage;
106    }
107
108    public static String getPageOnCreatedDocumentType(Type docType) {
109        String returnPage = null;
110        if (docType != null) {
111            TypeView view = docType.getView("after-create");
112            if (view == null) {
113                returnPage = getPageOnSelectedDocumentType(docType);
114            } else {
115                returnPage = view.getValue();
116            }
117        }
118        log.debug("Return page -> " + returnPage);
119        return returnPage;
120    }
121
122}