Statistics
| Revision:

root / tmp / org.txm.core / src / groovy / filters / Concatenator / Concatenator.groovy @ 187

History | View | Annotate | Download (3 kB)

1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21

    
22
//
23
// This file is part of the TXM platform.
24
//
25
// The TXM platform is free software: you can redistribute it and/or modif y
26
// it under the terms of the GNU General Public License as published by
27
// the Free Software Foundation, either version 3 of the License, or
28
// (at your option) any later version.
29
//
30
// The TXM platform is distributed in the hope that it will be useful,
31
// but WITHOUT ANY WARRANTY; without even the implied warranty of
32
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33
// GNU General Public License for more details.
34
//
35
// You should have received a copy of the GNU General Public License
36
// along with the TXM platform.  If not, see <http://www.gnu.org/licenses/>.
37
// 
38
// 
39
// 
40
// $LastChangedDate:$
41
// $LastChangedRevision:$
42
// $LastChangedBy:$ 
43
//
44
package filters.Concatenator;
45

    
46
import java.io.BufferedWriter;
47
import java.io.File;
48
import java.io.FileOutputStream;
49
import java.io.OutputStreamWriter;
50
import java.io.PrintStream;
51

    
52
import org.txm.importer.filters.*;
53

    
54
// TODO: Auto-generated Javadoc
55
/**
56
 * The Class Concatenator.
57
 */
58
class Concatenator extends Filter {
59
        
60
        /** The destination. */
61
        String destination;
62

    
63
        /* (non-Javadoc)
64
         * @see org.txm.importer.filters.Filter#before()
65
         */
66
        boolean before() {
67
                if (destination == "") {
68
                        println("You need to define destination file before launching this filter");
69
                        return false;
70
                }
71
                def f = new File(destination);
72
                this.output = new OutputStreamWriter(new FileOutputStream(f), "UTF-8");
73
                return true;
74
        }
75

    
76
        /* (non-Javadoc)
77
         * @see org.txm.importer.filters.Filter#SetUsedParam(java.lang.Object)
78
         */
79
        void SetUsedParam(Object args) {
80
                if (args.size() == 1) {
81
                        destination = args[0];
82
                } else {
83
                        System.out
84
                                        .println("Concatenator need 1 args : \nString:destinatione");
85
                }
86
        }
87

    
88
        /* (non-Javadoc)
89
         * @see org.txm.importer.filters.Filter#after()
90
         */
91
        void after() {
92
                System.out.println("Concatenator readed lines : " + linecounter);
93
                this.output.close();
94
        }
95

    
96
        /* (non-Javadoc)
97
         * @see org.txm.importer.filters.Filter#filter()
98
         */
99
        void filter() {
100
                output.write(line + lineSeparator);
101
                output.flush();
102
        }
103
}