KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > riotfamily > riot > runtime > RiotRuntime


1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1
3  * The contents of this file are subject to the Mozilla Public License Version
4  * 1.1 (the "License"); you may not use this file except in compliance with
5  * the License. You may obtain a copy of the License at
6  * http://www.mozilla.org/MPL/
7  *
8  * Software distributed under the License is distributed on an "AS IS" basis,
9  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10  * for the specific language governing rights and limitations under the
11  * License.
12  *
13  * The Original Code is Riot.
14  *
15  * The Initial Developer of the Original Code is
16  * Neteye GmbH.
17  * Portions created by the Initial Developer are Copyright (C) 2006
18  * the Initial Developer. All Rights Reserved.
19  *
20  * Contributor(s):
21  * Felix Gnass [fgnass at neteye dot de]
22  *
23  * ***** END LICENSE BLOCK ***** */

24 package org.riotfamily.riot.runtime;
25
26 import javax.servlet.ServletContext JavaDoc;
27
28 import org.riotfamily.riot.RiotVersion;
29 import org.springframework.beans.factory.BeanFactoryUtils;
30 import org.springframework.context.ApplicationContext;
31 import org.springframework.util.Assert;
32 import org.springframework.web.context.ServletContextAware;
33
34 /**
35  * Bean that exposes the riot-servlet prefix, the resource path and the
36  * riot version.
37  * <p>
38  * By default, Riot assumes that the riot-servlet is mapped to
39  * <code>/riot/*</code>. In order to use a different mapping, you have to set
40  * the context attribute <code>riotServletPrefix</code> in your
41  * <code>web.xml</code>.
42  * </p>
43  */

44 public class RiotRuntime implements ServletContextAware {
45
46     public static final String JavaDoc SERVLET_PREFIX_ATTRIBUTE = "riotServletPrefix";
47     
48     public static final String JavaDoc DEFAULT_SERVLET_PREFIX = "/riot";
49     
50     private String JavaDoc servletPrefix;
51     
52     private String JavaDoc resourceMapping;
53
54     private String JavaDoc resourcePath;
55
56     public void setResourceMapping(String JavaDoc resourceMapping) {
57         this.resourceMapping = resourceMapping;
58     }
59
60     public void setServletContext(ServletContext JavaDoc context) {
61         Assert.notNull(resourceMapping, "A resourceMapping must be specified.");
62         servletPrefix = (String JavaDoc) context.getInitParameter(SERVLET_PREFIX_ATTRIBUTE);
63         if (servletPrefix == null) {
64             servletPrefix = DEFAULT_SERVLET_PREFIX;
65         }
66         resourcePath = servletPrefix + resourceMapping + '/' + getVersionString() + '/';
67     }
68     
69     public String JavaDoc getServletPrefix() {
70         return servletPrefix;
71     }
72     
73     public String JavaDoc getResourcePath() {
74         return resourcePath;
75     }
76     
77     public String JavaDoc getVersionString() {
78         return RiotVersion.getVersionString();
79     }
80
81     public static RiotRuntime getRuntime(ApplicationContext context) {
82         return (RiotRuntime) BeanFactoryUtils.beanOfTypeIncludingAncestors(
83                 context, RiotRuntime.class);
84     }
85 }
86
Popular Tags