comparison src/org/nwoca/ssdt/tools/html2wiki/BadTableDataTransformer.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 BadTableDataTransformer implements Transformer {
18
19 private Pattern startPattern = Pattern.compile("<td>");;
20 private Pattern terminationPattern = Pattern.compile("<td>|<tr>|</table>");
21 private Pattern endTRPattern = Pattern.compile("</td>");
22
23 private String terminator = "</td>";
24
25 public BadTableDataTransformer() {
26 }
27
28 public void apply(StringBuffer buffer) {
29 Matcher startMatcher = startPattern.matcher(buffer);
30 Matcher terminateMatcher = terminationPattern.matcher(buffer);
31 Matcher checkTerminator = endTRPattern.matcher(buffer);
32
33 int index = 0;
34 while (startMatcher.find(index)) {
35 if(terminateMatcher.find(startMatcher.end())) {
36
37 checkTerminator.region(startMatcher.end(),terminateMatcher.start());
38 if (!checkTerminator.find()) {
39
40 buffer.insert(terminateMatcher.start(),terminator);
41 }
42 index = terminateMatcher.start();
43 } else {
44 index = startMatcher.end();
45 }
46
47 }
48
49 }
50
51 public String toString() {
52 return "Closing: " + startPattern.pattern() + " with " + terminator;
53 }
54
55 }