Class JTidyTask

  • All Implemented Interfaces:
    java.lang.Cloneable

    public class JTidyTask
    extends org.apache.tools.ant.Task
    JTidy ant task.

    Parameters

    Attribute Description Required
    srcfile source file Yes, unless a nested <fileset> element is used.
    destfile destination file for output With the srcfile attribute, either destfile or destdir can be used. With nested <fileset> elements only destdir is allowed.
    destdir destination directory for output
    properties Path to a valid tidy properties file No
    flatten Ignore the directory structure of the source files, and copy all files into the directory specified by the destdir attribute. No; defaults to false.
    failonerror boolean to control whether failure to execute should throw a BuildException or just print an error. If set to true errors in input files which tidy is enable to fix will cause a failure. No; defaults to false.

    Nested elements

    • Fileset : if you need to run tidy on more than one file, you can specify nested filesets.
    • Parameter : you can specify any tidy configuration option directly using a nested parameter element.

    Setup

    Adds the following typedef to setup the JTidy task in your build.xml:

     <taskdef name="tidy" classname="org.w3c.tidy.ant.JTidyTask"/>
     

    This will work if JTidy jar is copied to ant lib directory. If you need to reference the jar elsewhere on the filesystem you can add a nested classpath element:

     <taskdef name="tidy" classname="org.w3c.tidy.ant.JTidyTask">
       <classpath>
         <pathelement location="${lib.dir}/jtidy.jar"/>
       </classpath>
     </taskdef>
     

    Examples

     <tidy destdir="out" properties="/path/to/tidy.properties">
       <fileset dir="inputdir" />
       <parameter name="drop-font-tags" value="true" />
     </tidy>
     
    Version:
    $Revision: 1120 $ ($Author: aditsu $)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.io.File destdir
      Destination directory for output.
      private java.io.File destfile
      Destination file for output.
      private boolean failonerror
      Control whether failure to execute should throw a BuildException.
      private java.util.List filesets
      Filesets.
      private boolean flatten
      Don't output directories.
      private java.io.File properties
      Properties file.
      private java.util.Properties props
      Configured properties.
      private java.io.File srcfile
      Source file.
      private Tidy tidy
      tidy instance.
      • 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

      Constructors 
      Constructor Description
      JTidyTask()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addConfiguredParameter​(org.apache.tools.ant.types.Parameter prop)
      Setter method for any property using the ant type Parameter.
      void addFileset​(org.apache.tools.ant.types.FileSet fileSet)
      Adds a fileset to be processed Fileset
      void execute()
      Run the task.
      protected void executeSet()
      Run tidy on filesets.
      protected void executeSingle()
      A single file has been specified.
      void init()
      Initializes the task.
      protected void processFile​(java.io.File inputFile, java.io.File outputFile)
      Run tidy on a file.
      void setDestdir​(java.io.File destdir)  
      void setDestfile​(java.io.File destfile)  
      void setFailonerror​(boolean failonerror)  
      void setFlatten​(boolean flatten)  
      void setProperties​(java.io.File properties)  
      void setSrcfile​(java.io.File srcfile)  
      protected void validateParameters()
      Validates task parameters.
      • Methods inherited from class org.apache.tools.ant.Task

        bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, 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

      • filesets

        private java.util.List filesets
        Filesets.
      • destdir

        private java.io.File destdir
        Destination directory for output.
      • destfile

        private java.io.File destfile
        Destination file for output.
      • srcfile

        private java.io.File srcfile
        Source file.
      • failonerror

        private boolean failonerror
        Control whether failure to execute should throw a BuildException.
      • flatten

        private boolean flatten
        Don't output directories.
      • tidy

        private Tidy tidy
        tidy instance.
      • props

        private java.util.Properties props
        Configured properties.
      • properties

        private java.io.File properties
        Properties file.
    • Constructor Detail

      • JTidyTask

        public JTidyTask()
    • Method Detail

      • setDestdir

        public void setDestdir​(java.io.File destdir)
        Parameters:
        destdir - The destdir to set.
      • setDestfile

        public void setDestfile​(java.io.File destfile)
        Parameters:
        destfile - The destfile to set.
      • setSrcfile

        public void setSrcfile​(java.io.File srcfile)
        Parameters:
        srcfile - The srcfile to set.
      • setFailonerror

        public void setFailonerror​(boolean failonerror)
        Parameters:
        failonerror - The failonerror to set.
      • setFlatten

        public void setFlatten​(boolean flatten)
        Parameters:
        flatten - The flatten to set.
      • setProperties

        public void setProperties​(java.io.File properties)
        Parameters:
        properties - The properties to set.
      • addFileset

        public void addFileset​(org.apache.tools.ant.types.FileSet fileSet)
        Adds a fileset to be processed Fileset
        Parameters:
        fileSet -
      • addConfiguredParameter

        public void addConfiguredParameter​(org.apache.tools.ant.types.Parameter prop)
        Setter method for any property using the ant type Parameter.
        Parameters:
        prop - Ant type Parameter
      • init

        public void init()
        Initializes the task.
        Overrides:
        init in class org.apache.tools.ant.Task
      • validateParameters

        protected void validateParameters()
                                   throws org.apache.tools.ant.BuildException
        Validates task parameters.
        Throws:
        org.apache.tools.ant.BuildException - if any invalid parameter is found
      • execute

        public void execute()
                     throws org.apache.tools.ant.BuildException
        Run the task.
        Overrides:
        execute in class org.apache.tools.ant.Task
        Throws:
        org.apache.tools.ant.BuildException - The exception raised during task execution.
      • executeSingle

        protected void executeSingle()
        A single file has been specified.
      • executeSet

        protected void executeSet()
        Run tidy on filesets.
      • processFile

        protected void processFile​(java.io.File inputFile,
                                   java.io.File outputFile)
        Run tidy on a file.
        Parameters:
        inputFile - input file
        outputFile - output file