01: /* ***** BEGIN LICENSE BLOCK *****
02: * Version: MPL 1.1
03: * The contents of this file are subject to the Mozilla Public License Version
04: * 1.1 (the "License"); you may not use this file except in compliance with
05: * the License. You may obtain a copy of the License at
06: * http://www.mozilla.org/MPL/
07: *
08: * Software distributed under the License is distributed on an "AS IS" basis,
09: * 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;
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 SERVLET_PREFIX_ATTRIBUTE = "riotServletPrefix";
47:
48: public static final String DEFAULT_SERVLET_PREFIX = "/riot";
49:
50: private String servletPrefix;
51:
52: private String resourceMapping;
53:
54: private String resourcePath;
55:
56: public void setResourceMapping(String resourceMapping) {
57: this .resourceMapping = resourceMapping;
58: }
59:
60: public void setServletContext(ServletContext context) {
61: Assert.notNull(resourceMapping,
62: "A resourceMapping must be specified.");
63: servletPrefix = (String) context
64: .getInitParameter(SERVLET_PREFIX_ATTRIBUTE);
65: if (servletPrefix == null) {
66: servletPrefix = DEFAULT_SERVLET_PREFIX;
67: }
68: resourcePath = servletPrefix + resourceMapping + '/'
69: + getVersionString() + '/';
70: }
71:
72: public String getServletPrefix() {
73: return servletPrefix;
74: }
75:
76: public String getResourcePath() {
77: return resourcePath;
78: }
79:
80: public String getVersionString() {
81: return RiotVersion.getVersionString();
82: }
83:
84: public static RiotRuntime getRuntime(ApplicationContext context) {
85: return (RiotRuntime) BeanFactoryUtils
86: .beanOfTypeIncludingAncestors(context,
87: RiotRuntime.class);
88: }
89: }
|