01: /*
02: * DebugTemplate.java
03: *
04: * Brazil project web application Framework,
05: * export version: 1.1
06: * Copyright (c) 2000 Sun Microsystems, Inc.
07: *
08: * Sun Public License Notice
09: *
10: * The contents of this file are subject to the Sun Public License Version
11: * 1.0 (the "License"). You may not use this file except in compliance with
12: * the License. A copy of the License is included as the file "license.terms",
13: * and also available at http://www.sun.com/
14: *
15: * The Original Code is from:
16: * Brazil project web application Framework release 1.1.
17: * The Initial Developer of the Original Code is: suhler.
18: * Portions created by suhler are Copyright (C) Sun Microsystems, Inc.
19: * All Rights Reserved.
20: *
21: * Contributor(s): suhler.
22: *
23: * Version: 1.4
24: * Created by suhler on 00/11/17
25: * Last modified by suhler on 00/12/11 13:31:09
26: */
27:
28: package sunlabs.brazil.template;
29:
30: import sunlabs.brazil.util.Format;
31: import java.io.Serializable;
32:
33: /**
34: * Template class for printing stuff to stderr (for template debugging)
35: * This class is used by the TemplateHandler
36: * <p>
37: * A new HTML tag,
38: * <code><debug></code> is defined. Any text between the
39: * <code><debug</code> and <code>></code> is printed on stderr,
40: * along with the
41: * session id and the url. Variable substitutions of the form
42: * ${...} are performed on the text.
43: * <p>
44: * The property <code>debug</code> must be present for this template
45: * to function. Otherwise, all <code>debug</code> tags are removed.
46: *
47: * @author Stephen Uhler
48: * @version %V% 00/12/11
49: */
50:
51: public class DebugTemplate extends Template implements Serializable {
52: private static final String DEBUG = "debug";
53: transient boolean debug;
54:
55: public boolean init(RewriteContext hr) {
56: debug = (hr.request.props.getProperty(hr.prefix + DEBUG) != null);
57: return true;
58: }
59:
60: public void tag_debug(RewriteContext hr) {
61: if (debug) {
62: String stuff = hr.getArgs();
63: if (stuff != null) {
64: String map = Format.subst(hr.request.props, stuff);
65: System.err.println("Debug " + hr.sessionId + ":"
66: + hr.request.url + " " + map);
67: hr.append("\n<!--DEBUG " + stuff + "\n " + map
68: + "-->\n");
69: }
70: }
71: hr.killToken();
72: }
73: }
|