001/*
002 * (C) Copyright 2006-2007 Nuxeo SAS (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Nuxeo - initial API and implementation
016 *
017 * $Id$
018 */
019
020package org.nuxeo.ecm.webapp.helpers;
021
022import org.apache.commons.logging.Log;
023import org.apache.commons.logging.LogFactory;
024import org.nuxeo.ecm.platform.types.Type;
025import org.nuxeo.ecm.platform.types.TypeView;
026
027/**
028 * Encapsulates the page handling logic. Based on a document type, computes what page should be displayed to the user.
029 *
030 * @author <a href="mailto:rcaraghin@nuxeo.com">Razvan Caraghin</a>
031 * @author <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a>
032 * @deprecated
033 */
034@Deprecated
035public class ApplicationControllerHelper {
036
037    protected static final String DEFAULT_VIEW = "view_documents";
038
039    protected static final String CREATE_VIEW = "create_document";
040
041    protected static final String EDIT_VIEW = "edit_document";
042
043    private static final Log log = LogFactory.getLog(ApplicationControllerHelper.class);
044
045    // Utility class.
046    private ApplicationControllerHelper() {
047    }
048
049    public static String getPageOnSelectedDocumentType(Type docType) {
050        String returnPage = null;
051        if (docType != null) {
052            String view = docType.getDefaultView();
053            if (view != null) {
054                returnPage = view;
055            } else {
056                returnPage = DEFAULT_VIEW;
057            }
058        }
059        log.debug("Return page -> " + returnPage);
060        return returnPage;
061    }
062
063    // Not used.
064    public static String getPageOnEditDocumentType(Type docType) {
065        String returnPage = null;
066        if (docType != null) {
067            String view = docType.getEditView();
068            if (view != null) {
069                returnPage = view;
070            } else {
071                returnPage = EDIT_VIEW;
072            }
073        }
074        log.debug("Return page -> " + returnPage);
075        return returnPage;
076    }
077
078    public static String getPageOnEditedDocumentType(Type docType) {
079        String returnPage = null;
080        if (docType != null) {
081            TypeView view = docType.getView("after-edit");
082            if (view == null) {
083                returnPage = getPageOnSelectedDocumentType(docType);
084            } else {
085                returnPage = view.getValue();
086            }
087        }
088        log.debug("Return page -> " + returnPage);
089        return returnPage;
090    }
091
092    public static String getPageOnCreateDocumentType(Type docType) {
093        String returnPage = null;
094        if (docType != null) {
095            String view = docType.getCreateView();
096            if (view != null) {
097                returnPage = view;
098            } else {
099                returnPage = CREATE_VIEW;
100            }
101        }
102        log.debug("Return page -> " + returnPage);
103        return returnPage;
104    }
105
106    public static String getPageOnCreatedDocumentType(Type docType) {
107        String returnPage = null;
108        if (docType != null) {
109            TypeView view = docType.getView("after-create");
110            if (view == null) {
111                returnPage = getPageOnSelectedDocumentType(docType);
112            } else {
113                returnPage = view.getValue();
114            }
115        }
116        log.debug("Return page -> " + returnPage);
117        return returnPage;
118    }
119
120}