Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / test / InjectMetadataCSV.groovy @ 966

History | View | Annotate | Download (1.1 kB)

1 321 mdecorde
package org.txm.test;
2 321 mdecorde
import org.txm.metadatas.*;
3 321 mdecorde
4 321 mdecorde
def txmfilesdir = new File("C:\\Documents and Settings\\alavrent\\xml\\metadata")
5 321 mdecorde
def outdir = new File("C:\\Documents and Settings\\alavrent\\xml\\metadata\\meta")
6 321 mdecorde
outdir.mkdir()
7 966 mdecorde
def allmetadatasfile = Metadatas.findMetadataFile(new File("C:\\Documents and Settings\\alavrent\\xml\\metadata"));
8 321 mdecorde
println "-- INJECT METADATA - from csv file: "+allmetadatasfile+" in directory: "+txmfilesdir
9 321 mdecorde
def metadatas = new Metadatas(allmetadatasfile, "UTF-8", ",","\"", 1)
10 321 mdecorde
if(metadatas != null)
11 321 mdecorde
{
12 321 mdecorde
        println("Injecting metadata: "+metadatas.getHeadersList()+" in texts of directory "+txmfilesdir)
13 321 mdecorde
        for (File infile : txmfilesdir.listFiles()) {
14 321 mdecorde
                if(!infile.isFile() || infile.getName().endsWith(".csv.xml") || !infile.getName().endsWith(".xml"))
15 321 mdecorde
                        continue;
16 321 mdecorde
17 321 mdecorde
                print "."
18 321 mdecorde
                File outfile = new File(outdir, infile.getName());
19 321 mdecorde
                String tag = "text";
20 321 mdecorde
21 321 mdecorde
                if(!metadatas.injectMetadatasInXmlTXM(infile, outfile))
22 321 mdecorde
                {
23 321 mdecorde
                        outfile.delete();
24 321 mdecorde
                        println "Error: Injection failed, stop import"
25 321 mdecorde
                        return;
26 321 mdecorde
                }
27 321 mdecorde
        }
28 321 mdecorde
        println ""
29 321 mdecorde
}