Enable word wrapping with preference key editor.wrap.words (false by default)
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.wiki / src / net / sourceforge / phpeclipse / wiki / actions / mediawiki / connect / MediaWikiConnector.java
index 9225b17..ca80eec 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";
@@ -311,6 +311,37 @@ public class MediaWikiConnector {
     return result;
   }
 
+  public Loaded loadCategory(String actionURL, String charSet, String title) throws UnexpectedAnswerException, MethodException,
+      PageNotEditableException {
+    GetMethod method = new GetMethod(actionURL);
+    method.setFollowRedirects(false);
+    method.addRequestHeader("User-Agent", userAgent);
+    NameValuePair[] params = new NameValuePair[] { new NameValuePair("title", title) };
+    method.setQueryString(EncodingUtil.formUrlEncode(params, charSet));
+
+    Loaded 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);
+      } 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();