00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 package dochelper;
00011
00012 import java.util.HashMap;
00013 import java.util.regex.MatchResult;
00014 import java.util.regex.Matcher;
00015 import java.util.regex.Pattern;
00016 import java.util.regex.PatternSyntaxException;
00017
00036 public class DocPattern implements TransformDefinition {
00037
00039 TransformDefinition node;
00040
00042 Pattern regExp;
00043
00044
00045
00046
00047
00048
00049 private String name;
00050
00051
00052 HashMap<String, String> params;
00053
00067 public DocPattern(String pattern) throws PatternSyntaxException {
00068 this.regExp = Pattern.compile(pattern);
00069 this.params = new HashMap<String, String>();
00070 params.put("expression", pattern);
00071 }
00072
00086 public DocPattern(String pattern, TransformDefinition transform) throws PatternSyntaxException {
00087 this(pattern);
00088 this.node = transform;
00089 params.put("transform", this.node.getText());
00090 params.put("expression", pattern);
00091 }
00092
00105 public ResultNode execute(String value) {
00106
00107 ResultNode result = new ResultNode(null, params, name);
00108
00109
00110 if(node == null)
00111 return result;
00112
00113
00114 Matcher match = regExp.matcher(value);
00115
00116
00117
00118 while(match.find()) {
00119 ResultNode leaf = new ResultNode(node.render(match.toMatchResult()), null, "Match");
00120 result.addChild(leaf);
00121 }
00122
00123 return result;
00124 }
00125
00134 public String render(MatchResult mr) {
00135 return null;
00136 }
00137
00146 public String getText() {
00147 return null;
00148 }
00149
00153 public String getName() {
00154 return name;
00155 }
00156
00161 public void setName(String name) {
00162 this.name = name;
00163 }
00164
00165 }