KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > riotfamily > website > generic > view > DumpModelViewResolver


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) 2007
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.website.generic.view;
25
26 import java.util.Locale JavaDoc;
27
28 import org.springframework.core.Ordered;
29 import org.springframework.web.servlet.View;
30 import org.springframework.web.servlet.ViewResolver;
31
32 /**
33  * ViewResolver that returns a {@link DumpModelView} if the the viewName
34  * equals the {@link #setDumpViewName(String) set dumpViewName}.
35  * <p>
36  * In order to dump the model whenever a controller returns no view, add the
37  * following to bean definitions to the context of your DispatcherServlet:
38  * <pre>
39  * &lt;bean id="viewNameTranslator" class="{@link org.riotfamily.website.generic.view.FixedViewNameTranslator}" /&gt;
40  * &lt;bean class="{@link org.riotfamily.website.generic.view.DumpModelViewResolver}" /&gt;
41  * </pre>
42  * @author Felix Gnass [fgnass at neteye dot de]
43  * @since 6.4
44  */

45 public class DumpModelViewResolver implements ViewResolver, Ordered {
46
47     private DumpModelView dumpModelView = new DumpModelView();
48
49     private String JavaDoc dumpViewName = FixedViewNameTranslator.DEFAULT_VIEW_NAME;
50     
51     public int getOrder() {
52         return Ordered.HIGHEST_PRECEDENCE;
53     }
54     
55     /**
56      * Sets the URL of a CSS style sheet that should be used to style the
57      * output.
58      */

59     public void setStyleSheet(String JavaDoc styleSheet) {
60         dumpModelView.setStyleSheet(styleSheet);
61     }
62     
63     /**
64      * Sets the viewName that should be resolved to the DumpModelView.
65      * Default is {@link FixedViewNameTranslator#DEFAULT_VIEW_NAME}.
66      */

67     public void setDumpViewName(String JavaDoc dumpViewName) {
68         this.dumpViewName = dumpViewName;
69     }
70
71     public View resolveViewName(String JavaDoc viewName, Locale JavaDoc locale) {
72         if (dumpViewName.equals(viewName)) {
73             return dumpModelView;
74         }
75         return null;
76     }
77 }
78
Popular Tags