/**
* Delay a new store to 1 second
*/
- private Throttle storeThrottle = new Throttle(1000);
+ private Throttle loadThrottle = new Throttle(WikiEditorPlugin.HTTP_GET_THROTTLE);
+
+ /**
+ * Delay a new store to 1 second
+ */
+ private Throttle storeThrottle = new Throttle(WikiEditorPlugin.HTTP_PUT_THROTTLE);
class Throttle {
private long nextTime = 0;
this.minimumDelay = minimumDelay;
}
+ public Throttle(String key) {
+ Preferences prefs = WikiEditorPlugin.getDefault().getPluginPreferences();
+ String minimumDelay = prefs.getString(key);
+ this.minimumDelay = Integer.parseInt(minimumDelay);
+ }
+
/** this is called from the client */
public synchronized void delay() throws InterruptedException {
long delay = nextTime - System.currentTimeMillis();
return result;
}
- public Loaded loadCategory(String actionURL, String charSet, String title) throws UnexpectedAnswerException, MethodException,
+ public String loadHTMLPage(String actionURL, String charSet) throws UnexpectedAnswerException, MethodException,
PageNotEditableException {
GetMethod method = new GetMethod(actionURL);
- method.setFollowRedirects(false);
+ method.setFollowRedirects(true);
method.addRequestHeader("User-Agent", userAgent);
- NameValuePair[] params = new NameValuePair[] { new NameValuePair("title", title) };
- method.setQueryString(EncodingUtil.formUrlEncode(params, charSet));
+// NameValuePair[] params = new NameValuePair[] { new NameValuePair("title", title) };
+// method.setQueryString(EncodingUtil.formUrlEncode(params, charSet));
- Loaded result;
+ String result = "";
try {
int responseCode = client.executeMethod(method);
String responseBody = method.getResponseBodyAsString();
// log(method);
if (responseCode == 200) {
- Parsed parsed = parseBody(charSet, responseBody);
- Content content = new Content(parsed.timestamp, parsed.body);
- result = new Loaded(actionURL, charSet, parsed.title, content);
+ result = responseBody;
+// Parsed parsed = parseBody(charSet, responseBody);
+// Content content = new Content(parsed.timestamp, parsed.body);
+// result = new Loaded(actionURL, charSet, parsed.title, content);
} else {
throw new UnexpectedAnswerException("load not successful: expected 200 OK, got " + method.getStatusLine());
}
public ArrayList loadXML(IWikipedia config, String actionURL, String pages) throws UnexpectedAnswerException, MethodException,
InterruptedException {
- storeThrottle.delay();
+ loadThrottle.delay();
PostMethod method = new PostMethod(actionURL);
method.setFollowRedirects(false);
method.addRequestHeader("User-Agent", userAgent);