001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.lastmodified;
022:
023: import com.liferay.portal.kernel.servlet.BrowserSniffer;
024: import com.liferay.portal.kernel.servlet.HttpHeaders;
025: import com.liferay.portal.kernel.util.ParamUtil;
026: import com.liferay.portal.model.ColorScheme;
027: import com.liferay.portal.model.Theme;
028: import com.liferay.portal.service.impl.ThemeLocalUtil;
029: import com.liferay.portal.theme.ThemeDisplay;
030: import com.liferay.portal.util.WebKeys;
031:
032: import javax.servlet.http.HttpServletRequest;
033: import javax.servlet.http.HttpServletResponse;
034:
035: import org.apache.struts.action.Action;
036: import org.apache.struts.action.ActionForm;
037: import org.apache.struts.action.ActionForward;
038: import org.apache.struts.action.ActionMapping;
039:
040: /**
041: * <a href="LastModifiedAction.java.html"><b><i>View Source</i></b></a>
042: *
043: * @author Brian Wing Shun Chan
044: *
045: */
046: public abstract class LastModifiedAction extends Action {
047:
048: public ActionForward execute(ActionMapping mapping,
049: ActionForm form, HttpServletRequest req,
050: HttpServletResponse res) throws Exception {
051:
052: ThemeDisplay themeDisplay = (ThemeDisplay) req
053: .getAttribute(WebKeys.THEME_DISPLAY);
054:
055: Theme theme = themeDisplay.getTheme();
056: ColorScheme colorScheme = themeDisplay.getColorScheme();
057:
058: String themeId = ParamUtil.getString(req, "themeId");
059: String colorSchemeId = ParamUtil
060: .getString(req, "colorSchemeId");
061:
062: // The layout id is not always passed to this request. Therefore,
063: // ServicePreAction could set the wrong theme and color scheme. This
064: // check ensures that the theme and color scheme used is the one passed
065: // to it from the request parameters.
066:
067: // See:
068: // com.liferay.common.taglib.IncludeTag
069: // com.liferay.portal.events.ServicePreAction
070: // /c/portal/css
071: // /c/portal/css_cached
072: // /c/portal/javascript
073: // /c/portal/javascript_cached
074:
075: if ((theme == null)
076: || (colorScheme == null)
077: || (!theme.getThemeId().equals(themeId))
078: || (!colorScheme.getColorSchemeId().equals(
079: colorSchemeId))) {
080:
081: boolean wapTheme = BrowserSniffer.is_wap_xhtml(req);
082:
083: theme = ThemeLocalUtil.getTheme(
084: themeDisplay.getCompanyId(), themeId, wapTheme);
085: colorScheme = ThemeLocalUtil.getColorScheme(themeDisplay
086: .getCompanyId(), themeId, colorSchemeId, wapTheme);
087:
088: themeDisplay.setLookAndFeel(theme, colorScheme);
089:
090: req.setAttribute(WebKeys.THEME, theme);
091: req.setAttribute(WebKeys.COLOR_SCHEME, colorScheme);
092: }
093:
094: res.addHeader(HttpHeaders.CACHE_CONTROL, "max-age=0");
095:
096: res.setDateHeader(HttpHeaders.LAST_MODIFIED, System
097: .currentTimeMillis());
098:
099: return mapping.findForward("modified.jsp");
100: }
101:
102: public abstract String getLastModifiedKey(HttpServletRequest req);
103:
104: public abstract String getLastModifiedValue(String key);
105:
106: public abstract void setLastModifiedValue(String key, String value);
107:
108: }
|