KickJava   Java API By Example, From Geeks To Geeks.

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


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.Iterator JavaDoc;
27 import java.util.Map JavaDoc;
28
29 import javax.servlet.http.HttpServletRequest JavaDoc;
30 import javax.servlet.http.HttpServletResponse JavaDoc;
31
32 import org.riotfamily.common.markup.DocumentWriter;
33 import org.riotfamily.common.markup.Html;
34 import org.riotfamily.common.web.util.ServletUtils;
35 import org.springframework.core.style.StylerUtils;
36 import org.springframework.web.servlet.View;
37
38 /**
39  * View that dumps the content of the model as HTML page.
40  *
41  * @see DumpModelViewResolver
42  * @author Felix Gnass [fgnass at neteye dot de]
43  * @since 6.4
44  */

45 public class DumpModelView implements View {
46
47     public static final String JavaDoc DEFAULT_STYLE_SHEET =
48             "http://www.riotfamily.org/downloads/dump-model.css";
49     
50     private String JavaDoc styleSheet = DEFAULT_STYLE_SHEET;
51     
52     /**
53      * Sets the URL of a CSS style sheet that should be used to style the
54      * output. Default is http://www.riotfamily.org/downloads/dump-model.css.
55      * If the URL is not external, the context-path is added automatically.
56      *
57      * @param styleSheet URL to use, or <code>null</code> for an unformatted output.
58      */

59     public void setStyleSheet(String JavaDoc styleSheet) {
60         this.styleSheet = styleSheet;
61     }
62
63     public String JavaDoc getContentType() {
64         return "text/html";
65     }
66     
67     public void render(Map JavaDoc model, HttpServletRequest JavaDoc request,
68             HttpServletResponse JavaDoc response) throws Exception JavaDoc {
69         
70         DocumentWriter out = new DocumentWriter(response.getWriter());
71         out.start(Html.HTML);
72         
73         out.start(Html.HEAD);
74         out.start(Html.TITLE).body("Model Dump").end();
75         if (styleSheet != null) {
76             out.start(Html.LINK).attribute(Html.LINK_REL, "stylesheet")
77                     .attribute(Html.LINK_HREF,
78                     ServletUtils.resolveUrl(styleSheet, request)).end();
79         }
80         out.end();
81         
82         out.start(Html.BODY).start(Html.DL);
83         Iterator JavaDoc it = model.entrySet().iterator();
84         while (it.hasNext()) {
85             Map.Entry JavaDoc entry = (Map.Entry JavaDoc) it.next();
86             out.start(Html.DT).body(entry.getKey().toString()).end();
87             out.start(Html.DD).body(StylerUtils.style(entry.getValue())).end();
88         }
89         out.closeAll();
90     }
91 }
92
Popular Tags