org/nothing/SomeTest.java

1  /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *     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  
<h1>What's this?</h1> Based on the Slop parser, Javateach creates a nice HTML page from the source code of a Java class. The idea is to write explanations of the code inline, allowing explanations and code to stay together, and keeping line numbers accurate. <h1>Teaching comments</h1> Comments like this one, surrounded by lpstart/lpend will be extracted from the source code to create an HTML presentation which mixes teaching comments and code.
30  
31  import org.xml.sax.ContentHandler;
32  import org.xml.sax.SAXException;
33  
34  
Here we could explain what class comments are about.
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  
<h2>Here's the class declaration</h2> This class does nothing useful, it does not even compile, it is only used to test the javateach formatting. <br/> Code indentation is preserved, this is set by SlopGenerator parameters in the sitemap.
50  
51  public class SomeTest implements SlopParser,SlopConstants {
52      private ContentHandler contentHandler;
53  
54      /** chars that can be part of a field name (other than letters) */
55      private final static String DEFAULT_TAGNAME_CHARS = "-_";
56      private String tagnameChars = DEFAULT_TAGNAME_CHARS;
57  
58  
lp markers have to start in column 1. <br/> HTML constructs are <b>allowed</b> in lp comments: <ul> <li>You like bullet points, I'm sure...</li> <li>Here's the second one</li> </ul> Links also work, like <a href="http://www.perdu.com" target="_new">this</a>.
68  
69      /** optionally preserve whitespace in input */
70      private boolean preserveSpace = false;
71  
72      /** result of parsing a line */
73      static class ParsedLine {
74          final String name;
75          final String contents;
76  
77          ParsedLine(String elementName, String elementContents) {
78              name = elementName;
79              contents = elementContents;
80          }
81      }
82  
83  
SetValidTagname() is used to define a list of valid character for XML element names.
87  
88      /** set the list of valid chars for tag names (in addition to letters) */
89      public void setValidTagnameChars(String str) {
90          tagnameChars = str;
91      }
92  
93  }