Statistics
| Revision:

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

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

    
30
import java.io.File;
31

    
32
import java.io.BufferedReader;
33
import java.io.FileInputStream;
34
import java.io.InputStreamReader;
35
import org.txm.importer.filters.*;
36

    
37
// TODO: Auto-generated Javadoc
38
/**
39
 * The Class FusionHeader.
40
 */
41
class FusionHeader extends Filter {
42
        
43
        /** The xml header file. */
44
        String xmlHeaderFile = "";
45
        
46
        /** The first loop. */
47
        boolean firstLoop = true;
48
        
49
        /** The HEADER. */
50
        BufferedReader HEADER;
51
        
52
        /** The cut headerfilter. */
53
        Thread cutHeaderfilter;
54

    
55
        /* (non-Javadoc)
56
         * @see org.txm.importer.filters.Filter#SetUsedParam(java.lang.Object)
57
         */
58
        void SetUsedParam(Object args) {
59
                if (args.size() == 2) {
60
                        xmlHeaderFile = args[0].toString();
61
                        cutHeaderfilter = (Thread) args[1];
62
                } else {
63
                        System.err
64
                                        .println("CutHeader needs 2 args\nString:xmlHEADERFilePath\nThread:cutHeaderFilter");
65
                        System.exit(-1);
66
                }
67
        }
68

    
69
        /* (non-Javadoc)
70
         * @see org.txm.importer.filters.Filter#after()
71
         */
72
        void after() {
73
                try {
74
                        HEADER.close();
75
                        HEADER= null;
76
                } catch (Exception e) {
77
                        System.err
78
                                        .println("Can't close Header file, one cause might be that the header file is not correctly built");
79
                }
80
        }
81

    
82
        /* (non-Javadoc)
83
         * @see org.txm.importer.filters.Filter#before()
84
         */
85
        boolean before() {
86
                if (xmlHeaderFile == "" || cutHeaderfilter == null) {
87
                        System.err
88
                                        .println("CutHeader needs 2 args\nString:xmlHEADERFilePath\nThread:cutHeaderFilter");
89
                }
90
                // System.out.println("start FUSIONHEADER");
91

    
92
                return true;
93
        }
94

    
95
        /* (non-Javadoc)
96
         * @see org.txm.importer.filters.Filter#filter()
97
         */
98
        protected void filter()
99
        {
100
                if (firstLoop) {
101
                        //println("BEGIN COPYING HEADER");
102
                
103
                        String templine;
104
                        File inputFile = new File(xmlHeaderFile)
105
                        if ( !inputFile.exists()) {
106
                                System.err.println("ERROR : DOES NOT EXISTS "+xmlHeaderFile);
107
                        }
108
                        HEADER = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile), encodage));
109
                        while (!HEADER.ready()) {
110
                                Thread.sleep(10);
111
                                //system.out.println("waiting for cutHeader to finish");
112
                        }
113
                        //HEADER = new FileReader("/home/ayepdieu/xml/header (copie).xml");
114
                        //System.out.println("ready ? "+HEADER.ready());
115
                        while ((templine = this.HEADER.readLine()) != null) {
116
                                //println(templine+lineSeparator);
117
                                output.print(templine+lineSeparator);
118
                        }
119
                        //println("FINISH COPYING HEADER");
120
                        firstLoop=false;
121
                        HEADER.close();
122
                }
123
                output.print(line+lineSeparator);
124
        }
125
}