com.ashridgetech.jamda.common
Class XmlScraper

java.lang.Object
  |
  +--com.ashridgetech.jamda.common.Scraper
        |
        +--com.ashridgetech.jamda.common.XmlScraper

public class XmlScraper
extends Scraper

A doclet which extracts the text of method bodies and field initial values, and places the text in an XML file. The XML has the following format:

     <codeElements>
       <method name="com.ashridgetech.jamda.common.Scraper.scrapeClass(com.sun.javadoc.ClassDoc)" >
         <![CDATA[
         System.out.println( "Class: " + doc );
 
         SourcePosition pos = doc.position();
         fileName = pos.file().getPath();
 ]]>
       </method>
       <field name="com.ashridgetech.jamda.common.Scraper.LBRACE">
         <![CDATA['{']]>
       </field>
     </codeElements>
 
For abstract methods or fields with no initialiser the following format is used:
     <codeElements>
       <method name="com.ashridgetech.jamda.common.Scraper.scrapeMethod(com.sun.javadoc.ClassDoc)"
          abstract="true"/>
       <field name="com.ashridgetech.jamda.common.Scraper.elements" noInit="true"/>
     </codeElements>
 
No DTD is currently defined for this file - the elements shown above are the only ones used.

Author:
Paul Boocock version 1.0

Field Summary
static java.lang.String OUTPUT_FILE_OPTION
          The command line option for the output file.
 
Fields inherited from class com.ashridgetech.jamda.common.Scraper
DOUBLE_QUOTE, EQUALS, LBRACE, MAX_FILE_SIZE, RBRACE, SEMICOLON, SINGLE_QUOTE
 
Constructor Summary
XmlScraper(com.sun.javadoc.RootDoc root)
          Construct a XmlScraper which will scrape from the classes in root.
 
Method Summary
protected  void handleConstructor(com.sun.javadoc.ConstructorDoc memberDoc, java.lang.String body)
          Use the body code scraped for one constructor.
protected  void handleField(com.sun.javadoc.FieldDoc fieldDoc, java.lang.String initValue)
          Use the body code scraped for one field.
protected  void handleMethod(com.sun.javadoc.MethodDoc memberDoc, java.lang.String body)
          Use the body code scraped for one method.
static int optionLength(java.lang.String option)
          Doclet API method to allow recognition of the OUTPUT_FILE_OPTION command-line option
 void scrape()
          Perform the scraping process.
static boolean start(com.sun.javadoc.RootDoc root)
          The standard method which must be provided by a doclet.
static boolean validOptions(java.lang.String[][] options, com.sun.javadoc.DocErrorReporter reporter)
          Doclet API method to validate option usage.
 
Methods inherited from class com.ashridgetech.jamda.common.Scraper
extract, extractBody, extractInitialValue, getRoot, scrapeClass, scrapeConstructor, scrapeField, scrapeMethod
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OUTPUT_FILE_OPTION

public static final java.lang.String OUTPUT_FILE_OPTION
The command line option for the output file. Set to "-outputFile".

See Also:
Constant Field Values
Constructor Detail

XmlScraper

public XmlScraper(com.sun.javadoc.RootDoc root)
Construct a XmlScraper which will scrape from the classes in root.

Parameters:
root - the root of the Javadoc information passed to the doclet
Method Detail

start

public static boolean start(com.sun.javadoc.RootDoc root)
The standard method which must be provided by a doclet.

Parameters:
root - the root of the Javadoc information passed to the doclet
Returns:
true if the processing succeeds

scrape

public void scrape()
            throws java.lang.Exception
Perform the scraping process. Opens and closes the output file.

Overrides:
scrape in class Scraper
java.lang.Exception

handleConstructor

protected void handleConstructor(com.sun.javadoc.ConstructorDoc memberDoc,
                                 java.lang.String body)
                          throws java.lang.Exception
Use the body code scraped for one constructor. The name used is like a member name, with the class name repeated as the member name. For example com.ashridgetech.jamda.common.XmlScraper.XmlScraper. Ignores default constructors created by the compiler.

Overrides:
handleConstructor in class Scraper
Parameters:
memberDoc - the Javadoc information for the constructor being scraped
body - the code for the constructor body, including whitespace, but excluding the opening and closing braces.
java.lang.Exception

handleMethod

protected void handleMethod(com.sun.javadoc.MethodDoc memberDoc,
                            java.lang.String body)
Use the body code scraped for one method.

Overrides:
handleMethod in class Scraper
Parameters:
memberDoc - the Javadoc information for the method being scraped
body - the code for the method body, including whitespace, but excluding the opening and closing braces. Will be null if the method has no body.

handleField

protected void handleField(com.sun.javadoc.FieldDoc fieldDoc,
                           java.lang.String initValue)
Use the body code scraped for one field.

Overrides:
handleField in class Scraper
Parameters:
fieldDoc - the Javadoc information for the field being scraped
initValue - the code for the initialiser, trimmed of leading and trailing whitespace, and excluding the opening '=' and closing semicolon. Will be null if there is no initial value.

optionLength

public static int optionLength(java.lang.String option)
Doclet API method to allow recognition of the OUTPUT_FILE_OPTION command-line option

Parameters:
option - the option name to test
Returns:
2 for OUTPUT_FILE_OPTION, 0 for any other tag

validOptions

public static boolean validOptions(java.lang.String[][] options,
                                   com.sun.javadoc.DocErrorReporter reporter)
Doclet API method to validate option usage. Checks the presence of exactly one OUTPUT_FILE_OPTION command-line option, as well as the checks made by the superclass method Scraper.validOptions(java.lang.String[][], com.sun.javadoc.DocErrorReporter).

Parameters:
options - the options to test
Returns:
true if the options are valid


Copyright © 2003 Ashridge Technologies Ltd. All Rights Reserved.