00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 package dochelper;
00011
00012 import dochelper.exceptions.InitializationException;
00013 import dochelper.util.FileUtils;
00014 import java.io.File;
00015 import java.io.IOException;
00016 import java.util.regex.MatchResult;
00017
00025 public class FileTransformDefinition implements TransformDefinition {
00026
00027 private final String TEXT;
00028
00033 public FileTransformDefinition(File file) throws InitializationException {
00034 try {
00035 TEXT = FileUtils.FileToString(file);
00036 }
00037 catch(IOException ioe) {
00038 throw new InitializationException(ioe.getMessage());
00039 }
00040 }
00041
00047 public FileTransformDefinition(String path) throws InitializationException {
00048 File file = new File(path);
00049 try {
00050 TEXT = FileUtils.FileToString(file);
00051 }
00052 catch(IOException ioe) {
00053 throw new InitializationException(ioe.getMessage());
00054 }
00055 }
00056
00072 public String render(MatchResult result) {
00073
00074 String strResult = this.getText();
00075
00076
00077 int groups = result.groupCount();
00078
00079
00080 for (int i = 0; i <= groups; i++) {
00081 String groupID = "\\$" + i;
00082 strResult = strResult.replaceAll(groupID, result.group(i));
00083 }
00084
00085 return strResult;
00086 }
00087
00094 public String getText() {
00095 return TEXT;
00096 }
00097
00098
00099 }