Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / scripts / importer / doc / pager.groovy @ 1688

History | View | Annotate | Download (13 kB)

1 321 mdecorde
// Copyright © 2010-2013 ENS de Lyon.
2 321 mdecorde
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3 321 mdecorde
// Lyon 2, University of Franche-Comté, University of Nice
4 321 mdecorde
// Sophia Antipolis, University of Paris 3.
5 1110 mdecorde
//
6 321 mdecorde
// The TXM platform is free software: you can redistribute it
7 321 mdecorde
// and/or modify it under the terms of the GNU General Public
8 321 mdecorde
// License as published by the Free Software Foundation,
9 321 mdecorde
// either version 2 of the License, or (at your option) any
10 321 mdecorde
// later version.
11 1110 mdecorde
//
12 321 mdecorde
// The TXM platform is distributed in the hope that it will be
13 321 mdecorde
// useful, but WITHOUT ANY WARRANTY; without even the implied
14 321 mdecorde
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 321 mdecorde
// PURPOSE. See the GNU General Public License for more
16 321 mdecorde
// details.
17 1110 mdecorde
//
18 321 mdecorde
// You should have received a copy of the GNU General
19 321 mdecorde
// Public License along with the TXM platform. If not, see
20 321 mdecorde
// http://www.gnu.org/licenses.
21 321 mdecorde
//
22 321 mdecorde
//
23 321 mdecorde
//
24 321 mdecorde
// $LastChangedDate: 2012-04-24 14:30:47 +0200 (mar., 24 avr. 2012) $
25 321 mdecorde
// $LastChangedRevision: 2174 $
26 321 mdecorde
// $LastChangedBy: mdecorde $
27 321 mdecorde
//
28 986 mdecorde
package org.txm.scripts.importer.doc;
29 321 mdecorde
30 986 mdecorde
import org.txm.scripts.importer.*;
31 321 mdecorde
import org.xml.sax.Attributes;
32 1000 mdecorde
import org.txm.importer.scripts.filters.*;
33 321 mdecorde
import java.io.File;
34 321 mdecorde
import java.io.IOException;
35 321 mdecorde
import java.util.ArrayList;
36 321 mdecorde
import javax.xml.parsers.SAXParserFactory;
37 321 mdecorde
import javax.xml.parsers.ParserConfigurationException;
38 321 mdecorde
import javax.xml.parsers.SAXParser;
39 321 mdecorde
import javax.xml.stream.*;
40 321 mdecorde
import java.net.URL;
41 321 mdecorde
import org.xml.sax.InputSource;
42 321 mdecorde
import org.xml.sax.helpers.DefaultHandler;
43 321 mdecorde
44 321 mdecorde
// TODO: Auto-generated Javadoc
45 321 mdecorde
/**
46 321 mdecorde
 * Build edition from xml-tei-odt
47 321 mdecorde
 * @author mdecorde
48 321 mdecorde
 *
49 321 mdecorde
 */
