01: /*
02: * TOCTemplate.java
03: *
04: * Brazil project web application Framework,
05: * export version: 1.1
06: * Copyright (c) 1999-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.7
24: * Created by suhler on 99/09/01
25: * Last modified by suhler on 00/05/31 13:49:33
26: */
27:
28: package sunlabs.brazil.template;
29:
30: /**
31: * Template class for extracting table of contents information
32: * out of an html page by examining the "H1" tags, and setting
33: * request properties that can be used to build a table of contents.
34: * This class is used by the TemplateHandler.
35: *
36: * @author Stephen Uhler
37: * @version %V% TOCTemplate.java
38: */
39:
40: public class TOCTemplate extends Template {
41: StringBuffer extract; // the extracted TOC
42: int count = 0;
43:
44: public boolean init(RewriteContext hr) {
45: extract = new StringBuffer();
46: count = 0;
47: return true;
48: }
49:
50: /**
51: * Add a name anchor to the H1 tag, so we can go there,
52: * and set the request properties:<code>TOC.[anchor]</code>
53: * to the text of the <code>H1</code> tag.
54: */
55:
56: public void tag_h1(RewriteContext hr) {
57: String propName = "h1_toc_" + ++count;
58: hr.append("<a name=" + propName + "></a>");
59: hr.appendToken();
60:
61: while (hr.nextToken()) {
62: String tag = hr.getTag();
63: if (tag != null && tag.equalsIgnoreCase("/h1")) {
64: break;
65: }
66: extract.append(hr.getToken());
67: }
68: hr.request.props.put("TOC." + propName, extract.toString());
69: extract.setLength(0);
70: }
71: }
|