Statistics
| Revision:

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

History | View | Annotate | Download (15.4 kB)

1 187 sjacqu01
// Copyright © 2010-2013 ENS de Lyon.
2 187 sjacqu01
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3 187 sjacqu01
// Lyon 2, University of Franche-Comté, University of Nice
4 187 sjacqu01
// Sophia Antipolis, University of Paris 3.
5 187 sjacqu01
//
6 187 sjacqu01
// The TXM platform is free software: you can redistribute it
7 187 sjacqu01
// and/or modify it under the terms of the GNU General Public
8 187 sjacqu01
// License as published by the Free Software Foundation,
9 187 sjacqu01
// either version 2 of the License, or (at your option) any
10 187 sjacqu01
// later version.
11 187 sjacqu01
//
12 187 sjacqu01
// The TXM platform is distributed in the hope that it will be
13 187 sjacqu01
// useful, but WITHOUT ANY WARRANTY; without even the implied
14 187 sjacqu01
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 187 sjacqu01
// PURPOSE. See the GNU General Public License for more
16 187 sjacqu01
// details.
17 187 sjacqu01
//
18 187 sjacqu01
// You should have received a copy of the GNU General
19 187 sjacqu01
// Public License along with the TXM platform. If not, see
20 187 sjacqu01
// http://www.gnu.org/licenses.
21 187 sjacqu01
22 187 sjacqu01
//
23 187 sjacqu01
// This file is part of the TXM platform.
24 187 sjacqu01
//
25 187 sjacqu01
// The TXM platform is free software: you can redistribute it and/or modif y
26 187 sjacqu01
// it under the terms of the GNU General Public License as published by
27 187 sjacqu01
// the Free Software Foundation, either version 3 of the License, or
28 187 sjacqu01
// (at your option) any later version.
29 187 sjacqu01
//
30 187 sjacqu01
// The TXM platform is distributed in the hope that it will be useful,
31 187 sjacqu01
// but WITHOUT ANY WARRANTY; without even the implied warranty of
32 187 sjacqu01
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33 187 sjacqu01
// GNU General Public License for more details.
34 187 sjacqu01
//
35 187 sjacqu01
// You should have received a copy of the GNU General Public License
36 187 sjacqu01
// along with the TXM platform.  If not, see <http://www.gnu.org/licenses/>.
37 187 sjacqu01
//
38 187 sjacqu01
//
39 187 sjacqu01
//
40 187 sjacqu01
// $LastChangedDate: 2017-01-24 18:11:42 +0100 (Tue, 24 Jan 2017) $
41 187 sjacqu01
// $LastChangedRevision: 3400 $
42 187 sjacqu01
// $LastChangedBy: mdecorde $
43 187 sjacqu01
//
44 187 sjacqu01
package org.txm.importer.bfm;
45 187 sjacqu01
46 187 sjacqu01
import org.txm.importer.*;
47 187 sjacqu01
import org.xml.sax.Attributes;
48 187 sjacqu01
import org.txm.importer.filters.*;
49 187 sjacqu01
import java.io.File;
50 187 sjacqu01
import java.io.IOException;
51 187 sjacqu01
import java.util.ArrayList;
52 187 sjacqu01
import javax.xml.parsers.SAXParserFactory;
53 187 sjacqu01
import javax.xml.parsers.ParserConfigurationException;
54 187 sjacqu01
import javax.xml.parsers.SAXParser;
55 187 sjacqu01
import javax.xml.stream.*;
56 187 sjacqu01
import java.net.URL;
57 187 sjacqu01
import org.xml.sax.InputSource;
58 187 sjacqu01
import org.xml.sax.helpers.DefaultHandler;
59 187 sjacqu01
60 187 sjacqu01
// TODO: Auto-generated Javadoc
61 187 sjacqu01
/**
62 187 sjacqu01
 * Build BFM texts HTML edition from the TEI-TXM files. <br/>
63 187 sjacqu01
 * The result is similar to the one of the XSLT script made by Alexis Lavrentiev
64 187 sjacqu01
 * (BFM & ICAR3). <br/>
65 187 sjacqu01
 *
66 187 sjacqu01
 * @author mdecorde
67 187 sjacqu01
 */
