00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 package dochelper.xins;
00011
00012 import dochelper.TransformDefinitionImpl;
00013 import java.util.regex.MatchResult;
00014 import java.util.regex.Matcher;
00015 import java.util.regex.Pattern;
00016
00021 public class XINSCAPIPatternTransform extends TransformDefinitionImpl {
00022
00024 Pattern regExp;
00025
00027 public XINSCAPIPatternTransform(String text) {
00028 super(text);
00029 this.regExp = Pattern.compile( "\\$(u|l)\\((\\w+)\\)" );
00030 }
00031
00046 public String render(MatchResult result) {
00047
00048 String strResult = this.getText();
00049
00050
00051 int groups = result.groupCount();
00052
00053
00054 for (int i = 0; i <= groups; i++) {
00055 String groupID = "\\$" + i;
00056 strResult = strResult.replaceAll(groupID, result.group(i));
00057 }
00058
00059
00060 Matcher matches = regExp.matcher(strResult);
00061
00062 while(matches.find()) {
00063
00064
00065 result = matches.toMatchResult();
00066 if(result.group(1).equals("u")) {
00067 strResult = strResult.replace("$u("+result.group(2)+")", result.group(2).toUpperCase());
00068 }
00069 else if(result.group(1).equals("l")) {
00070 strResult = strResult.replace("$l("+result.group(2)+")", result.group(2).toLowerCase());
00071 }
00072
00073 }
00074
00075 return strResult;
00076 }
00077
00078 }