Mercurial > public > html2wiki
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/nwoca/ssdt/tools/html2wiki/BadTableDataTransformer.java Fri May 12 16:45:42 2006 -0400 @@ -0,0 +1,55 @@ +/* + * CloseTagTransformer.java + * + * Created on May 10, 2006, 10:42 AM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package org.nwoca.ssdt.tools.html2wiki; + +import java.util.regex.*; +/** + * + * @author SMITH + */ +public class BadTableDataTransformer implements Transformer { + + private Pattern startPattern = Pattern.compile("<td>");; + private Pattern terminationPattern = Pattern.compile("<td>|<tr>|</table>"); + private Pattern endTRPattern = Pattern.compile("</td>"); + + private String terminator = "</td>"; + + public BadTableDataTransformer() { + } + + public void apply(StringBuffer buffer) { + Matcher startMatcher = startPattern.matcher(buffer); + Matcher terminateMatcher = terminationPattern.matcher(buffer); + Matcher checkTerminator = endTRPattern.matcher(buffer); + + int index = 0; + while (startMatcher.find(index)) { + if(terminateMatcher.find(startMatcher.end())) { + + checkTerminator.region(startMatcher.end(),terminateMatcher.start()); + if (!checkTerminator.find()) { + + buffer.insert(terminateMatcher.start(),terminator); + } + index = terminateMatcher.start(); + } else { + index = startMatcher.end(); + } + + } + + } + + public String toString() { + return "Closing: " + startPattern.pattern() + " with " + terminator; + } + +}