68 187 sjacqu01
class pager {
69 187 sjacqu01
        private List<String> NoSpaceBefore;
70 187 sjacqu01
71 187 sjacqu01
        /** The No space after. */
72 187 sjacqu01
        private List<String> NoSpaceAfter;
73 187 sjacqu01
74 187 sjacqu01
        /** The wordcount. */
75 187 sjacqu01
        private int wordcount = 0;
76 187 sjacqu01
77 187 sjacqu01
        /** The pagecount. */
78 187 sjacqu01
        private int pagecount = 0;
79 187 sjacqu01
80 187 sjacqu01
        /** The wordmax. */
81 187 sjacqu01
        private int wordmax = 0;
82 187 sjacqu01
83 187 sjacqu01
        /** The wordid. */
84 187 sjacqu01
        private String wordid;
85 187 sjacqu01
86 187 sjacqu01
        /** The first word. */
87 187 sjacqu01
        private boolean firstWord = true;
88 187 sjacqu01
89 187 sjacqu01
        /** The wordvalue. */
90 187 sjacqu01
        private String wordvalue;
91 187 sjacqu01
92 187 sjacqu01
        /** The interpvalue. */
93 187 sjacqu01
        private String interpvalue;
94 187 sjacqu01
95 187 sjacqu01
        /** The lastword. */
96 187 sjacqu01
        private String lastword = " ";
97 187 sjacqu01
98 187 sjacqu01
        /** The wordtype. */
99 187 sjacqu01
        private String wordtype;
100 187 sjacqu01
101 187 sjacqu01
        /** The flagform. */
102 187 sjacqu01
        private boolean flagform = false;
103 187 sjacqu01
104 187 sjacqu01
        /** The flaginterp. */
105 187 sjacqu01
        private boolean flaginterp = false;
106 187 sjacqu01
107 187 sjacqu01
        /** The url. */
108 187 sjacqu01
        private URL url;
109 187 sjacqu01
110 187 sjacqu01
        /** The input data. */
111 187 sjacqu01
        private def inputData;
112 187 sjacqu01
113 187 sjacqu01
        /** The factory. */
114 187 sjacqu01
        private def factory;
115 187 sjacqu01
116 187 sjacqu01
        /** The parser. */
117 187 sjacqu01
        private XMLStreamReader parser;
118 187 sjacqu01
119 187 sjacqu01
        /** The writer. */
120 187 sjacqu01
        private OutputStreamWriter writer;
121 187 sjacqu01
122 187 sjacqu01
        /** The multiwriter. */
123 187 sjacqu01
        private OutputStreamWriter multiwriter = null;
124 187 sjacqu01
        StaxStackWriter pagedWriter = null;
125 187 sjacqu01
126 187 sjacqu01
        /** The infile. */
127 187 sjacqu01
        private File infile;
128 187 sjacqu01
129 187 sjacqu01
        /** The outfile. */
130 187 sjacqu01
        private File outfile;
131 187 sjacqu01
        private File outDir;
132 187 sjacqu01
133 187 sjacqu01
        /** The pages. */
134 187 sjacqu01
        ArrayList<File> pages = new ArrayList<File>();
135 187 sjacqu01
136 187 sjacqu01
        /** The idxstart. */
137 187 sjacqu01
        ArrayList<String> idxstart = new ArrayList<String>();
138 187 sjacqu01
139 187 sjacqu01
        /** The titre id. */
140 187 sjacqu01
        private String titreId;
141 187 sjacqu01
142 187 sjacqu01
        private String basename;
143 187 sjacqu01
        private String textname;
144 187 sjacqu01
145 187 sjacqu01
        private def xpathProperties;
146 187 sjacqu01
147 187 sjacqu01
        /**
148 187 sjacqu01
         * Instantiates a new pager.
149 187 sjacqu01
         *
150 187 sjacqu01
         * @param infile the file to convert
151 187 sjacqu01
         * @param outfile the result file
152 187 sjacqu01
         * @param NoSpaceBefore the punctuation marks that don't have a space before
153 187 sjacqu01
         * @param NoSpaceAfter the punctuation marks that don't have a space after
154 187 sjacqu01
         * @param max the max number of word per page
155 187 sjacqu01
         */
156 187 sjacqu01
        pager(File infile, File outDir, String textname, List<String> NoSpaceBefore,
157 187 sjacqu01
        List<String> NoSpaceAfter, int max, String basename, Properties xpathprops) {
158 187 sjacqu01
                this.wordmax = max;
159 187 sjacqu01
                this.NoSpaceBefore = NoSpaceBefore;
160 187 sjacqu01
                this.NoSpaceAfter = NoSpaceAfter;
161 187 sjacqu01
                this.basename = basename;
162 187 sjacqu01
                this.textname = textname;
163 187 sjacqu01
                this.outDir = outDir;
164 187 sjacqu01
                this.xpathProperties = xpathprops;
165 187 sjacqu01
                this.url = infile.toURI().toURL();
166 187 sjacqu01
                this.infile = infile;
167 187 sjacqu01
168 187 sjacqu01
                inputData = url.openStream();
169 187 sjacqu01
                factory = XMLInputFactory.newInstance();
170 187 sjacqu01
                parser = factory.createXMLStreamReader(inputData);
171 187 sjacqu01
                process();
172 187 sjacqu01
        }
173 187 sjacqu01
174 187 sjacqu01
        private def closeMultiWriter()
175 187 sjacqu01
        {
176 187 sjacqu01
                if (pagedWriter != null) {
177 187 sjacqu01
                        def tags = pagedWriter.getTagStack().clone();
178 187 sjacqu01
179 187 sjacqu01
                        if (firstWord) { // there was no words
180 187 sjacqu01
                                this.idxstart.add("w_0")
181 187 sjacqu01
                                pagedWriter.write("<span id=\"w_0\"/>");
182 187 sjacqu01
                        }
183 187 sjacqu01
                        pagedWriter.writeEndElements();
184 187 sjacqu01
                        pagedWriter.close();
185 187 sjacqu01
                        return tags;
186 187 sjacqu01
                } else {
187 187 sjacqu01
                        return [];
188 187 sjacqu01
                }
189 187 sjacqu01
        }
190 187 sjacqu01
191 187 sjacqu01
        /**
192 187 sjacqu01
         * Creates the next output.
193 187 sjacqu01
         *
194 187 sjacqu01
         * @return true, if successful
195 187 sjacqu01
         */
196 187 sjacqu01
        private boolean createNextOutput()
197 187 sjacqu01
        {
198 187 sjacqu01
                wordcount = 0;
199 187 sjacqu01
                try {
200 187 sjacqu01
                        def tags = closeMultiWriter();
201 187 sjacqu01
                        for (int i = 0 ; i < tags.size() ; i++) {
202 187 sjacqu01
                                String tag = tags[i]
203 187 sjacqu01
                                if ("body" != tag) {
204 187 sjacqu01
                                        tags.remove(i--)
205 187 sjacqu01
                                } else {
206 187 sjacqu01
                                        tags.remove(i--) // remove "body"
207 187 sjacqu01
                                        break; // remove elements until "body tag
208 187 sjacqu01
                                }
209 187 sjacqu01
                        }
210 187 sjacqu01
                        File outfile = new File(outDir, textname+"_"+(++pagecount)+".html")
211 187 sjacqu01
                        pages.add(outfile);
212 187 sjacqu01
                        firstWord = true; // waiting for next word
213 187 sjacqu01
214 187 sjacqu01
                        pagedWriter = new StaxStackWriter(outfile, "UTF-8");
215 187 sjacqu01
216 187 sjacqu01
                        pagedWriter.writeStartDocument("UTF-8", "1.0")
217 187 sjacqu01
                        pagedWriter.writeStartElement("html")
218 187 sjacqu01
                        pagedWriter.writeEmptyElement("meta", ["http-equiv":"Content-Type", "content":"text/html","charset":"UTF-8"]);
219 187 sjacqu01
                        pagedWriter.writeStartElement("head")
220 187 sjacqu01
                        pagedWriter.writeStartElement("title")
221 187 sjacqu01
                        pagedWriter.writeCharacters(basename.toUpperCase()+" - "+textname+" - Edition - Page "+pagecount)
222 187 sjacqu01
                        pagedWriter.writeEndElement() // </title>
223 187 sjacqu01
                        pagedWriter.writeEndElement() // </head>
224 187 sjacqu01
                        pagedWriter.writeStartElement("body") //<body>
225 187 sjacqu01
                        pagedWriter.writeStartElements(tags);
226 187 sjacqu01
                        return true;
227 187 sjacqu01
                } catch (Exception e) {
228 187 sjacqu01
                        System.out.println(e.getLocalizedMessage());
229 187 sjacqu01
                        return false;
230 187 sjacqu01
                }
231 187 sjacqu01
        }
232 187 sjacqu01
233 187 sjacqu01
        /**
234 187 sjacqu01
         * Creates the output.
235 187 sjacqu01
         *
236 187 sjacqu01
         * @param outfile the outfile
237 187 sjacqu01
         * @return true, if successful
238 187 sjacqu01
         */
239 187 sjacqu01
        private boolean createOutput(File outfile) {
240 187 sjacqu01
                try {
241 187 sjacqu01
                        return createNextOutput();
242 187 sjacqu01
                } catch (Exception e) {
243 187 sjacqu01
                        System.out.println(e.getLocalizedMessage());
244 187 sjacqu01
                        return false;
245 187 sjacqu01
                }
246 187 sjacqu01
        }
247 187 sjacqu01
248 187 sjacqu01
        /**
249 187 sjacqu01
         * Gets the page files.
250 187 sjacqu01
         *
251 187 sjacqu01
         * @return the pages create during the processing
252 187 sjacqu01
         */
253 187 sjacqu01
        public ArrayList<File> getPageFiles() {
254 187 sjacqu01
                return pages;
255 187 sjacqu01
        }
256 187 sjacqu01
257 187 sjacqu01
        /**
258 187 sjacqu01
         * Gets the idx.
259 187 sjacqu01
         *
260 187 sjacqu01
         * @return the word's indexes
261 187 sjacqu01
         */
262 187 sjacqu01
        public ArrayList<String> getIdx() {
263 187 sjacqu01
                return idxstart;
264 187 sjacqu01
        }
265 187 sjacqu01
266 187 sjacqu01
        /**
267 187 sjacqu01
         * process the infile.
268 187 sjacqu01
         */
269 187 sjacqu01
        void process() {
270 187 sjacqu01
                String localname = "";
271 187 sjacqu01
272 187 sjacqu01
                boolean closeTitre = false;
273 187 sjacqu01
                boolean closeAmen = false;
274 187 sjacqu01
275 187 sjacqu01
                boolean flagchoice = false;
276 187 sjacqu01
                boolean flagcorr = false;
277 187 sjacqu01
                boolean flagsic = false;
278 187 sjacqu01
                boolean flagreg = false;
279 187 sjacqu01
                boolean flagexpan = false;
280 187 sjacqu01
                boolean flagorig = false;
281 187 sjacqu01
                boolean flagabbr = false;
282 187 sjacqu01
                boolean flagforeign = false;
283 187 sjacqu01
                int levelSupplied = 0;
284 187 sjacqu01
                boolean flagSurplus = false;
285 187 sjacqu01
                boolean flagDel = false;
286 187 sjacqu01
287 187 sjacqu01
                // option for metadata from BFM TEI header
288 187 sjacqu01
                def mValues = [:];
289 187 sjacqu01
                def xpathprocessor = new XPathResult(infile)
290 187 sjacqu01
                for (String name : xpathProperties.keySet()) {
291 187 sjacqu01
                        String value = xpathprocessor.getXpathResponse(xpathProperties.get(name), "N/A");
292 187 sjacqu01
                        mValues.put(name, value.replace("\n", " "));
293 187 sjacqu01
                }
294 187 sjacqu01
                if (mValues.containsKey("forme") && !mValues.get("forme").equals("N/A")) {
295 187 sjacqu01
                        if (mValues.get("forme").startsWith("#forme_")) {
296 187 sjacqu01
                                mValues.put("forme", mValues.get("forme").substring(7));
297 187 sjacqu01
                        } else if (mValues.get("forme").startsWith("#")) {
298 187 sjacqu01
                                mValues.put("forme", mValues.get("forme").substring(1));
299 187 sjacqu01
                        } else {
300 187 sjacqu01
                                mValues.put("forme", mValues.get("forme"));
301 187 sjacqu01
                        }
302 187 sjacqu01
                }
303 187 sjacqu01
                createNextOutput();
304 187 sjacqu01
                for (int event = parser.next(); event != XMLStreamConstants.END_DOCUMENT; event = parser.next())
305 187 sjacqu01
                {
306 187 sjacqu01
                        switch (event) {
307 187 sjacqu01
                                case XMLStreamConstants.START_ELEMENT:
308 187 sjacqu01
                                        localname = parser.getLocalName();
309 187 sjacqu01
                                        switch (localname) {
310 187 sjacqu01
                                                case "text":
311 187 sjacqu01
                                                        pagedWriter.writeStartElement("h1",
312 187 sjacqu01
                                                        ["align":"center", "style":"color:darkviolet;font-family:Times;font-weight:bold;font-style:italic;font-size=200%", "class":"text"])
313 187 sjacqu01
                                                        pagedWriter.writeCharacters(mValues.get("titre"))
314 187 sjacqu01
                                                        pagedWriter.writeEndElement(); // h1
315 187 sjacqu01
                                                        pagedWriter.writeStartElement("p")
316 187 sjacqu01
                                                        pagedWriter.writeEmptyElement("hr")
317 187 sjacqu01
                                                        pagedWriter.writeCharacters("auteur : "+mValues.get("auteur"))
318 187 sjacqu01
                                                        pagedWriter.writeEmptyElement("br");
319 187 sjacqu01
                                                        pagedWriter.writeCharacters("date de composition : "+mValues.get("datecompolibre"));
320 187 sjacqu01
                                                        pagedWriter.writeEmptyElement("br");
321 187 sjacqu01
                                                        pagedWriter.writeCharacters("domaine : "+mValues.get("domaine"))
322 187 sjacqu01
                                                        pagedWriter.writeEmptyElement("br");
323 187 sjacqu01
                                                        pagedWriter.writeCharacters("genre : "+mValues.get("genre"))
324 187 sjacqu01
                                                        pagedWriter.writeEmptyElement("br");
325 187 sjacqu01
                                                        pagedWriter.writeCharacters("forme : "+mValues.get("forme"))
326 187 sjacqu01
                                                        pagedWriter.writeEmptyElement("br");
327 187 sjacqu01
                                                        pagedWriter.writeCharacters("dialecte : "+mValues.get("dialecte"))
328 187 sjacqu01
                                                        pagedWriter.writeEmptyElement("br");
329 187 sjacqu01
                                                        pagedWriter.writeEmptyElement("hr")
330 187 sjacqu01
                                                        pagedWriter.writeEndElement(); // p
331 187 sjacqu01
                                                        break;
332 187 sjacqu01
                                                case "head":
333 187 sjacqu01
                                                        pagedWriter.writeStartElement("h2")
334 187 sjacqu01
                                                        break;
335 187 sjacqu01
                                                case "lg":
336 187 sjacqu01
                                                case "p":
337 187 sjacqu01
                                                        pagedWriter.writeStartElement("p")
338 187 sjacqu01
                                                        break;
339 187 sjacqu01
                                                case "pb":
340 187 sjacqu01
                                                        createNextOutput();
341 187 sjacqu01
                                                        if (parser.getAttributeValue(null,"n") != null) {
342 187 sjacqu01
                                                                pagedWriter.writeStartElement("p", ["style":"color:red", "align":"center"]);
343 187 sjacqu01
                                                                pagedWriter.writeCharacters("- "+parser.getAttributeValue(null,"n")+" -")
344 187 sjacqu01
                                                                pagedWriter.writeEndElement() // p
345 187 sjacqu01
                                                        }
346 187 sjacqu01
                                                        break;
347 187 sjacqu01
348 187 sjacqu01
                                                case "ab":
349 187 sjacqu01
                                                        if (parser.getAttributeValue(null,"n") != null) {
350 187 sjacqu01
                                                                pagedWriter.writeStartElement("p", ["align":"center"]);
351 187 sjacqu01
                                                                pagedWriter.writeCharacters(parser.getAttributeValue(null,"n"))
352 187 sjacqu01
                                                                pagedWriter.writeEndElement() // p
353 187 sjacqu01
                                                        }
354 187 sjacqu01
                                                        break;
355 187 sjacqu01
                                                case "l":
356 187 sjacqu01
                                                        pagedWriter.writeEmptyElement("br");
357 187 sjacqu01
                                                        break;
358 187 sjacqu01
                                                case "div":
359 187 sjacqu01
                                                        if (parser.getAttributeValue(null,"type") == "titre") {
360 187 sjacqu01
                                                                pagedWriter.writeStartElement("h3")
361 187 sjacqu01
                                                                closeTitre = true;
362 187 sjacqu01
                                                        } else if (parser.getAttributeValue(null,"type") == "amen") {
363 187 sjacqu01
                                                                pagedWriter.writeStartElement("h3")
364 187 sjacqu01
                                                                closeAmen = true;
365 187 sjacqu01
                                                        }
366 187 sjacqu01
                                                        break;
367 187 sjacqu01
                                                case "w":
368 187 sjacqu01
                                                        interpvalue = "";
369 187 sjacqu01
                                                        for (int i = 0 ; i < parser.getAttributeCount(); i++) {
370 187 sjacqu01
                                                                if (parser.getAttributeLocalName(i).equals("type")) {
371 187 sjacqu01
                                                                        interpvalue = " pos: "+parser.getAttributeValue(i);
372 187 sjacqu01
                                                                }
373 187 sjacqu01
                                                        }
374 187 sjacqu01
                                                        wordid = parser.getAttributeValue(null, "id");
375 187 sjacqu01
376 187 sjacqu01
                                                        if (firstWord) {
377 187 sjacqu01
                                                                firstWord = false;
378 187 sjacqu01
                                                                this.idxstart.add(wordid);
379 187 sjacqu01
                                                        }
380 187 sjacqu01
                                                        wordcount++;
381 187 sjacqu01
                                                        if (wordcount >= wordmax) {
382 187 sjacqu01
                                                                createNextOutput();
383 187 sjacqu01
                                                        }
384 187 sjacqu01
                                                        break;
385 187 sjacqu01
386 187 sjacqu01
                                                case "choice":
387 187 sjacqu01
                                                        flagchoice = true;
388 187 sjacqu01
                                                        break;
389 187 sjacqu01
                                                case "corr":
390 187 sjacqu01
                                                        flagcorr = true;
391 187 sjacqu01
                                                        break;
392 187 sjacqu01
                                                case "sic":
393 187 sjacqu01
                                                        flagsic = true;
394 187 sjacqu01
                                                        break;
395 187 sjacqu01
                                                case "reg":
396 187 sjacqu01
                                                        flagreg = true;
397 187 sjacqu01
                                                        break;
398 187 sjacqu01
                                                case "orig":
399 187 sjacqu01
                                                        flagorig = true;
400 187 sjacqu01
                                                        break;
401 187 sjacqu01
                                                case "foreign":
402 187 sjacqu01
                                                        flagforeign = true;
403 187 sjacqu01
                                                        break;
404 187 sjacqu01
                                                case "supplied":
405 187 sjacqu01
                                                        levelSupplied = levelSupplied +1;
406 187 sjacqu01
                                                        if(flagform)
407 187 sjacqu01
                                                                wordvalue = wordvalue+"[";
408 187 sjacqu01
                                                        break;
409 187 sjacqu01
410 187 sjacqu01
                                                case "surplus":
411 187 sjacqu01
                                                        flagSurplus = true;
412 187 sjacqu01
                                                        pagedWriter.writeStartElement("span", ["class": "surplus", "style":"color:red;"])
413 187 sjacqu01
                                                        break;
414 187 sjacqu01
415 187 sjacqu01
                                                case "del":
416 187 sjacqu01
                                                        flagDel = true;
417 187 sjacqu01
                                                        pagedWriter.writeStartElement("span", ["class": "del", "style":"color:red;text-decoration:line-through;"])
418 187 sjacqu01
                                                        break;
419 187 sjacqu01
420 187 sjacqu01
                                                case "ana":
421 187 sjacqu01
                                                        flaginterp=true;
422 187 sjacqu01
                                                        interpvalue+=" "+parser.getAttributeValue(null,"type").substring(1)+":"
423 187 sjacqu01
                                                        break;
424 187 sjacqu01
425 187 sjacqu01
                                                case "form":
426 187 sjacqu01
                                                        wordvalue="";
427 187 sjacqu01
                                                        flagform=true;
428 187 sjacqu01
                                        }
429 187 sjacqu01
                                        break;
430 187 sjacqu01
                                case XMLStreamConstants.END_ELEMENT:
431 187 sjacqu01
                                        localname = parser.getLocalName();
432 187 sjacqu01
                                        switch (localname) {
433 187 sjacqu01
                                                case "head":
434 187 sjacqu01
                                                        pagedWriter.writeEndElement() // h2
435 187 sjacqu01
                                                        break;
436 187 sjacqu01
437 187 sjacqu01
                                                case "div":
438 187 sjacqu01
                                                        if (closeTitre) {
439 187 sjacqu01
                                                                pagedWriter.writeEndElement() // h3
440 187 sjacqu01
                                                                closeTitre = false;
441 187 sjacqu01
                                                        } else if(closeAmen) {
442 187 sjacqu01
                                                                pagedWriter.writeEndElement() // h3
443 187 sjacqu01
                                                                closeTitre = false;
444 187 sjacqu01
                                                        }
445 187 sjacqu01
                                                        break;
446 187 sjacqu01
447 187 sjacqu01
                                                case "lb":
448 187 sjacqu01
                                                        pagedWriter.writeEmptyElement("br")
449 187 sjacqu01
                                                        break;
450 187 sjacqu01
                                                case "lg":
451 187 sjacqu01
                                                case "p":
452 187 sjacqu01
                                                        pagedWriter.writeEndElement() // p
453 187 sjacqu01
                                                        break;
454 187 sjacqu01
455 187 sjacqu01
                                                case "choice":
456 187 sjacqu01
                                                        flagchoice = false;
457 187 sjacqu01
                                                        break;
458 187 sjacqu01
                                                case "corr":
459 187 sjacqu01
                                                        flagcorr = false;
460 187 sjacqu01
                                                        break;
461 187 sjacqu01
                                                case "sic":
462 187 sjacqu01
                                                        flagsic = false;
463 187 sjacqu01
                                                        break;
464 187 sjacqu01
                                                case "reg":
465 187 sjacqu01
                                                        flagreg = false;
466 187 sjacqu01
                                                        break;
467 187 sjacqu01
                                                case "orig":
468 187 sjacqu01
                                                        flagorig = false;
469 187 sjacqu01
                                                        break;
470 187 sjacqu01
                                                case "foreign":
471 187 sjacqu01
                                                        flagforeign = false;
472 187 sjacqu01
                                                        break;
473 187 sjacqu01
                                                case "supplied":
474 187 sjacqu01
                                                        levelSupplied = levelSupplied -1;
475 187 sjacqu01
                                                        if (flagform)
476 187 sjacqu01
                                                                wordvalue = wordvalue+"]";
477 187 sjacqu01
                                                        break;
478 187 sjacqu01
                                                case "surplus":
479 187 sjacqu01
                                                        flagSurplus = false;
480 187 sjacqu01
                                                        pagedWriter.writeCharacters(")")
481 187 sjacqu01
                                                        pagedWriter.writeEndElement() // span
482 187 sjacqu01
                                                        break;
483 187 sjacqu01
484 187 sjacqu01
                                                case "del":
485 187 sjacqu01
                                                        flagDel = false;
486 187 sjacqu01
                                                        pagedWriter.writeEndElement() // span
487 187 sjacqu01
                                                        break;
488 187 sjacqu01
489 187 sjacqu01
                                                case "form":
490 187 sjacqu01
                                                        flagform = false
491 187 sjacqu01
                                                        break;
492 187 sjacqu01
493 187 sjacqu01
                                                case "ana":
494 187 sjacqu01
                                                        flaginterp = false
495 187 sjacqu01
                                                        break;
496 187 sjacqu01
497 187 sjacqu01
                                                case "w":
498 187 sjacqu01
                                                        int l = lastword.length();
499 187 sjacqu01
                                                        String color = "";
500 187 sjacqu01
                                                        if (flagcorr)
501 187 sjacqu01
                                                                color = "color: green;";
502 187 sjacqu01
                                                        else if (flagreg)
503 187 sjacqu01
                                                                color = "color: darkgreen;";
504 187 sjacqu01
                                                        else if (flagforeign)
505 187 sjacqu01
                                                                color = "color: darkred;";
506 187 sjacqu01
                                                        else if (levelSupplied == 1)
507 187 sjacqu01
                                                                color = "color: blue;";
508 187 sjacqu01
                                                        else if (levelSupplied == 2)
509 187 sjacqu01
                                                                color = "color: darkblue;";
510 187 sjacqu01
                                                        if (!flagchoice || flagcorr || flagreg) {
511 187 sjacqu01
                                                                String endOfLastWord = "";
512 187 sjacqu01
                                                                if (l > 0)
513 187 sjacqu01
                                                                        endOfLastWord = lastword.subSequence(l-1, l);
514 187 sjacqu01
515 187 sjacqu01
                                                                if (NoSpaceBefore.contains(wordvalue) ||
516 187 sjacqu01
                                                                NoSpaceAfter.contains(lastword) ||
517 187 sjacqu01
                                                                wordvalue.startsWith("-") ||
518 187 sjacqu01
                                                                NoSpaceAfter.contains(endOfLastWord))
519 187 sjacqu01
                                                                {
520 187 sjacqu01
                                                                        //multiwriter.write("<span title=\""+interpvalue+"\" id=\""+wordid+"\" "+color+">");
521 187 sjacqu01
                                                                } else {
522 187 sjacqu01
                                                                        //multiwriter.write(" <span title=\""+interpvalue+"\" id=\""+wordid+"\" "+color+">");
523 187 sjacqu01
                                                                        pagedWriter.writeCharacters(" ")
524 187 sjacqu01
                                                                }
525 187 sjacqu01
526 187 sjacqu01
                                                                pagedWriter.writeStartElement("span", ["title":interpvalue, "id":wordid, "style":color]) // span
527 187 sjacqu01
                                                                pagedWriter.writeCharacters(wordvalue)
528 187 sjacqu01
                                                                pagedWriter.writeEndElement() // span
529 187 sjacqu01
                                                                lastword=wordvalue;
530 187 sjacqu01
                                                        }
531 187 sjacqu01
                                                        break;
532 187 sjacqu01
                                        }
533 187 sjacqu01
                                        break;
534 187 sjacqu01
535 187 sjacqu01
                                case XMLStreamConstants.CHARACTERS:
536 187 sjacqu01
                                        if (flagform && parser.getText().length() > 0)
537 187 sjacqu01
                                                        wordvalue += (parser.getText());
538 187 sjacqu01
                                        if (flaginterp && parser.getText().length() > 0)
539 187 sjacqu01
                                                        interpvalue += (parser.getText());
540 187 sjacqu01
                                        break;
541 187 sjacqu01
                        }
542 187 sjacqu01
                }
543 187 sjacqu01
                closeMultiWriter();
544 187 sjacqu01
        }
545 187 sjacqu01
}