diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/nwoca/ssdt/tools/html2wiki/BadTableRowTransformer.java	Fri May 12 16:45:42 2006 -0400
@@ -0,0 +1,59 @@
+/*
+ * 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 BadTableRowTransformer implements Transformer {
+    
+    private Pattern startPattern = Pattern.compile("<tr>");;
+    private Pattern terminationPattern = Pattern.compile("<tr>|</table>");;
+    private Pattern endTRPattern = Pattern.compile("</tr>");
+    
+    private String terminator = "</tr>";
+    
+    /** Creates a new instance of CloseTagTransformer */
+    public BadTableRowTransformer() {
+    }
+    
+    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.start(),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;
+    }
+    
+}