cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject cvs commit: cocoon-2.1/src/blocks/slop/samples/javateach/java-source/org/nothing
Date Tue, 14 Oct 2003 12:00:05 GMT
bdelacretaz    2003/10/14 05:00:05

  Added:       src/blocks/slop/samples/javateach javateach.css
  javateach sample - poor man's literate programming tool
  Revision  Changes    Path
  1.1                  cocoon-2.1/src/blocks/slop/samples/javateach/javateach.css
  Index: javateach.css
      CSS stylesheet for javateach
      Main looks inspired from linotype CSS stylesheets
  #content {
      font-family: "georgia", "times", "times new roman", serif;
  h1 {
      margin-bottom: 0;
      font-variant: small-caps;
      background: transparent;
      font-size: 150%;
  h1.pageTitle {
      font-size: 180%;
      border-bottom: solid red 1px;
  h2 {
      margin-bottom: 0;
      background: transparent;
      font-size: 125%;
  h3 {
      margin-bottom: 0;
      background: transparent;
  a {
  	text-decoration: none;
  	color: #000;
  	border-bottom: 1px dotted #777;
  	margin: 0px 2px 0px 2px;
  	padding: 1px 1px 1px 1px;
  a:hover {
  	border: 1px dotted #000;
  	background-color: #eee;
  	padding: 1px 2px 1px 2px;
  	margin: 0px;
  a:active {
  	background-color: #ccc !important;
  	position: relative;
  	top: 1px;
  	left: 1px;
  	padding: 1px 2px 1px 2px;
  	margin: 0px;
  a:focus {
  	border: 1px solid #fff !important;
  	background-color: #ccc !important;
  	padding: 1px 2px 1px 2px;
  	margin: 0px;
  .lineNumber {
      display: inline;
      color: grey;
  pre {
      border: 1px dotted #000;
      padding: 10px;
      margin: 20px;
      font-size: 120%;
      background: #FFFFCC;
  .teachingComments {
      margin-left: 10px;
  .commentLine {
      display: inline;
  1.1                  cocoon-2.1/src/blocks/slop/samples/javateach/jt-to-html.xsl
  Index: jt-to-html.xsl
  <?xml version="1.0"?>
      Convert slop output to HTML for the javateach sample
      $Id: jt-to-html.xsl,v 1.1 2003/10/14 12:00:05 bdelacretaz Exp $
      <xsl:param name="pageTitle" select="'Javateach sample - using the Cocoon SLOP parser'"/>
      <!-- keys based on last preceding lpstart or lpend, used to split between code and
teaching comments -->
          match="slop:*" use="generate-id(preceding::slop:*[self::slop:__lpstart|self::slop:__lpend][1])"
      <xsl:template match="/">
                  <title><xsl:value-of select="$pageTitle"/></title>
                  <link rel="stylesheet" type="text/css" href="css/javateach.css"/>
                  <div id="content">
                      <h1 class="pageTitle"><xsl:value-of select="$pageTitle"/></h1>
                      <div class="code">
and not(self::slop:__lpstart)]"
                      <xsl:apply-templates select="slop:parsed-text/slop:__lpstart|slop:parsed-text/slop:__lpend"/>
      <xsl:template match="slop:__lpstart">
          <div class="teachingComments">
              <xsl:apply-templates select="key('lastMarkKey',generate-id(.))" mode="teachingComments"/>
      <xsl:template match="slop:__lpend">
          <div class="code">
                  <xsl:apply-templates select="key('lastMarkKey',generate-id(.))" mode="code"/>
      <xsl:template match="slop:*" mode="teachingComments">
          <xsl:value-of select="concat(substring-after(.,'//'),'&#xD;')" disable-output-escaping="yes"/>
      <xsl:template match="slop:*" mode="code">
          <span class="lineNumber">
              <xsl:value-of select="concat(@line-number,'  ')"/>
          <span class="codeLine">
              <xsl:value-of select="concat(.,'&#xD;')"/>
  1.1                  cocoon-2.1/src/blocks/slop/samples/javateach/java-source/org/nothing/
  // (currently lpstart comments at the very start do not work)
  package org.nothing;
  //  <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.
  import org.xml.sax.ContentHandler;
  import org.xml.sax.SAXException;
  //  Here we could explain what class comments are about.
  /** Simple example of java code parsing with Slop.
   *  The aim is to create a minimal "literate programming" system for teaching,
   *  where java code is decorated with narrative comments. */
  //  <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.
  public class SomeTest implements SlopParser,SlopConstants {
      private ContentHandler contentHandler;
      /** chars that can be part of a field name (other than letters) */
      private final static String DEFAULT_TAGNAME_CHARS = "-_";
      private String tagnameChars = DEFAULT_TAGNAME_CHARS;
  // 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="" target="_new">this</a>.
      /** optionally preserve whitespace in input */
      private boolean preserveSpace = false;
      /** result of parsing a line */
      static class ParsedLine {
          final String name;
          final String contents;
          ParsedLine(String elementName, String elementContents) {
              name = elementName;
              contents = elementContents;
  //    SetValidTagname() is used to define a list of valid character for XML element
  //    names.
      /** set the list of valid chars for tag names (in addition to letters) */
      public void setValidTagnameChars(String str) {
          tagnameChars = str;

View raw message