KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > ui > rendering > util > WeblogPreviewRequest


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. The ASF licenses this file to You
4  * under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License. For additional information regarding
15  * copyright in this work, please see the NOTICE file in the top level
16  * directory of this distribution.
17  */

18
19 package org.apache.roller.ui.rendering.util;
20
21 import javax.servlet.http.HttpServletRequest JavaDoc;
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.roller.RollerException;
25 import org.apache.roller.ThemeNotFoundException;
26 import org.apache.roller.model.RollerFactory;
27 import org.apache.roller.model.ThemeManager;
28 import org.apache.roller.pojos.Theme;
29
30
31 /**
32  * Represents a request for a weblog preview.
33  */

34 public class WeblogPreviewRequest extends WeblogPageRequest {
35     
36     private static Log log = LogFactory.getLog(WeblogPreviewRequest.class);
37     
38     private static final String JavaDoc PREVIEW_SERVLET = "/roller-ui/authoring/preview";
39     
40     // lightweight attributes
41
private String JavaDoc themeName = null;
42     
43     // heavyweight attributes
44
private Theme theme = null;
45     
46     
47     public WeblogPreviewRequest(HttpServletRequest JavaDoc request)
48             throws InvalidRequestException {
49         
50         // let parent go first
51
super(request);
52         
53         // all we need to worry about is the query params
54
// the only param we expect is "theme"
55
if(request.getParameter("theme") != null) {
56             this.themeName = request.getParameter("theme");
57         }
58         
59         if(log.isDebugEnabled()) {
60             log.debug("theme = "+this.themeName);
61         }
62     }
63     
64     
65     boolean isValidDestination(String JavaDoc servlet) {
66         return (servlet != null && PREVIEW_SERVLET.equals(servlet));
67     }
68     
69     
70     public String JavaDoc getThemeName() {
71         return themeName;
72     }
73
74     public void setThemeName(String JavaDoc theme) {
75         this.themeName = theme;
76     }
77     
78     // override so that previews never show login status
79
public String JavaDoc getAuthenticUser() {
80         return null;
81     }
82     
83     // override so that previews never show login status
84
public boolean isLoggedIn() {
85         return false;
86     }
87
88     public Theme getTheme() {
89         
90         if(theme == null && themeName != null) {
91             try {
92                 ThemeManager themeMgr = RollerFactory.getRoller().getThemeManager();
93                 theme = themeMgr.getTheme(themeName);
94             } catch(ThemeNotFoundException tnfe) {
95                 // bogus theme specified ... don't worry about it
96
} catch(RollerException re) {
97                 log.error("Error looking up theme "+themeName, re);
98             }
99         }
100         
101         return theme;
102     }
103
104     public void setTheme(Theme theme) {
105         this.theme = theme;
106     }
107     
108 }
109
Popular Tags