<!--
  Author: bmihelac@mihelac.org, www.informatikamihelac.com
-->
<project name="oox2odx" default="oox2odx"> 
  <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
  
  <description>
    This Ant script converts OpenOffice.org documents saved with SRC680 build prior to m64 so they 
    can be loaded into SRC680m64 and future builds.
    
    More info: http://www.informatikamihelac.com/en/products/community/ooo_document_conversion_ant_script/
  </description>

  <target name="oox2odx">
    <copy todir="_converted">
      <fileset dir=".">
        <include name="**/*.oo?" />
      </fileset>
      <mapper type="regexp" from="([^.]*\.o)o(.)" to="\1d\2"/>
    </copy>
    <foreach target="ConvertFile" param="source">
      <fileset dir=".">
        <include name="**/*.oo?" />
        <include name="_converted/*.od?" />
      </fileset>
    </foreach>
  </target>
  
  <target name="ConvertFile">
    <unzip src="${source}" dest="_converted">
      <patternset>
        <include name="mimetype"/>
        <include name="META-INF/manifest.xml"/>
      </patternset>
    </unzip>
    <replace file="_converted/mimetype" token="x-vnd.oasis.openoffice" value="vnd.oasis.opendocument" />
    <replace file="_converted/META-INF/manifest.xml" token="x-vnd.oasis.openoffice" value="vnd.oasis.opendocument" />
    <zip destfile="${source}" basedir="_converted" compress="FALSE" includes="mimetype,META-INF/manifest.xml" update="TRUE" />
    <delete file="_converted/mimetype" />
    <delete dir="_converted/META-INF" />
  </target>
  
</project>

