Statistics
| Revision:

root / tmp / org.txm.core / src / groovy / org / txm / importer / transcriber / pager.groovy @ 187

History | View | Annotate | Download (22.1 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 org.txm.importer.transcriber
29

    
30
import java.io.File;
31
import java.util.ArrayList;
32

    
33
import javax.xml.stream.*
34

    
35
import org.txm.importer.ApplyXsl2
36
import org.txm.metadatas.Metadatas
37
import org.txm.utils.FileCopy;
38

    
39

    
40
// TODO: Auto-generated Javadoc
41
/** Build Discours corpus simple edition from a xml-tei.
42
 * 
43
 *  @author mdecorde
44
 *  
45
 */
46
class pager {
47
        
48
        boolean SIMPLE_TOOLTIP = false; // show less properties in word tooltips
49
        String ENQ_HIGHLIGHT_ELEMENT = "b"
50
        
51
        List<String> NoSpaceBefore;
52

    
53
        /** The No space after. */
54
        List<String> NoSpaceAfter;
55

    
56
        /** The pages. */
57
        def pages = [];
58
        def indexes = [];
59

    
60
        /** The wordcount. */
61
        int wordcount = 0;
62

    
63
        /** The pagecount. */
64
        int pagecount = 0;
65

    
66
        /** The wordmax. */
67
        int wordmax = 10;
68

    
69
        /** The wordid. */
70
        String wordid;
71

    
72
        /** The first word. */
73
        boolean firstWord = true;
74

    
75
        /** The wordvalue. */
76
        String wordvalue;
77

    
78
        /** The interpvalue. */
79
        String interpvalue;
80

    
81
        /** The lastword. */
82
        String lastword = " ";
83

    
84
        /** The wordtype. */
85
        String wordtype;
86

    
87
        /** The flagform. */
88
        boolean flagform = false;
89

    
90
        /** The flaginterp. */
91
        boolean flaginterp = false;
92

    
93
        boolean flagcomment = false;
94

    
95
        /** The url. */
96
        private def url;
97

    
98
        /** The input data. */
99
        private def inputData;
100

    
101
        /** The factory. */
102
        private def factory;
103

    
104
        /** The parser. */
105
        private XMLStreamReader parser;
106

    
107
        /** The writer. */
108
        XMLStreamWriter writer;
109
        BufferedOutputStream output;
110

    
111
        File txmfile;
112

    
113
        File outfile;
114

    
115
        String corpusname ="";
116
        String cuttingTag = "pb"
117
        String txtname;
118
        File htmlDir;
119
        File defaultDir;
120
        Metadatas metadatas;
121

    
122
        def interviewers = [];
123
        def eventTranslations = ["^^":"mot inconnu", "?":"orthographe incertaine",
124
                "()":"rupture de syntaxe", "b":"bruit indéterminé",
125
                "*":"mot corrigé",
126
                "bb":"bruit de bouche", "bg":"bruit de gorge",
127
                "ch":"voix chuchotée", "conv":"conversations de fond",
128
                "e":"expiration", "i":"inspiration",
129
                "mic":"bruits micro", "n":"reniflement",
130
                "nontrant":"non transcrit", "pap":"froissement de papiers",
131
                "pf":"souffle", "pi":"inintelligible",
132
                "pif":"inaudible", "r":"respiration",
133
                "rire":"rire du locuteur", "shh":"soufle électrique",
134
                "sif":"sifflement du locuteur", "tx":"toux"];
135
        String currentTime = "";
136
        boolean bold = false;
137
        int writenLength = 0;
138
        boolean spokenTurn = false;
139
        boolean firstSync = false;
140
        boolean firstWho = false;
141
        /**
142
         * Instantiates a new pager.
143
         *
144
         * @param infile the infile
145
         * @param outfile the outfile
146
         * @param NoSpaceBefore the no space before
147
         * @param NoSpaceAfter the no space after
148
         * @param max the max
149
         * @param metadatas the metadatas
150
         */
151
        pager(File txmfile, File htmlDir, String txtname, List<String> NoSpaceBefore,
152
        List<String> NoSpaceAfter, int max, String corpusname, String cuttingTag, Metadatas metadatas) {
153
                this.metadatas = metadatas
154
                this.wordmax = max;
155
                this.cuttingTag = cuttingTag;
156
                this.corpusname = corpusname;
157
                this.NoSpaceBefore = NoSpaceBefore;
158
                this.NoSpaceAfter = NoSpaceAfter;
159
                this.url = txmfile.toURI().toURL();
160
                this.txmfile = txmfile;
161
                this.htmlDir = htmlDir;
162
                this.txtname = txtname;
163

    
164
                inputData = url.openStream();
165
                factory = XMLInputFactory.newInstance();
166
                parser = factory.createXMLStreamReader(inputData);
167

    
168
                defaultDir = new File(htmlDir, "default")
169
                defaultDir.mkdir()
170
                new File(htmlDir, "onepage").mkdir()
171
                outfile = new File(htmlDir, "onepage/${txtname}.html");
172
                createOutput(outfile)
173

    
174
                try {
175
                        process();
176
                } catch(Exception e) {
177
                        org.txm.utils.logger.Log.printStackTrace(e);
178
                        if (writer != null) {
179
                                writer.close();
180
                                output.close();
181
                        }
182
                }
183
        }
184

    
185
        /**
186
         * Creates the output.
187
         *
188
         * @param outfile the outfile
189
         * @return true, if successful
190
         */
191
        private boolean createOutput(File outfile) {
192
                try {
193
                        //println "write html in : "+outfile
194
                        XMLOutputFactory outfactory = XMLOutputFactory.newInstance();
195
                        output = new BufferedOutputStream(new FileOutputStream(outfile))
196
                        writer = outfactory.createXMLStreamWriter(output, "UTF-8");//create a new file
197

    
198
                        return true;
199
                } catch (Exception e) {
200
                        System.out.println(e.getLocalizedMessage());
201
                        return false;
202
                }
203
        }
204
        
205
        /** The events. */
206
        List<String> events = [];
207
        String previousEvent = "", nextEvent = "";
208
        /**
209
         * Process.
210
         */
211
        void process() {
212

    
213
                String previousElem = "";
214
                boolean parolesRaportees = false;
215
                boolean firstWord = true;
216
                boolean shouldBreak = false;
217
                boolean overlapping = false;
218
                int nbBreak = 0;
219
                String previousSPK;
220
                String localname = "";
221
                ArrayList<String> whos = [];
222
                HashMap<String, String> speakers = new HashMap<String, String>();
223
                HashMap<String, String> topics = new HashMap<String, String>();
224

    
225
                writer.writeStartDocument("UTF-8","1.0");
226
                writer.writeStartElement("html");
227
                //<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
228
                writer.writeStartElement("meta");
229
                writer.writeAttribute("http-equiv", "Content-Type");
230
                writer.writeAttribute("content", "text/html");
231
                writer.writeAttribute("charset", "UTF-8");
232
                writer.writeEndElement();
233
                writer.writeStartElement("head");
234

    
235
                //<link rel="stylesheet" type="text/css" href="class.css" />
236
                writer.writeStartElement("link");
237
                writer.writeAttribute("rel", "stylesheet");
238
                writer.writeAttribute("type", "text/css");
239
                writer.writeAttribute("href", "transcriber.css");
240
                writer.writeEndElement();
241
                writer.writeEndElement();
242

    
243
                nbBreak++
244
                writer.writeStartElement("body");
245
                writer.writeEmptyElement("pb");
246
                writer.writeAttribute("id", ""+nbBreak);
247
                pages << new File(defaultDir, "${txtname}_${nbBreak}.html")
248

    
249
                for (int event = parser.next(); event != XMLStreamConstants.END_DOCUMENT; event = parser.next()) {
250
                        switch (event) {
251
                                case XMLStreamConstants.START_ELEMENT:
252
                                        localname = parser.getLocalName();
253
                                        switch (localname) {
254
                                                case "text":
255
                                                        writer.writeStartElement("h2");
256
                                                        writer.writeAttribute("class","titre");
257
                                                        String title = parser.getAttributeValue(null, "title");
258
                                                        if (title != null) {
259
                                                                writer.writeCharacters(title);
260
                                                        } else {
261
                                                                writer.writeCharacters("Transcription "+txmfile.getName().substring(0, txmfile.getName().length() - 4));
262
                                                        }
263
                                                        writer.writeEndElement();
264
                                                        if(metadatas != null) {
265
                                                                writer.writeStartElement("table");
266
                                                                boolean grey = false;
267
                                                                for (String name : metadatas.getPropertyNames()) {
268
                                                                        if ("title" == name) continue; // ignore "title" metadata
269
                                                                        grey = !grey;
270
                                                                        writer.writeStartElement("tr");
271
                                                                        if (grey)
272
                                                                                writer.writeAttribute("style","background-color:lightgrey;")
273
                                                                        String value = parser.getAttributeValue(null, name);
274
                                                                        if (value != null) {
275
                                                                                writer.writeStartElement("td");
276
                                                                                writer.writeCharacters(name);
277
                                                                                writer.writeEndElement();
278
                                                                                writer.writeStartElement("td");
279
                                                                                writer.writeCharacters(value);
280
                                                                                writer.writeEndElement();
281
                                                                        }
282
                                                                        //get enqueteur to style their names
283
                                                                        if (name.startsWith("enq")) {
284
                                                                                interviewers.add(value)
285
                                                                        }
286
                                                                        writer.writeEndElement();
287
                                                                }
288
                                                                writer.writeEndElement();
289
                                                        }
290
                                                        break;
291
                                                case "Topics":
292
                                                /*writer.writeStartElement("h2");
293
                                         writer.writeCharacters("Topics");
294
                                         writer.writeEndElement();
295
                                         writer.writeStartElement("ul");
296
                                         */
297
                                                        break;
298
                                                case "Topic":
299
                                                        topics.put(parser.getAttributeValue(null,"id"), parser.getAttributeValue(null,"desc"))
300
                                                /*writer.writeStartElement("li");
301
                                         writer.writeCharacters(parser.getAttributeValue(null,"desc"));
302
                                         writer.writeStartElement("ul");
303
                                         for(int i = 0 ; i < parser.getAttributeCount() ; i++)
304
                                         {
305
                                         if(parser.getAttributeLocalName(i) != "desc")
306
                                         {
307
                                         writer.writeStartElement("li");
308
                                         writer.writeCharacters(parser.getAttributeLocalName(i)+": "+parser.getAttributeValue(i));
309
                                         writer.writeEndElement();
310
                                         }
311
                                         }
312
                                         writer.writeEndElement();
313
                                         writer.writeEndElement();
314
                                         */
315
                                                        break;
316
                                                case "Speakers":
317
                                                /*writer.writeStartElement("h2");
318
                                         writer.writeCharacters("Speakers");
319
                                         writer.writeEndElement();
320
                                         writer.writeStartElement("ul");*/
321
                                                        break;
322
                                                case "Speaker":
323
                                                        whos.add(parser.getAttributeValue(null,"name"));
324
                                                        speakers.put(parser.getAttributeValue(null,"id"), parser.getAttributeValue(null,"name"))
325
                                                /*writer.writeStartElement("li");
326
                                         writer.writeStartElement("ul");
327
                                         writer.writeCharacters(parser.getAttributeValue(null,"name"));
328
                                         for(int i = 0 ; i < parser.getAttributeCount() ; i++)
329
                                         {
330
                                         if(parser.getAttributeLocalName(i) != "name")
331
                                         {
332
                                         writer.writeStartElement("li");
333
                                         writer.writeCharacters(parser.getAttributeLocalName(i)+": "+parser.getAttributeValue(i));
334
                                         writer.writeEndElement();
335
                                         }
336
                                         }
337
                                         writer.writeEndElement();
338
                                         writer.writeEndElement();*/
339
                                                        break;
340
                                                case "Comment":
341
                                                        spokenTurn = true;
342
                                                        writenLength++;
343
                                                        writer.writeStartElement("span");
344
                                                        writer.writeAttribute("class", "comment");
345
                                                        writer.writeCharacters(" ["+parser.getAttributeValue(0)+"] ");
346
                                                        writer.writeEndElement();
347
                                                        flagcomment = true;
348
                                                        break;
349
                                                case "div":
350
                                                        writer.writeStartElement("div");
351
                                                        writer.writeAttribute("class", "section");
352
                                                        String type = parser.getAttributeValue(null,"type");
353
                                                        String desc = parser.getAttributeValue(null,"topic");
354
                                                        if (type != null && desc != null) {
355
                                                                writer.writeStartElement("h3");
356
                                                                writer.writeCharacters(type+": "+desc);
357
                                                                for (int i = 0 ; i < parser.getAttributeCount() ; i++) {
358
                                                                        String name = parser.getAttributeLocalName(i);
359
                                                                        if (!"type".equals(name)
360
                                                                        && !"topic".equals(name)
361
                                                                        && !"startTime".equals(name)
362
                                                                        && !"endTime".equals(name)) {
363
                                                                                writer.writeCharacters(", "+name+": "+parser.getAttributeValue(i));
364
                                                                        }
365
                                                                }
366
                                                                writer.writeEndElement(); // h3
367
                                                        }
368
                                                        break;
369
                                                case "sp":
370
                                                        endBoldIfNeeded()
371
                                                        firstSync = true;
372
                                                        firstWho = true;
373
                                                        spokenTurn = false;
374
                                                        overlapping = false
375

    
376
                                                        writer.writeStartElement("p");
377
                                                        writer.writeAttribute("class", "turn");
378

    
379
                                                        overlapping = ("true" == parser.getAttributeValue(null,"overlap"))
380
                                                        String spid = parser.getAttributeValue(null,"speaker");
381
                                                        whos = []
382
                                                        if (overlapping) {
383
                                                                writer.writeEmptyElement("br");
384
                                                                writeSpeaker(parser.getAttributeValue(null,"speaker"), false)
385
                                                                
386
                                                                writer.writeEmptyElement("br");
387
                                                                whos = spid.split(" ")
388
                                                        }
389

    
390
                                                        break;
391
                                                case "u":
392
                                                        writer.writeCharacters("\n");
393
                                                        this.currentTime = parser.getAttributeValue(null,"time");
394
                                                
395
                                                        if (previousElem == "u" && writenLength == 0) { // if previous u had no words, it was a silence
396
                                                                writer.writeStartElement("span");
397
                                                                writer.writeAttribute("class", "event");
398
                                                                writer.writeCharacters("[silence]");
399
                                                                writer.writeEndElement(); // span
400
                                                                writer.writeEmptyElement("br");
401
                                                        }
402
                                                        
403
                                                        String spk = parser.getAttributeValue(null, "spk")
404
                                                        if (spk != null && spk != previousSPK) {
405
                                                                endBoldIfNeeded()
406
                                                                writer.writeEmptyElement("br");
407
                                                                writeSpeaker(parser.getAttributeValue(null, "spk"), overlapping)
408
                                                                startBoldIfNeeded()
409
                                                        }
410

    
411
                                                        writeCurrentTime()
412
                                                        previousSPK = spk
413

    
414
                                                //                                                        writenLength = 0;
415
                                                /*writer.writeStartElement("span");
416
                                         writer.writeAttribute("class", "sync");
417
                                         writer.writeCharacters("["+parser.getAttributeValue(null,"time")+"]");
418
                                         writer.writeEndElement();*/
419

    
420
                                                        break;
421
                                                case "event":
422
                                                        spokenTurn = true;
423
                                                        writenLength++;
424
                                                        String desc = parser.getAttributeValue(null,"desc");
425
                                                        desc = translateEvent(desc);
426
                                                        String type = parser.getAttributeValue(null,"type");
427
                                                        if (desc.equals("paroles rapportées")) {
428
                                                                if (parser.getAttributeValue(null, "extent") == "end")
429
                                                                        writer.writeCharacters("» ");
430
                                                                else if (parser.getAttributeValue(null, "extent") == "begin")
431
                                                                        writer.writeCharacters(" «");
432
                                                        } else {
433
                                                                writer.writeStartElement("span");
434
                                                                writer.writeAttribute("class", "event");
435
                                                                if (parser.getAttributeValue(null, "extent") == "end") {
436
                                                                        writer.writeCharacters(" <"+desc+"] ");
437
                                                                        if(events.size() > 0)
438
                                                                                events.remove(events.size()-1)
439
                                                                }
440
                                                                else if (parser.getAttributeValue(null, "extent") == "begin")         {
441

    
442
                                                                        writer.writeCharacters(" ["+desc+"> ");
443
                                                                        events.add(desc)
444
                                                                }
445
                                                                else if (parser.getAttributeValue(null, "extent") == "previous") {
446
                                                                        if(parser.getAttributeValue(null, "type") == "pronounce")
447
                                                                                writer.writeCharacters("_["+desc+"] ");
448
                                                                        else
449
                                                                                writer.writeCharacters("_["+desc+"] ");
450
                                                                        previousEvent = desc;
451
                                                                }
452
                                                                else if (parser.getAttributeValue(null, "extent") == "next") {
453
                                                                        writer.writeCharacters(" ["+desc+"]_");
454
                                                                        nextEvent = desc
455
                                                                }
456
                                                                else
457
                                                                        writer.writeCharacters(" ["+desc+"] ");
458
                                                                writer.writeEndElement(); // span@class=event
459
                                                        }
460
                                                        break;
461
                                                case "w":
462
                                                        for(int i = 0 ; i < parser.getAttributeCount() ; i++)
463
                                                                if(parser.getAttributeLocalName(i) == "id") {
464
                                                                        wordid = (parser.getAttributeValue(i));
465
                                                                        break;
466
                                                                }
467
                                                        if (firstWord) {
468
                                                                indexes << wordid
469
                                                                firstWord = false;
470
                                                        }
471
                                                        wordcount++;
472
                                                        if (wordcount >= wordmax) {
473
                                                                shouldBreak = true;
474
                                                        }
475
                                                        break;
476

    
477
                                                case "ana":
478
                                                        
479
                                                        String type = parser.getAttributeValue(null,"type").substring(1);
480
                                                        if (SIMPLE_TOOLTIP) {
481
                                                                if (type.contains("lemma") || type.contains("pos")) {
482
                                                                        flaginterp=true;
483
                                                                        interpvalue+=", ";
484
                                                                }
485
                                                        } else {
486
                                                                flaginterp=true;
487
                                                                interpvalue+=", "+type+"="
488
                                                        }
489
                                                        break;
490

    
491
                                                case "form":
492
                                                        wordvalue="";
493
                                                        interpvalue ="";
494
                                                        flagform=true;
495
                                                        break;
496
                                        }
497
                                        previousElem = localname;
498
                                        break;
499
                                case XMLStreamConstants.END_ELEMENT:
500
                                        localname = parser.getLocalName();
501
                                        switch(localname)
502
                                        {
503
                                                case "text":
504
                                                        break;
505
                                                case "Topics":
506
                                                //writer.writeEndElement();
507
                                                        break;
508
                                                case "Topic":
509
                                                        break;
510
                                                case "Speakers":
511
                                                //println "Speakers: "+speakers
512
                                                //writer.writeEndElement();
513
                                                        break;
514
                                                case "Speaker":
515
                                                        break;
516

    
517
                                                case "div":
518
                                                //writer.writeCharacters("}");
519
                                                        
520
                                                        writer.writeEndElement(); // div
521
                                                        writer.writeCharacters("\n");
522
                                                        break;
523
                                                case "sp":
524
                                                        //println "CLOSING: "+parser.getLocalName()
525
                                                        endBoldIfNeeded()
526
                                                        if (!spokenTurn) {
527
                                                                writer.writeStartElement("span");
528
                                                                writer.writeAttribute("class", "event");
529
                                                                writer.writeCharacters("[silence]");
530
                                                                writer.writeEndElement();
531
                                                                writer.writeEmptyElement("br");
532
                                                        }
533

    
534
                                                        writer.writeEndElement(); // p
535

    
536
                                                        if (shouldBreak) {
537
                                                                nbBreak++
538
                                                                writer.writeEmptyElement("pb");
539
                                                                writer.writeAttribute("id", ""+nbBreak);
540
                                                                writer.writeCharacters("\n");
541
                                                                
542
                                                                pages << new File(defaultDir, "${txtname}_${nbBreak}.html")
543
                                                                indexes << wordid
544

    
545
                                                                wordcount = 0;
546
                                                                shouldBreak = false;
547
                                                        }
548
                                                        writer.writeCharacters("\n");
549
                                                        break;
550
                                                case "u":
551
                                                        //writer.writeEndElement() // span@class=u
552
                                                        //writer.writeEmptyElement("br");
553
                                                //if (overlapping) writer.writeEndElement(); // b
554
                                                        break;
555
                                                case "event":
556
                                                        break;
557
                                                case "form":
558
                                                        flagform = false
559
                                                        break;
560
                                                case "ana":
561
                                                        flaginterp = false
562
                                                        break;
563
                                                case "w":
564
                                                        writenLength++;
565
                                                        spokenTurn = true;
566
                                                        int l = lastword.length();
567
                                                        String endOfLastWord = "";
568
                                                        if(l > 0)
569
                                                                endOfLastWord = lastword.subSequence(l-1, l);
570

    
571
                                                        if(interpvalue != null)
572
                                                                interpvalue = interpvalue.replace("\"","&quot;");
573
                                                        if(events.size() > 0)
574
                                                                interpvalue = interpvalue.replace("event=", "event="+events.toString().replace("\"","&quot;")); // remove ", "
575

    
576
                                                        if(nextEvent.length() > 0)
577
                                                        {
578
                                                                interpvalue = interpvalue.replace("event=", "event="+nextEvent+", ")
579
                                                                nextEvent = ""
580
                                                        }
581
                                                        interpvalue = interpvalue.replace("=, ","='', "); // add '' to empty interp value
582
                                                        if (interpvalue.startsWith(", ")) interpvalue = interpvalue.substring(2)
583
//                                                        println "** SPACE TEST"
584
//                                                        println "NoSpaceBefore: "+NoSpaceBefore+" contains ? "+wordvalue
585
//                                                        println "NoSpaceAfter: "+NoSpaceAfter+" contains ? "+lastword
586
//                                                        println "wordvalue starts with '-' ? "+wordvalue
587
//                                                        println "NoSpaceAfter: "+NoSpaceAfter+" contains endOfLastWord ? "+endOfLastWord
588
                                                        if(NoSpaceBefore.contains(wordvalue) ||
589
                                                        NoSpaceAfter.contains(lastword) ||
590
                                                        wordvalue.startsWith("-") ||
591
                                                        NoSpaceAfter.contains(endOfLastWord)) {
592
//                                                                println " NO SPACE"
593
                                                        } else {
594
//                                                                println " SPACE"
595
                                                                writer.writeCharacters(" ");
596
                                                        }
597

    
598
                                                        if (interpvalue.contains("rapp1")) {
599
                                                                writer.writeCharacters(" «");
600
                                                        } else if (wordvalue == "\"") {
601
                                                                // don't write this char
602
                                                        } else {
603
                                                                writer.writeStartElement("span");
604
                                                                writer.writeAttribute("class", "word");
605
                                                                writer.writeAttribute("title", interpvalue);
606
                                                                writer.writeAttribute("id", wordid);
607
                                                                writer.writeCharacters(wordvalue);
608
                                                                writer.writeEndElement();
609
                                                        }
610
                                                        if (interpvalue.contains("orth")) {
611
                                                                writer.writeStartElement("span");
612
                                                                writer.writeAttribute("class", "event");
613
                                                                writer.writeCharacters("_[?]");
614
                                                                writer.writeEndElement();
615
                                                        }
616
                                                        if (interpvalue.contains("corr")) {
617
                                                                writer.writeStartElement("span");
618
                                                                writer.writeAttribute("class", "event");
619
                                                                writer.writeCharacters("_[!]");
620
                                                                writer.writeEndElement();
621
                                                        }
622

    
623
                                                        if (interpvalue.contains("rapp2")) {
624
                                                                writer.writeCharacters(" » ");
625
                                                        }
626
                                                        
627
                                                        lastword=wordvalue;
628
                                                        break;
629
                                        }
630
                                        
631
                                        break;
632

    
633
                                case XMLStreamConstants.CHARACTERS:
634
                                        if(flagform)
635
                                                if(parser.getText().length() > 0)
636
                                                        wordvalue+=(parser.getText().trim());
637
                                        if(flaginterp)
638
                                                if(parser.getText().length() > 0)
639
                                                        interpvalue+=(parser.getText().trim());
640
                                        break;
641
                        }
642
                }
643
                writer.writeEndElement();
644

    
645
                writer.writeEmptyElement("pb");
646
                nbBreak++
647
                writer.writeAttribute("id", ""+nbBreak);
648

    
649
                writer.writeEndElement();
650
                writer.close();
651
                output.close();
652

    
653
                File txmhome = new File(org.txm.Toolbox.getParam(org.txm.Toolbox.USER_TXM_HOME));
654
                File xlsDir  = new File(txmhome, "xsl");
655
                File xslfile = new File(xlsDir,"breakByMilestone.xsl");
656
                if (!xslfile.exists()) {
657
                        println ""
658
                }
659
                //                println "xsl: "+xslfile
660
                //                println "html: "+outfile
661
                //                println "pages: "+pages
662
                //                println "words: "+indexes
663

    
664

    
665
                                if (pages.size() > 1) {
666
                                        for (int i = 1 ; i < nbBreak ; i++) {
667
                                                ApplyXsl2 a = new ApplyXsl2(xslfile.getAbsolutePath());
668
                                                String[] params = ["pbval1", i,"pbval2", i+1];
669
                
670
                                                File resultfile = pages[i-1]
671
                                                //println "BBmilestones: "+i+" "+(i+1)+" in file "+resultfile
672
                                                //println "process $outfile -> $resultfile"
673
                                                a.process(outfile.getAbsolutePath(), resultfile.getAbsolutePath(), params);
674
                                        }
675
                                } else {
676
                                        File page = pages[0]
677
                                        FileCopy.copy(outfile, page)
678
                                }
679
        }
680

    
681
        private void writeCurrentTime()
682
        {
683
                writer.writeStartElement("span");
684
                writer.writeAttribute("class", "sync");
685
                writer.writeCharacters(currentTime);
686
                writer.writeEndElement();
687
        }
688

    
689
        private void writeSpeaker(String spk, boolean overlapping) {
690
                
691
                writer.writeStartElement("span");
692
                writer.writeAttribute("class", "spk");
693
                if(interviewers.contains(spk))
694
                        bold = true;
695
                else
696
                        bold = false;
697
                spk = spk.replaceAll('^([^0-9]*)([0-9]+)$', '$1 $2');
698
                if (overlapping) writer.writeCharacters("// ")
699
                writer.writeCharacters(spk+": ")
700
                writer.writeEndElement(); // span@class=spk
701
        }
702

    
703
        private String translateEvent(String desc) {
704
                if(eventTranslations.containsKey(desc))
705
                        return eventTranslations.get(desc);
706
                else
707
                        return desc;
708
        }
709
        
710
        boolean boldOpenned = false;
711
        private void startBoldIfNeeded() {
712
                if (bold) {
713
                        writer.writeStartElement(ENQ_HIGHLIGHT_ELEMENT);
714
                        boldOpenned = true;
715
                }
716
        }
717
        
718
        private endBoldIfNeeded() {
719
                if (boldOpenned) {
720
//                        println "CLOSE BOLD"
721
                        writer.writeEndElement(); // b
722
                        boldOpenned = false;
723
                }
724
        }
725

    
726
        //        private String formatTime(float time, boolean doshort)
727
        //        {
728
        //                String rez = " ";
729
        //                //                if(time >= 3600) // >= 1h
730
        //                //                {
731
        //                float h = time / 3600;
732
        //                time = time%3600;
733
        //                float min = (time%3600) / 60;
734
        //                int sec = (int)time%60;
735
        //
736
        //                if(min < 10)
737
        //                        rez = ""+(int)h+":0"+(int)min;//+":"+time%60;
738
        //                else
739
        //                        rez = ""+(int)h+":"+(int)min;//+":"+time%60;
740
        //                //if (!doshort)
741
        //                if (sec > 9)
742
        //                        rez += ":"+(int)time%60;
743
        //                else
744
        //                        rez += ":0"+(int)time%60;
745
        //                //                }
746
        //                //                else if(time >= 60) // >= 1min
747
        //                //                {
748
        //                //                        int min = time/60;
749
        //                //                        if(min < 10)
750
        //                //                                rez = "00:0"+min;//+":"+time%60;
751
        //                //                        else
752
        //                //                                rez = "00:"+min;//+":"+time%60;
753
        //                //                        if(!doshort)
754
        //                //                                rez += ":"+(int)time%60;
755
        //                //                }
756
        //                //                else // < 60
757
        //                //                {
758
        //                //                        if(time < 10)
759
        //                //                                return " 0:0"+time;
760
        //                //                        else
761
        //                //                                return " 0:"+time;
762
        //                //                }
763
        //                return rez;
764
        //        }
765

    
766
        /**
767
         * Gets the page files.
768
         *
769
         * @return the page files
770
         */
771
        public ArrayList<File> getPageFiles() {
772
                return pages;
773
        }
774

    
775
        /**
776
         * Gets the idx.
777
         *
778
         * @return the idx
779
         */
780
        public ArrayList<String> getIdx() {
781
                return indexes;
782
        }
783
}