|
a/tool/src/www/WebRequest.java |
|
b/tool/src/www/WebRequest.java |
|
... |
|
... |
14 |
package www;
|
14 |
package www;
|
15 |
|
15 |
|
16 |
import definitions.is;
|
16 |
import definitions.is;
|
17 |
import java.io.File;
|
17 |
import java.io.File;
|
18 |
import java.net.MalformedURLException;
|
18 |
import java.net.MalformedURLException;
|
|
|
19 |
import java.net.URISyntaxException;
|
19 |
import java.net.URL;
|
20 |
import java.net.URL;
|
20 |
import java.util.ArrayList;
|
21 |
import java.util.ArrayList;
|
21 |
import java.util.logging.Level;
|
22 |
import java.util.logging.Level;
|
22 |
import java.util.logging.Logger;
|
23 |
import java.util.logging.Logger;
|
23 |
import main.controller;
|
24 |
import main.controller;
|
|
... |
|
... |
43 |
|
44 |
|
44 |
public String
|
45 |
public String
|
45 |
originIP; // if deriving from the web, what is the IP Address?
|
46 |
originIP; // if deriving from the web, what is the IP Address?
|
46 |
|
47 |
|
47 |
private String
|
48 |
private String
|
48 |
answer; // what should be provide as answer (in HTML)
|
49 |
answer, // what should be provide as answer (in HTML)
|
|
|
50 |
templateText = ""; // when we want to use a template
|
49 |
|
51 |
|
50 |
// defines the specific type of request that is being handled here
|
52 |
// defines the specific type of request that is being handled here
|
51 |
public RequestType
|
53 |
public RequestType
|
52 |
requestType = RequestType.UNKNOWN;
|
54 |
requestType = RequestType.UNKNOWN;
|
53 |
|
55 |
|
|
... |
|
... |
94 |
*/
|
96 |
*/
|
95 |
public boolean hasAnswer(){
|
97 |
public boolean hasAnswer(){
|
96 |
return wasAnswered;
|
98 |
return wasAnswered;
|
97 |
}
|
99 |
}
|
98 |
|
100 |
|
|
|
101 |
|
|
|
102 |
|
|
|
103 |
|
99 |
/**
|
104 |
/**
|
100 |
* When we have an answer ready, the next step is storing it inside
|
105 |
* When we have an answer ready, the next step is storing it inside
|
101 |
* using this method.
|
106 |
* using this method.
|
102 |
* @param text The HTML text that will be provided as answer
|
107 |
* @param text The HTML text that will be provided as answer
|
103 |
*/
|
108 |
*/
|
|
... |
|
... |
107 |
System.err.println("WR001 - Answer for request was already given");
|
112 |
System.err.println("WR001 - Answer for request was already given");
|
108 |
return;
|
113 |
return;
|
109 |
}
|
114 |
}
|
110 |
// set the answer text
|
115 |
// set the answer text
|
111 |
answer = text;
|
116 |
answer = text;
|
|
|
117 |
//System.out.println(text);
|
112 |
wasAnswered = true;
|
118 |
wasAnswered = true;
|
113 |
timeEnd = System.currentTimeMillis();
|
119 |
timeEnd = System.currentTimeMillis();
|
114 |
// place this answer on the queue to be solved
|
120 |
// place this answer on the queue to be solved
|
115 |
controller.display(this);
|
121 |
controller.display(this);
|
116 |
// all done in our side
|
122 |
// all done in our side
|
|
... |
|
... |
149 |
parameters = new ArrayList<String[]>();
|
155 |
parameters = new ArrayList<String[]>();
|
150 |
}
|
156 |
}
|
151 |
parameters.add(parameter);
|
157 |
parameters.add(parameter);
|
152 |
}
|
158 |
}
|
153 |
|
159 |
|
|
|
160 |
|
|
|
161 |
/**
|
|
|
162 |
* Defines an HTML page as the template to be written as answer
|
|
|
163 |
* @param pageHTML an HTML file on disk
|
|
|
164 |
*/
|
|
|
165 |
public void setTemplate(String pageHTML){
|
|
|
166 |
File file = new File(BaseFolder, pageHTML);
|
|
|
167 |
|
|
|
168 |
// in case the file does not exist, complain here
|
|
|
169 |
if(file.exists() == false){
|
|
|
170 |
log.write(is.ERROR, "WRs44 - File not found to be used as template:"
|
|
|
171 |
+ " %1", file.getAbsolutePath());
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
templateText = utils.files.readAsString(file);
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
|
|
|
178 |
/**
|
|
|
179 |
* Changes the text on the template
|
|
|
180 |
* @param oldText original text with old value
|
|
|
181 |
* @param newText what we want to see as new value
|
|
|
182 |
*/
|
|
|
183 |
public void changeTemplate(String oldText, String newText){
|
|
|
184 |
templateText = templateText.replaceAll(oldText, newText);
|
|
|
185 |
}
|
|
|
186 |
|
|
|
187 |
/**
|
|
|
188 |
* Closes the request using the template text as source for reply
|
|
|
189 |
*/
|
|
|
190 |
public void close(){
|
|
|
191 |
setAnswer(templateText);
|
|
|
192 |
}
|
|
|
193 |
|
154 |
/**
|
194 |
/**
|
155 |
* If there is a page available, give it back
|
195 |
* If there is a page available, give it back
|
156 |
* @return The URL object with the respective Page object
|
196 |
* @return The URL object with the respective Page object
|
157 |
*/
|
197 |
*/
|
158 |
public URL getPage() {
|
198 |
public URL getPage() {
|