Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorspingel2007-07-28 17:31:43 +0000
committerspingel2007-07-28 17:31:43 +0000
commit7521ada7e9e63cda8e2945b7b188944d5b8961df (patch)
tree9a5ddea2777fb8fcaa4790eded834c6af24c9081 /org.eclipse.mylyn.trac.core/src/org
parent4644b45561aa790f7cdcfef32420e571a5585c8f (diff)
downloadorg.eclipse.mylyn.tasks-7521ada7e9e63cda8e2945b7b188944d5b8961df.tar.gz
org.eclipse.mylyn.tasks-7521ada7e9e63cda8e2945b7b188944d5b8961df.tar.xz
org.eclipse.mylyn.tasks-7521ada7e9e63cda8e2945b7b188944d5b8961df.zip
NEW - bug 196585: Java wrapper for the Trac XmlRpcPlugin Wiki API
https://bugs.eclipse.org/bugs/show_bug.cgi?id=196585
Diffstat (limited to 'org.eclipse.mylyn.trac.core/src/org')
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/ITracWikiClient.java211
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/InvalidWikiPageException.java35
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracXmlRpcClient.java172
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracWikiPage.java50
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracWikiPageInfo.java77
5 files changed, 544 insertions, 1 deletions
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/ITracWikiClient.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/ITracWikiClient.java
index a1e947404..24add52fe 100644
--- a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/ITracWikiClient.java
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/ITracWikiClient.java
@@ -8,7 +8,17 @@
package org.eclipse.mylyn.internal.trac.core;
+import java.io.InputStream;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.mylyn.internal.trac.core.model.TracWikiPage;
+import org.eclipse.mylyn.internal.trac.core.model.TracWikiPageInfo;
+
/**
+ * Interface for the WikiRPC API provided by the Trac XML-RPC Plugin
+ *
* @author Xiaoyang Guan
*
*/
@@ -25,4 +35,205 @@ public interface ITracWikiClient {
*/
public String wikiToHtml(String sourceText) throws TracException;
+ /**
+ * Validates the Trac XML-RPC WikiRPC API version of the repository
+ *
+ * @throws TracException
+ */
+ public void validateWikiRPCAPI() throws TracException;
+
+ /**
+ * Gets the list of the names of all pages from the repository
+ *
+ * @return The array of the names of all Wiki pages
+ * @throws TracException
+ */
+ public String[] getAllWikiPageNames() throws TracException;
+
+ /**
+ * Gets the latest version of a Wiki page from the repository
+ *
+ * @param pageName
+ * the name of the Wiki page
+ * @return the Wiki page at the latest version
+ * @throws TracException
+ */
+ public TracWikiPage getWikiPage(String pageName) throws TracException;
+
+ /**
+ * Gets a specific version of a Wiki page from the repository
+ *
+ * @param pageName
+ * the name of the Wiki page
+ * @param version
+ * the version of the Wiki page
+ * @return the Wiki page at the specified version
+ * @throws TracException
+ */
+ public TracWikiPage getWikiPage(String pageName, int version) throws TracException;
+
+ /**
+ * Gets the information about the latest version of a Wiki page from the repository
+ *
+ * @param pageName
+ * the name of the Wiki page
+ * @return The information about the page at the latest version
+ * @throws TracException
+ */
+ public TracWikiPageInfo getWikiPageInfo(String pageName) throws TracException;
+
+ /**
+ * Gets the information about the specified version of a Wiki page from the repository
+ *
+ * @param pageName
+ * the name of the Wiki page
+ * @param version
+ * the version of the Wiki page
+ * @return The information about the page at the specified version
+ * @throws TracException
+ */
+ public TracWikiPageInfo getWikiPageInfo(String pageName, int version) throws TracException;
+
+ /**
+ * Gets the information about all versions of a Wiki page from the repository
+ *
+ * @param pageName
+ * the name of the Wiki page
+ * @return The list of the information about all versions of the page
+ * @throws TracException
+ */
+ public List<TracWikiPageInfo> getWikiPageInfoAllVersions(String pageName) throws TracException;
+
+ /**
+ * Gets the raw Wiki text of the latest version of a Wiki page from the repository
+ *
+ * @param pageName
+ * the name of the Wiki page
+ * @return the raw Wiki text of the page, latest version
+ * @throws TracException
+ */
+ public String getWikiPageContent(String pageName) throws TracException;
+
+ /**
+ * Gets the raw Wiki text of the specified version of a Wiki page from the repository
+ *
+ * @param pageName
+ * the name of the Wiki page
+ * @param version
+ * the version of the Wiki page
+ * @return the raw Wiki text of the page, specified version
+ * @throws TracException
+ */
+ public String getWikiPageContent(String pageName, int version) throws TracException;
+
+ /**
+ * Gets the rendered HTML of the latest version of a Wiki page from the repository
+ *
+ * @param pageName
+ * the name of the Wiki page
+ * @return the rendered HTML of the page, latest version
+ * @throws TracException
+ */
+ public String getWikiPageHTML(String pageName) throws TracException;
+
+ /**
+ * Gets the rendered HTML of the specified version of a Wiki page from the repository
+ *
+ * @param pageName
+ * the name of the Wiki page
+ * @param version
+ * the version of the Wiki page
+ * @return the rendered HTML of the page, specified version
+ * @throws TracException
+ */
+ public String getWikiPageHTML(String pageName, int version) throws TracException;
+
+ /**
+ * Gets the list of information about all pages that have been modified since a given date from the repository
+ *
+ * @param since
+ * the date from which the changes to the Wiki pages should be retrieved
+ * @return list of information about the modified pages
+ * @throws TracException
+ */
+ public List<TracWikiPageInfo> getRecentWikiChanges(Date since) throws TracException;
+
+ /**
+ * Writes the content of a Wiki page to the repository
+ *
+ * @param pageName
+ * the name of the Wiki page
+ * @param content
+ * the content of the page to be written
+ * @param attributes
+ * a Map used to set any Wiki-specific things, which the server can freely ignore or incorporate.
+ * Standard names are:
+ * <ul>
+ * <li> comment (String): A comment for the page.
+ * <li> minoredit (Boolean): This was a minor edit only.
+ * </ul>
+ * @return <code>true</code> if successful
+ * @throws TracException
+ */
+ public boolean putWikipage(String pageName, String content, Map<String, Object> attributes) throws TracException;
+
+ /**
+ * Gets the list of the names of attachments on a given Wiki page from the repository
+ *
+ * @param pageName
+ * the name of the Wiki page
+ * @return an array of the names of attachments on the given page. Returns an empty array if the page has no
+ * attachment or the page does not exist.
+ * @throws TracException
+ */
+ public String[] listWikiPageAttachments(String pageName) throws TracException;
+
+ /**
+ * Gets the content of an attachment on a Wiki page from the repository
+ *
+ * @param attachmentName
+ * the path of the attachment, in the format of "pagename/filename"
+ * @return An InputStream of the content of the attachment
+ * @throws TracException
+ */
+ public InputStream getWikiPageAttachment(String attachmentName) throws TracException;
+
+ /**
+ * (over)writes an attachment on a Wiki page to the repository. If the named attachment did not exist on the
+ * repository, it is created; if it already exists, its content is overwritten with the new content. This method is
+ * compatible with WikiRPC. ITracWikiClient.putWikiPageAttachmentEx has a more extensive set of (Trac-specific)
+ * features.
+ *
+ * @param attachmentName
+ * the path of the attachment, in the format of "pagename/filename"
+ * @param in
+ * An InputStream of the content of the attachment
+ * @return <code>true</code> if successful
+ * @throws TracException
+ */
+ public boolean putWikiPageAttachment(String attachmentName, InputStream in) throws TracException;
+
+ /**
+ * Attach a file to a Wiki page on the repository. This method is not compatible with WikiRPC.
+ *
+ * @see ITracWikiClient.putAttachment
+ *
+ * @param pageName
+ * the name of the Wiki page
+ * @param fileName
+ * the name of the file to be attached
+ * @param description
+ * the description of the attachment
+ * @param in
+ * An InputStream of the content of the attachment
+ * @param replace
+ * whether to overwrite an existing attachment with the same filename
+ * @return The (possibly transformed) filename of the attachment. If <code>replace</code> is <code>true</code>,
+ * the returned name is always the same as the argument <code>fileName</code>; if <code>replace</code>
+ * is <code>false</code> and an attachment with name <code>fileName</code> already exists, a number is
+ * appended to the file name (before suffix) and the generated filename of the attachment is returned.
+ * @throws TracException
+ */
+ public String putWikiPageAttachmentEx(String pageName, String fileName, String description, InputStream in,
+ boolean replace) throws TracException;
}
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/InvalidWikiPageException.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/InvalidWikiPageException.java
new file mode 100644
index 000000000..9abb95605
--- /dev/null
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/InvalidWikiPageException.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Mylyn project committers and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.trac.core;
+
+/**
+ * Indicates an error while parsing the page info retrieved from a repository. If the requested page name or version
+ * doesn't exist on the repository, the XmlRpcPlugin returns an Integer of 0 without generating any error info.
+ *
+ * @author Xiaoyang Guan
+ */
+public class InvalidWikiPageException extends TracRemoteException {
+
+ private static final long serialVersionUID = 7505355497334178587L;
+
+ public InvalidWikiPageException() {
+ }
+
+ public InvalidWikiPageException(String message) {
+ super(message);
+ }
+
+ public InvalidWikiPageException(Throwable cause) {
+ super(cause);
+ }
+
+ public InvalidWikiPageException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracXmlRpcClient.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracXmlRpcClient.java
index 442b655f1..f62134cb3 100644
--- a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracXmlRpcClient.java
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracXmlRpcClient.java
@@ -44,6 +44,8 @@ import org.eclipse.mylyn.internal.trac.core.model.TracTicketResolution;
import org.eclipse.mylyn.internal.trac.core.model.TracTicketStatus;
import org.eclipse.mylyn.internal.trac.core.model.TracTicketType;
import org.eclipse.mylyn.internal.trac.core.model.TracVersion;
+import org.eclipse.mylyn.internal.trac.core.model.TracWikiPage;
+import org.eclipse.mylyn.internal.trac.core.model.TracWikiPageInfo;
import org.eclipse.mylyn.internal.trac.core.model.TracTicket.Key;
import org.eclipse.mylyn.internal.trac.core.util.TracHttpClientTransportFactory;
import org.eclipse.mylyn.internal.trac.core.util.TracUtils;
@@ -55,8 +57,9 @@ import org.eclipse.mylyn.web.core.WebClientUtil;
* Represents a Trac repository that is accessed through the Trac XmlRpcPlugin.
*
* @author Steffen Pingel
+ * @author Xiaoyang Guan
*/
-public class TracXmlRpcClient extends AbstractTracClient {
+public class TracXmlRpcClient extends AbstractTracClient implements ITracWikiClient {
public static final String XMLRPC_URL = "/xmlrpc";
@@ -68,6 +71,10 @@ public class TracXmlRpcClient extends AbstractTracClient {
private static final int NO_SUCH_METHOD_ERROR = 1;
+ private static final int LATEST_VERSION = -1;
+
+ public static final int REQUIRED_WIKI_RPC_VERSION = 2;
+
private XmlRpcClient xmlrpc;
private TracHttpClientTransportFactory factory;
@@ -652,8 +659,171 @@ public class TracXmlRpcClient extends AbstractTracClient {
return parseDate(result[2]);
}
+ public void validateWikiRPCAPI() throws TracException {
+ if (((Integer) call("wiki.getRPCVersionSupported")) < 2)
+ validate();
+ }
+
public String wikiToHtml(String sourceText) throws TracException {
return (String) call("wiki.wikiToHtml", sourceText);
}
+ public String[] getAllWikiPageNames() throws TracException {
+ Object[] result = (Object[]) call("wiki.getAllPages");
+ String[] wikiPageNames = new String[result.length];
+ for (int i = 0; i < wikiPageNames.length; i++) {
+ wikiPageNames[i] = (String) result[i];
+ }
+ return wikiPageNames;
+ }
+
+ public TracWikiPageInfo getWikiPageInfo(String pageName) throws TracException {
+ return getWikiPageInfo(pageName, LATEST_VERSION);
+ }
+
+ public TracWikiPageInfo getWikiPageInfo(String pageName, int version) throws TracException {
+ // Note: if an unexpected null value is passed to XmlRpcPlugin, XmlRpcClient will throw a TracRemoteException.
+ // So, this null-parameter checking may be omitted if resorting to XmlRpcClient is more appropriate.
+ if (pageName == null)
+ throw new IllegalArgumentException("Wiki page name cannot be null");
+
+ Object result = (version == LATEST_VERSION) ? call("wiki.getPageInfo", pageName) //
+ : call("wiki.getPageInfoVersion", pageName, version);
+ return parseWikiPageInfo(result);
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<TracWikiPageInfo> getWikiPageInfoAllVersions(String pageName) throws TracException {
+ TracWikiPageInfo latestVersion = getWikiPageInfo(pageName);
+ Map<String, Object>[] calls = new Map[latestVersion.getVersion() - 1];
+ for (int i = 0; i < calls.length; i++) {
+ calls[i] = createMultiCall("wiki.getPageInfoVersion", pageName, i + 1);
+ }
+
+ Object[] result = multicall(calls);
+
+ List<TracWikiPageInfo> versions = new ArrayList<TracWikiPageInfo>(result.length + 1);
+ for (Object item : result) {
+ Object pageInfoResult = getMultiCallResult(item);
+ versions.add(parseWikiPageInfo(pageInfoResult));
+ }
+ versions.add(latestVersion);
+
+ return versions;
+ }
+
+ private TracWikiPageInfo parseWikiPageInfo(Object pageInfoResult) throws InvalidWikiPageException {
+ // Note: Trac XML-RPC Plugin returns 0 (as Integer) if pageName or version doesn't exist,
+ // and XmlRpcClient doesn't throw an Exception in this case
+ if (pageInfoResult instanceof Map<?, ?>) {
+ TracWikiPageInfo pageInfo = new TracWikiPageInfo();
+ Map<?, ?> infoMap = (Map<?, ?>) pageInfoResult;
+ pageInfo.setPageName((String) infoMap.get("name"));
+ pageInfo.setAuthor((String) infoMap.get("author"));
+ pageInfo.setLastModified(parseDate(infoMap.get("lastModified")));
+ pageInfo.setVersion((Integer) infoMap.get("version"));
+ return pageInfo;
+ } else {
+ throw new InvalidWikiPageException("Wiki page name or version does not exist");
+ }
+ }
+
+ public String getWikiPageContent(String pageName) throws TracException {
+ return getWikiPageContent(pageName, LATEST_VERSION);
+ }
+
+ public String getWikiPageContent(String pageName, int version) throws TracException {
+ // Note: if an unexpected null value is passed to XmlRpcPlugin, XmlRpcClient will throw a TracRemoteException.
+ // So, this null-parameter checking may be omitted if resorting to XmlRpcClient is more appropriate.
+ if (pageName == null)
+ throw new IllegalArgumentException("Wiki page name cannot be null");
+ if (version == LATEST_VERSION) {
+ // XmlRpcClient throws a TracRemoteException if pageName or version doesn't exist
+ return (String) call("wiki.getPage", pageName);
+ } else {
+ return (String) call("wiki.getPageVersion", pageName, version);
+ }
+ }
+
+ public String getWikiPageHTML(String pageName) throws TracException {
+ return getWikiPageHTML(pageName, LATEST_VERSION);
+ }
+
+ public String getWikiPageHTML(String pageName, int version) throws TracException {
+ if (pageName == null) {
+ throw new IllegalArgumentException("Wiki page name cannot be null");
+ }
+
+ if (version == LATEST_VERSION) {
+ // XmlRpcClient throws a TracRemoteException if pageName or version doesn't exist
+ return (String) call("wiki.getPageHTML", pageName);
+ } else {
+ return (String) call("wiki.getPageHTMLVersion", pageName, version);
+ }
+ }
+
+ public List<TracWikiPageInfo> getRecentWikiChanges(Date since) throws TracException {
+ if (since == null) {
+ throw new IllegalArgumentException("Date parameter cannot be null");
+ }
+
+ Object[] result = (Object[]) call("wiki.getRecentChanges", since);
+ List<TracWikiPageInfo> changes = new ArrayList<TracWikiPageInfo>(result.length);
+ for (Object item : result) {
+ changes.add(parseWikiPageInfo(item));
+ }
+ return changes;
+ }
+
+ public TracWikiPage getWikiPage(String pageName) throws TracException {
+ return getWikiPage(pageName, LATEST_VERSION);
+ }
+
+ public TracWikiPage getWikiPage(String pageName, int version) throws TracException {
+ TracWikiPage page = new TracWikiPage();
+ page.setPageInfo(getWikiPageInfo(pageName, version));
+ page.setContent(getWikiPageContent(pageName, version));
+ page.setPageHTML(getWikiPageHTML(pageName, version));
+ return page;
+ }
+
+ public boolean putWikipage(String pageName, String content, Map<String, Object> attributes) throws TracException {
+ Boolean result = (Boolean) call("wiki.putPage", pageName, content, attributes);
+ return result.booleanValue();
+ }
+
+ public String[] listWikiPageAttachments(String pageName) throws TracException {
+ Object[] result = (Object[]) call("wiki.listAttachments", pageName);
+ String[] attachments = new String[result.length];
+ for (int i = 0; i < attachments.length; i++) {
+ attachments[i] = (String) result[i];
+ }
+ return attachments;
+ }
+
+ public InputStream getWikiPageAttachment(String attachmentName) throws TracException {
+ byte[] data = (byte[]) call("wiki.getAttachment", attachmentName);
+ return new ByteArrayInputStream(data);
+ }
+
+ public boolean putWikiPageAttachment(String attachmentName, InputStream in) throws TracException {
+ byte[] data;
+ try {
+ data = readData(in, new NullProgressMonitor());
+ } catch (IOException e) {
+ throw new TracException(e);
+ }
+ return (Boolean) call("wiki.putAttachment", attachmentName, data);
+ }
+
+ public String putWikiPageAttachmentEx(String pageName, String fileName, String description, InputStream in,
+ boolean replace) throws TracException {
+ byte[] data;
+ try {
+ data = readData(in, new NullProgressMonitor());
+ } catch (IOException e) {
+ throw new TracException(e);
+ }
+ return (String) call("wiki.putAttachmentEx", pageName, fileName, description, data, replace);
+ }
} \ No newline at end of file
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracWikiPage.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracWikiPage.java
new file mode 100644
index 000000000..07d1baf49
--- /dev/null
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracWikiPage.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Mylyn project committers and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.trac.core.model;
+
+/**
+ * Represents a Trac Wiki page at a specific version.
+ *
+ * @author Xiaoyang Guan
+ */
+public class TracWikiPage {
+
+ private TracWikiPageInfo pageInfo;
+
+ private String content;
+
+ private String pageHTML;
+
+ public TracWikiPage() {
+ }
+
+ public TracWikiPageInfo getPageInfo() {
+ return pageInfo;
+ }
+
+ public void setPageInfo(TracWikiPageInfo pageInfo) {
+ this.pageInfo = pageInfo;
+ }
+
+ public String getContent() {
+ return content;
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
+
+ public String getPageHTML() {
+ return pageHTML;
+ }
+
+ public void setPageHTML(String pageHTML) {
+ this.pageHTML = pageHTML;
+ }
+}
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracWikiPageInfo.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracWikiPageInfo.java
new file mode 100644
index 000000000..729e2996d
--- /dev/null
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracWikiPageInfo.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Mylyn project committers and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.trac.core.model;
+
+import java.util.Date;
+
+/**
+ * Information about a Trac Wiki page at a specific version
+ *
+ * @author Xiaoyang Guan
+ */
+public class TracWikiPageInfo {
+
+ private String pageName;
+
+ private String author;
+
+ private Date lastModified;
+
+ private int version;
+
+ private String comment;
+
+ public TracWikiPageInfo() {
+ }
+
+ public String getPageName() {
+ return pageName;
+ }
+
+ public void setPageName(String pageName) {
+ this.pageName = pageName;
+ }
+
+ public String getAuthor() {
+ return author;
+ }
+
+ public void setAuthor(String author) {
+ this.author = author;
+ }
+
+ public Date getLastModified() {
+ return lastModified;
+ }
+
+ public void setLastModified(Date lastModified) {
+ this.lastModified = lastModified;
+ }
+
+ public int getVersion() {
+ return version;
+ }
+
+ public void setVersion(int version) {
+ this.version = version;
+ }
+
+ public String getComment() {
+ return comment;
+ }
+
+ public void setComment(String comment) {
+ this.comment = comment;
+ }
+
+ public String toString() {
+ return pageName + ": version " + version + " by " + author + " last modified at " + lastModified;
+ }
+
+}

Back to the top