Statistics
| Revision:

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

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.io.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

    
468
                                                        wordcount++;
469
                                                        if (wordcount >= wordmax) {
470
                                                                shouldBreak = true;
471
                                                        }
472

    
473
                                                        if (firstWord) {
474
                                                                indexes << wordid
475
                                                                firstWord = false;
476
                                                        }
477

    
478
                                                        break;
479

    
480
                                                case "ana":
481

    
482
                                                        String type = parser.getAttributeValue(null,"type").substring(1);
483
                                                        if (SIMPLE_TOOLTIP) {
484
                                                                if (type.contains("lemma") || type.contains("pos")) {
485
                                                                        flaginterp=true;
486
                                                                        interpvalue+=", ";
487
                                                                }
488
                                                        } else {
489
                                                                flaginterp=true;
490
                                                                interpvalue+=", "+type+"="
491
                                                        }
492
                                                        break;
493

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

    
520
                                                case "div":
521
                                                //writer.writeCharacters("}");
522

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

    
537
                                                        writer.writeEndElement(); // p
538

    
539
                                                        if (shouldBreak) {
540
                                                                nbBreak++
541
                                                                writer.writeEmptyElement("pb");
542
                                                                writer.writeAttribute("id", ""+nbBreak);
543
                                                                writer.writeCharacters("\n");
544

    
545
                                                                pages << new File(defaultDir, "${txtname}_${nbBreak}.html")
546
                                                                indexes << wordid
547

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

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

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

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

    
626
                                                        if (interpvalue.contains("rapp2")) {
627
                                                                writer.writeCharacters(" » ");
628
                                                        }
629

    
630
                                                        lastword=wordvalue;
631
                                                        break;
632
                                        }
633

    
634
                                        break;
635

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

    
648
                writer.writeEmptyElement("pb");
649
                nbBreak++
650
                writer.writeAttribute("id", ""+nbBreak);
651

    
652
                writer.writeEndElement();
653
                writer.close();
654
                output.close();
655

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

    
667

    
668
                if (pages.size() > 1) {
669
                        for (int i = 1 ; i < nbBreak ; i++) {
670
                                ApplyXsl2 a = new ApplyXsl2(xslfile.getAbsolutePath());
671
                                String[] params = ["pbval1", i,"pbval2", i+1];
672

    
673
                                File resultfile = pages[i-1]
674
                                //println "BBmilestones: "+i+" "+(i+1)+" in file "+resultfile
675
                                //println "process $outfile -> $resultfile"
676
                                a.process(outfile.getAbsolutePath(), resultfile.getAbsolutePath(), params);
677
                        }
678
                } else {
679
                        File page = pages[0]
680
                        FileCopy.copy(outfile, page)
681
                }
682
        }
683

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

    
692
        private void writeSpeaker(String spk, boolean overlapping) {
693

    
694
                writer.writeStartElement("span");
695
                writer.writeAttribute("class", "spk");
696
                if(interviewers.contains(spk))
697
                        bold = true;
698
                else
699
                        bold = false;
700
                spk = spk.replaceAll('^([^0-9]*)([0-9]+)$', '$1 $2');
701
                if (overlapping) writer.writeCharacters("// ")
702
                writer.writeCharacters(spk+": ")
703
                writer.writeEndElement(); // span@class=spk
704
        }
705

    
706
        private String translateEvent(String desc) {
707
                if(eventTranslations.containsKey(desc))
708
                        return eventTranslations.get(desc);
709
                else
710
                        return desc;
711
        }
712

    
713
        boolean boldOpenned = false;
714
        private void startBoldIfNeeded() {
715
                if (bold) {
716
                        writer.writeStartElement(ENQ_HIGHLIGHT_ELEMENT);
717
                        boldOpenned = true;
718
                }
719
        }
720

    
721
        private endBoldIfNeeded() {
722
                if (boldOpenned) {
723
                        //                        println "CLOSE BOLD"
724
                        writer.writeEndElement(); // b
725
                        boldOpenned = false;
726
                }
727
        }
728

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

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

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