--- a/tool/src/www/WebRequest.java
+++ b/tool/src/www/WebRequest.java
@@ -16,6 +16,7 @@
import definitions.is;
import java.io.File;
import java.net.MalformedURLException;
+import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.logging.Level;
@@ -45,7 +46,8 @@
originIP; // if deriving from the web, what is the IP Address?
private String
- answer; // what should be provide as answer (in HTML)
+ answer, // what should be provide as answer (in HTML)
+ templateText = ""; // when we want to use a template
// defines the specific type of request that is being handled here
public RequestType
@@ -96,6 +98,9 @@
return wasAnswered;
}
+
+
+
/**
* When we have an answer ready, the next step is storing it inside
* using this method.
@@ -109,6 +114,7 @@
}
// set the answer text
answer = text;
+ //System.out.println(text);
wasAnswered = true;
timeEnd = System.currentTimeMillis();
// place this answer on the queue to be solved
@@ -151,6 +157,40 @@
parameters.add(parameter);
}
+
+ /**
+ * Defines an HTML page as the template to be written as answer
+ * @param pageHTML an HTML file on disk
+ */
+ public void setTemplate(String pageHTML){
+ File file = new File(BaseFolder, pageHTML);
+
+ // in case the file does not exist, complain here
+ if(file.exists() == false){
+ log.write(is.ERROR, "WRs44 - File not found to be used as template:"
+ + " %1", file.getAbsolutePath());
+ }
+
+ templateText = utils.files.readAsString(file);
+ }
+
+
+ /**
+ * Changes the text on the template
+ * @param oldText original text with old value
+ * @param newText what we want to see as new value
+ */
+ public void changeTemplate(String oldText, String newText){
+ templateText = templateText.replaceAll(oldText, newText);
+ }
+
+ /**
+ * Closes the request using the template text as source for reply
+ */
+ public void close(){
+ setAnswer(templateText);
+ }
+
/**
* If there is a page available, give it back
* @return The URL object with the respective Page object