Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / macro / text / Text2TXTMacro.groovy @ 499

History | View | Annotate | Download (1.2 kB)

1
package org.txm.macro.text;
2
// STANDARD DECLARATIONS
3

    
4
import org.kohsuke.args4j.*
5
import groovy.transform.Field
6
import org.txm.rcp.swt.widget.parameters.*
7
import org.txm.doc.*;
8
import org.txm.importer.*;
9

    
10
// BEGINNING OF PARAMETERS
11
@Field @Option(name="inputDirectory", usage="the directory containing the DOC/ODT/RTF files to convert", widget="Folder", required=true, def="")
12
File inputDirectory
13

    
14
@Field @Option(name="extension", usage="an example file", widget="String", required=true, def="(odt|doc|rtf|html)")
15
String extension = "doc"
16

    
17
// Open the parameters input dialog box
18
if (!ParametersDialog.open(this)) return;
19

    
20
boolean debug = false;
21

    
22
ConvertDocument converter;
23
def files = []
24
try {
25
        converter = new ConvertDocument();
26
        inputDirectory.eachFileMatch(~/.+\.$extension/) { docFile ->
27
                String name = docFile.getName()
28
                name = name.substring(0, name.lastIndexOf("."))
29
                def txtFile = new File(docFile.getParentFile(), name+".txt")
30
                converter.autoFile(docFile, txtFile, "txt")
31
                files << docFile
32
        }
33
} catch(Exception e) {
34
        println "Error while processing directory: "+e;
35
        if (debug) e.printStackTrace();
36
}
37
if (converter != null) converter.stop();
38

    
39
println "Processed directory: $inputDirectory"
40
println "files: "+files