<!-- 

	All content on this website (including text, images, source
	code and any other original works), unless otherwise noted,
	is licensed under a Creative Commons License.

	http://creativecommons.org/licenses/by-nc-sa/2.5/

	Copyright (C) Open-Xchange Inc., 2006-2011
	Mail: info@open-xchange.com

	@author Viktor Pracht <viktor.pracht@open-xchange.com>
	@author Stefan Preuss <stefan.preuss@open-xchange.org>

 -->

<project name="HEAD-gui" default="all" basedir=".">
	<property name="htdoc" value="/var/www"/>
    <property name="final" location="build"/>
	<property name="builddir" location="tmp"/>
	<property name="langdir" location="${final}/lang"/>
	<property name="lib.dir" location="lib"/>
	<property name="jsdoc.dir" location="sdk/jsdoc"/>
    <property name="jsdoc.toolkit" location="${lib.dir}/jsdoc-toolkit"/>
	<property name="saxonjar" location="${lib.dir}/saxon8.jar"/>
	<property name="file.encoding" value="UTF-8"/>
    <property name="src" location="src"/>
	<!--<property name="cssdir" value="default"/>-->
	
	<property name="helplocation" value="help"/>
	<!-- PVERSION is for the product version -->
	<property name="version" value="6.19.0.0"/>
	<property name="oxversion" value="6.19.0"/>
	<property name="oxrevision" value="5"/>
	<property name="pversion" value="${oxversion} Rev${oxrevision}"/>
	<property name="project.name" value="open-xchange-gui"/>
	<property name="composite.name" value="${project.name}-${version}"/>
	<property name="pkg.name" value="open-xchange-gui"/>
	<property name="deb.optargs" value=""/>
	<property name="destdir" value=""/>	
	<property name="build.sysclasspath" value="first"/>
	
    <target name="count">
        <condition property="vmargs" value="-Xbootclasspath/p:${lib.dir}/js.jar">
            <isset property="hasBrokenRhino"/>
        </condition>
        <!-- no idea how to do that else condition here in an elegant way -->
        <condition property="vmargs" value="">
            <not>
                <isset property="vmargs"/>
            </not>
        </condition>
        <java jar="${lib.dir}/js.jar" fork="true" failonerror="true"
              jvmargs="${vmargs}" outputproperty="build.version">
            <arg file="${src}/timestamp.js"/>
        </java>
        <echo level="info" message="Build ${build.version}"/>
    </target>
    
	<target name="fastbuild" description="Fast build, ALL bundle">
		<!-- set fast mode -->
		<property name="bundle.all" value="true"/>
		<property name="skip.minimize" value="true"/>
		<property name="skip.language" value="true"/>
		<property name="skip.css" value="true"/>
		<property name="skip.copy" value="true"/>
		<!-- build all -->
		<antcall target="all.internal"/>
	</target>
	
	<target name="fastbuild-full" description="Fast build, FULL bundle">
        <!-- set fast mode -->
        <property name="bundle.full" value="true"/>
		<property name="skip.css" value="true"/>
        <property name="skip.minimize" value="true"/>
		<property name="skip.language" value="true"/>
		<property name="skip.css" value="true"/>
		<property name="skip.copy" value="true"/>
        <!-- build all -->
        <antcall target="all.internal"/>
    </target>
	
	<condition property="javamail.complete">
	    <and>
	      <available classname="javax.activation.DataHandler"/>
	      <available classname="javax.mail.Transport"/>
	    </and>
    </condition>

	<target name="compress" unless="skip.compress">
		<gzip src="${file}" destfile="${file}z"/>
	</target>

	<target name="minimize" unless="skip.minimize">
        <java jar="lib/yuicompressor-2.4.2.jar" fork="true">
           <arg line="--type js --line-break 500 --nomunge -o ${file} ${file}"/>
        </java>
	</target>

    <target name="js">
    	
    	<concat destfile="${final}/concat_wtk.js" fixlastline="yes">
            <header> /* spacer */ (function () { var $ = jQuery; </header>
            <filelist dir="js/wtk">
            	<!-- General Classes -->
                <file name="classes/util.js"/>
                <file name="classes/widget.js"/>
                <file name="classes/container.js"/>
                <file name="classes/layoutManager.js"/>
                <file name="classes/statefulContainer.js"/>
                <file name="classes/viewControl.js"/>
                <file name="classes/desktop.js"/>
                <file name="classes/selection.js"/>
                <file name="classes/tree.js"/>
                <file name="classes/ui_widgets.js"/>
                <file name="classes/dnd.js"/>
            	<!-- Panel Classes -->
            	<file name="classes/menu.js"/>
            	<file name="classes/tabControl.js"/>
                <file name="classes/panelMenu.js"/>
                <!-- Initializers -->
                <file name="init_wtk.js"/>
                <file name="init_toppanel.js"/>
                <file name="init_sidepanel.js"/>
                <file name="init_foldertree.js"/>
                <file name="init_configtree.js"/>
            	<file name="init_controller.js"/>
            	<file name="init_toolbar.js"/>
            	<file name="init_toolbar_core.js"/>
            	<file name="init_toolbar_portal.js"/>
            	<file name="init_toolbar_mail.js"/>
            	<file name="init_toolbar_calendar.js"/>
            	<file name="init_toolbar_tasks.js"/>
            	<file name="init_toolbar_infostore.js"/>
                <file name="init_toolbar_contacts.js"/>
                <file name="init_toolbar_config.js"/>
            	<file name="init_toolbar_permissions.js"/>
                <file name="init_toolbar_messaging.js"/>
            	<file name="init_toolbar_window.js"/>
                <file name="init_toolbar_window_mail.js"/>
            	<file name="init_toolbar_window_mail_detail.js"/>
                <file name="init_toolbar_window_calendar.js"/>
            	<file name="init_toolbar_window_contact.js"/>
                <file name="init_toolbar_window_task.js"/>
            	<file name="init_toolbar_window_distributionlist.js"/>
            	<file name="init_toolbar_window_infostore.js"/>
            </filelist>
            <footer>}());</footer>
        </concat>
    	
		<concat destfile="${final}/concat_init.js" fixlastline="yes">
			<filelist dir=".">	
				<file name="js/jquery.min.js"/>
                <file name="js/jquery.ui.min.js"/>
				<file name="js/init.js"/>
				<file name="js/util.js"/>
				<file name="js/events.js"/>
				<file name="js/i18n.js"/>
				<file name="js/global.js"/>
				<file name="js/Selection.js"/>
                <file name="js/popup.js"/>
				<file name="js/miniconfig.js"/>
				<file name="js/effects.js"/>
				<file name="js/OXCache.js"/>
				<file name="js/Cache.js"/>
				<file name="js/fsm.js"/>
				<file name="js/api.js"/>
				<file name="js/window.js"/>
				<file name="js/api_ext.js"/>
				<file name="js/api_help.js"/>
				<file name="js/controller.js"/>
				<file name="js/notifier.js"/>
				<file name="js/modules.js"/>
			</filelist>
			<filelist dir="${final}" files="concat_wtk.js"/>
		</concat>
        <replace file="${final}/concat_init.js">
            <include name="global.js"/>
            <replacefilter 
                token="@ox:version@" 
                value="${version}"/>
            <replacefilter 
                token="@ox:revision@" 
                value="${revision}"/>
            <replacefilter 
                token="@ox:pversion@" 
                value="${pversion}"/>
            <replacefilter 
                token="@helplocation@" 
                value="${helplocation}"/>
            <replacefilter 
                token="@ox:build@" 
                value="${build.version}"/>
        </replace>
        <antcall target="minimize"><param name="file" value="${final}/concat_init.js"/></antcall>
        <antcall target="compress"><param name="file" value="${final}/concat_init.js"/></antcall>

        <concat destfile="${final}/concat_all.js" fixlastline="yes">
            <filelist dir="js"> 
                <file name="livegrid.js"/>
                <file name="tree.js"/>
                <file name="Combobox.js"/>
                <file name="menu/menu.js"/>
            	<file name="sidepanel/foldercommon.js"/>
                <file name="Alerts.js"/>
            </filelist>
        </concat>
        <antcall target="compress"><param name="file" value="${final}/concat_all.js"/></antcall>
    		
	    <concat destfile="${final}/concat_calendarnew.js" fixlastline="yes">
	        <filelist dir="${final}" files="newAppointment.js"/>
			<filelist dir=".">		
				<file name="js/subwindow.js"/>
				<file name="js/participants.js"/>
				<file name="js/participants_external.js"/>
				<file name="js/attachments.js"/>		
				<file name="js/Series.js"/>
				<file name="js/calendar/newAppointment.js"/>
				<file name="js/calendar/calendarcommon.js"/>
				<file name="js/calendar/minicalendarClass.js"/>
				<file name="js/calendar/Conflicts.js"/>
				<file name="js/effects.js"/>
				<file name="js/Hover.js"/>
				<file name="js/HoverContents.js"/>
				<file name="js/categories.js"/>
				<file name="js/inplace.js"/>
			</filelist>
		</concat>
        <antcall target="compress"><param name="file" value="${final}/concat_calendarnew.js"/></antcall>

        <concat destfile="${final}/concat_config.js" fixlastline="yes">
			<filelist dir="js/config">
				<file name="config.js"/>
				<file name="config_tags.js"/>
				<file name="config_settings.js"/>
				<file name="config_mail.js"/>
				<file name="config_mail_accounts.js"/>
				<file name="config_mail_messaging.js"/>
				<file name="config_mail_signatures.js"/>
				<file name="config_calendar.js"/>
				<file name="config_import.js"/>
				<file name="config_calendar_teams.js"/>
				<file name="config_contacts.js"/>
				<file name="config_tasks.js"/>
				<file name="config_infostore.js"/>
				<file name="config_portal.js"/>
				<file name="config_portal_ext.js"/>
			    <file name="config_oauth.js"/>
			</filelist>
		</concat>
        <antcall target="compress"><param name="file" value="${final}/concat_config.js"/></antcall>

        <concat destfile="${final}/concat_calendar.js" fixlastline="yes">
			<filelist dir="js/calendar">
				<file name="teamview.js"/>
				<file name="calendar.js"/>
				<file name="calendarcommon.js"/>
				<file name="calendarList.js"/>
				<file name="month.js"/>
				<file name="workweek.js"/>
				<file name="week.js"/>
				<file name="detailAppointment.js"/>
			</filelist>
		</concat>
        <antcall target="compress"><param name="file" value="${final}/concat_calendar.js"/></antcall>

        <concat destfile="${final}/concat_mailnew.js" fixlastline="yes">
            <filelist dir="${final}" files="newMail.js"/>
			<filelist dir=".">
				<file name="js/autocomplete.js"/>
				<file name="js/subwindow.js"/>
				<file name="js/mail/newMail.js"/>
				<file name="js/mail/common.js"/>
				<file name="js/attachments.js"/>
				<file name="js/searchContactsAddressBook.js"/>
				
			</filelist>
		</concat>
        <antcall target="compress"><param name="file" value="${final}/concat_mailnew.js"/></antcall>

        <concat destfile="${final}/concat_maildetail.js" fixlastline="yes">
            <filelist dir="${final}" files="detailMail.js"/>
			<filelist dir=".">
		        <file name="js/effects.js"/>
				<file name="js/miniconfig.js"/>
				<file name="js/subwindow.js"/>
				<file name="js/config/config.js"/>
				<file name="js/Print.js"/>
				<file name="js/mail/detailMail.js"/>
				<file name="js/mail/common.js"/>
				<file name="js/mail/mailcore.js"/>
			</filelist>
		</concat>
        <antcall target="compress"><param name="file" value="${final}/concat_maildetail.js"/></antcall>

		<concat destfile="${final}/concat_contactsnew.js" fixlastline="yes">
			<filelist dir="." files="js/searchContactsAddressBook.js"/>
		    <filelist dir="${final}" files="newContact.js"/>
	        <filelist dir=".">
				<file name="js/subwindow.js"/>
				<file name="js/attachments.js"/>
				<file name="js/contacts/newContact.js"/>
				<file name="js/categories.js"/>
				<file name="js/inplace.js"/>
		        <file name="js/calendar/calendarcommon.js"/>
		        <file name="js/calendar/minicalendarClass.js"/>
			</filelist>
		</concat>
        <antcall target="compress"><param name="file" value="${final}/concat_contactsnew.js"/></antcall>

        <concat destfile="${final}/concat_tasksnew.js" fixlastline="yes">
            <filelist dir="${final}" files="newTask.js"/>
			<filelist dir=".">
				<file name="js/subwindow.js"/>
				<file name="js/Series.js"/>
				<file name="js/tasks/newTask.js"/>
				<file name="js/participants.js"/>
				<file name="js/participants_external.js"/>
				<file name="js/attachments.js"/>
				<file name="js/config/config.js"/>
				<file name="js/categories.js"/>
				<file name="js/inplace.js"/>
		        <file name="js/calendar/calendarcommon.js"/>
		        <file name="js/calendar/minicalendarClass.js"/>
			</filelist>
		</concat>
        <antcall target="compress"><param name="file" value="${final}/concat_tasksnew.js"/></antcall>

        <concat destfile="${final}/concat_distributionnew.js" fixlastline="yes">
            <filelist dir="${final}" files="newDistributionList.js"/>
			<filelist dir=".">
				<file name="js/searchContactsAddressBook.js"/>
				<file name="js/subwindow.js"/>
				<file name="js/tree.js"/>
				<file name="js/attachments.js"/>
				<file name="js/contacts/newDistributionList.js"/>
		        <file name="js/participants.js"/>
		        <file name="js/calendar/calendarcommon.js"/>
		        <file name="js/calendar/minicalendarClass.js"/>
			</filelist>
		</concat>
        <antcall target="compress"><param name="file" value="${final}/concat_distributionnew.js"/></antcall>

        <concat destfile="${final}/concat_infostorenew.js" fixlastline="yes">
            <filelist dir="${final}" files="newInfoItemMain.js"/>
			<filelist dir=".">
				<file name="js/subwindow.js"/>
				<file name="js/tree.js"/>
				<file name="js/infostore/newInfoStore.js"/>
				<file name="js/categories.js"/>
				<file name="js/inplace.js"/>
			</filelist>
		</concat>
        <antcall target="compress"><param name="file" value="${final}/concat_infostorenew.js"/></antcall>

        <concat destfile="${final}/concat_ox.js" fixlastline="yes">
            <filelist dir=".">
                <file name="js/nodemapping.js"/>
    	        <file name="js/HoverContents.js"/>
            </filelist>
        </concat>
		<antcall target="compress"><param name="file" value="${final}/concat_ox.js"/></antcall>

        <concat destfile="${final}/concat_messaging.js" fixlastline="yes">
            <filelist dir="js/messaging">
                <file name="messaging.js"/>
                <file name="mapping.js"/>
            </filelist>
        </concat>
        <antcall target="compress"><param name="file" value="${final}/concat_messaging.js"/></antcall>

        <concat destfile="${final}/concat_portal.js" fixlastline="yes">
            <filelist dir="js/portal">
                <file name="uwa_api.js"/>
                <file name="uwa_messaging.js"/>
                <file name="portal.js"/>
                <file name="portalitemClass.js"/>
            </filelist>
        </concat>
        <antcall target="compress"><param name="file" value="${final}/concat_portal.js"/></antcall>

        <concat destfile="${final}/concat_mail.js" fixlastline="yes">
            <filelist dir="js/mail">
                <file name="mail.js"/>
            	<file name="common.js"/>
                <file name="mailcore.js"/>
            </filelist>
        </concat>
        <antcall target="compress"><param name="file" value="${final}/concat_mail.js"/></antcall>

        <concat destfile="${final}/concat_minicalendar.js" fixlastline="yes">
            <filelist dir="js/calendar">
                <file name="calendarcommon.js"/>
                <file name="minicalendarClass.js"/> 
            </filelist>
        </concat>
        <antcall target="compress"><param name="file" value="${final}/concat_minicalendar.js"/></antcall>

        <concat destfile="${final}/concat_contacts.js" fixlastline="yes">
            <filelist dir="js/contacts">
                <file name="api_routing_planner.js"/>
                <file name="contacts.js"/>
                <file name="plugin_routing_planner.js"/>
            </filelist>
        </concat>
        <antcall target="compress"><param name="file" value="${final}/concat_contacts.js"/></antcall>

        <concat destfile="${final}/concat_infostore.js" fixlastline="yes">
            <filelist dir="js/infostore">
                <file name="infolist.js"/>
                <file name="infosplit.js"/>
                <file name="infostore.js"/>
            </filelist>
        </concat>
        <antcall target="compress"><param name="file" value="${final}/concat_infostore.js"/></antcall>

        <concat destfile="${final}/concat_sidepanel.js" fixlastline="yes">
            <filelist dir="js">
                <file name="sidepanel/folderprops.js"/>
                <file name="reminder.js"/>
                <file name="rightshandling.js"/>
                <file name="AcceptDeny.js"/>
                <file name="Alerts.js"/>
                <file name="calendar/Conflicts.js"/>
            </filelist>
        </concat>
        <antcall target="compress"><param name="file" value="${final}/concat_sidepanel.js"/></antcall>
    	
    	 <concat destfile="${final}/concat_print.js" fixlastline="yes">
            <filelist dir=".">
            	<file name="js/jquery.min.js"/>
                <file name="js/api.js"/>
            </filelist>
        </concat>
        <antcall target="compress"><param name="file" value="${final}/concat_print.js"/></antcall>

        <concat destfile="${final}/concat_core.js" fixlastline="yes">
			<filelist dir="js">
				<file name="Print.js"/>
				<file name="livegrid.js"/>
				<file name="dnd.js"/>
				<file name="tree.js"/>
				<file name="Combobox.js"/>
				<file name="Hover.js"/>
				<file name="participants.js"/>
				<file name="attachments.js"/>
				<file name="Series.js"/>
				<file name="MoveCopy.js"/>
				<file name="inplace.js"/>
                <file name="configuration.js"/>
				<file name="pubsub.js"/>
				<file name="autocomplete.js"/>
                <file name="categories.js"/>
				<file name="calendar/calendarcommon.js"/>
                <file name="calendar/minicalendarClass.js"/>
				<file name="sidepanel/folderprops.js"/>
				<file name="reminder.js"/>
				<file name="rightshandling.js"/>
				<file name="AcceptDeny.js"/>
				<file name="Alerts.js"/>
				<file name="calendar/Conflicts.js"/>
			</filelist>
			<filelist dir="js/menu">
				<file name="menu.js"/>
			</filelist>
			<filelist dir="js">
				<file name="core.js"/>
			</filelist>
			<filelist dir="js/sidepanel">
				<file name="foldercommon.js"/>
			</filelist>
		</concat>
        <antcall target="compress"><param name="file" value="${final}/concat_core.js"/></antcall>

	    <copy overwrite="true" todir="${final}">
	        <fileset dir="js">
		        <include name="popupTriggerCb.js"/>
		        <include name="mail/mailFileBrowser.js"/>
                <include name="tasks/tasks.js"/>
	        	<include name="browser.js"/>
	            <include name="check.js"/>
	        	<include name="jquery.min.js"/>
	        </fileset>
            <flattenmapper/>
	    </copy>
        <antcall target="compress"><param name="file" value="${final}/popupTriggerCb.js"/></antcall>
        <antcall target="compress"><param name="file" value="${final}/mailFileBrowser.js"/></antcall>
        <antcall target="compress"><param name="file" value="${final}/tasks.js"/></antcall>
        <antcall target="compress"><param name="file" value="${final}/check.js"/></antcall>
    	
    	<!-- Bundles -->
    	<antcall target="bundle.js.all"/>
    	<antcall target="bundle.js.full"/>
    	<antcall target="bundle.js.pim"/>
    	<antcall target="bundle.js.mail"/>
    		
    </target>
    	
    <!-- Bundle "ALL" -->
    <target name="bundle.js.all" if="bundle.all">
    	<concat destfile="${final}/bundle_all.js" fixlastline="yes">
            <filelist dir="${final}">
            	<file name="concat_core.js"/>
	            <file name="concat_messaging.js"/>
            	<file name="concat_portal.js"/>
	        </filelist>
            <filelist dir=".">
                <file name="js/mail/mail.js"/>
            	<file name="js/mail/common.js"/>
                <file name="js/mail/mailcore.js"/>
            </filelist>
            <filelist dir="${final}" files="concat_calendar.js"/>
            <filelist dir=".">
                <file name="js/contacts/api_routing_planner.js"/>
                <file name="js/contacts/contacts.js"/>
                <file name="js/contacts/plugin_routing_planner.js"/>
                <file name="js/infostore/infolist.js"/>
                <file name="js/infostore/infosplit.js"/>
                <file name="js/infostore/infostore.js"/>
                <file name="js/tasks/tasks.js"/>
            </filelist>
            <filelist dir="${final}" files="concat_config.js"/>
        </concat>
        <antcall target="minimize"><param name="file" value="${final}/bundle_all.js"/></antcall>
        <antcall target="compress"><param name="file" value="${final}/bundle_all.js"/></antcall>
    </target>
	
    <!-- Bundle "FULL" -->
	<target name="bundle.js.full" if="bundle.full">
        <concat destfile="${final}/bundle_full.js" fixlastline="yes">
            <filelist dir="${final}" files="concat_core.js"/>
        	<filelist dir="${final}" files="concat_portal.js"/>
			<filelist dir=".">
				<file name="js/mail/mail.js"/>
				<file name="js/mail/common.js"/>
				<file name="js/mail/mailcore.js"/>
		    </filelist>
            <filelist dir="${final}" files="concat_calendar.js"/>
            <filelist dir=".">
				<file name="js/contacts/api_routing_planner.js"/>
				<file name="js/contacts/contacts.js"/>
				<file name="js/contacts/plugin_routing_planner.js"/>
				<file name="js/infostore/infolist.js"/>
				<file name="js/infostore/infosplit.js"/>
				<file name="js/infostore/infostore.js"/>
				<file name="js/tasks/tasks.js"/>
			</filelist>
            <filelist dir="${final}" files="concat_config.js"/>
		</concat>
		<antcall target="minimize"><param name="file" value="${final}/bundle_full.js"/></antcall>
    	<antcall target="compress"><param name="file" value="${final}/bundle_full.js"/></antcall>
	</target>
	
	<!-- Bundle "PIM" -->
	<target name="bundle.js.pim" if="bundle.pim">
    	<concat destfile="${final}/bundle_pim.js" fixlastline="yes">
            <filelist dir="${final}" files="concat_core.js"/>
    		<filelist dir="${final}" files="concat_portal.js"/>
            <filelist dir=".">
                <file name="js/mail/mail.js"/>
            	<file name="js/mail/common.js"/>
                <file name="js/mail/mailcore.js"/>
            </filelist>
            <filelist dir="${final}" files="concat_calendar.js"/>
            <filelist dir=".">
                <file name="js/contacts/api_routing_planner.js"/>
                <file name="js/contacts/contacts.js"/>
                <file name="js/contacts/plugin_routing_planner.js"/>
                <file name="js/tasks/tasks.js"/>
            </filelist>
            <filelist dir="${final}" files="concat_config.js"/>
        </concat>
        <antcall target="minimize"><param name="file" value="${final}/bundle_pim.js"/></antcall>
        <antcall target="compress"><param name="file" value="${final}/bundle_pim.js"/></antcall>
	</target>
	
	<!-- Bundle "MAIL" -->
	<target name="bundle.js.mail" if="bundle.mail">
        <concat destfile="${final}/bundle_mail.js" fixlastline="yes">
            <filelist dir="${final}" files="concat_core.js"/>
            <filelist dir=".">
                <file name="js/mail/mail.js"/>
            	<file name="js/mail/common.js"/>
                <file name="js/mail/mailcore.js"/>
                <file name="js/contacts/api_routing_planner.js"/>
                <file name="js/contacts/contacts.js"/>
                <file name="js/contacts/plugin_routing_planner.js"/>
            </filelist>
            <filelist dir="${final}" files="concat_config.js"/>
        </concat>
        <antcall target="minimize"><param name="file" value="${final}/bundle_mail.js"/></antcall>
        <antcall target="compress"><param name="file" value="${final}/bundle_mail.js"/></antcall>
	</target>

	
	<target name="css" depends="copydirs" unless="skip.css">
		<antcall target="css.fast"/>
	</target>
		
	<target name="theme.concat">
		<!-- concat -->
		<echo file="${builddir}/concat_${name}.css" append="false"></echo>
		<concat destfile="${builddir}/concat_${name}.css" append="yes" fixlastline="yes">
            <filelist dir="themes/${name}/css">
                <file name="global.css"/>
                <file name="bgimages.css"/>
                <file name="calendar.css"/>
                <file name="popup.css"/>
                <file name="branding.css"/>
            </filelist>
        </concat>
		<!-- reset css dir -->
		<delete dir="${final}/themes/${name}/css"/>
		<mkdir dir="${final}/themes/${name}/css"/>
	    <copy file="themes/${name}/css/iframe.css" tofile="${final}/themes/${name}/css/iframe.css" overwrite="true"/>
        <!-- precompress -->
        <gzip src="${builddir}/concat_${name}.css" destfile="${final}/themes/${name}/css/concat.cssz"/>
	</target>
		
    <target name="css.fast">
    	
		<concat destfile="${final}/ox.css" fixlastline="yes">
			<filelist dir="css">				
				<file name="menu/menu.css"/>							
				<file name="popup.css"/>							
				<file name="tree.css"/>												
				<file name="participants.css"/>								
				<file name="sidepanel/sidepanel.css"/>
				<file name="mail/mail.css"/>
				<file name="contacts/contacts.css"/>
				<file name="calendar/calendar.css"/>
				<file name="calendar/minicalendar.css"/>
				<file name="global.css"/>
				<file name="tasks/tasks.css"/>
				<file name="livegrid.css"/>
				<file name="hover.css"/>
				<file name="confirm.css"/>
                <file name="wtk.css"/>
				<file name="panel.css"/>
				<file name="branding.css"/>
			</filelist>
	    </concat>
    	
    	<!-- default theme -->
    	<antcall target="theme.concat"><param name="name" value="default"/></antcall>
    	<!-- light_breeze -->
    	<antcall target="theme.concat"><param name="name" value="light_breeze"/></antcall>
    	
    	<copy overwrite="true" todir="${final}/themes/login">
            <fileset dir="themes/login" includes="*.*"/>
        </copy>

    	<copy overwrite="true" todir="${final}/themes/loading">
            <fileset dir="themes/loading" includes="*.*"/>
        </copy>
    	
    	<copy overwrite="true" todir="${final}">
	        <fileset dir="css">
			    <include name="calendar/newappointment.css"/>
	            <include name="contacts/newcontact.css"/>
                <include name="tasks/newtask.css"/>
	            <include name="mail/newmail.css"/>
	            <include name="print.css"/>
	            <include name="ugly.css"/>
	        </fileset>
	        <flattenmapper/>
	    </copy>
	</target>

	<target name="inject-js">
		<!-- param = file, id -->
        <loadfile property="props" srcFile="${final}/${file}"/>
	    <replaceregexp file="${builddir}/${target}" match="&lt;div id=&quot;${id}" replace="&lt;div id=&quot;${id}-js&quot;&gt;${props}&lt;/div&gt;\0" byline="false" flags="mg"/>
	</target>
    
	<target name="bundle">
		<!-- param: target -->
		<!-- remove duplicate doctype definitions -->
        <echo level="info">Removing doctype duplicates</echo>
        <replaceregexp file="${builddir}/${target}.html" match="&lt;!DOCTYPE[^&gt;]+&gt;\s*" replace="" byline="false" flags="mg"/>
        <!-- revive closed tags -->
        <echo level="info">Repairing unclosed tags</echo>
        <replaceregexp file="${builddir}/${target}.html" match="&lt;((img|input|br|col)\s[^&gt;]*)&gt;" replace="&lt;\1/&gt;" byline="false" flags="mg"/>
        <replaceregexp file="${builddir}/${target}.html" match="&lt;(col|hr|br)&gt;" replace="&lt;\1/&gt;" byline="false" flags="mg"/>
        <!-- inject JS -->
        <echo level="info">Injecting javascript snippets</echo>
        <antcall target="inject-js"><param name="target" value="${target}.html"/><param name="file" value="mainpage.js"/><param name="id" value="mainpage-scaffold"/></antcall>
        <antcall target="inject-js"><param name="target" value="${target}.html"/><param name="file" value="messaging.js"/><param name="id" value="messaging-scaffold"/></antcall>
        <antcall target="inject-js"><param name="target" value="${target}.html"/><param name="file" value="mail_core.js"/><param name="id" value="mail-core-scaffold"/></antcall>
        <antcall target="inject-js"><param name="target" value="${target}.html"/><param name="file" value="calendar_core.js"/><param name="id" value="calendar-core-scaffold"/></antcall>
        <antcall target="inject-js"><param name="target" value="${target}.html"/><param name="file" value="contacts_core.js"/><param name="id" value="contacts-core-scaffold"/></antcall>
        <antcall target="inject-js"><param name="target" value="${target}.html"/><param name="file" value="infostore_core.js"/><param name="id" value="infostore-core-scaffold"/></antcall>
        <antcall target="inject-js"><param name="target" value="${target}.html"/><param name="file" value="tasks_core.js"/><param name="id" value="tasks-core-scaffold"/></antcall>
        
        <!-- finalize -->
        <echo level="info">Building ${target}.xml</echo>
        <concat destfile="${final}/${target}.xml" fixlastline="yes">
            <header>&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;scaffolds&gt;&lt;![CDATA[</header>
            <filelist dir="${builddir}"><file name="${target}.html"/></filelist>
            <footer>]]&gt;&lt;/scaffolds&gt;</footer>
        </concat>
        <!-- precompress -->
        <echo level="info">Precompressing ${target}.xml</echo>
        <gzip src="${final}/${target}.xml" destfile="${final}/${target}.xmlz"/>
	</target>
	
    <target name="html" depends="prepare,count">
        <condition property="vmargs" value="-Xbootclasspath/p:${lib.dir}/js.jar">
            <isset property="hasBrokenRhino"/>
        </condition>
        <!-- no idea how to do that else condition here in an elegant way -->
        <condition property="vmargs" value="">
            <not>
                <isset property="vmargs"/>
            </not>
        </condition>
    	
    	<!-- Force delete of ox.html, otherwise injection of build number may not work together with the auto-build -->
    	<delete file="${final}/ox.html"/>
    	
    	<echo level="info">Processing html files</echo>
        <java jvmargs="${vmargs}" jar="${lib.dir}/js.jar" fork="true" failonerror="true">
            <arg file="${src}/build.js"/>
            <arg value="src=${src}"/>
            <arg value="dest=${builddir}"/>
        	<arg value="final=${final}"/>
            <arg value="pversion=${pversion}"/>
            <arg value="version=${version}"/>
        	<arg value="build=${build.version}"/>
            <arg value="run=oldxslt"/>
        </java>

    	<!-- Set build number -->
    	<echo level="info">Inject build number ${build.version}</echo>
    	<replace dir="${final}" includes="**/*.html">
            <replacefilter token="#build.version#" value="${build.version}"/>
        </replace>
    	
    	<antcall target="bundle.html.all"/>
    	<antcall target="bundle.html.full"/>
    	<antcall target="bundle.html.pim"/>
    	<antcall target="bundle.html.mail"/>
    	
    	<!-- Copy audit tool -->
    	<copy overwrite="true" todir="${final}">
    	    <fileset dir="tests">
    	        <include name="audit.html"/>
    	    	<include name="audit.js"/>
            </fileset>
    		<fileset dir="html">
    			<include name="blank.html"/>
    		</fileset>
            <flattenmapper/>
        </copy>
    	
    </target>
	
	<!-- concat html files "ALL" -->
	<target name="bundle.html.all" if="bundle.all">
        <echo level="info">Concatenating html files "ALL"</echo>
        <concat destfile="${builddir}/bundle_all.html" fixlastline="yes">
            <filelist dir="${final}">
                <file name="mainpage.html"/>
            	<file name="messaging.html"/>
                <file name="mail_core.html"/>
                <file name="calendar_core.html"/>
                <file name="contacts_core.html"/>
                <file name="infostore_core.html"/>
                <file name="tasks_core.html"/>
            </filelist>
        </concat>
        <antcall target="bundle"><param name="target" value="bundle_all"/></antcall>
	</target>
	
	<!-- concat html files "FULL" -->
	<target name="bundle.html.full" if="bundle.full">
        <echo level="info">Concatenating html files "FULL"</echo>
        <concat destfile="${builddir}/bundle_full.html" fixlastline="yes">
            <filelist dir="${final}">
                <file name="mainpage.html"/>
                <file name="mail_core.html"/>
                <file name="calendar_core.html"/>
                <file name="contacts_core.html"/>
                <file name="infostore_core.html"/>
                <file name="tasks_core.html"/>
            </filelist>
        </concat>
        <antcall target="bundle"><param name="target" value="bundle_full"/></antcall>
	</target>
	
	<!-- concat html files "PIM" -->
	<target name="bundle.html.pim" if="bundle.pim">
        <echo level="info">Concatenating html files "PIM"</echo>
        <concat destfile="${builddir}/bundle_pim.html" fixlastline="yes">
            <filelist dir="${final}">
                <file name="mainpage.html"/>
                <file name="mail_core.html"/>
                <file name="calendar_core.html"/>
                <file name="contacts_core.html"/>
                <file name="tasks_core.html"/>
            </filelist>
        </concat>
        <antcall target="bundle"><param name="target" value="bundle_pim"/></antcall>
    </target>
		
    <!-- concat html files "MAIL" -->
	<target name="bundle.html.mail" if="bundle.mail">
        <echo level="info">Concatenating html files "MAIL"</echo>
        <concat destfile="${builddir}/bundle_mail.html" fixlastline="yes">
            <filelist dir="${final}">
            	<file name="mainpage.html"/>
                <file name="mail_core.html"/>
                <file name="contacts_core.html"/>
            </filelist>
        </concat>
        <antcall target="bundle"><param name="target" value="bundle_mail"/></antcall>
    </target>
	
    <target name="copydirs" depends="prepare" unless="skip.copy">
        <copy overwrite="true" todir="${final}">
            <fileset dir=".">
                <include name="plugins/**"/>
                <include name="themes/**"/>
                <include name="3rdparty/**"/>
            </fileset>
        </copy>
    </target>
	
	<target name="copydirs.plugins" depends="prepare" unless="skip.copy">
        <copy overwrite="true" todir="${final}">
            <fileset dir=".">
                <include name="plugins/**"/>
            </fileset>
        </copy>
    </target>
    
	<target name="pot">
	    <property name="targetdir" value="i18n"/>
	    
	  	<xslt basedir="html" destdir="${builddir}" style="i18n/pot.xsl"
	  	      extension=".pot" classpath="${saxonjar}">
	  		<param name="root" expression="/html/"/>
			<xmlcatalog>
				<dtd publicId="-//W3C//DTD XHTML 1.0 Strict//EN"
				     location="dtd/xhtml1-strict.dtd"/>
			</xmlcatalog>
			<factory>
	  		   <attribute name="http://saxon.sf.net/feature/linenumbering" value="true"/>
			</factory>
		</xslt>

		<property name="string" value="(?:&quot;((?:[^\n&quot;\\]|\\[^\n89])*)&quot;|&apos;((?:[^\n&apos;\\]|\\[^\n89])*)&apos;)"/>
		<concat destfile="${builddir}/js.pot">
			<fileset dir="js" includes ="**/*.js" excludes="jquery*"/>
			<fileset dir="plugins" includes="**/*.js"/>
			<filterchain>
				<replaceregex pattern="(${string}|//#[^\n]*|/\*i18n( context)?\*/)|(/\*.*?\*/)|(//[^#][^\n]*)" replace="\1" flags="gs" byline="false"/>
				
                <replaceregex pattern="\b(?:_|gettext)\s*\(\s*${string}\s*\)"
                              replace="&#10;msgid &quot;\1\2&quot;&#10;msgstr &quot;&quot;&#10;"
                              flags="g" byline="false"/>
                <replaceregex pattern="\bpgettext\s*\(\s*${string}\s*,\s*${string}\s*\)"
                              replace="&#10;msgctxt &quot;\1\2&quot;&#10;msgid &quot;\3\4&quot;&#10;msgstr &quot;&quot;&#10;"
                              flags="g" byline="false"/>
                <replaceregex pattern="\bdpgettext\s*\(\s*${string}\s*,\s*${string}\s*,\s*${string}\s*\)"
                              replace="&#10;msgctxt &quot;\3\4&quot;&#10;msgid &quot;\5\6&quot;&#10;msgstr &quot;&quot;&#10;"
                              flags="g" byline="false"/>
                
                <replaceregex pattern="\bngettext\s*\(\s*${string}\s*,\s*${string}\s*,"
                              replace="&#10;msgid &quot;\1\2&quot;&#10;msgid_plural &quot;\3\4&quot;&#10;msgstr[0] &quot;&quot;&#10;msgstr[1] &quot;&quot;&#10;"
                              flags="g" byline="false"/>
                <replaceregex pattern="\bnpgettext\s*\(\s*${string}\s*,\s*${string}\s*,\s*${string}\s*,"
                              replace="&#10;msgctxt &quot;\1\2&quot;&#10;msgid &quot;\3\4&quot;&#10;msgid_plural &quot;\5\6&quot;&#10;msgstr[0] &quot;&quot;&#10;msgstr[1] &quot;&quot;&#10;"
                              flags="g" byline="false"/>
				<replaceregex pattern="\bdnpgettext\s*\(\s*${string}\s*,\s*${string}\s*,\s*${string}\s*,\s*${string}\s*,"
				              replace="&#10;msgctxt &quot;\3\4&quot;&#10;msgid &quot;\5\6&quot;&#10;msgid_plural &quot;\7\8&quot;&#10;msgstr[0] &quot;&quot;&#10;msgstr[1] &quot;&quot;&#10;"
				              flags="g" byline="false"/>
				
				<replaceregex pattern="//(#[^\n]*)" replace="&#10;\1"/>
				<replaceregex pattern="${string}[^&quot;&apos;\n]*/\*i18n\*/"
				              replace="&#10;msgid &quot;\1\2&quot;&#10;msgstr &quot;&quot;&#10;"
				              flags="g"/>
                <replaceregex pattern="${string}[^&quot;&apos;\n]*/\*i18n context\*/"
                              replace="&#10;msgctxt &quot;\1\2&quot;&#10;"
                              flags="g"/>
                <replaceregex pattern="${string}[^&quot;&apos;\n]*/\*i18n singular\*/"
                              replace="&#10;msgid &quot;\1\2&quot;&#10;"
                              flags="g"/>
                <replaceregex pattern="${string}[^&quot;&apos;\n]*/\*i18n plural\*/"
                              replace="&#10;msgid_plural &quot;\1\2&quot;&#10;msgstr &quot;&quot;&#10;"
                              flags="g"/>
				<linecontainsregexp>
					<regexp pattern="^(#.|msgctxt|msgid|msgstr|msgid_plural)"/>
				</linecontainsregexp>
			</filterchain>
		</concat>

		<concat destfile="${targetdir}/ox.pot">
			<fileset file="i18n/header.pot"/>
			<fileset dir="${builddir}" includes="**/*.pot"/>
		</concat>
		<exec executable="msguniq" failonerror="yes">
			<arg value="--force-po"/>
		    <arg value="-s"/>
			<arg value="-o"/>
			<arg value="${targetdir}/ox.pot"/>
			<arg value="${targetdir}/ox.pot"/>
		</exec>
	</target>

	<target name="msgcat.check">
		<uptodate property="msgcat.${lang}"
		          targetfile="${builddir}/ox.${lang}.po">
            <srcfiles file="i18n/${lang}/ox.${lang}.po"/>
            <srcfiles file="i18n/${lang}/errors.${lang}.po"/>
		</uptodate>
	</target>
	
	<target name="msgcat" depends="msgcat.check" unless="msgcat.${lang}">
        <concat destfile="${builddir}/ox.${lang}.po">
            <fileset file="i18n/${lang}/ox.${lang}.po"/>
            <fileset file="i18n/${lang}/errors.${lang}.po"/>
        </concat>
	</target>
	
	<target name="lang" depends="prepare" unless="skip.language">
		<antcall target="msgcat"><param name="lang" value="de_DE"/></antcall>
		<antcall target="msgcat"><param name="lang" value="fr_FR"/></antcall>
		<copy overwrite="true" todir="${langdir}" encoding="UTF-8">

			<fileset dir="${builddir}" includes="ox.*.po"/>
			<fileset dir="i18n" includes="**/ox.*.po">
				<present present="srconly" targetdir="${builddir}">
					<mapper type="flatten"/>
				</present>
			</fileset>
			
			<chainedmapper>
				<flattenmapper/>
				<globmapper from="ox.*.po" to="*.js"/>
			</chainedmapper>
			<filterchain>
				<replaceregex pattern="&#13;&#10;" replace="&#10;" byline="false" flags="gm"/>
				<replaceregex pattern="&quot;(\s*&#10;)+\s*&quot;" byline="false" flags="gm"/>
				<linecontainsregexp>
					<regexp pattern="^[^#]"/>
				</linecontainsregexp>
                <replaceregex pattern="^msgctxt (.*)&quot;(\s*\n)+msgid &quot;(.*?)(\s*\n)+msgstr (.*?)\s*$"
                              replace="\1\\\\0\3:\5," flags="gm" byline="false"/>
				<replaceregex pattern="^msgid (.*?)(\s*\n)+msgstr (.*?)\s*$"
				              replace="\1:\3," flags="gm" byline="false"/>
                <replaceregex pattern="^msgctxt (.*)&quot;(\s*\n)+msgid &quot;(.*)&quot;(\s*\n)+msgid_plural &quot;([^&quot;]*&quot;)(((\s*\n)+msgstr\[.*)*)"
                              replace="\1\\\\0\3\\\\x01\5:{\6}" flags="gm" byline="false"/>
				<replaceregex pattern="^msgid (.*)&quot;(\s*\n)+msgid_plural &quot;([^&quot;]*&quot;)(((\s*\n)+msgstr\[.*)*)"
				              replace="\1\\\\x01\3:{\4}" flags="gm" byline="false"/>
				<replaceregex pattern="^msgstr\[([0-9]+)\] (.*?)\s*$"
				              replace="\1:\2," flags="g"/>
                <replaceregex pattern="^.*Project-Id-Version:\s*[Ee]rror.*$" replace=""/>
				<replaceregex pattern="^.*Plural-Forms:\s*nplurals\s*=\s*([0-9]+)\s*;\s*plural\s*=\s*([^;]*);.*&quot;,$"
					          replace="{nplurals: \1, plural: function(n) { return \2; }, dictionary: {"/>
				<replaceregex pattern=",\s*$" replace="}}" byline="false"/>
			</filterchain>
		</copy>
		<copy overwrite="true" file="i18n/languages.js" tofile="${langdir}/languages.js"/>
		<!-- precompress de_DE, en_GB, en_USD -->
		<gzip src="${final}/lang/de_DE.js" destfile="${final}/lang/de_DE.jsz"/>
		<gzip src="${final}/lang/en_GB.js" destfile="${final}/lang/en_GB.jsz"/>
		<gzip src="${final}/lang/en_US.js" destfile="${final}/lang/en_US.jsz"/>
	</target>

    <target name="jsdoc" description="Build JSDOC files">
        <mkdir dir="${jsdoc.dir}"/>
        <java jar="${jsdoc.toolkit}/jsrun.jar" fork="true"
              dir="${jsdoc.toolkit}" failonerror="true">
            <arg value="app/run.js"/>
            <arg value="-t=templates/jsdoc"/>
            <arg value="-d=${jsdoc.dir}"/>
            <arg value="${basedir}/js/util.js"/>
            <arg value="${basedir}/js/configuration.js"/>
            <arg value="${basedir}/js/i18n.js"/>
            <arg value="${basedir}/js/modules.js"/>
        	<arg value="${basedir}/js/api.js"/>
        	<arg value="${basedir}/js/api_ext.js"/>
        </java>
    </target>

	<target name="all" description="Default target">
	    <property name="bundle.all" value="true"/>
        <property name="bundle.full" value="true"/>
	    <property name="bundle.pim" value="true"/>
        <property name="bundle.mail" value="true"/>
		<antcall target="all.internal"/>
	</target>
	
	<target name="all.internal" depends="count,css,html,js,lang,copydirs"/>
		
	<target name="all_with_clean" description="Clean + Build ALL">
		<antcall target="clean"/>
		<antcall target="all"/>
	</target>

	<target name="clean" description="Clean">
		<delete dir="${doc}"/>
		<delete dir="${builddir}"/>
		<delete dir="${jsdoc.dir}"/>
		<delete dir="${langdir}"/>
		<delete dir="${final}"/>
		<delete>
			<fileset dir="." includes="*.html,*.js,*.css,i18n/ox.pot,*-stamp"/>
		</delete>
		<delete dir="debian/${project.name}"/>
		<delete dir="debian/${pkg.name}"/>
		<delete file="debian/${project.name}-${version}.tar.bz2"
			dir="debian/${project.name}-${version}"/>
		<delete file="debian/files"/>
	</target>

	<target name="install-themes">
		<copy overwrite="true" todir="${destdir}/${htdoc}">
			<fileset dir="${final}" includes="themes/**/*"/>
		</copy>
	</target>
	<target name="install-gui">
		<copy overwrite="true" todir="${destdir}/${htdoc}">
			<fileset dir="${final}" excludes="themes/**"/>
		</copy>
	</target>
	<target name="deploy" depends="all_with_clean" description="Copy to installation folder, requires build">
		<antcall target="install-gui"></antcall>
		<antcall target="install-themes"></antcall>
	</target>

	<target name="install-theme">
		<!-- specify -Dtheme.name=<directory> when calling ant -->
		<copy overwrite="true" todir="${destdir}/${htdoc}">
			<fileset dir="${final}" includes="themes/${theme.name}/**"/>
		</copy>
	</target>
	<target name="install" depends="all_with_clean" description="Clean, ALL, Copy to installation folder">
		<antcall target="install-gui"></antcall>
	</target>

   <target name="dist" depends="clean">
		<property name="dist-package" value="dist-package"/>
    	<delete dir="${dist-package}"/>
      <mkdir dir="${dist-package}/${composite.name}"/>
      <copy overwrite="true" todir="${dist-package}/${composite.name}">
         <fileset dir=".">
             <exclude name="**${dist-package}/**"/>
             <exclude name="**debian/**"/>
             <exclude name="**CVS/**"/>
         	 <exclude name=".**/**"/>
             <exclude name="Todo"/>
         </fileset>
        </copy>
        <tar destfile="../${composite.name}.tar.gz"
        basedir="${dist-package}"
        includes="${composite.name}/"
        compression="gzip"/>
    	<delete dir="${dist-package}"/>
   </target>

	<target name="deb" depends="clean">
		<exec executable="dpkg-buildpackage">
		  <arg line="-rfakeroot -uc -us ${deb.optargs}"/>
		</exec>
		<antcall target="clean"></antcall>
	</target>

    <!-- New layout engine and API -->
	
    <target name="prepare">
        <mkdir dir="${builddir}"/>
    	<mkdir dir="${final}"/>
        <mkdir dir="${langdir}"/>
    </target>
    <target name="new" depends="prepare">
        <java jar="${lib.dir}/js.jar" fork="true" failonerror="true">
            <arg file="${src}/build.js"/>
            <arg value="src=${src}"/>
            <arg value="dest=${builddir}"/>
        </java>
    </target>
    <target name="log" depends="prepare">
        <mkdir dir="${builddir}"/>
        <java jar="${lib.dir}/js.jar" fork="true" failonerror="true">
            <arg file="${src}/build.js"/>
            <arg value="src=${src}"/>
            <arg value="dest=${builddir}"/>
            <arg vlaue="log=${builddir}"/>
        </java>
    </target>
    <target name="debug" depends="prepare">
        <java classname="org.mozilla.javascript.tools.debugger.Main"
              fork="true" failonerror="true">
            <arg file="${src}/build.js"/>

        	<arg value="src=${src}"/>
            <arg value="dest=${basedir}"/>
            <arg value="pversion=${pversion}"/>
            <arg value="version=${version}"/>
            <arg value="run=oldxslt"/>
        	<arg value="newhtml=1"/>
        	
        	<arg value="log=${builddir}"/>
            <classpath>
                <pathelement location="${lib.dir}/js.jar"/>
                <pathelement path="${java.class.path}"/>
            </classpath>
        </java>
    </target>
	
</project>
