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.business.WeblogManager;
029: import org.apache.roller.pojos.Theme;
030: import org.apache.roller.pojos.WeblogEntryData;
031: import org.apache.roller.util.URLUtilities;
032:
033: /**
034: * Represents a request for a weblog preview.
035: */
036: public class WeblogPreviewRequest extends WeblogPageRequest {
037:
038: private static Log log = LogFactory
039: .getLog(WeblogPreviewRequest.class);
040:
041: private static final String PREVIEW_SERVLET = "/roller-ui/authoring/preview";
042:
043: // lightweight attributes
044: private String themeName = null;
045: private String previewEntry = null;
046:
047: // heavyweight attributes
048: private Theme theme = null;
049: private WeblogEntryData weblogEntry = null;
050:
051: public WeblogPreviewRequest(HttpServletRequest request)
052: throws InvalidRequestException {
053:
054: // let parent go first
055: super (request);
056:
057: // we may have a specific theme to preview
058: if (request.getParameter("theme") != null) {
059: this .themeName = request.getParameter("theme");
060: }
061:
062: // we may also have a specific entry to preview
063: if (request.getParameter("previewEntry") != null) {
064: this .previewEntry = URLUtilities.decode(request
065: .getParameter("previewEntry"));
066: }
067:
068: if (log.isDebugEnabled()) {
069: log.debug("theme = " + this .themeName);
070: }
071: }
072:
073: boolean isValidDestination(String servlet) {
074: return (servlet != null && PREVIEW_SERVLET.equals(servlet));
075: }
076:
077: public String getThemeName() {
078: return themeName;
079: }
080:
081: public void setThemeName(String theme) {
082: this .themeName = theme;
083: }
084:
085: // override so that previews never show login status
086: public String getAuthenticUser() {
087: return null;
088: }
089:
090: // override so that previews never show login status
091: public boolean isLoggedIn() {
092: return false;
093: }
094:
095: public Theme getTheme() {
096:
097: if (theme == null && themeName != null) {
098: try {
099: ThemeManager themeMgr = RollerFactory.getRoller()
100: .getThemeManager();
101: theme = themeMgr.getTheme(themeName);
102: } catch (ThemeNotFoundException tnfe) {
103: // bogus theme specified ... don't worry about it
104: } catch (RollerException re) {
105: log.error("Error looking up theme " + themeName, re);
106: }
107: }
108:
109: return theme;
110: }
111:
112: public void setTheme(Theme theme) {
113: this .theme = theme;
114: }
115:
116: public String getPreviewEntry() {
117: return previewEntry;
118: }
119:
120: public void setPreviewEntry(String previewEntry) {
121: this .previewEntry = previewEntry;
122: }
123:
124: // if we have a preview entry we would prefer to return that
125: public WeblogEntryData getWeblogEntry() {
126:
127: if (weblogEntry == null
128: && (previewEntry != null || super .getWeblogAnchor() != null)) {
129:
130: String anchor = previewEntry;
131: if (previewEntry == null) {
132: anchor = super .getWeblogAnchor();
133: }
134:
135: try {
136: WeblogManager wmgr = RollerFactory.getRoller()
137: .getWeblogManager();
138: weblogEntry = wmgr.getWeblogEntryByAnchor(getWeblog(),
139: anchor);
140: } catch (RollerException ex) {
141: log.error("Error getting weblog entry " + anchor, ex);
142: }
143: }
144:
145: return weblogEntry;
146: }
147:
148: public void setWeblogEntry(WeblogEntryData weblogEntry) {
149: this.weblogEntry = weblogEntry;
150: }
151:
152: }
|