001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (C) Alkacon Software (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.loader; 029 030import org.opencms.file.CmsObject; 031import org.opencms.file.CmsResource; 032import org.opencms.main.CmsException; 033 034import java.util.Map; 035 036import javax.servlet.http.HttpServletRequest; 037 038/** 039 * Interface for template context providers.<p> 040 * 041 * Implementations of this class are used to dynamically determine a template used for rendering 042 * a page at runtime, e.g. there could be one template for desktop browsers and another for mobile 043 * browsers. 044 * 045 * It is possible to override the template using a cookie containing the name of the template context 046 * which should be used as a value. The cookie name is determined by the template context provider.<p> 047 */ 048public interface I_CmsTemplateContextProvider { 049 050 /** 051 * Gets a map of all template contexts, with the template context names as keys.<p> 052 * 053 * @return the map of template context providers 054 */ 055 Map<String, CmsTemplateContext> getAllContexts(); 056 057 /** 058 * Returns the style sheet to be used for the editor.<p> 059 * 060 * @param cms the current CMS context 061 * @param editedResourcePath the path of the edited resource 062 * 063 * @return the path of the style sheet to be used for the resource 064 */ 065 String getEditorStyleSheet(CmsObject cms, String editedResourcePath); 066 067 /** 068 * Gets the name of the cookie which should be used for overriding the template context.<p> 069 * 070 * @return the name of the cookie used for overriding the template context 071 */ 072 String getOverrideCookieName(); 073 074 /** 075 * Determines the template context from the current CMS context, request, and resource.<p> 076 * 077 * @param cms the CMS context 078 * @param request the current request 079 * @param resource the resource being rendered 080 * 081 * @return the current template context 082 */ 083 CmsTemplateContext getTemplateContext(CmsObject cms, HttpServletRequest request, CmsResource resource); 084 085 /** 086 * Initializes the context provider using a CMS object.<p> 087 * 088 * @param cms the current CMS context 089 * @param config the template context provider configuration 090 */ 091 void initialize(CmsObject cms, String config); 092 093 /** 094 * Gets the value which should be used instead of a property which was read from the template resource.<p> 095 * 096 * This is needed because before template context providers, it was common to store template-specific configuration in 097 * a property on the template JSP. Since template context providers make the result ambiguous, this method is intended 098 * as a replacement.<p> 099 * 100 * @param cms the CMS context to use 101 * @param propertyName the name of the property 102 * @param fallbackValue the value to return if no value is found or an error occurs 103 * 104 * @return the common property value 105 * 106 * @throws CmsException if something goes wrong 107 */ 108 String readCommonProperty(CmsObject cms, String propertyName, String fallbackValue) throws CmsException; 109 110}