Statistics
| Revision:

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

History | View | Annotate | Download (2.7 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
// 
24
// $LastChangedDate:$
25
// $LastChangedRevision:$
26
// $LastChangedBy:$ 
27
//
28
package filters.CutHeader;
29

    
30
import java.util.regex.Matcher
31
import java.util.regex.Pattern
32

    
33
import org.txm.importer.filters.Filter;
34

    
35
// TODO: Auto-generated Javadoc
36
/**
37
 * The Class CutHeader.
38
 */
39
class CutHeader extends Filter
40
{
41
        
42
        /** The xml header file. */
43
        String xmlHeaderFile = ""; 
44
        
45
        /** The header. */
46
        boolean header = true;
47
        
48
        /** The HEADER. */
49
        OutputStreamWriter HEADER;
50
        
51
        /* (non-Javadoc)
52
         * @see org.txm.importer.filters.Filter#SetUsedParam(java.lang.Object)
53
         */
54
        void SetUsedParam(Object args) {
55
                if (args.size() == 1) {
56
                        xmlHeaderFile = args[0].toString();
57
                } else {
58
                        System.err.println("CutHeader needs 1 args\nString:xmlHEADERFilePath");
59
                        System.exit(-1);
60
                }
61
        }
62
        
63
        /* (non-Javadoc)
64
         * @see org.txm.importer.filters.Filter#after()
65
         */
66
        void after()
67
        {
68
                HEADER.close();
69
                //println("AFTER CUTHEADER");
70
        }
71
        
72
        /* (non-Javadoc)
73
         * @see org.txm.importer.filters.Filter#filter()
74
         */
75
        protected void filter()
76
        {
77
                if(header) {
78
                        //if(line ==~ /\s*<text>\s*/ )
79
                        if (line.startsWith("<text ") || line.startsWith("<text>")) {
80
                                header = false;
81
                                HEADER.close();
82
                                output.print(line+lineSeparator);
83
                        } else {
84
                                //print(line+lineSeparator);
85
                                HEADER.print(line+lineSeparator);
86
                        }
87
                } else {
88
                        output.write(line+lineSeparator);        
89
                }
90
                //System.out.println( "!"+linecounter);
91
        }
92
        
93
        /* (non-Javadoc)
94
         * @see org.txm.importer.filters.Filter#before()
95
         */
96
        boolean before() {
97
                if (xmlHeaderFile == "") {
98
                        println("need to define xmlHeaderFile before lauching this filter");
99
                        return false;
100
                }
101
                File outputFile = new File(xmlHeaderFile)
102
                //HEADER = new PrintWriter(new BufferedWriter(new FileWriter(outputFile)));
103
                HEADER = new OutputStreamWriter(new FileOutputStream(outputFile) , this.encodageSortie);
104
                //println("BEFORE CUTHEADER");
105
                return true;
106
        }
107
}