50 321 mdecorde
class pager {
51 321 mdecorde
        List<String> NoSpaceBefore;
52 321 mdecorde
53 321 mdecorde
        /** The No space after. */
54 321 mdecorde
        List<String> NoSpaceAfter;
55 321 mdecorde
56 321 mdecorde
        /** The wordcount. */
57 321 mdecorde
        int wordcount = 0;
58 321 mdecorde
59 321 mdecorde
        /** The pagecount. */
60 321 mdecorde
        int pagecount = 0;
61 321 mdecorde
62 321 mdecorde
        /** The wordmax. */
63 321 mdecorde
        int wordmax = 0;
64 321 mdecorde
65 321 mdecorde
        /** The basename. */
66 321 mdecorde
        String basename = "";
67 321 mdecorde
        String txtname = "";
68 321 mdecorde
        File outdir;
69 321 mdecorde
70 321 mdecorde
        /** The wordid. */
71 321 mdecorde
        String wordid;
72 321 mdecorde
73 321 mdecorde
        /** The first word. */
74 321 mdecorde
        boolean firstWord = true;
75 321 mdecorde
76 321 mdecorde
        /** The wordvalue. */
77 321 mdecorde
        String wordvalue;
78 321 mdecorde
79 321 mdecorde
        /** The interpvalue. */
80 321 mdecorde
        String interpvalue;
81 321 mdecorde
82 321 mdecorde
        /** The lastword. */
83 321 mdecorde
        String lastword = " ";
84 321 mdecorde
85 321 mdecorde
        /** The wordtype. */
86 321 mdecorde
        String wordtype;
87 321 mdecorde
88 321 mdecorde
        /** The flagform. */
89 321 mdecorde
        boolean flagform = false;
90 321 mdecorde
91 321 mdecorde
        /** The flaginterp. */
92 321 mdecorde
        boolean flaginterp = false;
93 321 mdecorde
94 321 mdecorde
        /** The url. */
95 321 mdecorde
        private def url;
96 321 mdecorde
97 321 mdecorde
        /** The input data. */
98 321 mdecorde
        private def inputData;
99 321 mdecorde
100 321 mdecorde
        /** The factory. */
101 321 mdecorde
        private def factory;
102 321 mdecorde
103 321 mdecorde
        /** The parser. */
104 321 mdecorde
        private XMLStreamReader parser;
105 321 mdecorde
106 321 mdecorde
        /** The writer. */
107 321 mdecorde
        OutputStreamWriter writer;
108 321 mdecorde
109 321 mdecorde
        /** The multiwriter. */
110 321 mdecorde
        OutputStreamWriter multiwriter = null;
111 1110 mdecorde
112 321 mdecorde
        /** The pagedWriter. */
113 321 mdecorde
        StaxStackWriter pagedWriter = null;
114 321 mdecorde
115 321 mdecorde
        /** The infile. */
116 321 mdecorde
        File infile;
117 321 mdecorde
118 321 mdecorde
        /** The outfile. */
119 321 mdecorde
        File outfile;
120 321 mdecorde
121 321 mdecorde
        /** The pages. */
122 321 mdecorde
        ArrayList<File> pages = new ArrayList<File>();
123 321 mdecorde
124 321 mdecorde
        /** The idxstart. */
125 321 mdecorde
        ArrayList<String> idxstart = new ArrayList<String>();
126 321 mdecorde
        String editionPage;
127 321 mdecorde
128 321 mdecorde
        /**
129 321 mdecorde
         * Instantiates a new pager.
130 321 mdecorde
         *
131 321 mdecorde
         * @param infile the infile
132 321 mdecorde
         * @param outfile the outfile
133 321 mdecorde
         * @param NoSpaceBefore the no space before
134 321 mdecorde
         * @param NoSpaceAfter the no space after
135 321 mdecorde
         * @param max the max
136 321 mdecorde
         * @param basename the basename
137 321 mdecorde
         */
138 321 mdecorde
        pager(File infile, File outdir, String txtname, List<String> NoSpaceBefore,
139 321 mdecorde
        List<String> NoSpaceAfter, int max, String basename, String editionPage) {
140 321 mdecorde
                this.editionPage = editionPage;
141 321 mdecorde
                this.basename = basename;
142 321 mdecorde
                this.txtname = txtname;
143 321 mdecorde
                this.outdir = outdir;
144 321 mdecorde
                this.wordmax = max;
145 321 mdecorde
                this.NoSpaceBefore = NoSpaceBefore;
146 321 mdecorde
                this.NoSpaceAfter = NoSpaceAfter;
147 321 mdecorde
                this.url = infile.toURI().toURL();
148 321 mdecorde
                this.infile = infile;
149 321 mdecorde
150 321 mdecorde
                inputData = url.openStream();
151 321 mdecorde
                factory = XMLInputFactory.newInstance();
152 321 mdecorde
                parser = factory.createXMLStreamReader(inputData);
153 321 mdecorde
                process();
154 321 mdecorde
        }
155 321 mdecorde
156 321 mdecorde
        private def closeMultiWriter()
157 321 mdecorde
        {
158 321 mdecorde
                if (pagedWriter != null) {
159 321 mdecorde
                        def tags = pagedWriter.getTagStack().clone();
160 321 mdecorde
                        if (firstWord) { // there was no words
161 321 mdecorde
                                this.idxstart.add("w_0")
162 321 mdecorde
                                pagedWriter.write("<span id=\"w_0\"/>");
163 321 mdecorde
                        }
164 321 mdecorde
165 321 mdecorde
                        pagedWriter.writeEndElements();
166 321 mdecorde
                        pagedWriter.close();
167 321 mdecorde
                        return tags;
168 321 mdecorde
169 321 mdecorde
                        //                        pagedWriter.write("</body>");
170 321 mdecorde
                        //                        pagedWriter.write("</html>");
171 321 mdecorde
                        //                        pagedWriter.close();
172 321 mdecorde
                } else {
173 321 mdecorde
                        return [];
174 321 mdecorde
                }
175 321 mdecorde
        }
176 321 mdecorde
177 321 mdecorde
        /**
178 321 mdecorde
         * Creates the next output.
179 321 mdecorde
         *
180 321 mdecorde
         * @return true, if successful
181 321 mdecorde
         */
182 321 mdecorde
        private boolean createNextOutput()
183 321 mdecorde
        {
184 321 mdecorde
                wordcount = 0;
185 321 mdecorde
                try {
186 321 mdecorde
                        def tags = closeMultiWriter()
187 321 mdecorde
                        for (int i = 0 ; i < tags.size() ; i++) {
188 321 mdecorde
                                String tag = tags[i]
189 321 mdecorde
                                if ("body" != tag) {
190 321 mdecorde
                                        tags.remove(i--)
191 321 mdecorde
                                } else {
192 321 mdecorde
                                        tags.remove(i--) // remove "body"
193 321 mdecorde
                                        break; // remove elements until "body tag
194 321 mdecorde
                                }
195 321 mdecorde
                        }
196 321 mdecorde
                        File outfile = new File(outdir, txtname+"_"+(++pagecount)+".html")
197 321 mdecorde
                        pages.add(outfile)
198 321 mdecorde
                        firstWord = true // waiting for next word
199 321 mdecorde
200 321 mdecorde
                        pagedWriter = new StaxStackWriter(outfile , "UTF-8");
201 321 mdecorde
                        pagedWriter.writeStartDocument("UTF-8", "1.0")
202 321 mdecorde
                        pagedWriter.writeStartElement("html")
203 321 mdecorde
                        pagedWriter.writeEmptyElement("meta", ["http-equiv":"Content-Type", "content":"text/html","charset":"UTF-8"])
204 321 mdecorde
                        pagedWriter.writeStartElement("head")
205 321 mdecorde
                        pagedWriter.writeEmptyElement("link", ["rel":"stylesheet", "href":txtname+".css"])
206 321 mdecorde
                        pagedWriter.writeEmptyElement("link", ["rel":"stylesheet", "href":"doc.css"])
207 321 mdecorde
                        pagedWriter.writeStartElement("title")
208 321 mdecorde
                        pagedWriter.writeCharacters(basename.toUpperCase()+" Edition - Page "+pagecount)
209 321 mdecorde
                        pagedWriter.writeEndElement() // </title>
210 321 mdecorde
                        pagedWriter.writeEndElement() // </head>
211 321 mdecorde
                        pagedWriter.writeStartElement("body") //<body>
212 321 mdecorde
                        pagedWriter.writeStartElements(tags)
213 321 mdecorde
                        return true;
214 321 mdecorde
                } catch (Exception e) {
215 321 mdecorde
                        System.out.println(e.getLocalizedMessage());
216 321 mdecorde
                        return false;
217 321 mdecorde
                }
218 321 mdecorde
        }
219 321 mdecorde
220 321 mdecorde
        /**
221 321 mdecorde
         * Creates the output.
222 321 mdecorde
         *
223 321 mdecorde
         * @param outfile the outfile
224 321 mdecorde
         * @return true, if successful
225 321 mdecorde
         */
226 321 mdecorde
        private boolean createOutput() {
227 321 mdecorde
                try {
228 321 mdecorde
                        return createNextOutput();
229 321 mdecorde
                } catch (Exception e) {
230 321 mdecorde
                        System.out.println(e.getLocalizedMessage());
231 321 mdecorde
                        return false;
232 321 mdecorde
                }
233 321 mdecorde
        }
234 321 mdecorde
235 321 mdecorde
        /**
236 321 mdecorde
         * Gets the page files.
237 321 mdecorde
         *
238 321 mdecorde
         * @return the page files
239 321 mdecorde
         */
240 321 mdecorde
        public ArrayList<File> getPageFiles() {
241 321 mdecorde
                return pages;
242 321 mdecorde
        }
243 321 mdecorde
244 321 mdecorde
        /**
245 321 mdecorde
         * Gets the idx.
246 321 mdecorde
         *
247 321 mdecorde
         * @return the idx
248 321 mdecorde
         */
249 321 mdecorde
        public ArrayList<String> getIdx() {
250 321 mdecorde
                return idxstart;
251 321 mdecorde
        }
252 321 mdecorde
253 321 mdecorde
        void gotoText() {
254 321 mdecorde
                for (int event = parser.next(); event != XMLStreamConstants.END_DOCUMENT; event = parser.next()) {
255 321 mdecorde
                        switch (event) {
256 321 mdecorde
                                case XMLStreamConstants.END_ELEMENT:
257 321 mdecorde
                                        if(parser.getLocalName() == "teiHeader")
258 321 mdecorde
                                                return;
259 321 mdecorde
                        }
260 321 mdecorde
                }
261 321 mdecorde
        }
262 321 mdecorde
        /**
263 321 mdecorde
         * Process.
264 321 mdecorde
         */
265 321 mdecorde
        void process() {
266 321 mdecorde
                try {
267 1110 mdecorde
                        String localname = "";
268 1110 mdecorde
                        String figurerend = ""
269 1110 mdecorde
                        boolean unordered = false;
270 1110 mdecorde
                        createNextOutput();
271 1110 mdecorde
272 1110 mdecorde
                        gotoText();
273 1110 mdecorde
                        for (int event = parser.next(); event != XMLStreamConstants.END_DOCUMENT; event = parser.next()) {
274 1110 mdecorde
                                switch (event) {
275 1110 mdecorde
                                        case XMLStreamConstants.START_ELEMENT:
276 1110 mdecorde
                                                localname = parser.getLocalName();
277 1110 mdecorde
278 1110 mdecorde
                                                if (localname == editionPage) {
279 1110 mdecorde
                                                        createNextOutput();
280 1110 mdecorde
                                                        wordcount=0;
281 1110 mdecorde
                                                        if (parser.getAttributeValue(null,"n") != null) {
282 1110 mdecorde
                                                                pagedWriter.writeStartElement("p", ["style":"color:red", "align":"center"])
283 1110 mdecorde
                                                                pagedWriter.writeCharacters("- "+parser.getAttributeValue(null,"n")+" -")
284 1110 mdecorde
                                                                pagedWriter.writeEndElement() // p
285 1110 mdecorde
                                                        }
286 479 mdecorde
                                                }
287 1110 mdecorde
288 1110 mdecorde
                                                switch (localname) {
289 1110 mdecorde
                                                        case "textunit":
290 1110 mdecorde
                                                                if (parser.getAttributeValue(null,"id") != null) {
291 1110 mdecorde
                                                                        pagedWriter.writeStartElement("h3")
292 1110 mdecorde
                                                                        pagedWriter.writeCharacters(parser.getAttributeValue(null,"id"))
293 1110 mdecorde
                                                                        pagedWriter.writeEndElement() // h3
294 1110 mdecorde
                                                                }
295 1110 mdecorde
                                                                pagedWriter.writeStartElement("table")
296 1110 mdecorde
                                                                for (int i = 0 ; i < parser.getAttributeCount() ; i++) {
297 1110 mdecorde
                                                                        pagedWriter.writeStartElement("tr")
298 1110 mdecorde
                                                                        pagedWriter.writeStartElement("td")
299 1110 mdecorde
                                                                        pagedWriter.writeCharacters(parser.getAttributeLocalName(i))
300 1110 mdecorde
                                                                        pagedWriter.writeEndElement() // td
301 1110 mdecorde
                                                                        pagedWriter.writeStartElement("td")
302 1110 mdecorde
                                                                        pagedWriter.writeCharacters(parser.getAttributeValue(i))
303 1110 mdecorde
                                                                        pagedWriter.writeEndElement() // td
304 1110 mdecorde
                                                                        pagedWriter.writeEndElement() // tr
305 1110 mdecorde
                                                                }
306 1110 mdecorde
                                                                pagedWriter.writeEndElement() // table
307 1110 mdecorde
                                                                pagedWriter.writeEmptyElement("br")
308 1110 mdecorde
                                                                break;
309 1110 mdecorde
                                                        case "head":
310 1110 mdecorde
                                                                String rend = parser.getAttributeValue(null, "rend")
311 1110 mdecorde
                                                                if (rend == null) rend = "normal"
312 1110 mdecorde
                                                                pagedWriter.writeStartElement("h2", ["class":rend])
313 1110 mdecorde
                                                                break;
314 1110 mdecorde
                                                        case "figure":
315 1110 mdecorde
                                                                figurerend = parser.getAttributeValue(null, "rend")
316 1110 mdecorde
                                                                break;
317 1110 mdecorde
                                                        case "graphic":
318 1110 mdecorde
                                                                String url = parser.getAttributeValue(null, "url")
319 1110 mdecorde
                                                                if (url.startsWith("..//")) url = url.substring(4);
320 1110 mdecorde
                                                                else if (url.startsWith("../")) url = url.substring(3);
321 1110 mdecorde
322 1110 mdecorde
                                                                if (url != null) {
323 1110 mdecorde
                                                                        pagedWriter.writeStartElement("div")
324 1110 mdecorde
                                                                        pagedWriter.writeEmptyElement("img", ["class":figurerend, "src":url])
325 1110 mdecorde
                                                                        pagedWriter.writeEndElement() // div
326 1110 mdecorde
                                                                }
327 1110 mdecorde
                                                                figurerend = "";
328 1110 mdecorde
                                                                break;
329 1110 mdecorde
                                                        case "lg":
330 1110 mdecorde
                                                        case "p":
331 1110 mdecorde
                                                        case "q":
332 1110 mdecorde
                                                                String rend = parser.getAttributeValue(null, "rend")
333 1110 mdecorde
                                                                if (rend == null) rend = "normal"
334 1110 mdecorde
                                                                pagedWriter.writeStartElement("p", ["class":rend])
335 1110 mdecorde
                                                                break;
336 1110 mdecorde
                                                        //case "pb":
337 1110 mdecorde
                                                        case "table":
338 1110 mdecorde
                                                                pagedWriter.writeStartElement("table", ["class":parser.getAttributeValue(null, "rend")])
339 1110 mdecorde
                                                                break;
340 1110 mdecorde
                                                        case "row":
341 321 mdecorde
                                                                pagedWriter.writeStartElement("tr")
342 1110 mdecorde
                                                                break;
343 1110 mdecorde
                                                        case "cell":
344 321 mdecorde
                                                                pagedWriter.writeStartElement("td")
345 1110 mdecorde
                                                                break;
346 1110 mdecorde
                                                        case "lb":
347 1110 mdecorde
                                                        case "br":
348 1110 mdecorde
                                                                pagedWriter.writeEmptyElement("br")
349 1110 mdecorde
                                                                break;
350 1110 mdecorde
                                                        case "list":
351 1110 mdecorde
                                                                String type = parser.getAttributeValue(null,"type");
352 1110 mdecorde
                                                                if ("unordered" == type) {
353 1110 mdecorde
                                                                        unordered = true;
354 1110 mdecorde
                                                                        pagedWriter.writeStartElement("ul")
355 1110 mdecorde
                                                                } else {
356 1110 mdecorde
                                                                        unordered = false
357 1110 mdecorde
                                                                        pagedWriter.writeStartElement("ol")
358 1110 mdecorde
                                                                }
359 1110 mdecorde
                                                                break
360 1110 mdecorde
                                                        case "item":
361 1110 mdecorde
                                                                pagedWriter.writeStartElement("li")
362 1110 mdecorde
                                                                break;
363 1110 mdecorde
                                                        case "hi":
364 1110 mdecorde
                                                                pagedWriter.writeStartElement("b")
365 1110 mdecorde
                                                                break;
366 1110 mdecorde
                                                        case "emph":
367 1110 mdecorde
                                                                pagedWriter.writeStartElement("i")
368 1110 mdecorde
                                                                break;
369 1110 mdecorde
                                                        case "w":
370 1110 mdecorde
                                                                wordid = parser.getAttributeValue(null,"id");
371 321 mdecorde
372 1110 mdecorde
                                                                if (firstWord) {
373 1110 mdecorde
                                                                        firstWord = false;
374 1110 mdecorde
                                                                        this.idxstart.add(wordid);
375 1110 mdecorde
                                                                }
376 1110 mdecorde
                                                                wordcount++;
377 321 mdecorde
378 1110 mdecorde
                                                                break;
379 1110 mdecorde
                                                        case "ana":
380 1110 mdecorde
                                                                flaginterp=true;
381 1110 mdecorde
                                                                interpvalue+=" "+parser.getAttributeValue(null,"type").substring(1)+":"
382 1110 mdecorde
                                                                break;
383 321 mdecorde
384 1110 mdecorde
                                                        case "form":
385 1110 mdecorde
                                                                wordvalue="";
386 1110 mdecorde
                                                                interpvalue ="";
387 1110 mdecorde
                                                                flagform=true;
388 1110 mdecorde
                                                }
389 1110 mdecorde
                                                break;
390 1110 mdecorde
                                        case XMLStreamConstants.END_ELEMENT:
391 1110 mdecorde
                                                localname = parser.getLocalName();
392 1110 mdecorde
                                                switch(localname)
393 1110 mdecorde
                                                {
394 1110 mdecorde
                                                        case "head":
395 1110 mdecorde
                                                                pagedWriter.writeEndElement(); // h2
396 1110 mdecorde
                                                                pagedWriter.writeCharacters("\t")
397 1110 mdecorde
                                                                break;
398 1110 mdecorde
                                                        case "lg":
399 1110 mdecorde
                                                        case "p":
400 1110 mdecorde
                                                        case "q":
401 1110 mdecorde
                                                                pagedWriter.writeEndElement(); // p
402 1110 mdecorde
                                                                pagedWriter.writeCharacters("\t")
403 1110 mdecorde
                                                                if (wordcount >= wordmax) {
404 1110 mdecorde
                                                                        createNextOutput();
405 1110 mdecorde
                                                                }
406 1110 mdecorde
                                                                break;
407 1115 mdecorde
408 1110 mdecorde
                                                        case "list":
409 1110 mdecorde
                                                                pagedWriter.writeEndElement(); // ul or ol
410 1110 mdecorde
                                                                pagedWriter.writeCharacters("\t")
411 1110 mdecorde
                                                                break
412 1110 mdecorde
                                                        case "item":
413 1110 mdecorde
                                                                pagedWriter.writeEndElement(); // li
414 1110 mdecorde
                                                                pagedWriter.writeCharacters("\t")
415 1110 mdecorde
                                                                break;
416 1110 mdecorde
                                                        case "hi":
417 1110 mdecorde
                                                                pagedWriter.writeEndElement(); // b
418 1110 mdecorde
                                                                break;
419 1110 mdecorde
                                                        case "emph":
420 1110 mdecorde
                                                                pagedWriter.writeEndElement(); // i
421 1110 mdecorde
                                                                break;
422 1110 mdecorde
                                                        case "table":
423 1110 mdecorde
                                                                pagedWriter.writeEndElement(); // table
424 1110 mdecorde
                                                                pagedWriter.writeCharacters("\t")
425 1110 mdecorde
                                                                break;
426 1110 mdecorde
                                                        case "row":
427 1110 mdecorde
                                                                pagedWriter.writeEndElement(); // tr
428 1110 mdecorde
                                                                pagedWriter.writeCharacters("\t")
429 1110 mdecorde
                                                                break;
430 1110 mdecorde
                                                        case "cell":
431 1110 mdecorde
                                                                pagedWriter.writeEndElement(); // td
432 1110 mdecorde
                                                                break;
433 1110 mdecorde
                                                        case "form":
434 1110 mdecorde
                                                                flagform = false
435 1110 mdecorde
                                                                break;
436 1110 mdecorde
                                                        case "ana":
437 1110 mdecorde
                                                                flaginterp = false
438 1110 mdecorde
                                                                break;
439 1110 mdecorde
                                                        case "w":
440 1110 mdecorde
                                                                int l = lastword.length();
441 1110 mdecorde
                                                                String endOfLastWord = "";
442 1110 mdecorde
                                                                if (l > 0)
443 1110 mdecorde
                                                                        endOfLastWord = lastword.subSequence(l-1, l);
444 321 mdecorde
445 1110 mdecorde
                                                                if (interpvalue != null)
446 1110 mdecorde
                                                                        interpvalue = interpvalue;
447 321 mdecorde
448 1110 mdecorde
                                                                if (NoSpaceBefore.contains(wordvalue) ||
449 321 mdecorde
                                                                NoSpaceAfter.contains(lastword) ||
450 321 mdecorde
                                                                wordvalue.startsWith("-") ||
451 321 mdecorde
                                                                NoSpaceAfter.contains(endOfLastWord))
452 1110 mdecorde
                                                                {
453 1110 mdecorde
                                                                        // multiwriter.write("<span title=\""+interpvalue+"\" id=\""+wordid+"\">");
454 1110 mdecorde
                                                                } else {
455 1110 mdecorde
                                                                        // multiwriter.write(" <span title=\""+interpvalue+"\" id=\""+wordid+"\">");
456 1110 mdecorde
                                                                        pagedWriter.writeCharacters(" ");
457 1110 mdecorde
                                                                }
458 1110 mdecorde
                                                                pagedWriter.writeStartElement("span", ["title":interpvalue, "id":wordid]);
459 1110 mdecorde
                                                                pagedWriter.writeCharacters(wordvalue);
460 1110 mdecorde
                                                                pagedWriter.writeEndElement() // span
461 1110 mdecorde
                                                                lastword=wordvalue;
462 1110 mdecorde
                                                                break;
463 1110 mdecorde
                                                }
464 1110 mdecorde
                                                break;
465 1110 mdecorde
                                        case XMLStreamConstants.CHARACTERS:
466 1110 mdecorde
                                                if (flagform)
467 1110 mdecorde
                                                        if (parser.getText().length() > 0)
468 1110 mdecorde
                                                                wordvalue+=(parser.getText());
469 1110 mdecorde
                                                if (flaginterp)
470 1110 mdecorde
                                                        if (parser.getText().length() > 0)
471 1110 mdecorde
                                                                interpvalue+=(parser.getText());
472 1110 mdecorde
                                                break;
473 1110 mdecorde
                                }
474 321 mdecorde
                        }
475 1110 mdecorde
                        //writer.write("</body>");
476 1110 mdecorde
                        //writer.write("</html>");
477 1110 mdecorde
                        //writer.close();
478 1110 mdecorde
                        closeMultiWriter();
479 1688 mdecorde
                        if (parser != null) parser.close();
480 1688 mdecorde
                        if (inputData != null) inputData.close();
481 1110 mdecorde
                } catch(Exception e) {
482 1110 mdecorde
                        println "Error while processing ${infile} at "+parser.getLocation().getLineNumber()+": "+e
483 1110 mdecorde
                        org.txm.utils.logger.Log.printStackTrace(e);
484 1688 mdecorde
                        pagedWriter.close();
485 1688 mdecorde
                        if (parser != null) parser.close();
486 1688 mdecorde
                        if (inputData != null) inputData.close();
487 1688 mdecorde
                 }
488 321 mdecorde
        }
489 321 mdecorde
}