Index: TXM/trunk/org.txm.tigersearch.rcp/src/org/txm/searchengine/ts/TIGERSearchEngine.java
===================================================================
--- TXM/trunk/org.txm.tigersearch.rcp/src/org/txm/searchengine/ts/TIGERSearchEngine.java	(revision 3305)
+++ TXM/trunk/org.txm.tigersearch.rcp/src/org/txm/searchengine/ts/TIGERSearchEngine.java	(revision 3306)
@@ -336,7 +336,10 @@
 				"log4j.appender.Logfile.layout.ConversionPattern=%5r %-5p [%t] %c{2} - %m%n");
 		
 		BasicConfigurator.configure();
-		File master = new File(sourceDirectory, "main.xml");
+		
+		String driverFilename = TigerSearchPreferences.getInstance().getString(TigerSearchPreferences.DRIVER_FILENAME);
+		
+		File master = new File(sourceDirectory, driverFilename);
 		if (!master.exists()) {
 			File[] xmlFiles = sourceDirectory.listFiles(new FileFilter() {
 						public boolean accept(File file) {
Index: TXM/trunk/org.txm.tigersearch.rcp/groovy/org/txm/scripts/importer/tigersearch/TSImport.groovy
===================================================================
--- TXM/trunk/org.txm.tigersearch.rcp/groovy/org/txm/scripts/importer/tigersearch/TSImport.groovy	(revision 3305)
+++ TXM/trunk/org.txm.tigersearch.rcp/groovy/org/txm/scripts/importer/tigersearch/TSImport.groovy	(revision 3306)
@@ -17,6 +17,7 @@
 import org.txm.importer.xtz.*
 import org.txm.scripts.importer.xtz.*
 import org.txm.searchengine.ts.TIGERSearchEngine
+import org.txm.tigersearch.preferences.TigerSearchPreferences
 
 class TSImport extends XTZImport {
 	
@@ -43,12 +44,170 @@
 		super.start(); // call the usual XTZ import
 		
 		if (isSuccessful) {
-			TIGERSearchEngine.buildTIGERCorpus(this.sourceDirectory, this.binaryDirectory, corpusName);
+			
+			File tigerXmlSrcDir = new File(binaryDirectory, "src")
+			
+			String driverFilename = TigerSearchPreferences.getInstance().getString(TigerSearchPreferences.DRIVER_FILENAME);
+			
+			File master = new File(tigerXmlSrcDir, driverFilename)
+			
+			File srcmaster = new File(sourceDirectory, driverFilename)
+			if (srcmaster.exists()) {
+				println "Using source TIGER driver file: $srcmaster -> $master"
+				FileCopy.copy(srcmaster, master)
+			} else {
+				println "Building TIGER driver file: $master..."
+				String headerFilename = TigerSearchPreferences.getInstance().getString(TigerSearchPreferences.HEADER_FILENAME);
+				File header = new File(sourceDirectory, headerFilename)
+				if (!header.exists()) {
+					// parse TIGER-XML files to buidl a default header file
+				}
+				
+				//build the master file using the TIGER-XML files of sourceDirectory
+				// if necesary converts a driver (with <corpus>) file into a subcorpus (with <subcorpus>file
+				def xmlFiles = tigerXmlSrcDir.listFiles()
+				
+				HashMap<String, HashSet<String>> tfeatures = new HashMap<String, HashSet<String>>()
+				HashMap<String, HashSet<String>> ntfeatures = new HashMap<String, HashSet<String>>()
+				HashSet<String> edges = new HashSet<String>()
+				HashSet<String> secedges = new HashSet<String>()
+				for (def xmlFile : xmlFiles) {
+					//println xmlFile
+					def doc = new XmlSlurper().parse(xmlFile)
+					def terminals = null
+					
+					if (doc.name() == "corpus") terminals = doc.body.s.graph.terminals
+					else terminals = doc.s.graph.terminals
+					
+					for (def terminal : doc.s.graph.terminals) {
+						
+						for (def t : terminal.t) {
+							def attributes = t.attributes()
+							for (def a : attributes.keySet()) {
+								if (a == "id") continue;
+								
+								if (!tfeatures.containsKey(a)) {
+									tfeatures[a] = new HashSet<String>();
+								}
+								
+								tfeatures[a].add(""+attributes[a])
+								
+							}
+						}
+					}
+					
+					def nonterminals = null
+					if (doc.name() == "corpus") nonterminals = doc.body.s.graph.nonterminals
+					else nonterminals = doc.s.graph.nonterminals
+					
+					for (def nterminal : nonterminals) {
+						
+						for (def nt : nterminal.nt) {
+							def attributes = nt.attributes()
+							for (def a : attributes.keySet()) {
+								if (a == "id") continue;
+								
+								if (!ntfeatures.containsKey(a)) {
+									ntfeatures[a] = new HashSet<String>();
+								}
+								
+								ntfeatures[a].add(""+attributes[a])
+								
+							}
+							for (def edge : nt.edge) {
+								edges.add(""+edge.@label)
+							}
+							for (def secedge : nt.secedge) {
+								secedges.add(""+secedge.@label)
+							}
+						}
+					}
+					
+					if (doc.name() == "corpus") { // convert file to a subcorpus file
+						doc.name = "subcorpus"
+						doc.head = {}
+					}
+				}
+				
+				def masterwriter = IOUtils.getWriter(master, "UTF-8")
+				masterwriter.println("""<?xml version="1.0" encoding="utf-8"?>
+<corpus id="$corpusName">
+ <head>
+  <meta>
+   <name>$corpusName</name>
+   <author>TXM</author>
+   <date></date>
+   <description>default master file generated by TXM for the TIGER import module</description>
+   <format>TIGER-XML</format>
+   <history></history>
+  </meta>
+  <annotation>""")
+				for (def f : tfeatures.keySet()) {
+					masterwriter.println("""   <feature domain="T" name="$f">""")
+					for (def v : tfeatures[f]) {
+						v = v.replace("<", "&lt;").replace(">", "&gt;")
+						masterwriter.println("""<value name="$v"/>""")
+					}
+					masterwriter.println("""   </feature>""")
+				}
+				masterwriter.flush()
+				for (def f : ntfeatures.keySet()) {
+					masterwriter.println("""   <feature domain="NT" name="$f">""")
+					for (def v : ntfeatures[f]) {
+						v = v.replace("<", "&lt;").replace(">", "&gt;")
+						masterwriter.println("""    <value name="$v"/>""")
+					}
+					masterwriter.println("""   </feature>""")
+				}
+				masterwriter.flush()
+				
+				masterwriter.println("""   <edgelabel>""")
+				for (def v : edges) {
+					v = v.replace("<", "&lt;").replace(">", "&gt;")
+					masterwriter.println("""    <value name="$v"/>""")
+				}
+				masterwriter.println("""   </edgelabel>""")
+				masterwriter.flush()
+				masterwriter.println("""   <secedgelabel>""")
+				for (def v : secedges) {
+					v = v.replace("<", "&lt;").replace(">", "&gt;")
+					masterwriter.println("""    <value name="$v"/>""")
+				}
+				masterwriter.println("""   </secedgelabel>""")
+				masterwriter.flush()
+				masterwriter.println("""
+  </annotation>
+ </head>
+ <body>""")
+				for (def xmlFileName : getTXMFilesOrder()) {
+					masterwriter.println("""  <subcorpus external="file:${xmlFileName}" name="${xmlFileName}"/>/>""")
+				}
+				masterwriter.flush()
+				masterwriter.println(""" </body>
+</corpus>
+""")
+masterwriter.flush()
+masterwriter.close()
+			}
+			TIGERSearchEngine.buildTIGERCorpus(tigerXmlSrcDir, this.binaryDirectory, corpusName);
 		}
 	}
 	
-	ArrayList<String> orderedFiles = null;
-	protected ArrayList<String> getTXMFilesOrder() {
-		orderedFiles;
-	}
+	//	ArrayList<String> orderedFiles = null;
+		protected ArrayList<String> getTXMFilesOrder() {
+			String driverFilename = TigerSearchPreferences.getInstance().getString(TigerSearchPreferences.DRIVER_FILENAME);
+			File driverFile = new File(binaryDirectory, "src/"+driverFilename)
+			if (driverFile.exists()) {
+				ArrayList<String> orderedFiles = new ArrayList<String>();
+				for (def s : new XmlSlurper().parse(driverFile).body.subcorpus) {
+					String name = ""+s.@external
+					if (name.startsWith("file:")) {
+						orderedFiles << name.substring(5);
+					}
+				}
+				return orderedFiles
+			} else {
+				return super.getTXMFilesOrder();
+			}
+		}
 }
\ No newline at end of file
Index: TXM/trunk/org.txm.tigersearch.rcp/groovy/org/txm/scripts/importer/tigersearch/TSImporter.groovy
===================================================================
--- TXM/trunk/org.txm.tigersearch.rcp/groovy/org/txm/scripts/importer/tigersearch/TSImporter.groovy	(revision 3305)
+++ TXM/trunk/org.txm.tigersearch.rcp/groovy/org/txm/scripts/importer/tigersearch/TSImporter.groovy	(revision 3306)
@@ -6,6 +6,7 @@
 import org.txm.importer.xtz.*
 import org.txm.metadatas.Metadatas
 import org.txm.scripts.importer.xtz.*
+import org.txm.tigersearch.preferences.TigerSearchPreferences
 import org.txm.utils.BundleUtils
 import org.txm.utils.FileUtils
 import org.txm.utils.io.FileCopy
@@ -42,15 +43,17 @@
 			Toolbox.getPreference(TBXPreferences.METADATA_TXTSEPARATOR), 1)
 		}
 
-
 		File sourceDirectory = inputDirectory
 		File binaryDirectory = module.getBinaryDirectory()
-
-		File master = new File(sourceDirectory, "main.xml")
 		
+		String driverFilename = TigerSearchPreferences.getInstance().getString(TigerSearchPreferences.DRIVER_FILENAME);
+		String headerFilename = TigerSearchPreferences.getInstance().getString(TigerSearchPreferences.HEADER_FILENAME);
+		
+		File master = new File(sourceDirectory, driverFilename)
+		
 		def xmlFiles = [] // the TIGER XML files
-		if (!master.exists() ) {
-			println "No main.xml ($master) file found, trying to find a proper TIGER XML file."
+		if (true || !master.exists() ) { // Managing the main.xml file is a pain, we'll do it later
+			//println "No main.xml ($master) file found, trying to find a proper TIGER XML file."
 //			master = new File(sourceDirectory, "main.xml")
 //			String subcorpora = "";
 			xmlFiles = sourceDirectory.listFiles(new FileFilter() {
@@ -60,24 +63,19 @@
 							String filename = file.getName()
 							if (filename.equals("import.xml")) return false;
 							if (!filename.endsWith(".xml")) return false;
+							if (filename.equals(driverFilename)) return false;
+							if (filename.equals(headerFilename)) return false;
 							
 							return true;
 						}
 					});
 			
-			if (xmlFiles.size() > 1) {
-				println "Error, the source directory contains more than one TIGER XML file ?"
-				isSuccessFul = false;
-				return;
-			}
-			if (xmlFiles.size() == 0) {
-				println "Error no XML file found in $sourceDirectory directory"
-				isSuccessFul = false;
-				return;
-			}
-			println "Using ${xmlFiles.get(0)} as TIGER XML source file."
+			println "Using ${xmlFiles} as TIGER XML source files."
 			
 		} else { // parse the master file
+			println "Using the TIGER MAIN file: $master"
+			
+			
 			for (def s : new XmlSlurper().parse(master).body.subcorpus) {
 				String name = ""+s.@external
 				if (name.startsWith("file:")) {
@@ -101,37 +99,34 @@
 		File tsXSLFile = new File(Toolbox.getTxmHomePath(), "xsl/ts.xsl");
 		BundleUtils.copyFiles("org.txm.tigersearch.rcp", "groovy", "org/txm/scripts/importer/tigersearch", "ts.xsl", tsXSLFile.getParentFile());
 
-		File xmltxmSrcDir = new File(binaryDirectory, "src"); // output directory of the TS XSL transformation
-		xmltxmSrcDir.mkdirs();
-		if (master.exists()) println "TIGER MAIN file: $master" 
-		println "TIGER XML files: $xmlFiles"
+		File tigerXmlSrcDir = new File(binaryDirectory, "src"); // output directory of the TS XSL transformation
+		tigerXmlSrcDir.deleteDir()
+		tigerXmlSrcDir.mkdirs();
+		
+		println "TIGER-XML files: $xmlFiles"
 		for (File xmlTigerFile : xmlFiles) {
-			FileCopy.copy(xmlTigerFile, new File(xmltxmSrcDir, xmlTigerFile.getName()));
+			FileCopy.copy(xmlTigerFile, new File(tigerXmlSrcDir, xmlTigerFile.getName()));
 		}
 
 		File tokenizedDir = new File(module.getBinaryDirectory(),"tokenized");
 		
-		if (!ApplyXsl2.processImportSources(tsXSLFile, xmltxmSrcDir, tokenizedDir)) {
-			println "Error while applying TS XSL file to $xmltxmSrcDir"
+		if (!ApplyXsl2.processImportSources(tsXSLFile, tigerXmlSrcDir, tokenizedDir)) {
+			println "Error while applying TS XSL file to $tigerXmlSrcDir"
 			isSuccessFul = false;
 			return;
 		}
 
 		File[] files = tokenizedDir.listFiles(IOUtils.HIDDENFILE_FILTER);
 		if (files == null || files.length == 0) {
-			println "Error while applying TS XSL file to $xmltxmSrcDir is empty"
+			println "Error while applying TS XSL file to $tigerXmlSrcDir is empty"
 			isSuccessFul = false;
 			return;
 		}
 
-		if (!doToXMLTXMStep()) return;
-		if (!doInjectMetadataStep()) return;
+		if (!doToXMLTXMStep()) return; // build the XML-TXM files
+		
+		if (!doInjectMetadataStep()) return; // inject the metadata in the XML-TXM files
 
-		module.orderedFiles = new ArrayList<String>();
-		for (def f : xmlFiles) {
-			String id = FileUtils.stripExtension(f)
-			module.orderedFiles.add(id)
-		}
 		isSuccessFul = outputDirectory.listFiles(IOUtils.HIDDENFILE_FILTER).size() > 0
 		
 		String cleanDirectories = project.getCleanAfterBuild();
