net.sweetohm.ant.xml
Class WordCountTask

java.lang.Object
  extended by org.apache.tools.ant.ProjectComponent
      extended by org.apache.tools.ant.Task
          extended by net.sweetohm.ant.util.FileTask
              extended by net.sweetohm.ant.xml.WordCountTask
All Implemented Interfaces:
java.lang.Cloneable

public class WordCountTask
extends FileTask

Count words in an XML document.

Version:
1.0
Author:
Michel CASABIANCA

Nested Class Summary
(package private)  class WordCountTask.Handler
          A class to handle content and parsing errors.
 
Field Summary
(package private)  java.util.List excludeElements
          The list of elements to exclude
(package private) static java.lang.String FILE
          The file prefix for system ID
(package private)  WordCountTask.Handler handler
          The handler
(package private)  java.util.List include
          The include stack (indicates if should include current element)
(package private)  java.util.Map includeAttributes
          The map of attributes to include (sorted by elements)
(package private)  int nbFiles
          The number of files
(package private)  int nbWords
          The number of words in the document being parsed
(package private)  javax.xml.parsers.SAXParser parser
          The SAX parser
(package private)  java.lang.String property
          The property for the number of words
(package private)  java.lang.String propertyFiles
          The property for the number of files
(package private)  boolean quiet
          Quiet flag (no message)
(package private)  java.lang.String separators
          The set of separator characters (between two words)
(package private)  java.util.List singleElements
          The list of elements which content is a single word
 
Fields inherited from class org.apache.tools.ant.Task
target, taskName, taskType, wrapper
 
Fields inherited from class org.apache.tools.ant.ProjectComponent
description, location, project
 
Constructor Summary
WordCountTask()
          Creates a new WordCountTask instance.
 
Method Summary
 void execute()
          Execute the task.
 void setDocumentProperties(java.lang.String file)
          Load a properties file defining document properties, that is the lists of elements to exclude, single elements, attributes to include and separator characters.
 void setExcludeElements(java.lang.String excludeList)
          Set the list of excluded elements from the word count.
 void setIncludeAttributes(java.lang.String includeList)
          Set the list of attributes to include as a coma separated list.
 void setProperty(java.lang.String property)
          Set the property where the word count is put.
 void setPropertyFiles(java.lang.String propertyFiles)
          Set the property where to put the file count.
 void setQuiet(boolean quiet)
          Indicates if the task should be quiet (no message for word and file count).
 void setSeparators(java.lang.String separators)
          Set the separator character list.
 void setSingleElements(java.lang.String singleList)
          Set the list of elements which content is considered a single word.
 
Methods inherited from class net.sweetohm.ant.util.FileTask
addFileset, getFiles, setDir, setFile
 
Methods inherited from class org.apache.tools.ant.Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
 
Methods inherited from class org.apache.tools.ant.ProjectComponent
clone, getDescription, getLocation, getProject, setDescription, setLocation, setProject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILE

static final java.lang.String FILE
The file prefix for system ID

See Also:
Constant Field Values

separators

java.lang.String separators
The set of separator characters (between two words)


parser

javax.xml.parsers.SAXParser parser
The SAX parser


handler

WordCountTask.Handler handler
The handler


excludeElements

java.util.List excludeElements
The list of elements to exclude


singleElements

java.util.List singleElements
The list of elements which content is a single word


includeAttributes

java.util.Map includeAttributes
The map of attributes to include (sorted by elements)


include

java.util.List include
The include stack (indicates if should include current element)


nbWords

int nbWords
The number of words in the document being parsed


nbFiles

int nbFiles
The number of files


property

java.lang.String property
The property for the number of words


propertyFiles

java.lang.String propertyFiles
The property for the number of files


quiet

boolean quiet
Quiet flag (no message)

Constructor Detail

WordCountTask

public WordCountTask()
              throws javax.xml.parsers.ParserConfigurationException,
                     org.xml.sax.SAXException
Creates a new WordCountTask instance.

Throws:
javax.xml.parsers.ParserConfigurationException - if an error occurs
org.xml.sax.SAXException - if an error occurs
Method Detail

setSeparators

public void setSeparators(java.lang.String separators)
Set the separator character list.

Parameters:
separators - The list of separators as a String.

setExcludeElements

public void setExcludeElements(java.lang.String excludeList)
Set the list of excluded elements from the word count. The words contained in such elements are ignored.

Parameters:
excludeList - The coma separated list of elements to exclude as a String.

setSingleElements

public void setSingleElements(java.lang.String singleList)
Set the list of elements which content is considered a single word.

Parameters:
singleList - The coma separated list of single elements.

setIncludeAttributes

public void setIncludeAttributes(java.lang.String includeList)
Set the list of attributes to include as a coma separated list. Each attribute is noted as "element@attribute".

Parameters:
includeList - The coma separated list of attributes.

setDocumentProperties

public void setDocumentProperties(java.lang.String file)
Load a properties file defining document properties, that is the lists of elements to exclude, single elements, attributes to include and separator characters.

Parameters:
file - The properties file as a String.

setProperty

public void setProperty(java.lang.String property)
Set the property where the word count is put.

Parameters:
property - The property to set.

setPropertyFiles

public void setPropertyFiles(java.lang.String propertyFiles)
Set the property where to put the file count.

Parameters:
propertyFiles - The property to set.

setQuiet

public void setQuiet(boolean quiet)
Indicates if the task should be quiet (no message for word and file count).

Parameters:
quiet - The quiet flag.

execute

public void execute()
             throws org.apache.tools.ant.BuildException
Execute the task.

Overrides:
execute in class org.apache.tools.ant.Task
Throws:
org.apache.tools.ant.BuildException - if an error occurs