KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > ui > MockRollerContext


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  * Created on Mar 4, 2004
20  */

21 package org.apache.roller.ui;
22 import java.io.File JavaDoc;
23
24 import javax.servlet.ServletContext JavaDoc;
25 import javax.servlet.ServletContextEvent JavaDoc;
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30 import org.apache.roller.RollerException;
31 import org.apache.roller.ui.core.*;
32
33 /**
34  * @author lance.lavandowska
35  */

36 public class MockRollerContext extends RollerContext {
37     private static Log mLogger =
38             LogFactory.getFactory().getInstance(MockRollerContext.class);
39     
40     private static ServletContext JavaDoc mContext = null;
41     
42     public void init(ServletContext JavaDoc sc) {
43         mLogger.debug("MockRollerContext initializing");
44         
45         // initialize super
46
super.contextInitialized(new ServletContextEvent JavaDoc(sc));
47         
48         // Save context in self and self in context
49
mContext = sc;
50         mContext.setAttribute(ROLLER_CONTEXT, this);
51         mContext.setAttribute("org.apache.roller.absoluteContextURL", "/");
52     }
53     //-----------------------------------------------------------------------
54
/** Because I cannot set the super's values, I have to
55      * overide the methods as well */

56     public static RollerContext getRollerContext() {
57         // get roller from servlet context
58
return (RollerContext) mContext.getAttribute(ROLLER_CONTEXT);
59     }
60     //-----------------------------------------------------------------------
61
/** Because I cannot set the super's values, I have to
62      * overide the methods as well */

63     public static ServletContext JavaDoc getServletContext() {
64         return mContext;
65     }
66     
67     //-----------------------------------------------------------------------
68
/** Because I cannot set the super's values, I have to
69      * overide the methods as well */

70     public String JavaDoc getRollerVersion() {
71         return super.getRollerVersion();
72     }
73     //-----------------------------------------------------------------------
74
/** Because I cannot set the super's values, I have to
75      * overide the methods as well */

76     public String JavaDoc getRollerBuildTime() {
77         return super.getRollerBuildTime();
78     }
79     //-----------------------------------------------------------------------
80
/** Because I cannot set the super's values, I have to
81      * overide the methods as well */

82     public String JavaDoc getRollerBuildUser() {
83         return super.getRollerBuildUser();
84     }
85     
86     //-----------------------------------------------------------------------
87
/** Because I cannot set the super's values, I have to
88      * overide the methods as well */

89     public String JavaDoc getAbsoluteContextUrl() {
90         return "";
91     }
92     //-----------------------------------------------------------------------
93
/** Because I cannot set the super's values, I have to
94      * overide the methods as well */

95     public String JavaDoc getAbsoluteContextUrl(HttpServletRequest JavaDoc request) {
96         return "http://localhost:8080/roller";
97     }
98     //-----------------------------------------------------------------------
99
/** Because I cannot set the super's values, I have to
100      * overide the methods as well */

101     /* not available anymore ... use the new config classes instead -- Allen G
102     public RollerConfigData getRollerConfig()
103     {
104         return super.getRollerConfig();
105     }
106      */

107     //------------------------------------------------------------------------
108
public String JavaDoc getConfigPath() {
109         String JavaDoc root = System.getProperty("ro.build");
110         String JavaDoc configPath =
111                 root
112                 + File.separator
113                 + "roller"
114                 + File.separator
115                 + "WEB-INF"
116                 + File.separator
117                 + "roller-config.xml";
118         return configPath;
119     }
120     protected void upgradeDatabaseIfNeeded() throws RollerException {
121         // for now, this is a no-op
122
}
123     
124 }
125
126
Popular Tags