Revision 479 tmp/org.txm.groovy.core/src/groovy/org/txm/importer/xtz/XTZDefaultPagerStep.groovy

XTZDefaultPagerStep.groovy (revision 479)
89 89
	def noteElements = new HashSet<String>();
90 90
	def outOfTextElements = new HashSet<String>();
91 91
	XTZPager pager;
92
	
92 93

  
93 94
	/**
94 95
	 * Instantiates a new pager.
......
128 129
		
129 130
		process();
130 131
	}
132
	
133
	public String getAttributeValue(def parser, String ns, String name) {
134
		for (int i = 0 ; i < parser.getAttributeCount() ; i++) {
135
			if (name == parser.getAttributeLocalName(i)) {
136
				return parser.getAttributeValue(i).toString()
137
			}
138
		}
139
		return "";
140
	}
131 141

  
142

  
132 143
	private def closeMultiWriter() {
133 144
		if (pagedWriter != null) {
134 145
			def tags = pagedWriter.getTagStack().clone();
......
180 191
			def tags = closeMultiWriter();
181 192
			for (int i = 0 ; i < tags.size() ; i++) {
182 193
				String tag = tags[i]
183
				if ("body" != tag) {
194
				if ("div" != tag) {
184 195
					tags.remove(i--)
185 196
				} else {
186
					tags.remove(i--) // remove "body"
187
					break; // remove elements until "body tag
197
					tags.remove(i--) // remove first "div"
198
					break; // remove elements until first "div" tag
188 199
				}
189 200
			}
190 201
			File outfile = new File(outdir, txtname+"_"+(++pagecount)+".html")
......
285 296
						currentOutOfTextElements << localname
286 297
					}			
287 298
					
288
					rend = parser.getAttributeValue(null, "rend")
299
					if (localname == paginationElement) {
300
						createNextOutput();
301
						wordcount=0;
302
						pagedWriter.write("\n");
303
						if (getAttributeValue(parser, null,"n") != null) {
304
							pagedWriter.writeElement("p", ["class":"txmeditionpb", "align":"center"], getAttributeValue(parser, null,"n"))
305
						}
306
					}
307
					
308
					rend = getAttributeValue(parser, null, "rend")
289 309
					if (rend == null) rend = "";
290 310
					switch (localname) {
291 311
						case "text":
......
293 313
							for (int i = 0 ; i < parser.getAttributeCount() ; i++) {
294 314
								attributes[parser.getAttributeLocalName(i)] = parser.getAttributeValue(i).toString()
295 315
							}
316
							
296 317
							pagedWriter.write("\n");
297 318
							pagedWriter.writeStartElement("p")
298 319
							pagedWriter.writeAttribute("class", rend);
......
317 338
							break;
318 339
						case "ref":
319 340
							pagedWriter.writeStartElement("a")
320
							pagedWriter.writeAttribute("href", parser.getAttributeValue(null, "target"));
341
							pagedWriter.writeAttribute("href", getAttributeValue(parser, null, "target"));
321 342

  
322 343
							pagedWriter.writeAttribute("target", "_blank");
323 344
							pagedWriter.writeAttribute("class", rend);
......
328 349
							break;
329 350
						case "graphic":
330 351
							pagedWriter.write("\n");
331
							String url = parser.getAttributeValue(null, "url")
352
							String url = getAttributeValue(parser, null, "url")
332 353
							if (url != null) {
333 354
								pagedWriter.writeStartElement("center", ["class":rend])
334 355
								pagedWriter.writeEmptyElement("img", ["src":url, "align":"middle"])
......
346 367
							pagedWriter.writeStartElement("td", ["class":rend])
347 368
							break;
348 369
						case "list":
349
							String type = parser.getAttributeValue(null,"type");
370
							String type = getAttributeValue(parser, null,"type");
350 371
							if ("unordered" == type) {
351 372
								pagedWriter.writeStartElement("ul", ["class":rend])
352 373
							} else {
......
375 396
							pagedWriter.write("\n");
376 397
							pagedWriter.writeStartElement("p", ["class":rend])
377 398
							break;
378
						case paginationElement:
379
							createNextOutput();
380
							wordcount=0;
381
							pagedWriter.write("\n");
382
							if (parser.getAttributeValue(null,"n") != null) {
383
								pagedWriter.writeElement("p", ["class":"txmeditionpb", "align":"center"], parser.getAttributeValue(null,"n"))
384
							}
385
							break;
386 399
						case "lb":
387 400
							pagedWriter.writeEmptyElement("br")
388 401
							break;
389 402
						case wordTag:
390
							wordid = parser.getAttributeValue(null,"id");
403
							wordid = getAttributeValue(parser, null,"id");
404
							
405
							wordcount++;
406
							if (wordcount >= wordmax) {
407
								createNextOutput();
408
							}
409
							
391 410
							if (firstWord) {
392 411
								firstWord = false;
393 412
								this.idxstart.add(wordid);
394 413
							}
395
							wordcount++;
396
							if (wordcount >= wordmax) {
397
								createNextOutput();
398
							}
414
							
399 415
							break;
400 416
						case "ana":
401 417
							flaginterp=true;
402
							interpvalue+=" "+parser.getAttributeValue(null,"type").substring(1)+":"
418
							interpvalue+=" "+getAttributeValue(parser, null, "type").substring(1)+":"
403 419
							break;
404 420
						case "form":
405 421
							wordvalue="";

Also available in: Unified diff