// Copyright 2004 Bradford Holcombe. All rights reserved. package com.bradfordholcombe.JSPWiki.filters; import com.ecyrd.jspwiki.WikiContext; import com.ecyrd.jspwiki.filters.BasicPageFilter; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * Replace strings of this pattern: * *
 * James A. Haught?
 * 
* * with * *
 * James A. Haught
 * 
* * @author bradfordholcombe */ public class EditLinkFilter extends BasicPageFilter { /** * @see com.ecyrd.jspwiki.filters.PageFilter#postTranslate(com.ecyrd.jspwiki.WikiContext, java.lang.String) */ public final String postTranslate( final WikiContext wikiContext, final String htmlContent ) { wikiContext.getClass(); Pattern pattern = Pattern.compile( "([^<]+)\\?" ); Matcher matcher = pattern.matcher( htmlContent ); StringBuffer result = new StringBuffer(); while( matcher.find() ) { //System.out.println( matcher.group() ); String replacement = "" + matcher.group( 1 ) + ""; //System.out.println( replacement ); matcher.appendReplacement( result, replacement ); //System.out.println(); } matcher.appendTail( result ); return result.toString(); } /** * Test the filter. * * @param args Command line arguments */ public static void main( String[] args ) { try { System.out.println( new File( "." ).getAbsolutePath() ); BufferedReader in = new BufferedReader( new FileReader( "docs/source2.html" ) ); StringBuffer input = new StringBuffer(); String line = in.readLine(); while( line != null ) { input.append( line ).append( '\n' ); line = in.readLine(); } EditLinkFilter filter = new EditLinkFilter(); String result = filter.postTranslate( null, input.toString() ); System.out.println( result ); } catch( IOException ioe ) { System.out.println( ioe ); } } }