Examples

This page has some examples of using ISDirValidator.

Basic example

This is the one example to see the use of ISDirValidator using the Antīs tasks.

<taskdef name="isdirectory" 
	classname="com.inigoserrano.isdirvalidator.ISDirectory"/>
<taskdef name="isfile" 
	classname="com.inigoserrano.isdirvalidator.ISFile"/>
<taskdef name="isfilepattern" 
	classname="com.inigoserrano.isdirvalidator.ISFilePattern"/>

<isdirectory dir="folder" />

<isdirectory dir="..\ISDirCheck\">
	<isfile file="build.xml" required="Y" />
	<isfile file="Definition.txt" required="N" />
	<isfilePattern filePattern="[az]*.txt" />
	<isfilePattern filePattern=".xml" />
</isdirectory>
	

Description

Frist we define the tags because they arenīt standard in Ant. We use the taskdef tag to do it.

<taskdef name="isdirectory" 
	classname="com.inigoserrano.isdirvalidator.ISDirectory"/>
<taskdef name="isfile" 
	classname="com.inigoserrano.isdirvalidator.ISFile"/>
<taskdef name="isfilepattern" 
	classname="com.inigoserrano.isdirvalidator.ISFilePattern"/>
	

The frist task is the simplest form (not very usefull) and checks that the directory "folder" exist. It takes the basedir of the Ant's project as the path


<isdirectory dir="folder" />

	

The second task check that the directory "ISDirCheck" exist. It takes the parent of the Antīs basedir as the path. It also check that some conditions are fullfill:

  • The build.xml file must exist
  • It can exist a file with name "Definicion.txt", but it is not obligatory (The attribute "required" could be ommited because this is its default value).
  • It can exist files that match the regular expression "[az]*.txt".
  • It can exist files that match the regular expression ".xml"

<isdirectory dir="..\ISDirCheck\">
	<isfile file="build.xml" required="Y" />
	<isfile file="Definition.txt" required="N" />
	<isfilePattern filePattern="[az]*.txt" />
	<isfilePattern filePattern=".xml" />
</isdirectory>

	

This task will fail

  • When exist a file "myPage.txt" because it is not build.xml nor Definition.txt nor it has .xml or .txt
  • When exist a file "Hello.txt" because it is not build.xml nor Definition.txt nor it has .xml and it has .txt but with a upper letter
  • The file build.xml dosnīt exist

WAR example

Another example of use coud be the definition of the structure of a Servlet's WAR folder.


<isdirectory dir="some dir root of a war file">
	<isfile file="index.jsp" required="Y" />
	<isfilePattern filePattern="^[a-zA-Z]+\.jsp$" /> 
	<isfilePattern filePattern="^[a-zA-Z]+\.htm$" />  
	...
</isdirectory>

<isdirectory dir="some dir with a war file/META-INF">
	<isfile file="MANIFEST.MF" required="Y" />
	...
</isdirectory>

<isdirectory dir="some dir with a war file/WEB-INF">
	<isfile file="web.xml" required="Y" />
	<isfilePattern filePattern="^[a-zA-Z-]+\.tld$" /> 
	...
</isdirectory>