01: /*
02: * CountTemplate.java
03: *
04: * Brazil project web application Framework,
05: * export version: 1.1
06: * Copyright (c) 1998-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): cstevens, suhler.
22: *
23: * Version: 1.5
24: * Created by suhler on 98/09/14
25: * Last modified by suhler on 00/05/31 13:48:18
26: */
27:
28: package sunlabs.brazil.template;
29:
30: import sunlabs.brazil.server.Server;
31:
32: /**
33: * SAMPLE Template class for counting links and images in a page.
34: * @author Stephen Uhler
35: * @version 1.0, 09/04/98
36: */
37:
38: public class CountTemplate extends Template {
39: private int images = 0; // the various counts
40: private int links = 0;
41:
42: /**
43: * Count all image tags
44: */
45:
46: public void tag_img(RewriteContext hr) {
47: images++;
48: }
49:
50: /**
51: * count all anchor tags
52: */
53:
54: public void tag_a(RewriteContext hr) {
55: links++;
56: }
57:
58: /**
59: * Log the image and link counters.
60: * Return false, to let another handler actually deal with the request
61: */
62:
63: public boolean done(RewriteContext hr) {
64: hr.request.props.put("Links", "" + links);
65: hr.request.props.put("Images", "" + images);
66: hr.request.log(Server.LOG_LOG, hr.request.url + " " + links
67: + " links, " + images + " images");
68: return false;
69: }
70: }
|