commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject cvs commit: jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/util TagXMLDoclet.java
Date Mon, 22 Jul 2002 10:49:11 GMT
jstrachan    2002/07/22 03:49:11

  Modified:    jelly/src/java/org/apache/commons/jelly/util
                        TagXMLDoclet.java
  Log:
  Patched the tag doclet so that the HTML documentation contained inside the javadoc comments
comes out as XML so that it can be styled via XSLT, JSL, DVSL etc.
  
  Revision  Changes    Path
  1.3       +48 -2     jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/util/TagXMLDoclet.java
  
  Index: TagXMLDoclet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/util/TagXMLDoclet.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TagXMLDoclet.java	15 Jul 2002 15:47:35 -0000	1.2
  +++ TagXMLDoclet.java	22 Jul 2002 10:49:11 -0000	1.3
  @@ -62,10 +62,13 @@
   
   package org.apache.commons.jelly.util;
   
  +import com.sun.javadoc.*;
  +
   import java.beans.Introspector;
   import java.io.*;
   import java.util.*;
  -import com.sun.javadoc.*;
  +
  +import org.cyberneko.html.parsers.SAXParser;
   
   import org.dom4j.io.OutputFormat;
   import org.dom4j.io.XMLWriter;
  @@ -275,7 +278,8 @@
           cm.startElement(xmlns, localName, "doc", emptyAtts);
           String commentText = doc.commentText();
           if (! commentText.equals("")) {
  -            cm.characters(commentText.toCharArray(), 0, commentText.length());
  +            parseHTML(commentText);
  +            // cm.characters(commentText.toCharArray(), 0, commentText.length());
           }
           Tag[] tags = doc.tags();
           for (int i = 0; i < tags.length; ++i) {
  @@ -306,6 +310,48 @@
   */        
       }
   
  +    protected void parseHTML(String text) throws SAXException {
  +        SAXParser parser = new SAXParser();
  +        parser.setProperty(
  +            "http://cyberneko.org/html/properties/names/elems",
  +            "lower"
  +        );
  +        parser.setProperty(
  +            "http://cyberneko.org/html/properties/names/attrs",
  +            "lower"
  +        );
  +        parser.setContentHandler(
  +            new DefaultHandler() {
  +                public void startElement(String namespaceURI, String localName, String
qName, Attributes atts) throws SAXException {
  +                    if ( validDocElementName( localName ) ) {
  +                        cm.startElement(namespaceURI, localName, qName, atts);
  +                    }
  +                }
  +                public void endElement(String namespaceURI, String localName, String qName)
throws SAXException {
  +                    if ( validDocElementName( localName ) ) {
  +                        cm.endElement(namespaceURI, localName, qName);
  +                    }
  +                }
  +                public void characters(char[] ch, int start, int length) throws SAXException
{
  +                    cm.characters(ch, start, length);
  +                }
  +            }
  +        );
  +        try {
  +            parser.parse( new InputSource(new StringReader( text )) );
  +        }
  +        catch (IOException e) {
  +            System.err.println( "This should never happen!" + e );
  +        }
  +    }
  +
  +    /**
  +     * @return true if the given name is a valid HTML markup element.
  +     */
  +    protected boolean validDocElementName(String name) {
  +        return ! name.equalsIgnoreCase( "html" ) && ! name.equalsIgnoreCase( "body"
);
  +    }
  +    
       /**
        * Generates doc for all tag elements.
        */
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message