hdoc_to_elasticsearch.ant 2.35 KB
Newer Older
1
<project name="hdoc_to_elasticsearch" default="executeTransformation"> 
Gregory's avatar
Gregory committed
2
	
Gregory's avatar
Gregory committed
3 4 5 6 7 8 9
	<!-- Use contribant -->
	<taskdef resource="net/sf/antcontrib/antcontrib.properties">
	  <classpath>
		<pathelement location="lib/ant-contrib-0.3.jar"/>
	  </classpath>
	</taskdef>

Gregory's avatar
Gregory committed
10 11
	<property file="build.properties"/>     
	
Gregory's avatar
Gregory committed
12
	<target name="jsonFiles"> 
Gregory's avatar
Gregory committed
13
		<echo message="Conversion begin" />
Gregory's avatar
Gregory committed
14
		<echo>Entry file : ${fileToParse}</echo>
Gregory's avatar
Gregory committed
15

Gregory's avatar
Gregory committed
16
		<!-- create subdirectory for each file -->
Gregory's avatar
Gregory committed
17 18 19 20 21 22 23 24
		<mkdir dir="${tmpHdoc}" />
		<basename property="fileToParseName" file="${inputPath}/${fileToParse}" suffix=".hdoc" />
		<mkdir dir="${tmpHdoc}/${fileToParseName}"/>
		
		<!--unzips the hdoc to be converted into the previously created directory --> 
		<unzip dest="${tmpHdoc}/${fileToParseName}">
			<fileset dir="${inputPath}"> 			
				<include name="${fileToParseName}.hdoc"/> 			
Gregory's avatar
Gregory committed
25 26 27 28
			</fileset> 		
		</unzip> 		

		<echo message="JSON File creation" /> 		
Gregory's avatar
Gregory committed
29
		<xslt in="${tmpHdoc}/${fileToParseName}/content.xml" out="${outputPath}/${fileToParseName}.json" style="xsl/content_extractor.xsl"/>
30 31 32 33 34 35 36 37 38
	</target> 	
	
	<!-- Check if input directory is empty -->
	<target name="check.dir">
		<fileset dir="${inputPath}" id="fileset">
			<include name="*.hdoc"/>
		</fileset>
		<pathconvert refid="fileset" property="dir.contains-files" setonempty="false"/>
	</target>
Gregory's avatar
Gregory committed
39
	
40 41 42
	
	<!-- Use converter on all files in input -->
	<target name="targetAllFiles"  depends="check.dir" if="dir.contains-files">
Gregory's avatar
Gregory committed
43 44 45 46 47 48
		<delete>
		   <fileset dir="${outputPath}">
			  <include name="*.json"/>
		   </fileset>
		</delete>
		<foreach target="jsonFiles" param="fileToParse">
49 50 51 52 53
			<path id="hdocFiles">
				<fileset dir="${inputPath}">
					<include name="*.hdoc"/>
				</fileset>
			</path>
Gregory's avatar
Gregory committed
54
		</foreach>
55
		<!-- Clear tmp files -->
Gregory's avatar
Gregory committed
56 57 58 59
		<delete includeemptydirs="true" verbose="true">
			<fileset dir="${tmpHdoc}"> </fileset>
			<dirset dir="${tmpHdoc}" includes="**/*" />
		</delete>
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
	</target> 

	<!-- Tell user that he needs to provide input -->
	<target name="noFileToUse" depends="check.dir" unless="dir.contains-files">
		<delete>
		   <fileset dir="${outputPath}">
			  <include name="*.json"/>
		   </fileset>
		</delete>
		<echo message="You need to provide file in input directory." />
	</target>	
	
	<!-- Main target --> 	
	<target name="executeTransformation" depends="targetAllFiles, noFileToUse">         
		<echo message="End transformation" />
Gregory's avatar
Gregory committed
75 76 77
	</target> 	

</project>
Gregory's avatar
Gregory committed
78