1   package test.tuigwaa;
2   
3   import java.util.regex.Matcher;
4   import java.util.regex.Pattern;
5   
6   import org.apache.commons.lang.StringUtils;
7   
8   import junit.framework.TestCase;
9   
10  public class WysiwygTest extends TestCase {
11  
12  	private static final String[] FORBIDDEN_LETTER = {";","//[","//]", "#", "////", "<", ">", "//n", "//r"};
13  	
14  	private static final String ARGS = "[^" + StringUtils.join(FORBIDDEN_LETTER, "") + "]+";
15  	
16  	private Pattern inlinePattern = Pattern.compile("&amp;([a-z]*)(//((" + ARGS
17  			+ ")//))?;");
18  	
19  	public void testReplace(){
20  		//String text = "aaa&amp;table(日本語,aaa);<br/> aa #line a &data(hoge,ho_ge); xxx とだ  &table(hoge); &xxx;けで";
21  		
22  		String text = "<font size=\"5\"><span style=\"color: rgb(255, 0, 0);\">&amp;data(応募者,名前);<br />";
23  				
24  		Matcher matcher = inlinePattern.matcher(text);
25  		
26  		StringBuffer buf = new StringBuffer();
27  		
28  		while(matcher.find()){
29  			System.out.println(matcher.group());
30  			//String pluginName = matcher.group(1);
31  			String args = matcher.group(3);
32  			
33  			System.out.println(args);
34  			String hoge = "xx$x";
35  			
36  			
37  			hoge = hoge.replaceAll("//$", "//////$");
38  			System.err.println(hoge);
39  			
40  			matcher.appendReplacement( buf , hoge );
41  		}
42  		matcher.appendTail(buf);
43  		System.out.println(buf.toString());
44  
45  		text = buf.toString();
46  		
47  		Pattern bpattern = Pattern.compile("^#([a-z]*)(//(([0-9A-Za-z,_]*)//))");
48  		matcher = bpattern.matcher(text);
49  		
50  		while(matcher.find()){
51  			System.err.println(matcher.group());
52  		}
53  	}
54  }