01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: // (currently lpstart comments at the very start do not work)
18: package org.nothing;
19:
20: //lpstart:
21: // <h1>What's this?</h1>
22: // Based on the Slop parser, Javateach creates a nice HTML page from the source code of a Java class.
23: // The idea is to write explanations of the code inline, allowing explanations and code to stay together,
24: // and keeping line numbers accurate.
25: //
26: // <h1>Teaching comments</h1>
27: // Comments like this one, surrounded by lpstart/lpend will be extracted from the source
28: // code to create an HTML presentation which mixes teaching comments and code.
29: //lpend:
30:
31: import org.xml.sax.ContentHandler;
32: import org.xml.sax.SAXException;
33:
34: //lpstart:
35: // Here we could explain what class comments are about.
36: //lpend:
37:
38: /** Simple example of java code parsing with Slop.
39: * The aim is to create a minimal "literate programming" system for teaching,
40: * where java code is decorated with narrative comments. */
41:
42: //lpstart:
43: // <h2>Here's the class declaration</h2>
44: // This class does nothing useful, it does not even compile, it is only used to
45: // test the javateach formatting.
46: // <br/>
47: // Code indentation is preserved, this is set by SlopGenerator parameters
48: // in the sitemap.
49: //lpend:
50: public class SomeTest implements SlopParser, SlopConstants {
51: private ContentHandler contentHandler;
52:
53: /** chars that can be part of a field name (other than letters) */
54: private final static String DEFAULT_TAGNAME_CHARS = "-_";
55: private String tagnameChars = DEFAULT_TAGNAME_CHARS;
56:
57: //lpstart:
58: // lp markers have to start in column 1.
59: // <br/>
60: // HTML constructs are <b>allowed</b> in lp comments:
61: // <ul>
62: // <li>You like bullet points, I'm sure...</li>
63: // <li>Here's the second one</li>
64: // </ul>
65: // Links also work, like <a href="http://www.perdu.com" target="_new">this</a>.
66: //lpend:
67:
68: /** optionally preserve whitespace in input */
69: private boolean preserveSpace = false;
70:
71: /** result of parsing a line */
72: static class ParsedLine {
73: final String name;
74: final String contents;
75:
76: ParsedLine(String elementName, String elementContents) {
77: name = elementName;
78: contents = elementContents;
79: }
80: }
81:
82: //lpstart:
83: // SetValidTagname() is used to define a list of valid character for XML element
84: // names.
85: //lpend:
86:
87: /** set the list of valid chars for tag names (in addition to letters) */
88: public void setValidTagnameChars(String str) {
89: tagnameChars = str;
90: }
91:
92: }
|