view src/org/nwoca/ssdt/tools/html2wiki/BadTableRowTransformer.java @ 14:c8442e0eff84

Remove <caption> tags. Generlized {table} around {code} blocks.
author smith@nwoca.org
date Tue, 01 Feb 2011 12:34:45 -0500
parents f8b1ea49d065
children
line wrap: on
line source
/*
 * 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;
    }
    
}