1) Added missing strings for italic, underline and strike through.
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.wiki / src / net / sourceforge / phpeclipse / wiki / actions / mediawiki / connect / MediaWikiConnector.java
index 9225b17..efc1fc9 100644 (file)
@@ -55,8 +55,8 @@ public class MediaWikiConnector {
       + ".*<input[^>]*\\svalue=\"(\\d*)\"[^>]*\\sname=\"wpEdittime\"[^>]*>" + ".*", Pattern.DOTALL);
 
   //  <input type='hidden' value="53ee6d8b42ff9b7d" name="wpEditToken" />
-  private static final Pattern EDIT_TOKEN = Pattern.compile(".*<input\\stype='hidden'\\svalue=\"(.*?)\"\\sname=\"wpEditToken\"\\s/>.*",
-      Pattern.DOTALL);
+  private static final Pattern EDIT_TOKEN = Pattern.compile(
+      ".*<input\\stype='hidden'\\svalue=\"(.*?)\"\\sname=\"wpEditToken\"\\s/>.*", Pattern.DOTALL);
 
   //setup default user agent
   final static public String userAgent = "plog4u.org/0.0";
@@ -69,7 +69,12 @@ public class MediaWikiConnector {
   /**
    * 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;
@@ -80,6 +85,12 @@ public class MediaWikiConnector {
       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();
@@ -311,9 +322,41 @@ public class MediaWikiConnector {
     return result;
   }
 
+  public String loadHTMLPage(String actionURL, String charSet) throws UnexpectedAnswerException, MethodException,
+      PageNotEditableException {
+    GetMethod method = new GetMethod(actionURL);
+    method.setFollowRedirects(true);
+    method.addRequestHeader("User-Agent", userAgent);
+//    NameValuePair[] params = new NameValuePair[] { new NameValuePair("title", title) };
+//    method.setQueryString(EncodingUtil.formUrlEncode(params, charSet));
+
+    String result = "";
+    try {
+      int responseCode = client.executeMethod(method);
+      String responseBody = method.getResponseBodyAsString();
+      //                       log(method);
+
+      if (responseCode == 200) {
+        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());
+      }
+    } catch (HttpException e) {
+      throw new MethodException("method failed", e);
+    } catch (IOException e) {
+      throw new MethodException("method failed", e);
+    } finally {
+      method.releaseConnection();
+    }
+    return result;
+  }
+
   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);