001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. The ASF licenses this file to You
004: * under the Apache License, Version 2.0 (the "License"); you may not
005: * 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. For additional information regarding
015: * copyright in this work, please see the NOTICE file in the top level
016: * directory of this distribution.
017: */
018:
019: package org.apache.roller.ui.rendering.util;
020:
021: import javax.servlet.http.HttpServletRequest;
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024: import org.apache.roller.RollerException;
025: import org.apache.roller.business.ThemeNotFoundException;
026: import org.apache.roller.business.RollerFactory;
027: import org.apache.roller.business.ThemeManager;
028: import org.apache.roller.pojos.Theme;
029:
030: /**
031: *
032: */
033: public class WeblogPreviewResourceRequest extends WeblogResourceRequest {
034:
035: private static Log log = LogFactory
036: .getLog(WeblogPreviewResourceRequest.class);
037:
038: // lightweight attributes
039: private String themeName = null;
040:
041: // heavyweight attributes
042: private Theme theme = null;
043:
044: public WeblogPreviewResourceRequest() {
045: }
046:
047: public WeblogPreviewResourceRequest(HttpServletRequest request)
048: throws InvalidRequestException {
049:
050: // let parent go first
051: super (request);
052:
053: // all we need to worry about is the query params
054: // the only param we expect is "theme"
055: if (request.getParameter("theme") != null) {
056: this .themeName = request.getParameter("theme");
057: }
058:
059: if (log.isDebugEnabled()) {
060: log.debug("theme = " + this .themeName);
061: }
062: }
063:
064: public String getThemeName() {
065: return themeName;
066: }
067:
068: public void setThemeName(String theme) {
069: this .themeName = theme;
070: }
071:
072: // override so that previews never show login status
073: public String getAuthenticUser() {
074: return null;
075: }
076:
077: // override so that previews never show login status
078: public boolean isLoggedIn() {
079: return false;
080: }
081:
082: public Theme getTheme() {
083:
084: if (theme == null && themeName != null) {
085: try {
086: ThemeManager themeMgr = RollerFactory.getRoller()
087: .getThemeManager();
088: theme = themeMgr.getTheme(themeName);
089: } catch (ThemeNotFoundException tnfe) {
090: // bogus theme specified ... don't worry about it
091: } catch (RollerException re) {
092: log.error("Error looking up theme " + themeName, re);
093: }
094: }
095:
096: return theme;
097: }
098:
099: public void setTheme(Theme theme) {
100: this.theme = theme;
101: }
102: }
|