Statistics
| Revision:

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

History | View | Annotate | Download (1.1 kB)

1
package org.txm.test;
2
import org.txm.metadatas.*;
3

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