KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > presentation > MockRollerContext


1 /*
2  * Created on Mar 4, 2004
3  */

4 package org.roller.presentation;
5 import java.io.File JavaDoc;
6 import javax.servlet.ServletContext JavaDoc;
7 import javax.servlet.ServletContextEvent JavaDoc;
8 import javax.servlet.http.HttpServletRequest JavaDoc;
9 import org.apache.commons.logging.Log;
10 import org.apache.commons.logging.LogFactory;
11 import org.roller.RollerException;
12
13 /**
14  * @author lance.lavandowska
15  */

16 public class MockRollerContext extends RollerContext
17 {
18     private static Log mLogger =
19         LogFactory.getFactory().getInstance(MockRollerContext.class);
20     private static ServletContext JavaDoc mContext = null;
21     public void init(ServletContext JavaDoc sc)
22     {
23         mLogger.debug("MockRollerContext initializing");
24         
25         // initialize super
26
super.contextInitialized(new ServletContextEvent JavaDoc(sc));
27         
28         // Save context in self and self in context
29
mContext = sc;
30         mContext.setAttribute(ROLLER_CONTEXT, this);
31         mContext.setAttribute("org.roller.absoluteContextURL", "/");
32     }
33     //-----------------------------------------------------------------------
34
/** Because I cannot set the super's values, I have to
35      * overide the methods as well */

36     public static RollerContext getRollerContext(ServletContext JavaDoc sc)
37     {
38         // get roller from servlet context
39
return (RollerContext) mContext.getAttribute(ROLLER_CONTEXT);
40     }
41     //-----------------------------------------------------------------------
42
/** Because I cannot set the super's values, I have to
43      * overide the methods as well */

44     public static ServletContext JavaDoc getServletContext()
45     {
46         return mContext;
47     }
48
49     //-----------------------------------------------------------------------
50
/** Because I cannot set the super's values, I have to
51      * overide the methods as well */

52     public String JavaDoc getRollerVersion()
53     {
54         return super.getRollerVersion();
55     }
56     //-----------------------------------------------------------------------
57
/** Because I cannot set the super's values, I have to
58      * overide the methods as well */

59     public String JavaDoc getRollerBuildTime()
60     {
61         return super.getRollerBuildTime();
62     }
63     //-----------------------------------------------------------------------
64
/** Because I cannot set the super's values, I have to
65      * overide the methods as well */

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

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

81     public String JavaDoc getAbsoluteContextUrl(HttpServletRequest JavaDoc request)
82     {
83         return request.getScheme() +"://" + request.getServerName() + "";
84     }
85     //-----------------------------------------------------------------------
86
/** Because I cannot set the super's values, I have to
87      * overide the methods as well */

88     /* not available anymore ... use the new config classes instead -- Allen G
89     public RollerConfigData getRollerConfig()
90     {
91         return super.getRollerConfig();
92     }
93     */

94     //------------------------------------------------------------------------
95
public String JavaDoc getConfigPath()
96     {
97         String JavaDoc root = System.getProperty("ro.build");
98         String JavaDoc configPath =
99             root
100                 + File.separator
101                 + "roller"
102                 + File.separator
103                 + "WEB-INF"
104                 + File.separator
105                 + "roller-config.xml";
106         return configPath;
107     }
108     protected void upgradeDatabaseIfNeeded() throws RollerException
109     {
110         // for now, this is a no-op
111
}
112
113 }
114
115
Popular Tags