Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / scripts / importer / xtz / XTZDefaultPagerStep.groovy @ 1000

History | View | Annotate | Download (14.8 kB)

1 986 mdecorde
package org.txm.scripts.importer.xtz;
2 321 mdecorde
3 321 mdecorde
import java.io.File;
4 321 mdecorde
import java.io.OutputStreamWriter;
5 321 mdecorde
import java.util.ArrayList;
6 321 mdecorde
import java.util.List;
7 321 mdecorde
8 321 mdecorde
import javax.xml.stream.*;
9 321 mdecorde
10 986 mdecorde
import org.txm.scripts.importer.StaxStackWriter;
11 1000 mdecorde
import org.txm.importer.xtz.*
12 321 mdecorde
13 321 mdecorde
public class XTZDefaultPagerStep {
14 321 mdecorde
15 321 mdecorde
        List<String> NoSpaceBefore;
16 321 mdecorde
17 321 mdecorde
        /** The No space after. */
18 321 mdecorde
        List<String> NoSpaceAfter;
19 321 mdecorde
20 321 mdecorde
        /** The wordcount. */
21 321 mdecorde
        int wordcount = 0;
22 321 mdecorde
23 321 mdecorde
        /** The pagecount. */
24 321 mdecorde
        int pagecount = 0;
25 321 mdecorde
26 321 mdecorde
        /** The wordmax. */
27 321 mdecorde
        int wordmax = 0;
28 321 mdecorde
29 321 mdecorde
        /** The basename. */
30 321 mdecorde
        String basename = "";
31 321 mdecorde
        String txtname = "";
32 321 mdecorde
        File outdir;
33 321 mdecorde
34 321 mdecorde
        /** The wordid. */
35 321 mdecorde
        String wordid;
36 321 mdecorde
37 321 mdecorde
        /** The first word. */
38 321 mdecorde
        boolean firstWord = true;
39 321 mdecorde
40 321 mdecorde
        /** The wordvalue. */
41 321 mdecorde
        String wordvalue = "";
42 321 mdecorde
43 321 mdecorde
        /** The interpvalue. */
44 321 mdecorde
        String interpvalue = "";
45 321 mdecorde
46 321 mdecorde
        /** The lastword. */
47 321 mdecorde
        String lastword = " ";
48 321 mdecorde
49 321 mdecorde
        /** The wordtype. */
50 321 mdecorde
        String wordtype;
51 321 mdecorde
52 321 mdecorde
        /** The flagform. */
53 321 mdecorde
        boolean flagform = false;
54 321 mdecorde
55 321 mdecorde
        /** The flaginterp. */
56 321 mdecorde
        boolean flaginterp = false;
57 321 mdecorde
58 321 mdecorde
        /** The url. */
59 321 mdecorde
        private def url;
60 321 mdecorde
61 321 mdecorde
        /** The input data. */
62 321 mdecorde
        private def inputData;
63 321 mdecorde
64 321 mdecorde
        /** The factory. */
65 321 mdecorde
        private def factory;
66 321 mdecorde
67 321 mdecorde
        /** The parser. */
68 321 mdecorde
        private XMLStreamReader parser;
69 321 mdecorde
70 321 mdecorde
        /** The writer. */
71 321 mdecorde
        OutputStreamWriter writer;
72 321 mdecorde
73 321 mdecorde
        /** The pagedWriter. */
74 321 mdecorde
        StaxStackWriter pagedWriter = null;
75 321 mdecorde
76 321 mdecorde
        /** The infile. */
77 321 mdecorde
        File infile;
78 321 mdecorde
79 321 mdecorde
        /** The outfile. */
80 321 mdecorde
        File outfile;
81 321 mdecorde
82 321 mdecorde
        /** The pages. */
83 698 mdecorde
        //TODO enhance this to store the page name/id as well
84 321 mdecorde
        ArrayList<File> pages = new ArrayList<File>();
85 321 mdecorde
86 321 mdecorde
        /** The idxstart. */
87 321 mdecorde
        ArrayList<String> idxstart = new ArrayList<String>();
88 321 mdecorde
        String paginationElement;
89 321 mdecorde
        def cssList;
90 321 mdecorde
        def wordTag = "w";
91 321 mdecorde
        def noteElements = new HashSet<String>();
92 321 mdecorde
        def outOfTextElements = new HashSet<String>();
93 321 mdecorde
        XTZPager pager;
94 479 mdecorde
95 321 mdecorde
96 321 mdecorde
        /**
97 321 mdecorde
         * Instantiates a new pager.
98 321 mdecorde
         *
99 321 mdecorde
         * @param infile the infile
100 321 mdecorde
         * @param outfile the outfile
101 321 mdecorde
         * @param NoSpaceBefore the no space before
102 321 mdecorde
         * @param NoSpaceAfter the no space after
103 321 mdecorde
         * @param max the max
104 321 mdecorde
         * @param basename the basename
105 321 mdecorde
         */
106 321 mdecorde
        public XTZDefaultPagerStep(XTZPager pager, File infile, String txtname, List<String> NoSpaceBefore,
107 321 mdecorde
        List<String> NoSpaceAfter, def cssList) {
108 321 mdecorde
                this.pager = pager;
109 321 mdecorde
                this.paginationElement = pager.page_element;
110 321 mdecorde
                this.cssList = cssList;
111 321 mdecorde
                this.basename = pager.corpusname;
112 321 mdecorde
                this.txtname = txtname;
113 321 mdecorde
                this.outdir = pager.outputDirectory;
114 321 mdecorde
                this.wordmax = pager.wordsPerPage;
115 321 mdecorde
                this.NoSpaceBefore = NoSpaceBefore;
116 321 mdecorde
                this.NoSpaceAfter = NoSpaceAfter;
117 321 mdecorde
                this.url = infile.toURI().toURL();
118 321 mdecorde
                this.infile = infile;
119 321 mdecorde
                this.wordTag= pager.wordTag;
120 321 mdecorde
                outdir.mkdirs()
121 321 mdecorde
122 321 mdecorde
                inputData = new BufferedInputStream(url.openStream());
123 321 mdecorde
                factory = XMLInputFactory.newInstance();
124 321 mdecorde
                parser = factory.createXMLStreamReader(inputData);
125 321 mdecorde
126 321 mdecorde
                String notesListString = pager.getImportModule().getParameters().getNoteElement().getTextContent()
127 321 mdecorde
                if (notesListString != null) for (def s : notesListString.split(",")) noteElements << s;
128 321 mdecorde
129 321 mdecorde
                String elems = pager.getImportModule().getParameters().getOutSideTextTagsAndKeepContentElement().getTextContent()
130 321 mdecorde
                if (elems != null) for (def s : elems.split(",")) outOfTextElements << s;
131 321 mdecorde
132 321 mdecorde
                process();
133 321 mdecorde
        }
134 479 mdecorde
135 479 mdecorde
        public String getAttributeValue(def parser, String ns, String name) {
136 479 mdecorde
                for (int i = 0 ; i < parser.getAttributeCount() ; i++) {
137 479 mdecorde
                        if (name == parser.getAttributeLocalName(i)) {
138 479 mdecorde
                                return parser.getAttributeValue(i).toString()
139 479 mdecorde
                        }
140 479 mdecorde
                }
141 479 mdecorde
                return "";
142 479 mdecorde
        }
143 321 mdecorde
144 479 mdecorde
145 321 mdecorde
        private def closeMultiWriter() {
146 321 mdecorde
                if (pagedWriter != null) {
147 321 mdecorde
                        def tags = pagedWriter.getTagStack().clone();
148 321 mdecorde
149 321 mdecorde
                        if (firstWord) { // there was no words
150 321 mdecorde
                                pagedWriter.writeCharacters("");
151 321 mdecorde
                                this.idxstart.add("${wordTag}_0")
152 321 mdecorde
                                pagedWriter.write("<span id=\"${wordTag}_0\"/>");
153 321 mdecorde
                                //                                }
154 321 mdecorde
                        }
155 321 mdecorde
                        pagedWriter.writeEndElements();
156 321 mdecorde
157 321 mdecorde
                        if (notes.size() > 0) {
158 321 mdecorde
                                pagedWriter.writeEmptyElement("hr", ["id":"notes", "width":"20%", "align":"left"]);
159 321 mdecorde
                                //pagedWriter.writeStartElement("ol");
160 321 mdecorde
                                int i = 1;
161 321 mdecorde
                                for (String note : notes) {
162 321 mdecorde
                                        //pagedWriter.writeStartElement("li");
163 321 mdecorde
                                        pagedWriter.writeStartElement("a", ["href":"#noteref_"+i, "name":"note_"+i]);
164 321 mdecorde
                                        pagedWriter.writeStartElement("sup")
165 321 mdecorde
                                        pagedWriter.writeCharacters(""+i)
166 321 mdecorde
                                        pagedWriter.writeEndElement() // </sub>
167 321 mdecorde
                                        pagedWriter.writeEndElement() // </a>
168 321 mdecorde
                                        pagedWriter.writeCharacters(note)
169 321 mdecorde
                                        pagedWriter.writeEmptyElement("br")
170 321 mdecorde
                                        //pagedWriter.writeEndElement() // </li>
171 321 mdecorde
                                        i++;
172 321 mdecorde
                                }
173 321 mdecorde
                                //pagedWriter.writeEndElement() // </ol>
174 321 mdecorde
                                notes.clear()
175 321 mdecorde
                        }
176 321 mdecorde
177 321 mdecorde
                        pagedWriter.close();
178 321 mdecorde
                        return tags;
179 321 mdecorde
                } else {
180 321 mdecorde
                        return [];
181 321 mdecorde
                }
182 321 mdecorde
        }
183 321 mdecorde
184 321 mdecorde
        /**
185 321 mdecorde
         * Creates the next output.
186 321 mdecorde
         *
187 321 mdecorde
         * @return true, if successful
188 321 mdecorde
         */
189 321 mdecorde
        private boolean createNextOutput() {
190 321 mdecorde
                wordcount = 0;
191 321 mdecorde
                try {
192 321 mdecorde
193 321 mdecorde
                        def tags = closeMultiWriter();
194 321 mdecorde
                        for (int i = 0 ; i < tags.size() ; i++) {
195 321 mdecorde
                                String tag = tags[i]
196 479 mdecorde
                                if ("div" != tag) {
197 321 mdecorde
                                        tags.remove(i--)
198 321 mdecorde
                                } else {
199 479 mdecorde
                                        tags.remove(i--) // remove first "div"
200 479 mdecorde
                                        break; // remove elements until first "div" tag
201 321 mdecorde
                                }
202 321 mdecorde
                        }
203 321 mdecorde
                        File outfile = new File(outdir, txtname+"_"+(++pagecount)+".html")
204 321 mdecorde
                        pages.add(outfile);
205 321 mdecorde
                        firstWord = true; // waiting for next word
206 321 mdecorde
207 321 mdecorde
                        pagedWriter = new StaxStackWriter(outfile, "UTF-8");
208 321 mdecorde
209 321 mdecorde
                        pagedWriter.writeStartDocument("UTF-8", "1.0")
210 321 mdecorde
                        pagedWriter.writeStartElement("html");
211 321 mdecorde
                        pagedWriter.writeEmptyElement("meta", ["http-equiv":"Content-Type", "content":"text/html","charset":"UTF-8"]);
212 321 mdecorde
                        for (String css : cssList) {
213 321 mdecorde
                                pagedWriter.writeEmptyElement("link", ["rel":"stylesheet", "type":"text/css","href":"$css"]);
214 321 mdecorde
                        }
215 321 mdecorde
                        pagedWriter.writeStartElement("head");
216 321 mdecorde
                        pagedWriter.writeStartElement("title")
217 321 mdecorde
                        pagedWriter.writeCharacters(basename.toUpperCase()+" Edition - Page "+pagecount)
218 321 mdecorde
                        pagedWriter.writeEndElement(); // </title>
219 321 mdecorde
                        pagedWriter.writeEndElement() // </head>
220 321 mdecorde
                        pagedWriter.writeStartElement("body") //<body>
221 321 mdecorde
                        pagedWriter.writeStartElement("div", ["class": "txmeditionpage"]) //<div>
222 321 mdecorde
                        pagedWriter.writeStartElements(tags);
223 321 mdecorde
                        return true;
224 321 mdecorde
                } catch (Exception e) {
225 321 mdecorde
                        System.out.println(e.getLocalizedMessage());
226 321 mdecorde
                        return false;
227 321 mdecorde
                }
228 321 mdecorde
        }
229 321 mdecorde
230 321 mdecorde
        /**
231 321 mdecorde
         * Creates the output.
232 321 mdecorde
         *
233 321 mdecorde
         * @param outfile the outfile
234 321 mdecorde
         * @return true, if successful
235 321 mdecorde
         */
236 321 mdecorde
        private boolean createOutput() {
237 321 mdecorde
                try {
238 321 mdecorde
                        return createNextOutput();
239 321 mdecorde
                } catch (Exception e) {
240 321 mdecorde
                        System.out.println(e.getLocalizedMessage());
241 321 mdecorde
                        return false;
242 321 mdecorde
                }
243 321 mdecorde
        }
244 321 mdecorde
245 321 mdecorde
        /**
246 321 mdecorde
         * Gets the page files.
247 321 mdecorde
         *
248 321 mdecorde
         * @return the page files
249 321 mdecorde
         */
250 321 mdecorde
        public ArrayList<File> getPageFiles() {
251 321 mdecorde
                return pages;
252 321 mdecorde
        }
253 321 mdecorde
254 321 mdecorde
        /**
255 321 mdecorde
         * Gets the idx.
256 321 mdecorde
         *
257 321 mdecorde
         * @return the idx
258 321 mdecorde
         */
259 321 mdecorde
        public ArrayList<String> getIdx() {
260 321 mdecorde
                return idxstart;
261 321 mdecorde
        }
262 321 mdecorde
263 321 mdecorde
        /**
264 321 mdecorde
         * Go to text.
265 321 mdecorde
         */
266 321 mdecorde
        private void goToText() {
267 321 mdecorde
                for (int event = parser.next(); event != XMLStreamConstants.END_DOCUMENT; event = parser.next()) {
268 321 mdecorde
                        if (event == XMLStreamConstants.END_ELEMENT)
269 321 mdecorde
                                if (parser.getLocalName().matches("teiHeader"))
270 321 mdecorde
                                        return;
271 321 mdecorde
                }
272 321 mdecorde
        }
273 321 mdecorde
274 321 mdecorde
        def notes = []
275 321 mdecorde
        def currentOutOfTextElements = [] // stack of element with out of text to edit opened element
276 321 mdecorde
        def writeOutOfTextToEditText = false
277 321 mdecorde
        /**
278 321 mdecorde
         * Process.
279 321 mdecorde
         */
280 321 mdecorde
        public boolean process() {
281 321 mdecorde
                boolean flagNote = false;
282 321 mdecorde
                String noteContent = "";
283 321 mdecorde
                String rend = ""
284 321 mdecorde
                goToText();
285 321 mdecorde
286 321 mdecorde
                String localname = "";
287 321 mdecorde
                createNextOutput();
288 321 mdecorde
289 321 mdecorde
                for (int event = parser.next(); event != XMLStreamConstants.END_DOCUMENT; event = parser.next()) {
290 321 mdecorde
                        rend = "";
291 321 mdecorde
                        switch (event) {
292 321 mdecorde
                                case XMLStreamConstants.START_ELEMENT:
293 321 mdecorde
                                        localname = parser.getLocalName();
294 321 mdecorde
                                        if (outOfTextElements.contains(localname)) {
295 321 mdecorde
                                                currentOutOfTextElements << localname
296 321 mdecorde
                                                writeOutOfTextToEditText = true;
297 321 mdecorde
                                        } else if (currentOutOfTextElements.size() > 0) {
298 321 mdecorde
                                                currentOutOfTextElements << localname
299 321 mdecorde
                                        }
300 321 mdecorde
301 479 mdecorde
                                        if (localname == paginationElement) {
302 479 mdecorde
                                                createNextOutput();
303 479 mdecorde
                                                wordcount=0;
304 479 mdecorde
                                                pagedWriter.write("\n");
305 479 mdecorde
                                                if (getAttributeValue(parser, null,"n") != null) {
306 479 mdecorde
                                                        pagedWriter.writeElement("p", ["class":"txmeditionpb", "align":"center"], getAttributeValue(parser, null,"n"))
307 479 mdecorde
                                                }
308 479 mdecorde
                                        }
309 479 mdecorde
310 479 mdecorde
                                        rend = getAttributeValue(parser, null, "rend")
311 321 mdecorde
                                        if (rend == null) rend = "";
312 321 mdecorde
                                        switch (localname) {
313 321 mdecorde
                                                case "text":
314 321 mdecorde
                                                        LinkedHashMap attributes = new LinkedHashMap();
315 321 mdecorde
                                                        for (int i = 0 ; i < parser.getAttributeCount() ; i++) {
316 321 mdecorde
                                                                attributes[parser.getAttributeLocalName(i)] = parser.getAttributeValue(i).toString()
317 321 mdecorde
                                                        }
318 479 mdecorde
319 321 mdecorde
                                                        pagedWriter.write("\n");
320 321 mdecorde
                                                        pagedWriter.writeStartElement("p")
321 321 mdecorde
                                                        pagedWriter.writeAttribute("class", rend);
322 321 mdecorde
                                                        if (attributes.containsKey("id")) {
323 321 mdecorde
                                                                pagedWriter.writeElement("h3", attributes["id"])
324 321 mdecorde
                                                        }
325 321 mdecorde
326 321 mdecorde
                                                        pagedWriter.writeStartElement("table");
327 321 mdecorde
                                                        for (String k : attributes.keySet()) {
328 321 mdecorde
                                                                if (k == "id") continue;
329 321 mdecorde
                                                                if (k == "rend") continue;
330 321 mdecorde
331 321 mdecorde
                                                                pagedWriter.writeStartElement("tr");
332 321 mdecorde
                                                                pagedWriter.writeElement("td", k);
333 321 mdecorde
                                                                pagedWriter.writeElement("td", attributes[k]);
334 321 mdecorde
                                                                pagedWriter.writeEndElement();
335 321 mdecorde
                                                        }
336 321 mdecorde
                                                        pagedWriter.writeEndElement() // table
337 321 mdecorde
                                                        pagedWriter.writeEndElement() // p
338 321 mdecorde
339 321 mdecorde
                                                        pagedWriter.writeCharacters("");
340 321 mdecorde
                                                        break;
341 321 mdecorde
                                                case "ref":
342 321 mdecorde
                                                        pagedWriter.writeStartElement("a")
343 479 mdecorde
                                                        pagedWriter.writeAttribute("href", getAttributeValue(parser, null, "target"));
344 321 mdecorde
345 321 mdecorde
                                                        pagedWriter.writeAttribute("target", "_blank");
346 321 mdecorde
                                                        pagedWriter.writeAttribute("class", rend);
347 321 mdecorde
                                                        break;
348 321 mdecorde
                                                case "head":
349 321 mdecorde
                                                        pagedWriter.write("\n");
350 321 mdecorde
                                                        pagedWriter.writeStartElement("h2", ["class":rend])
351 321 mdecorde
                                                        break;
352 321 mdecorde
                                                case "graphic":
353 321 mdecorde
                                                        pagedWriter.write("\n");
354 479 mdecorde
                                                        String url = getAttributeValue(parser, null, "url")
355 321 mdecorde
                                                        if (url != null) {
356 1000 mdecorde
                                                                // TEI <graphic rend="left-image" url="image.png"/> -> <center class="left-image"><img href="image.png"/></center> + <moncorpus>.css avec rule ".left-image"
357 1000 mdecorde
                                                                pagedWriter.writeStartElement("center", ["class":rend]) // css -> .<rend> { ... } styles OR
358 321 mdecorde
                                                                pagedWriter.writeEmptyElement("img", ["src":url, "align":"middle"])
359 321 mdecorde
                                                                pagedWriter.writeEndElement() // div
360 321 mdecorde
                                                        }
361 321 mdecorde
                                                        break;
362 321 mdecorde
                                                case "table":
363 321 mdecorde
                                                        pagedWriter.writeStartElement("table", ["class":rend])
364 321 mdecorde
                                                        pagedWriter.write("\n");
365 321 mdecorde
                                                        break;
366 321 mdecorde
                                                case "row":
367 321 mdecorde
                                                        pagedWriter.writeStartElement("tr", ["class":rend])
368 321 mdecorde
                                                        break;
369 321 mdecorde
                                                case "cell":
370 321 mdecorde
                                                        pagedWriter.writeStartElement("td", ["class":rend])
371 321 mdecorde
                                                        break;
372 321 mdecorde
                                                case "list":
373 479 mdecorde
                                                        String type = getAttributeValue(parser, null,"type");
374 321 mdecorde
                                                        if ("unordered" == type) {
375 321 mdecorde
                                                                pagedWriter.writeStartElement("ul", ["class":rend])
376 321 mdecorde
                                                        } else {
377 321 mdecorde
                                                                pagedWriter.writeStartElement("ol", ["class":rend])
378 321 mdecorde
                                                        }
379 321 mdecorde
                                                        break
380 321 mdecorde
                                                case "item":
381 321 mdecorde
                                                        pagedWriter.writeStartElement("li", ["class":rend])
382 321 mdecorde
                                                        break;
383 321 mdecorde
                                                case "hi":
384 321 mdecorde
                                                case "emph":
385 321 mdecorde
                                                        if ("i".equals(rend) || "italic".equals(rend)) {
386 321 mdecorde
                                                                pagedWriter.writeStartElement("i", ["class":rend])
387 321 mdecorde
                                                        } else if ("b".equals(rend) || "bold".equals(rend)) {
388 321 mdecorde
                                                                pagedWriter.writeStartElement("b", ["class":rend])
389 321 mdecorde
                                                        } else {
390 321 mdecorde
                                                                if ("emph".equals(localname)) {
391 321 mdecorde
                                                                        pagedWriter.writeStartElement("i", ["class":rend])
392 321 mdecorde
                                                                } else { // hi
393 321 mdecorde
                                                                        pagedWriter.writeStartElement("b", ["class":rend])
394 321 mdecorde
                                                                }
395 321 mdecorde
                                                        }
396 321 mdecorde
397 321 mdecorde
                                                        break;
398 321 mdecorde
                                                case "p":
399 321 mdecorde
                                                        pagedWriter.write("\n");
400 321 mdecorde
                                                        pagedWriter.writeStartElement("p", ["class":rend])
401 321 mdecorde
                                                        break;
402 321 mdecorde
                                                case "lb":
403 321 mdecorde
                                                        pagedWriter.writeEmptyElement("br")
404 321 mdecorde
                                                        break;
405 321 mdecorde
                                                case wordTag:
406 479 mdecorde
                                                        wordid = getAttributeValue(parser, null,"id");
407 479 mdecorde
408 479 mdecorde
                                                        wordcount++;
409 479 mdecorde
                                                        if (wordcount >= wordmax) {
410 479 mdecorde
                                                                createNextOutput();
411 479 mdecorde
                                                        }
412 479 mdecorde
413 321 mdecorde
                                                        if (firstWord) {
414 321 mdecorde
                                                                firstWord = false;
415 321 mdecorde
                                                                this.idxstart.add(wordid);
416 321 mdecorde
                                                        }
417 479 mdecorde
418 321 mdecorde
                                                        break;
419 321 mdecorde
                                                case "ana":
420 321 mdecorde
                                                        flaginterp=true;
421 479 mdecorde
                                                        interpvalue+=" "+getAttributeValue(parser, null, "type").substring(1)+":"
422 321 mdecorde
                                                        break;
423 321 mdecorde
                                                case "form":
424 321 mdecorde
                                                        wordvalue="";
425 321 mdecorde
                                                        interpvalue ="";
426 321 mdecorde
                                                        flagform=true;
427 321 mdecorde
                                                        break;
428 321 mdecorde
                                                default:
429 321 mdecorde
                                                        if (noteElements.contains(localname)) {
430 321 mdecorde
                                                                flagNote = true;
431 321 mdecorde
                                                                noteContent = ""
432 321 mdecorde
                                                        }
433 321 mdecorde
                                                        break;
434 321 mdecorde
                                        }
435 321 mdecorde
                                        break;
436 321 mdecorde
                                case XMLStreamConstants.END_ELEMENT:
437 321 mdecorde
                                        localname = parser.getLocalName();
438 321 mdecorde
                                        if (currentOutOfTextElements.size() > 0) currentOutOfTextElements.pop()
439 321 mdecorde
                                        writeOutOfTextToEditText = currentOutOfTextElements.size() > 0
440 321 mdecorde
441 321 mdecorde
                                        switch (localname) {
442 321 mdecorde
                                                case "p":
443 321 mdecorde
                                                        pagedWriter.writeEndElement() // </p>
444 321 mdecorde
                                                        pagedWriter.write("\n");
445 321 mdecorde
                                                        break;
446 321 mdecorde
                                                case "head":
447 321 mdecorde
                                                        pagedWriter.writeEndElement() // </h2>
448 321 mdecorde
                                                        pagedWriter.write("\n");
449 321 mdecorde
                                                        break;
450 321 mdecorde
                                                case "list":
451 321 mdecorde
                                                        pagedWriter.writeEndElement(); // ul or ol
452 321 mdecorde
                                                        pagedWriter.write("\n");
453 321 mdecorde
                                                        break
454 321 mdecorde
                                                case "item":
455 321 mdecorde
                                                        pagedWriter.writeEndElement(); // li
456 321 mdecorde
                                                        pagedWriter.write("\n");
457 321 mdecorde
                                                        break;
458 321 mdecorde
                                                case "hi":
459 321 mdecorde
                                                        pagedWriter.writeEndElement(); // b
460 321 mdecorde
                                                        break;
461 321 mdecorde
                                                case "emph":
462 321 mdecorde
                                                        pagedWriter.writeEndElement(); // i
463 321 mdecorde
                                                        break;
464 321 mdecorde
                                                case "table":
465 321 mdecorde
                                                        pagedWriter.writeEndElement(); // table
466 321 mdecorde
                                                        pagedWriter.write("\n");
467 321 mdecorde
                                                        break;
468 321 mdecorde
                                                case "row":
469 321 mdecorde
                                                        pagedWriter.writeEndElement(); // tr
470 321 mdecorde
                                                        break;
471 321 mdecorde
                                                case "cell":
472 321 mdecorde
                                                        pagedWriter.writeEndElement(); // td
473 321 mdecorde
                                                        break;
474 321 mdecorde
                                                case "ref":
475 321 mdecorde
                                                        pagedWriter.writeEndElement() // </a>
476 321 mdecorde
                                                        break;
477 321 mdecorde
                                                case "form":
478 321 mdecorde
                                                        flagform = false
479 321 mdecorde
                                                        break;
480 321 mdecorde
                                                case "ana":
481 321 mdecorde
                                                        flaginterp = false
482 321 mdecorde
                                                        break;
483 321 mdecorde
                                                case wordTag:
484 321 mdecorde
                                                        int l = lastword.length();
485 321 mdecorde
                                                        String endOfLastWord = "";
486 321 mdecorde
                                                        if (l > 0)
487 321 mdecorde
                                                                endOfLastWord = lastword.subSequence(l-1, l);
488 321 mdecorde
489 321 mdecorde
                                                        if (interpvalue != null)
490 321 mdecorde
                                                                interpvalue = interpvalue;
491 321 mdecorde
492 321 mdecorde
                                                        if (NoSpaceBefore.contains(wordvalue) ||
493 321 mdecorde
                                                        NoSpaceAfter.contains(lastword) ||
494 321 mdecorde
                                                        wordvalue.startsWith("-") ||
495 321 mdecorde
                                                        NoSpaceAfter.contains(endOfLastWord)) {
496 321 mdecorde
                                                                pagedWriter.writeStartElement("span", ["title":interpvalue, "id":wordid]);
497 321 mdecorde
                                                        } else {
498 321 mdecorde
                                                                pagedWriter.writeCharacters(" ");
499 321 mdecorde
                                                                pagedWriter.writeStartElement("span", ["title":interpvalue, "id":wordid]);
500 321 mdecorde
                                                        }
501 321 mdecorde
502 321 mdecorde
                                                        pagedWriter.writeCharacters(wordvalue);
503 321 mdecorde
                                                        pagedWriter.writeEndElement();
504 321 mdecorde
                                                        lastword=wordvalue;
505 321 mdecorde
                                                        break;
506 321 mdecorde
                                                default:
507 321 mdecorde
                                                        if (noteElements.contains(localname)) {
508 321 mdecorde
                                                                flagNote = false;
509 321 mdecorde
                                                                if (noteContent.length() > 0) {
510 321 mdecorde
                                                                        notes << noteContent;
511 321 mdecorde
                                                                        pagedWriter.writeStartElement("a", ["href":"#note_"+notes.size(), "name":"noteref_"+notes.size(), "title":noteContent]);
512 321 mdecorde
                                                                        pagedWriter.writeStartElement("sup")
513 321 mdecorde
                                                                        pagedWriter.writeCharacters(""+notes.size())
514 321 mdecorde
                                                                        pagedWriter.writeEndElement() // </sub>
515 321 mdecorde
                                                                        pagedWriter.writeEndElement() // </span>
516 321 mdecorde
                                                                }
517 321 mdecorde
                                                        }
518 321 mdecorde
                                                        break;
519 321 mdecorde
                                        }
520 321 mdecorde
                                        break;
521 321 mdecorde
                                case XMLStreamConstants.CHARACTERS:
522 321 mdecorde
                                        if (flagform && parser.getText().length() > 0) {
523 321 mdecorde
                                                wordvalue+=(parser.getText());
524 321 mdecorde
                                                if (flagNote == parser.getText().length() > 0)
525 321 mdecorde
                                                        noteContent += parser.getText().replace("\n", " ");
526 321 mdecorde
                                        } else        if (flaginterp && parser.getText().length() > 0) {
527 321 mdecorde
                                                interpvalue+=(parser.getText());
528 321 mdecorde
                                        } else if (flagNote == parser.getText().length() > 0) {
529 321 mdecorde
                                                noteContent += parser.getText().replace("\n", " ");
530 321 mdecorde
                                        } else if (writeOutOfTextToEditText) {
531 321 mdecorde
                                                pagedWriter.writeCharacters(parser.getText())
532 321 mdecorde
                                        }
533 321 mdecorde
                                        break;
534 321 mdecorde
                        }
535 321 mdecorde
                }
536 321 mdecorde
                closeMultiWriter();
537 321 mdecorde
        }
538 321 mdecorde
}