Statistics
| Revision:

root / tmp / org.txm.core / src / groovy / org / txm / doc / Workflow.groovy @ 187

History | View | Annotate | Download (2.7 kB)

1
/**
2
 * Main.
3
 *
4
 * @param args the args
5
 */
6
// Copyright © 2010-2013 ENS de Lyon.
7
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
8
// Lyon 2, University of Franche-Comté, University of Nice
9
// Sophia Antipolis, University of Paris 3.
10
// 
11
// The TXM platform is free software: you can redistribute it
12
// and/or modify it under the terms of the GNU General Public
13
// License as published by the Free Software Foundation,
14
// either version 2 of the License, or (at your option) any
15
// later version.
16
// 
17
// The TXM platform is distributed in the hope that it will be
18
// useful, but WITHOUT ANY WARRANTY; without even the implied
19
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20
// PURPOSE. See the GNU General Public License for more
21
// details.
22
// 
23
// You should have received a copy of the GNU General
24
// Public License along with the TXM platform. If not, see
25
// http://www.gnu.org/licenses.
26
//
27
//
28
//
29
// $LastChangedDate: 2013-05-06 17:38:43 +0200 (lun., 06 mai 2013) $
30
// $LastChangedRevision: 2386 $
31
// $LastChangedBy: mdecorde $
32
//
33
package org.txm.doc
34

    
35
import org.txm.importer.ConvertDocument;
36

    
37
// TODO: Auto-generated Javadoc
38
/* (non-Javadoc)
39
 * @see groovy.lang.Script#run()
40
 */
41
String home = System.getProperty("user.home");
42
File srcdir = new File(home, "xml/txmrefman")
43
File outdir = new File(home, "xml/txmrefman/TEI")
44
File xsldir = new File(home, "xsl")
45
File xslOdtTei = new File(xsldir, "tei/odt/odttotei.xsl");
46
File xslDocxTei = new File(xsldir, "tei/docx/from/docxtotei.xsl");
47

    
48
if (!xslOdtTei.exists()) {
49
        println "$xslOdtTei file does not exists"
50
        return;
51
}
52

    
53
outdir.deleteDir()
54
outdir.mkdirs()
55

    
56
println "start"
57
for (File file : srcdir.listFiles()) {
58
        ConvertDocument converter = new ConvertDocument();
59
        try {
60
                File teifile = new File(outdir, file.getName()+".xml");
61
                if (file.getName().endsWith(".odt")) {
62
                        if (!new DocumentToTei().run(file, xslOdtTei, teifile)) {
63
                                println "Odt to Tei failed"
64
                                return;
65
                        }
66
                } else if (file.getName().endsWith(".docx")) {
67
                        File odtFile = File.createTempFile("workflowodt", "sfsdf.odt", srcdir);
68
                        // convert doc to odt
69
                        converter.autoFile(file, odtFile, "odt")
70
                        if (!new DocumentToTei().run(odtFile, xslOdtTei, teifile)) {
71
                                println "Docx to Odt to Tei failed: "+file
72
                                odtFile.delete();
73
                                return;
74
                        }
75
                        odtFile.delete();
76
                } else if (file.getName().endsWith(".doc")) {
77
                        File odtFile = File.createTempFile("workflowodt", "sfsdf.odt", srcdir);
78
                        // convert doc to odt
79
                        converter.autoFile(file, odtFile, "odt")
80
                        if (!new DocumentToTei().run(odtFile, xslOdtTei, teifile)) {
81
                                println "Doc to Odt to Tei failed: "+file
82
                                odtFile.delete();
83
                                return;
84
                        }
85
                        odtFile.delete();
86
                }
87
        }
88
        catch(Exception e) { e.printStackTrace() }
89
        finally { converter.stop(); }
90
}
91

    
92
println "--Done"