comparison src/org/nwoca/ssdt/tools/html2wiki/BadTableRowTransformer.java @ 0:f8b1ea49d065

Initial version of crude HTML to WikiText converter. Customized for converting HTML files from DEC Document into Wiki markup.
author smith@nwoca.org
date Fri, 12 May 2006 16:45:42 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f8b1ea49d065
1 /*
2 * CloseTagTransformer.java
3 *
4 * Created on May 10, 2006, 10:42 AM
5 *
6 * To change this template, choose Tools | Template Manager
7 * and open the template in the editor.
8 */
9
10 package org.nwoca.ssdt.tools.html2wiki;
11
12 import java.util.regex.*;
13 /**
14 *
15 * @author SMITH
16 */
17 public class BadTableRowTransformer implements Transformer {
18
19 private Pattern startPattern = Pattern.compile("<tr>");;
20 private Pattern terminationPattern = Pattern.compile("<tr>|</table>");;
21 private Pattern endTRPattern = Pattern.compile("</tr>");
22
23 private String terminator = "</tr>";
24
25 /** Creates a new instance of CloseTagTransformer */
26 public BadTableRowTransformer() {
27 }
28
29 public void apply(StringBuffer buffer) {
30 Matcher startMatcher = startPattern.matcher(buffer);
31 Matcher terminateMatcher = terminationPattern.matcher(buffer);
32 Matcher checkTerminator = endTRPattern.matcher(buffer);
33
34 int index = 0;
35
36 while (startMatcher.find(index)) {
37
38 if(terminateMatcher.find(startMatcher.end())) {
39
40 checkTerminator.region(startMatcher.start(),terminateMatcher.start());
41 if (!checkTerminator.find()) {
42
43 buffer.insert(terminateMatcher.start(),terminator);
44 }
45 index = terminateMatcher.start();
46 } else {
47 index = startMatcher.end();
48 }
49
50
51 }
52
53 }
54
55 public String toString() {
56 return "Closing: " + startPattern.pattern() + " with " + terminator;
57 }
58
59 }