From b8ee6c0d9de048366c1c5ce80c3fc8588a6989cd Mon Sep 17 00:00:00 2001 From: sasinda Date: Sun, 19 Aug 2012 12:17:40 +0530 Subject: [PATCH] Begin work on new RestClient. Delay Specification of the interfaces until more experience is achieved. --- .../xwiki/android/rest/ral/FetchConfig.java | 107 ++ .../ral/algo/ConfigurableDocRetStraegy.java | 11 + .../ral/algo/ParallelDocRetreiveStrategy.java | 33 + .../xwiki/android/rest/ral/algo/optimizations | 13 + .../ral/wrappers/TranspDocumentWrapper.java | 110 ++ .../wrappers/TranspXSimpleObjectWrapper.java | 175 +++ .../transformation/RestModelTransformer.java | 36 + .../android/xmodel/entity/HistoryRecord.java | 25 + .../android/xmodel/entity/XWikiPage.java | 534 ++++++++ .../android/xmodel/entity/XWikiResource.java | 73 ++ .../rest/IllegalRestUsageException.java | 15 + .../android/rest/RestConnectorException.java | 29 + .../android/rest/XWikiRestConnector.java | 1141 +++++++++++++++++ .../xwiki/android/rest/XWikiRestfulAPI.java | 463 +++++++ .../rest/rpc/AttachmentOperations.java | 99 ++ .../android/rest/rpc/ClassOperations.java | 26 + .../android/rest/rpc/CommentOperations.java | 58 + .../android/rest/rpc/HistoryOperations.java | 25 + .../android/rest/rpc/ObjectOperations.java | 110 ++ .../android/rest/rpc/PageOperations.java | 110 ++ .../src/org/xwiki/android/rest/rpc/README | 19 + .../xwiki/android/rest/rpc/RestClient.java | 22 + .../android/rest/rpc/SearchOperations.java | 31 + .../android/rest/rpc/SpaceOperations.java | 21 + .../xwiki/android/rest/rpc/TagOperations.java | 33 + .../rest/rpc/TranslationOperations.java | 17 + .../android/rest/rpc/WikiOperations.java | 17 + .../org/xwiki/android/rest/rpc/XWikiAPI.java | 662 ++++++++++ .../xwiki/android/rest/rpc/XmlRestClient.java | 518 ++++++++ .../rest/rpc/_AttachmentOperations.java | 114 ++ .../android/rest/rpc/_CommentOperations.java | 104 ++ .../android/rest/rpc/_ObjectOperations.java | 131 ++ .../android/rest/rpc/_PageOperations.java | 132 ++ .../android/rest/rpc/_SpaceOperations.java | 51 + .../android/rest/rpc/_TagOperations.java | 94 ++ .../sample HttpClient with pooled connections | 100 ++ .../core/test/properties/TestConstants.java | 63 + .../org/xwiki/android/resources/Resource.java | 11 + 38 files changed, 5333 insertions(+) create mode 100644 xwiki-android-core/src/org/xwiki/android/rest/ral/FetchConfig.java create mode 100644 xwiki-android-core/src/org/xwiki/android/rest/ral/algo/ConfigurableDocRetStraegy.java create mode 100644 xwiki-android-core/src/org/xwiki/android/rest/ral/algo/ParallelDocRetreiveStrategy.java create mode 100644 xwiki-android-core/src/org/xwiki/android/rest/ral/algo/optimizations create mode 100644 xwiki-android-core/src/org/xwiki/android/rest/ral/wrappers/TranspDocumentWrapper.java create mode 100644 xwiki-android-core/src/org/xwiki/android/rest/ral/wrappers/TranspXSimpleObjectWrapper.java create mode 100644 xwiki-android-core/src/org/xwiki/android/rest/transformation/RestModelTransformer.java create mode 100644 xwiki-android-core/src/org/xwiki/android/xmodel/entity/HistoryRecord.java create mode 100644 xwiki-android-core/src/org/xwiki/android/xmodel/entity/XWikiPage.java create mode 100644 xwiki-android-core/src/org/xwiki/android/xmodel/entity/XWikiResource.java create mode 100644 xwiki-android-rest/src/org/xwiki/android/rest/IllegalRestUsageException.java create mode 100644 xwiki-android-rest/src/org/xwiki/android/rest/RestConnectorException.java create mode 100644 xwiki-android-rest/src/org/xwiki/android/rest/XWikiRestConnector.java create mode 100644 xwiki-android-rest/src/org/xwiki/android/rest/XWikiRestfulAPI.java create mode 100644 xwiki-android-rest/src/org/xwiki/android/rest/rpc/AttachmentOperations.java create mode 100644 xwiki-android-rest/src/org/xwiki/android/rest/rpc/ClassOperations.java create mode 100644 xwiki-android-rest/src/org/xwiki/android/rest/rpc/CommentOperations.java create mode 100644 xwiki-android-rest/src/org/xwiki/android/rest/rpc/HistoryOperations.java create mode 100644 xwiki-android-rest/src/org/xwiki/android/rest/rpc/ObjectOperations.java create mode 100644 xwiki-android-rest/src/org/xwiki/android/rest/rpc/PageOperations.java create mode 100644 xwiki-android-rest/src/org/xwiki/android/rest/rpc/README create mode 100644 xwiki-android-rest/src/org/xwiki/android/rest/rpc/RestClient.java create mode 100644 xwiki-android-rest/src/org/xwiki/android/rest/rpc/SearchOperations.java create mode 100644 xwiki-android-rest/src/org/xwiki/android/rest/rpc/SpaceOperations.java create mode 100644 xwiki-android-rest/src/org/xwiki/android/rest/rpc/TagOperations.java create mode 100644 xwiki-android-rest/src/org/xwiki/android/rest/rpc/TranslationOperations.java create mode 100644 xwiki-android-rest/src/org/xwiki/android/rest/rpc/WikiOperations.java create mode 100644 xwiki-android-rest/src/org/xwiki/android/rest/rpc/XWikiAPI.java create mode 100644 xwiki-android-rest/src/org/xwiki/android/rest/rpc/XmlRestClient.java create mode 100644 xwiki-android-rest/src/org/xwiki/android/rest/rpc/_AttachmentOperations.java create mode 100644 xwiki-android-rest/src/org/xwiki/android/rest/rpc/_CommentOperations.java create mode 100644 xwiki-android-rest/src/org/xwiki/android/rest/rpc/_ObjectOperations.java create mode 100644 xwiki-android-rest/src/org/xwiki/android/rest/rpc/_PageOperations.java create mode 100644 xwiki-android-rest/src/org/xwiki/android/rest/rpc/_SpaceOperations.java create mode 100644 xwiki-android-rest/src/org/xwiki/android/rest/rpc/_TagOperations.java create mode 100644 xwiki-android-rest/src/org/xwiki/android/rest/rpc/sample HttpClient with pooled connections create mode 100644 xwiki-android-test-core/src/org/xwiki/android/core/test/properties/TestConstants.java create mode 100644 xwiki-rest-model/xwiki-rest-model-simplexml/src/org/xwiki/android/resources/Resource.java diff --git a/xwiki-android-core/src/org/xwiki/android/rest/ral/FetchConfig.java b/xwiki-android-core/src/org/xwiki/android/rest/ral/FetchConfig.java new file mode 100644 index 0000000..759a178 --- /dev/null +++ b/xwiki-android-core/src/org/xwiki/android/rest/ral/FetchConfig.java @@ -0,0 +1,107 @@ +package org.xwiki.android.rest.ral; + + +/** + * Configure how much things you need to fetch. + * Note: Some fetchX() methods like fetchObjectSummaries(ClassName, offset, len) act as hints to fetch only the specified summaries. + * But the DocumentRao may fetch all object summaries. + * @author xwiki gsoc 2012 + * + */ +public class FetchConfig +{ + //parts of a doc. + public static int PAGE = 1; + public static int PAGE_SUMMARY=512; + /** + * all Objects except comment and tag objects. + */ + public static int OBJECTS = 2; + public static int OBJECT_SUMMARIES=1024; + public static int COMMENTS = 4; + public static int TAGS = 8; + public static int ATTACHMENT_SUMMARIES = 16; + public static int COMMENT_OBJECTS=32; + public static int TAG_OBJECT=64; + public static int HISTORY=128; + public static int TRANSLATIONS=256; + public static int ALL = 2147483647; + + + int parts; + + public FetchConfig(){ + } + + /** + * quick constructor to add parts. parts=PAGE || OBJECTS mean the retreived document will be filled with the objects + the page data. + * @param parts + */ + public FetchConfig(int parts) + { + this.parts=parts; + } + + + public FetchConfig fetchObjects(){ + return this; + } + public FetchConfig fetchObjects(String className) + { + return null; + } + + public FetchConfig fetchObjects(String className, String... properties) + { + return null; + } + public FetchConfig fetchObjects(String className, int offset, int len) + { + return this; + } + + public FetchConfig fetchObjects(String className, int offset, int len,String... properties) + { + return this; + } + + public FetchConfig fetchObjectSummaries() + { + return this; + } + + public FetchConfig fetchObjectSummaries(String className) + { + return this; + } + + public FetchConfig fetchObjectSummaries(String className, int offset, int len) + { + return this; + } + + public FetchConfig fetchComments() + { + return null; + } + public FetchConfig fetchComments(int offset, int len) + { + return null; + } + public FetchConfig fetchAttachmentSummaries() + { + return null; + } + public FetchConfig fetchAttachmentSummaries(int offset, int len) + { + return null; + } + + public FetchConfig fetchAttachments(){ + return this; + } + public FetchConfig fetchAttachment(String name){ + return this; + } + +} diff --git a/xwiki-android-core/src/org/xwiki/android/rest/ral/algo/ConfigurableDocRetStraegy.java b/xwiki-android-core/src/org/xwiki/android/rest/ral/algo/ConfigurableDocRetStraegy.java new file mode 100644 index 0000000..5b92827 --- /dev/null +++ b/xwiki-android-core/src/org/xwiki/android/rest/ral/algo/ConfigurableDocRetStraegy.java @@ -0,0 +1,11 @@ +package org.xwiki.android.rest.ral.algo; + +/** + * For fetching with a fetch config. + * @author xwiki gsoc 2012 + * + */ +public class ConfigurableDocRetStraegy +{ + +} diff --git a/xwiki-android-core/src/org/xwiki/android/rest/ral/algo/ParallelDocRetreiveStrategy.java b/xwiki-android-core/src/org/xwiki/android/rest/ral/algo/ParallelDocRetreiveStrategy.java new file mode 100644 index 0000000..acecc25 --- /dev/null +++ b/xwiki-android-core/src/org/xwiki/android/rest/ral/algo/ParallelDocRetreiveStrategy.java @@ -0,0 +1,33 @@ +package org.xwiki.android.rest.ral.algo; +/** + * + * + * Proof of Concept example. + * + */ +public class ParallelDocRetreiveStrategy +{ + +} + + +class Worker extends Thread{ + +} + +class Job{ + +} + +class RetreiveJob extends Job{ + +} +/** +class createJob extends Job{ + +} + +class UpdateJob extends Job{ + +} +**/ \ No newline at end of file diff --git a/xwiki-android-core/src/org/xwiki/android/rest/ral/algo/optimizations b/xwiki-android-core/src/org/xwiki/android/rest/ral/algo/optimizations new file mode 100644 index 0000000..9a18e96 --- /dev/null +++ b/xwiki-android-core/src/org/xwiki/android/rest/ral/algo/optimizations @@ -0,0 +1,13 @@ +How to parallel +Make Worker thread which can do Jobs. +CreateJob +{ pages, comments, tags, attachmnts, ...} +UpdateJob +{ comments , ...} +RetreiveJob +{ +pages, ... + +} +Worker knows what to do for each job. The worker is allowed to parallelize at any extent. +i.e upload each item in comments, page, etc parallel. \ No newline at end of file diff --git a/xwiki-android-core/src/org/xwiki/android/rest/ral/wrappers/TranspDocumentWrapper.java b/xwiki-android-core/src/org/xwiki/android/rest/ral/wrappers/TranspDocumentWrapper.java new file mode 100644 index 0000000..fd99045 --- /dev/null +++ b/xwiki-android-core/src/org/xwiki/android/rest/ral/wrappers/TranspDocumentWrapper.java @@ -0,0 +1,110 @@ +package org.xwiki.android.rest.ral.wrappers; + +import org.xwiki.android.xmodel.entity.Document; + +public class TranspDocumentWrapper extends DocumentWrapper +{ + + boolean pageSummary; + boolean page; + boolean historySummaries; + boolean comments; + boolean attachmentSummaries; + + + public TranspDocumentWrapper(Document doc) + { + super(doc); + } + +} + +/** + +page summary + +xwiki:Blog.BlogIntroduction +Blog.BlogIntroduction +xwiki +Blog +BlogIntroduction +First blog post +Blog.WebHome +xwiki:Blog.WebHome + +http://localhost:8080/xwiki/bin/view/Blog/BlogIntroduction + + +http://localhost:8080/xwiki/bin/view/Blog/BlogIntroduction + + +xwiki/2.0 + + + +page + + +xwiki:Blog.BlogIntroduction +Blog.BlogIntroduction +xwiki +Blog +BlogIntroduction +First blog post +Blog.WebHome +xwiki:Blog.WebHome + +http://localhost:8080/xwiki/bin/view/Blog/BlogIntroduction + + +http://localhost:8080/xwiki/bin/view/Blog/BlogIntroduction + + +xwiki/2.0 + +14.1 +14 +1 +2009-03-11T14:58:10+05:30 +XWiki.Admin +2012-07-11T16:58:21+05:30 +XWiki.superadmin + + + + + + + +xwiki:Blog.BlogIntroduction:49ea4e6b-9a83-4f63-9ab9-7b596176bce8 + +49ea4e6b-9a83-4f63-9ab9-7b596176bce8 +xwiki:Blog.BlogIntroduction +xwiki +Blog +BlogIntroduction +Blog.BlogPostClass +0 +Blog.News + + + + + + +xwiki:Blog.BlogIntroduction +xwiki +Blog +BlogIntroduction +14.1 +14 +1 +2012-07-11T16:58:21+05:30 +XWiki.superadmin + + +then comes hisotry page. + + +**/ + diff --git a/xwiki-android-core/src/org/xwiki/android/rest/ral/wrappers/TranspXSimpleObjectWrapper.java b/xwiki-android-core/src/org/xwiki/android/rest/ral/wrappers/TranspXSimpleObjectWrapper.java new file mode 100644 index 0000000..fb08c16 --- /dev/null +++ b/xwiki-android-core/src/org/xwiki/android/rest/ral/wrappers/TranspXSimpleObjectWrapper.java @@ -0,0 +1,175 @@ +package org.xwiki.android.rest.ral.wrappers; + +import java.util.Map; + +import org.xwiki.android.xmodel.xobjects.XProperty; +import org.xwiki.android.xmodel.xobjects.XSimpleObject; + +public class TranspXSimpleObjectWrapper extends XSimpleObjectWrapper +{ + + public TranspXSimpleObjectWrapper(XSimpleObject xso) + { + super(xso); + } + +//delegates + + @Override + public void setNew(boolean val) + { + xso.setNew(val); + } + + @Override + public boolean isNew() + { + return xso.isNew(); + } + + + @Override + public boolean isEdited() + { + return xso.isEdited(); + } + + @Override + public String getId() + { + return xso.getId(); + } + + @Override + public void setEdited(boolean altered) + { + xso.setEdited(altered); + } + + @Override + public void setId(String id) + { + xso.setId(id); + } + + @Override + public String getGuid() + { + return xso.getGuid(); + } + + @Override + public void setGuid(String guid) + { + xso.setGuid(guid); + } + + @Override + public String getPageid() + { + return xso.getPageid(); + } + + @Override + public void setPageid(String pageid) + { + xso.setPageid(pageid); + } + + @Override + public String getSpace() + { + return xso.getSpace(); + } + + @Override + public void setSpace(String space) + { + xso.setSpace(space); + } + + @Override + public String getWiki() + { + return xso.getWiki(); + } + + @Override + public void setWiki(String wiki) + { + xso.setWiki(wiki); + } + + @Override + public String getPageName() + { + return xso.getPageName(); + } + + @Override + public void setPageName(String pageName) + { + xso.setPageName(pageName); + } + + @Override + public String getClassName() + { + return xso.getClassName(); + } + + @Override + public int getNumber() + { + return xso.getNumber(); + } + + @Override + public void setNumber(int number) + { + xso.setNumber(number); + } + + @Override + public String getHeadline() + { + return xso.getHeadline(); + } + + @Override + public void setHeadline(String headline) + { + xso.setHeadline(headline); + } + + @Override + public Map getProperties() + { + return xso.getProperties(); + } + + @Override + public void setProperties(Map props) + { + xso.setProperties(props); + } + + @Override + public void setProperty(XProperty p) + { + xso.setProperty(p); + } + + @Override + public void setProperty(String key, XProperty p) + { + xso.setProperty(key, p); + } + + @Override + public void removeProperty(String pname) + { + xso.removeProperty(pname); + } + +} diff --git a/xwiki-android-core/src/org/xwiki/android/rest/transformation/RestModelTransformer.java b/xwiki-android-core/src/org/xwiki/android/rest/transformation/RestModelTransformer.java new file mode 100644 index 0000000..570c325 --- /dev/null +++ b/xwiki-android-core/src/org/xwiki/android/rest/transformation/RestModelTransformer.java @@ -0,0 +1,36 @@ +package org.xwiki.android.rest.transformation; + +import org.xwiki.android.resources.Comment; +import org.xwiki.android.resources.Object; +import org.xwiki.android.resources.Tags; +import org.xwiki.android.xmodel.xobjects.XComment; + +/** + * transforms XModel Objects to XModel 1st class entities and vice versa. + * @author xwiki gsoc 2012 + * + */ +public class RestModelTransformer +{ + public static Object toObject(Comment c){ + XComment xc=new XComment(); + xc.setAuthor(c.getAuthor()); + xc.setComment(c.getText()); + //xc.setDate(c.getDate()); + //TODO + return new XModelTranslator_XML().toObject(xc); + } + + public static Object toObject(Tags ts){ + throw new UnsupportedOperationException("//TODO"); + } + + public static Tags toTags(Object o){ + throw new UnsupportedOperationException("//TODO"); + } + + public static Comment toComment(Object o){ + throw new UnsupportedOperationException("//TODO"); + } + +} diff --git a/xwiki-android-core/src/org/xwiki/android/xmodel/entity/HistoryRecord.java b/xwiki-android-core/src/org/xwiki/android/xmodel/entity/HistoryRecord.java new file mode 100644 index 0000000..bffbec9 --- /dev/null +++ b/xwiki-android-core/src/org/xwiki/android/xmodel/entity/HistoryRecord.java @@ -0,0 +1,25 @@ +package org.xwiki.android.xmodel.entity; +/** + * equivelent to history summary. + * @author xwiki gsoc 2012 + * + */ +public class HistoryRecord +{ + +} + +/** + + +xwiki:Blog.test2 +xwiki +Blog +test2 +17.1 +17 +1 +2012-08-18T12:06:43+05:30 +XWiki.Admin + +**/ \ No newline at end of file diff --git a/xwiki-android-core/src/org/xwiki/android/xmodel/entity/XWikiPage.java b/xwiki-android-core/src/org/xwiki/android/xmodel/entity/XWikiPage.java new file mode 100644 index 0000000..a4d633e --- /dev/null +++ b/xwiki-android-core/src/org/xwiki/android/xmodel/entity/XWikiPage.java @@ -0,0 +1,534 @@ +package org.xwiki.android.xmodel.entity; + +import java.util.Date; +import java.util.List; +import org.xwiki.android.rest.reference.DocumentReference; +import org.xwiki.android.rest.reference.Link; + +/** + * Contains the properties of a Page +Additional methods for Document. + * + * @author xwiki dev: not saved to DB. Only the DocumentReference is saved. + */ + +public abstract class XWikiPage extends XWikiResource +{ + + // Resource fields + // + protected List links; + + protected String id;// id field in the resource representation. Mobile apps normally use ReSTful URL to + // identify a resource.Not this. + + protected String fullName; + + protected String wikiName;// wiki in page element + + protected String spaceName;// space in page element + + protected String name; // name in page element (same) + + protected String title; + + protected String parentFullName;// parent in resoruce repr. + + protected String parentId; + + protected String xwikiRelativeUrl; + + protected String xwikiAbsoluteUrl; + + protected List translations; + + protected String defalutTranslation; + + protected String syntax; + + protected String language; + + protected String version; + + protected int majorVersion; + + protected int minorVersion; + + protected Date created; // Date created. From date string in page. + + protected String creator; // user string + + protected Date modified; // Date string + + protected String modifier; // user string + + protected String content; + + // other fields + protected DocumentReference docRef; + + + /** + * Create page with given params.Also page 'Title' is set to pageName by default. + * @param wikiName + * @param spaceName + * @param pageName + */ + public XWikiPage(String wikiName, String spaceName, String pageName) + { + this.name = pageName; + this.wikiName = wikiName; + this.spaceName = spaceName; + this.title=pageName; + } + + /** + * @return + */ + public DocumentReference getDocumentReference() + { + docRef = new DocumentReference(wikiName, spaceName, name); + docRef.setVersion(version); + docRef.setLanguage(language); + return docRef; + } + + + + + + // /** + // * valid for only Documents retreived from server. + // * @return + // */ + // public boolean isCachedCopy(){ + // return offlineMode; + // } + + + + // resource value getter setters + // ----------------------------- + + + + /** + * Gets the value of the id property. + * + * @return possible object is {@link String } + */ + public String getId() + { + return id; + } + + + + /** + * Sets the value of the id property. + * + * @param value allowed object is {@link String } + */ + public void setId(String value) + { + this.id = value; + } + + /** + * Gets the value of the fullName property. * + * + * @return possible object is {@link String } + */ + public String getFullName() + { + return fullName; + } + + /** + * Sets the value of the fullName property. * + * + * @param value allowed object is {@link String } + */ + public void setFullName(String value) + { + this.fullName = value; + } + + /** + * Gets the value of the wiki property. + * + * @return possible object is {@link String } + */ + public String getWikiName() + { + return wikiName; + } + + /** + * Sets the value of the wiki property. + * + * @param value allowed object is {@link String } + */ + public void setWikiName(String value) + { + this.wikiName = value; + } + + /** + * Gets the value of the space property. + * + * @return possible object is {@link String } + */ + public String getSpaceName() + { + return spaceName; + } + + /** + * Sets the value of the space property. + * + * @param value allowed object is {@link String } + */ + public void setSpaceName(String value) + { + this.spaceName = value; + } + + // TODO:Consider refactor rename back to getName() ? confuse with name,fullName ? + /** + * get Page Name. + * @return the value of the name property in the Rest model "Page" element.. + */ + public String getPageName() + { + return name; + } + + /** + * Sets the value of the name property. + * + * @param value allowed object is {@link String } + */ + public void setPageName(String name) + { + this.name = name; + } + + /** + * Gets the value of the title property. + * + * @return possible object is {@link String } + */ + public String getTitle() + { + return title; + } + + /** + * Sets the value of the title property. + * + * @param value allowed object is {@link String } + */ + public void setTitle(String value) + { + this.title = value; + } + + /** + * Gets the value of the parent property. + * + * @return possible object is {@link String } + */ + public String getParentFullName() + { + return parentFullName; + } + + /** + * Sets the value of the parent property. + * + * @param value allowed object is {@link String } + */ + public void setParentFullName(String parent) + { + this.parentFullName = parent; + } + + /** + * Gets the value of the parentId property. + * + * @return possible object is {@link String } + */ + public String getParentId() + { + return parentId; + } + + /** + * Sets the value of the parentId property. + * + * @param value allowed object is {@link String } + */ + public void setParentId(String value) + { + this.parentId = value; + } + + /** + * Gets the value of the xwikiRelativeUrl property. + * + * @return possible object is {@link String } + */ + public String getXwikiRelativeUrl() + { + return xwikiRelativeUrl; + } + + /** + * Sets the value of the xwikiRelativeUrl property. + * + * @param value allowed object is {@link String } + */ + public void setXwikiRelativeUrl(String value) + { + this.xwikiRelativeUrl = value; + } + + /** + * Gets the value of the xwikiAbsoluteUrl property. + * + * @return possible object is {@link String } + */ + public String getXwikiAbsoluteUrl() + { + return xwikiAbsoluteUrl; + } + + /** + * Sets the value of the xwikiAbsoluteUrl property. + * + * @param value allowed object is {@link String } + */ + public void setXwikiAbsoluteUrl(String value) + { + this.xwikiAbsoluteUrl = value; + } + + /** + * Gets the value of the translations property. + * + * @return possible object is {@link Translations } + */ + public List getTranslations() + { + return translations; + } + + /** + * Sets the value of the translations property. + * + * @param value allowed object is {@link Translations } + */ + public void setTranslations(List translations) + { + this.translations = translations; + } + + public String getDefalutTranslation() + { + return defalutTranslation; + } + + public void setDefalutTranslation(String defalutTranslation) + { + this.defalutTranslation = defalutTranslation; + } + + /** + * Gets the value of the syntax property. + * + * @return possible object is {@link String } + */ + public String getSyntax() + { + return syntax; + } + + /** + * Sets the value of the syntax property. + * + * @param value allowed object is {@link String } + */ + public void setSyntax(String value) + { + this.syntax = value; + } + + public String getLanguage() + { + return language; + } + + /** + * Sets the value of the language property. + * + * @param value allowed object is {@link String } + */ + public void setLanguage(String value) + { + this.language = value; + + } + + /** + * Gets the value of the version property. + * + * @return possible object is {@link String } + */ + public String getVersion() + { + return version; + } + + /** + * Sets the value of the version property. + * + * @param value allowed object is {@link String } + */ + public void setVersion(String value) + { + this.version = value; + } + + /** + * Gets the value of the majorVersion property. + */ + public int getMajorVersion() + { + return majorVersion; + } + + /** + * Sets the value of the majorVersion property. + */ + public void setMajorVersion(int value) + { + this.majorVersion = value; + } + + /** + * Gets the value of the minorVersion property. + */ + public int getMinorVersion() + { + return minorVersion; + } + + /** + * Sets the value of the minorVersion property. + */ + public void setMinorVersion(int value) + { + this.minorVersion = value; + } + + /** + * Gets the value of the created property. + * + * @return possible object is {@link String } + */ + public Date getCreated() + { + return created; + } + + /** + * Sets the value of the created property. + * + * @param value allowed object is {@link String } + */ + public void setCreated(Date date) + { + this.created = date; + } + + /** + * Gets the value of the creator property. + * + * @return possible object is {@link String } + */ + public String getCreator() + { + return creator; + } + + /** + * Sets the value of the creator property. + * + * @param value allowed object is {@link String } + */ + public void setCreator(String value) + { + this.creator = value; + } + + /** + * Gets the value of the modified property. + * + * @return possible object is {@link String } + */ + public Date getModified() + { + return modified; + } + + /** + * Sets the value of the modified property. + * + * @param value allowed object is {@link String } + */ + public void setModified(Date d) + { + this.modified = d; + } + + /** + * Gets the value of the modifier property. + * + * @return possible object is {@link String } + */ + public String getModifier() + { + return modifier; + } + + /** + * Sets the value of the modifier property. + * + * @param value allowed object is {@link String } + */ + public void setModifier(String value) + { + this.modifier = value; + } + + /** + * Gets the value of the content property. + * + * @return possible object is {@link String } + */ + public String getContent() + { + return content; + } + + /** + * Sets the value of the content property. + * + * @param value allowed object is {@link String } + */ + public void setContent(String value) + { + this.content = value; + } + +} diff --git a/xwiki-android-core/src/org/xwiki/android/xmodel/entity/XWikiResource.java b/xwiki-android-core/src/org/xwiki/android/xmodel/entity/XWikiResource.java new file mode 100644 index 0000000..f186d87 --- /dev/null +++ b/xwiki-android-core/src/org/xwiki/android/xmodel/entity/XWikiResource.java @@ -0,0 +1,73 @@ +package org.xwiki.android.xmodel.entity; + +import java.io.Serializable; +import java.util.List; + +import org.xwiki.android.rest.reference.Link; + +public class XWikiResource implements Serializable +{ + + List links; + + private boolean isNew=true; + + private boolean edited=true; + + public void setNew(boolean val) + { + isNew = val; + } + + /** + * This value is set/get for the following purpose. if a resource is new always add this resource to the containing + * resource's new list. For example Document.add(myobj); myedit(myobj);//update the myobj in the newObjects list of + * Document. If the client edited a clone of the myobj and now wants to reset myobj. Use + * Document.setObject("client side gen key for myobj", myobj2); setObject will check whether the resource is new and + * update the newObjects list also. The Document.addObject() method will set this property to true. Otherwise do not + * touch this property explicitly + */ + public boolean isNew() + { + return isNew; + } + + public boolean isEdited() + { + return edited; + } + /** + * + * @param altered true=mark object for update. + */ + public void setEdited(boolean altered) + { + this.edited = altered; + } + + + public List getLinks() + { + return links; + } + + public void setLinks(List links){ + this.links=links; + } + + public void addLink(Link link) + { + links.add(link); + } + + public void removeLink(int index) + { + links.remove(index); + } + + public void clearLinks() + { + links.clear(); + } + +} diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/IllegalRestUsageException.java b/xwiki-android-rest/src/org/xwiki/android/rest/IllegalRestUsageException.java new file mode 100644 index 0000000..0871486 --- /dev/null +++ b/xwiki-android-rest/src/org/xwiki/android/rest/IllegalRestUsageException.java @@ -0,0 +1,15 @@ +package org.xwiki.android.rest; + +/** + * @author xwiki gsoc 2012 + * RUNTIME EXCEPTION + * This runtime exception is thrown for Rest API usage errors which cannot be corrected at + * runtime. + */ +public class IllegalRestUsageException extends RuntimeException +{ + public IllegalRestUsageException(String msg) + { + super(msg); + } +} diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/RestConnectorException.java b/xwiki-android-rest/src/org/xwiki/android/rest/RestConnectorException.java new file mode 100644 index 0000000..bc27c3f --- /dev/null +++ b/xwiki-android-rest/src/org/xwiki/android/rest/RestConnectorException.java @@ -0,0 +1,29 @@ +package org.xwiki.android.rest; + +public class RestConnectorException extends Exception +{ + + public RestConnectorException() + { + super(); + } + + public RestConnectorException(String detailMessage, Throwable throwable) + { + super(detailMessage, throwable); + // TODO Auto-generated constructor stub + } + + public RestConnectorException(String detailMessage) + { + super(detailMessage); + // TODO Auto-generated constructor stub + } + + public RestConnectorException(Throwable throwable) + { + super(throwable); + // TODO Auto-generated constructor stub + } + +} diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/XWikiRestConnector.java b/xwiki-android-rest/src/org/xwiki/android/rest/XWikiRestConnector.java new file mode 100644 index 0000000..2d93ee4 --- /dev/null +++ b/xwiki-android-rest/src/org/xwiki/android/rest/XWikiRestConnector.java @@ -0,0 +1,1141 @@ +package org.xwiki.android.rest; + +import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; + +import org.xwiki.android.resources.Attachments; +import org.xwiki.android.resources.Class; +import org.xwiki.android.resources.Classes; +import org.xwiki.android.resources.Comment; +import org.xwiki.android.resources.Comments; +import org.xwiki.android.resources.History; +import org.xwiki.android.resources.Object; +import org.xwiki.android.resources.Objects; +import org.xwiki.android.resources.Page; +import org.xwiki.android.resources.Pages; +import org.xwiki.android.resources.Properties; +import org.xwiki.android.resources.Property; +import org.xwiki.android.resources.SearchResults; +import org.xwiki.android.resources.Spaces; +import org.xwiki.android.resources.Tag; +import org.xwiki.android.resources.Tags; +import org.xwiki.android.resources.Translations; +import org.xwiki.android.resources.Wikis; +import org.xwiki.android.rest.rpc.HistoryOperations; +import org.xwiki.android.rest.rpc.RestClient; +import org.xwiki.android.rest.rpc.XWikiAPI; + +import android.util.Log; + +public class XWikiRestConnector implements XWikiAPI +{ + + private static final String TAG = "XWikiRestConnecion"; + + /** + * URL of the XWiki domain + */ + private String URLprefix; + + /** + * Username for accessing XWiki + */ + private String username; + + /** + * Password for accessing XWiki + */ + private String password; + + /** + * State of the gets has user authentication or not + */ + private boolean isAuthenticated = false; + + /** + * @param URLprefix URL of the XWiki domain + */ + public XWikiRestConnector(String URLprefix) + { + this.URLprefix = URLprefix; + isAuthenticated = false; + } + + /** + * Constructor for directly setting user credentials. + * + * @param URLprefix URL of the XWiki domain + * @param username username of the user account + * @param password password of the user account + */ + public XWikiRestConnector(String URLprefix, String username, String password) + { + this.URLprefix = URLprefix; + this.username = username; + this.password = password; + isAuthenticated = true; + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#setAuthentication(java.lang.String, java.lang.String) + */ + @Override + public void setAuthentication(String username, String password) + { + this.username = username; + this.password = password; + isAuthenticated = true; + } + + /** + * Converts strings to UCS Transformation Format - 8-bit(UTF-8) for calling XWiki RESTful API Does URL encoding of + * the keyword. + * + * @param word text to convert + * @return converted text + */ + private String urlEncode(String word) + { + + // Convert keyword to UTF-8 + try { + word = URLEncoder.encode(word, "UTF-8"); + + } catch (UnsupportedEncodingException e) { + Log.d("Error", "Unsupported keyword is found"); + word = "error in converting to UTF-8"; + e.printStackTrace(); + } + + return word; + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getSearch(java.lang.String, java.lang.String) + */ + @Override + public SearchResults searchInWiki(String wikiName, String keyword) throws RestConnectionException, RestException, + RestException + { + + wikiName = urlEncode(wikiName); + keyword = urlEncode(keyword); + + Search search = new Search(URLprefix); + + if (isAuthenticated) { + search.setAuthenticaion(username, password); + } + + return search.doWikiSearch(wikiName, keyword); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getSearch(java.lang.String, java.lang.String, java.lang.String) + */ + @Override + public SearchResults searchInSpace(String wikiName, String spaceName, String keyword) + throws RestConnectionException, RestException + { + + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + keyword = urlEncode(keyword); + + Search search = new Search(URLprefix); + if (isAuthenticated) { + search.setAuthenticaion(username, password); + } + return search.doSpacesSearch(wikiName, spaceName, keyword); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getWikis() + */ + @Override + public Wikis getWikis() throws RestConnectionException, RestException + { + + WikiResources wikiresources = new WikiResources(URLprefix); + if (isAuthenticated) { + wikiresources.setAuthenticaion(username, password); + } + Wikis wikis = wikiresources.getWikis(); + return wikis; + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getSpaces(java.lang.String) + */ + @Override + public Spaces getSpaces(String wikiName) throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + SpaceResources spacesresources = new SpaceResources(URLprefix, wikiName); + if (isAuthenticated) { + spacesresources.setAuthenticaion(username, password); + } + return spacesresources.getSpaces(); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getAllPages(java.lang.String, java.lang.String) + */ + @Override + public Pages getAllPages(String wikiName, String spaceName) throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + PageResources pagesresources = new PageResources(URLprefix, wikiName, spaceName); + if (isAuthenticated) { + pagesresources.setAuthenticaion(username, password); + } + return pagesresources.getAllPages(); + } + + @Override + public boolean existsPage(String wikiName, String spaceName, String pageName) throws RestConnectionException, + RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + + PageResources pagesresources = new PageResources(URLprefix, wikiName, spaceName); + if (isAuthenticated) { + pagesresources.setAuthenticaion(username, password); + } + return pagesresources.exists(pageName); + + } + + @Override + public Page getPage(String wikiName, String spaceName, String pageName) throws RestConnectionException, + RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + + PageResources pagesresources = new PageResources(URLprefix, wikiName, spaceName); + if (isAuthenticated) { + pagesresources.setAuthenticaion(username, password); + } + return pagesresources.getPage(pageName); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#addPage(java.lang.String, java.lang.String, java.lang.String, + * org.xwiki.android.resources.Page) + */ + @Override + public String addPage(String wikiName, String spaceName, String pageName, Page page) + throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + + PageResources pagesresources = new PageResources(URLprefix, wikiName, spaceName); + if (isAuthenticated) { + pagesresources.setAuthenticaion(username, password); + } + return pagesresources.addPage(page); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#deletePage(java.lang.String, java.lang.String, java.lang.String) + */ + @Override + public String deletePage(String wikiName, String spaceName, String pageName) throws RestConnectionException, + RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + + PageResources pagesresources = new PageResources(URLprefix, wikiName, spaceName); + if (isAuthenticated) { + pagesresources.setAuthenticaion(username, password); + } + return pagesresources.deletePage(pageName); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#deletePage(java.lang.String, java.lang.String, java.lang.String, + * java.lang.String) + */ + @Override + public String deletePage(String wikiName, String spaceName, String pageName, String language) + throws RestConnectionException, RestException + + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + + PageResources pagesresources = new PageResources(URLprefix, wikiName, spaceName); + if (isAuthenticated) { + pagesresources.setAuthenticaion(username, password); + } + return pagesresources.deletePageTranslation(pageName, language); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getPageHistory(java.lang.String, java.lang.String, + * java.lang.String) + */ + + @Override + public History getPageHistory(String wikiName, String spaceName, String pageName) throws RestConnectionException, + RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + + HistoryResources historyresources = new HistoryResources(URLprefix, wikiName, spaceName, pageName); + if (isAuthenticated) { + historyresources.setAuthenticaion(username, password); + } + return historyresources.getPageHistory(); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getPageInVersionHistory(java.lang.String, java.lang.String, + * java.lang.String, java.lang.String) + */ + + @Override + public Page getPageInVersionHistory(String wikiName, String spaceName, String pageName, String version) + throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + + PageResources pagesresources = new PageResources(URLprefix, wikiName, spaceName); + if (isAuthenticated) { + pagesresources.setAuthenticaion(username, password); + } + return pagesresources.getPageHistoryOnVersion(pageName, version); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getPageChildren(java.lang.String, java.lang.String, + * java.lang.String) + */ + + @Override + public Pages getPageChildren(String wikiName, String spaceName, String pageName) throws RestConnectionException, + RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + + PageResources pagesresources = new PageResources(URLprefix, wikiName, spaceName); + if (isAuthenticated) { + pagesresources.setAuthenticaion(username, password); + } + return pagesresources.getPageChildren(pageName); + + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getPageTags(java.lang.String, java.lang.String, java.lang.String) + */ + + @Override + public Tags getPageTags(String wikiName, String spaceName, String pageName) throws RestConnectionException, + RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + + TagResources tagresources = new TagResources(URLprefix, wikiName, spaceName, pageName); + if (isAuthenticated) { + tagresources.setAuthenticaion(username, password); + } + return tagresources.getTags(); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#addPageTag(java.lang.String, java.lang.String, java.lang.String, + * org.xwiki.android.resources.Tag) + */ + + @Override + public String addPageTag(String wikiName, String spaceName, String pageName, Tag tag) + throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + + TagResources tagresources = new TagResources(URLprefix, wikiName, spaceName, pageName); + if (isAuthenticated) { + tagresources.setAuthenticaion(username, password); + } + return tagresources.addTag(tag); + + } + + @Override + public String setTags(String wikiName, String spaceName, String pageName, Tags tags) + throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + + TagResources tagresources = new TagResources(URLprefix, wikiName, spaceName, pageName); + if (isAuthenticated) { + tagresources.setAuthenticaion(username, password); + } + return tagresources.setTags(tags); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getWikiTags(java.lang.String) + */ + + @Override + public Tags getWikiTags(String wikiName) throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + + TagResources tagresources = new TagResources(URLprefix, wikiName); + if (isAuthenticated) { + tagresources.setAuthenticaion(username, password); + } + return tagresources.getTags(); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getPageComments(java.lang.String, java.lang.String, + * java.lang.String) + */ + + @Override + public Comments getPageComments(String wikiName, String spaceName, String pageName) throws RestConnectionException, + RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + + CommentResources commentresources = new CommentResources(URLprefix, wikiName, spaceName, pageName); + if (isAuthenticated) { + commentresources.setAuthenticaion(username, password); + } + return commentresources.getPageComments(); + } + + @Override + public boolean existsPageComment(String wikiName, String spaceName, String pageName, int commentId) + throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + + CommentResources commentresources = new CommentResources(URLprefix, wikiName, spaceName, pageName); + if (isAuthenticated) { + commentresources.setAuthenticaion(username, password); + } + return commentresources.exists(commentId); + } + + @Override + public Comment getPageComment(String wikiName, String spaceName, String pageName, int commentId) + throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + + CommentResources commentresources = new CommentResources(URLprefix, wikiName, spaceName, pageName); + if (isAuthenticated) { + commentresources.setAuthenticaion(username, password); + } + return commentresources.getPageComment(commentId); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#addPageComment(java.lang.String, java.lang.String, + * java.lang.String, org.xwiki.android.resources.Comment) + */ + + @Override + public String addPageComment(String wikiName, String spaceName, String pageName, Comment comment) + throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + + CommentResources commentresources = new CommentResources(URLprefix, wikiName, spaceName, pageName); + if (isAuthenticated) { + commentresources.setAuthenticaion(username, password); + return commentresources.addPageComment(comment); + } else { + return "Autherization details are not provided"; + } + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getPageCommentsInHistory(java.lang.String, java.lang.String, + * java.lang.String, java.lang.String) + */ + + @Override + public Comments getPageCommentsInHistory(String wikiName, String spaceName, String pageName, String version) + throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + + CommentResources commentresources = new CommentResources(URLprefix, wikiName, spaceName, pageName); + if (isAuthenticated) { + commentresources.setAuthenticaion(username, password); + } + return commentresources.getPageCommentsInHistory(version); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getPageCommentsInHistory(java.lang.String, java.lang.String, + * java.lang.String, java.lang.String, java.lang.String) + */ + + @Override + public Comments getPageCommentsInHistory(String wikiName, String spaceName, String pageName, String version, + String commentId) throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + + CommentResources commentresources = new CommentResources(URLprefix, wikiName, spaceName, pageName); + if (isAuthenticated) { + commentresources.setAuthenticaion(username, password); + } + return commentresources.getPageCommentsInHistory(version, commentId); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getAllPageAttachments(java.lang.String, java.lang.String, + * java.lang.String) + */ + + @Override + public Attachments getAllPageAttachments(String wikiName, String spaceName, String pageName) + throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + + AttachmentResources attachmentresources = new AttachmentResources(URLprefix, wikiName, spaceName, pageName); + if (isAuthenticated) { + attachmentresources.setAuthenticaion(username, password); + } + + return attachmentresources.getAllPageAttachments(); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getPageAttachment(java.lang.String, java.lang.String, + * java.lang.String, java.lang.String) + */ + + @Override + public InputStream getPageAttachment(String wikiName, String spaceName, String pageName, String attachmentName) + throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + attachmentName = urlEncode(attachmentName); + + AttachmentResources attachmentresources = new AttachmentResources(URLprefix, wikiName, spaceName, pageName); + if (isAuthenticated) { + attachmentresources.setAuthenticaion(username, password); + } + return attachmentresources.getPageAttachment(attachmentName); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#addPageAttachment(java.lang.String, java.lang.String, + * java.lang.String, java.lang.String, java.lang.String) + */ + + @Override + public String putPageAttachment(String wikiName, String spaceName, String pageName, String filePath, + String attachmentName) throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + attachmentName = urlEncode(attachmentName); + + AttachmentResources attachmentresources = new AttachmentResources(URLprefix, wikiName, spaceName, pageName); + if (isAuthenticated) { + attachmentresources.setAuthenticaion(username, password); + } + return attachmentresources.putPageAttachment(filePath, attachmentName); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#deletePageAttachment(java.lang.String, java.lang.String, + * java.lang.String, java.lang.String) + */ + + @Override + public String deletePageAttachment(String wikiName, String spaceName, String pageName, String attachmentName) + throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + attachmentName = urlEncode(attachmentName); + + AttachmentResources attachmentresources = new AttachmentResources(URLprefix, wikiName, spaceName, pageName); + if (isAuthenticated) { + attachmentresources.setAuthenticaion(username, password); + } + return attachmentresources.deletePageAttachment(attachmentName); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getPageAttachmentsInHistory(java.lang.String, java.lang.String, + * java.lang.String, java.lang.String) + */ + + @Override + public Attachments getPageAttachmentsInHistory(String wikiName, String spaceName, String pageName, + String pageVersion) throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + + AttachmentResources attachmentresources = new AttachmentResources(URLprefix, wikiName, spaceName, pageName); + if (isAuthenticated) { + attachmentresources.setAuthenticaion(username, password); + } + return attachmentresources.getPageAttachmentsInHistory(pageVersion); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getPageAttachmentsInHistory(java.lang.String, java.lang.String, + * java.lang.String, java.lang.String, java.lang.String) + */ + + @Override + public InputStream getPageAttachmentsInHistory(String wikiName, String spaceName, String pageName, + String pageVersion, String attachmentName) throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + attachmentName = urlEncode(attachmentName); + + AttachmentResources attachmentresources = new AttachmentResources(URLprefix, wikiName, spaceName, pageName); + if (isAuthenticated) { + attachmentresources.setAuthenticaion(username, password); + } + return attachmentresources.getPageAttachmentsInHistory(pageVersion, attachmentName); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getPageAttachmentsInAttachmentHistory(java.lang.String, + * java.lang.String, java.lang.String, java.lang.String) + */ + + @Override + public Attachments getPageAttachmentsInAttachmentHistory(String wikiName, String spaceName, String pageName, + String attachmentName) throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + attachmentName = urlEncode(attachmentName); + + AttachmentResources attachmentresources = new AttachmentResources(URLprefix, wikiName, spaceName, pageName); + if (isAuthenticated) { + attachmentresources.setAuthenticaion(username, password); + } + return attachmentresources.getPageAttachmentsInAttachmentHistory(attachmentName); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getPageAttachmentsInAttachmentHistory(java.lang.String, + * java.lang.String, java.lang.String, java.lang.String, java.lang.String) + */ + + @Override + public InputStream getPageAttachmentsInAttachmentHistory(String wikiName, String spaceName, String pageName, + String attachmentName, String attachmentVersion) throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + attachmentName = urlEncode(attachmentName); + + AttachmentResources attachmentresources = new AttachmentResources(URLprefix, wikiName, spaceName, pageName); + if (isAuthenticated) { + attachmentresources.setAuthenticaion(username, password); + } + return attachmentresources.getPageAttachmentsInAttachmentHistory(attachmentName, attachmentVersion); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getWikiClasses(java.lang.String) + */ + + @Override + public Classes getWikiClasses(String wikiName) throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + + ClassResources classresources = new ClassResources(URLprefix, wikiName); + if (isAuthenticated) { + classresources.setAuthenticaion(username, password); + } + return classresources.getWikiClasses(); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getWikiClasses(java.lang.String, java.lang.String) + */ + + @Override + public Class getWikiClasses(String wikiName, String classname) throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + classname = urlEncode(classname); + + ClassResources classresources = new ClassResources(URLprefix, wikiName); + if (isAuthenticated) { + classresources.setAuthenticaion(username, password); + } + return classresources.getWikiClasses(classname); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getAllPageTranslations(java.lang.String, java.lang.String, + * java.lang.String) + */ + + @Override + public Translations getAllPageTranslations(String wikiName, String spaceName, String pageName) + throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + + TranslationResources translationresources = new TranslationResources(URLprefix, wikiName, spaceName, pageName); + if (isAuthenticated) { + translationresources.setAuthenticaion(username, password); + } + return translationresources.getAllTranslations(); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getPageTranslation(java.lang.String, java.lang.String, + * java.lang.String, java.lang.String) + */ + + @Override + public Page getPageTranslation(String wikiName, String spaceName, String pageName, String language) + throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + + PageResources pageresources = new PageResources(URLprefix, wikiName, spaceName); + if (isAuthenticated) { + pageresources.setAuthenticaion(username, password); + } + return pageresources.getPageTranslation(pageName, language); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getPageHistoryInLanguage(java.lang.String, java.lang.String, + * java.lang.String, java.lang.String) + */ + + @Override + public History getPageHistoryInLanguage(String wikiName, String spaceName, String pageName, String language) + throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + + HistoryResources historyresources = new HistoryResources(URLprefix, wikiName, spaceName, pageName); + if (isAuthenticated) { + historyresources.setAuthenticaion(username, password); + } + return historyresources.getPageHistory(language); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getPageTranslationInHistory(java.lang.String, java.lang.String, + * java.lang.String, java.lang.String, java.lang.String) + */ + + @Override + public Page getPageTranslationInHistory(String wikiName, String spaceName, String pageName, String language, + String version) throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + + PageResources pageresources = new PageResources(URLprefix, wikiName, spaceName); + if (isAuthenticated) { + pageresources.setAuthenticaion(username, password); + } + return pageresources.getPageTranslation(pageName, language, version); + } + + @Override + public boolean existsObject(String wikiName, String spaceName, String pageName, String objectClassname, + int objectNumber) throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + objectClassname = urlEncode(objectClassname); + String objNumber = urlEncode(objectNumber + ""); + + ObjectResources objectresources = new ObjectResources(URLprefix, wikiName, spaceName, pageName); + if (isAuthenticated) { + objectresources.setAuthenticaion(username, password); + } + boolean val = objectresources.exists(objectClassname, objNumber); + return val; + + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#addObject(java.lang.String, java.lang.String, java.lang.String, + * org.xwiki.android.resources.Object) + */ + + @Override + public String addObject(String wikiName, String spaceName, String pageName, Object object) + throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + + ObjectResources objectresources = new ObjectResources(URLprefix, wikiName, spaceName, pageName); + if (isAuthenticated) { + objectresources.setAuthenticaion(username, password); + } + return objectresources.addObject(object); + } + + /** + * Update object in a page + * + * @param objectClassname name of the class of the object + * @param objectNumber number of the object in the class + * @param object Object object to be updated in the page + * @return status of the HTTP put request + * @throws RestConnectionException + * @throws RestException + */ + @Override + public String updateObject(String wikiName, String spaceName, String pageName, String objectClassname, + int objectNumber, Object object) throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + + ObjectResources objectresources = new ObjectResources(URLprefix, wikiName, spaceName, pageName); + if (isAuthenticated) { + objectresources.setAuthenticaion(username, password); + } + return objectresources.updateObject(objectClassname, "" + objectNumber, object); + + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getAllObjects(java.lang.String, java.lang.String, java.lang.String) + */ + + @Override + public Objects getAllObjects(String wikiName, String spaceName, String pageName) throws RestConnectionException, + RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + + ObjectResources objectresources = new ObjectResources(URLprefix, wikiName, spaceName, pageName); + if (isAuthenticated) { + objectresources.setAuthenticaion(username, password); + } + return objectresources.getAllObjects(); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getObjectsInClass(java.lang.String, java.lang.String, + * java.lang.String, java.lang.String) + */ + + @Override + public Objects getObjectsInClass(String wikiName, String spaceName, String pageName, String objectClassname) + throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + objectClassname = urlEncode(objectClassname); + + ObjectResources objectresources = new ObjectResources(URLprefix, wikiName, spaceName, pageName); + if (isAuthenticated) { + objectresources.setAuthenticaion(username, password); + } + return objectresources.getObjectsInClassname(objectClassname); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getObject(java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, java.lang.String) + */ + + @Override + public Object getObject(String wikiName, String spaceName, String pageName, String objectClassname, int objectNumber) + throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + objectClassname = urlEncode(objectClassname); + String objectNumberStr = urlEncode("" + objectNumber); + + ObjectResources objectresources = new ObjectResources(URLprefix, wikiName, spaceName, pageName); + if (isAuthenticated) { + objectresources.setAuthenticaion(username, password); + } + return objectresources.getObject(objectClassname, objectNumberStr); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#deleteObject(java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, java.lang.String) + */ + + @Override + public String deleteObject(String wikiName, String spaceName, String pageName, String objectClassname, + String objectNumber) throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + objectClassname = urlEncode(objectClassname); + objectNumber = urlEncode(objectNumber); + + ObjectResources objectresources = new ObjectResources(URLprefix, wikiName, spaceName, pageName); + if (isAuthenticated) { + objectresources.setAuthenticaion(username, password); + } + return objectresources.deleteObject(objectClassname, objectNumber); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getObjectAllProperties(java.lang.String, java.lang.String, + * java.lang.String, java.lang.String, java.lang.String) + */ + + @Override + public Properties getObjectAllProperties(String wikiName, String spaceName, String pageName, + String objectClassname, String objectNumber) throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + objectClassname = urlEncode(objectClassname); + objectNumber = urlEncode(objectNumber); + + ObjectResources objectresources = new ObjectResources(URLprefix, wikiName, spaceName, pageName); + if (isAuthenticated) { + objectresources.setAuthenticaion(username, password); + } + return objectresources.getObjectProperties(objectClassname, objectNumber); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#getObjectProperty(java.lang.String, java.lang.String, + * java.lang.String, java.lang.String, java.lang.String, java.lang.String) + */ + + @Override + public Property getObjectProperty(String wikiName, String spaceName, String pageName, String objectClassname, + String objectNumber, String propertyName) throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + objectClassname = urlEncode(objectClassname); + objectNumber = urlEncode(objectNumber); + propertyName = urlEncode(propertyName); + + ObjectResources objectresources = new ObjectResources(URLprefix, wikiName, spaceName, pageName); + if (isAuthenticated) { + objectresources.setAuthenticaion(username, password); + } + return objectresources.getObjectProperty(objectClassname, objectNumber, propertyName); + } + + /* + * (non-Javadoc) + * @see org.xwiki.android.xmlrpc.XWikiRestfulAPI#addProperty(java.lang.String, java.lang.String, java.lang.String, + * java.lang.String, java.lang.String, org.xwiki.android.resources.Property) + */ + + @Override + public String addObjectProperty(String wikiName, String spaceName, String pageName, String objectClassname, + String objectNumber, Property property) throws RestConnectionException, RestException + { + wikiName = urlEncode(wikiName); + spaceName = urlEncode(spaceName); + pageName = urlEncode(pageName); + objectClassname = urlEncode(objectClassname); + objectNumber = urlEncode(objectNumber); + + ObjectResources objectresources = new ObjectResources(URLprefix, wikiName, spaceName, pageName); + if (isAuthenticated) { + objectresources.setAuthenticaion(username, password); + } + return objectresources.addObjectProperty(objectClassname, objectNumber, property); + } + + // connection methods + + public PageResources pageOperations(String wikiName, String spaceName) + { + PageResources pageOps= new PageResources(URLprefix, wikiName, spaceName); + if (isAuthenticated) { + pageOps.setAuthenticaion(username, password); + } + return pageOps; + } + + public ObjectResources objectOperations(String wikiName, String spaceName, String pageName) + { + ObjectResources ops= new ObjectResources(spaceName, wikiName, spaceName, pageName); + if (isAuthenticated) { + ops.setAuthenticaion(username, password); + } + return ops; + } + + public CommentResources commentOperations(String wikiName, String spaceName, String pageName) + { + CommentResources ops= new CommentResources(spaceName, wikiName, spaceName, pageName); + if (isAuthenticated) { + ops.setAuthenticaion(username, password); + } + return ops; + } + + public TagResources tagOperations(String wikiName, String spaceName, String pageName) + { + TagResources ops= new TagResources(spaceName, wikiName, spaceName, pageName); + if (isAuthenticated) { + ops.setAuthenticaion(username, password); + } + return ops; + } + + public AttachmentResources attachmentOperations(String wikiName, String spaceName, String pageName) + { + AttachmentResources ops= new AttachmentResources(spaceName, wikiName, spaceName, pageName); + if (isAuthenticated) { + ops.setAuthenticaion(username, password); + } + return ops; + } + + public HistoryResources historyOperations(String wikiName, String spaceName, String pageName) + { + HistoryResources ops= new HistoryResources(spaceName, wikiName, spaceName, pageName); + if (isAuthenticated) { + ops.setAuthenticaion(username, password); + } + return ops; + } + + public XWikiAPI getBaseAPI() + { + return this; + } + + public boolean isShutDown() + { + return false; + } + + public void shutDown() + { + Log.e(TAG, + "not implemented: should release any resources: Also see that HttpConnector does not release resources"); + // httpclient.getConnectionManager().shutdown(); + // refer: http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html + // throw new UnsupportedOperationException("should be releasing resources."); + } + +} diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/XWikiRestfulAPI.java b/xwiki-android-rest/src/org/xwiki/android/rest/XWikiRestfulAPI.java new file mode 100644 index 0000000..9990ef7 --- /dev/null +++ b/xwiki-android-rest/src/org/xwiki/android/rest/XWikiRestfulAPI.java @@ -0,0 +1,463 @@ +package org.xwiki.android.rest; + +import java.io.InputStream; + +import org.xwiki.android.resources.Attachments; +import org.xwiki.android.resources.Class; +import org.xwiki.android.resources.Classes; +import org.xwiki.android.resources.Comment; +import org.xwiki.android.resources.Comments; +import org.xwiki.android.resources.History; +import org.xwiki.android.resources.Object; +import org.xwiki.android.resources.Objects; +import org.xwiki.android.resources.Page; +import org.xwiki.android.resources.Pages; +import org.xwiki.android.resources.Properties; +import org.xwiki.android.resources.Property; +import org.xwiki.android.resources.SearchResults; +import org.xwiki.android.resources.Spaces; +import org.xwiki.android.resources.Tag; +import org.xwiki.android.resources.Tags; +import org.xwiki.android.resources.Translations; +import org.xwiki.android.resources.Wikis; +/** + * + * @author xwiki gsoc 2012 + * + */ +public interface XWikiRestfulAPI { + + /** + * Set the user credentials for accession + * + * @param username username of the user account in XWiki + * @param password password of the user account in XWiki + */ + void setAuthentication(String username, String password); + + /** + * @param wikiName name of the Wiki + * @param keyword text to search + * @return Search results of the searched keyword within Wiki contents + */ + SearchResults searchInWiki(String wikiName, String keyword) throws RestConnectorException; + + /** + * @param wikiName name of the Wiki + * @param spaceName name of the space + * @param keyword text to search + * @return Search results of the searched keyword in provided space + */ + SearchResults searchInSpace(String wikiName, + String spaceName, String keyword)throws RestConnectorException; + + /** + * @return list of wikis in the provided XWiki URL domain + */ + Wikis getWikis()throws RestConnectorException; + + /** + * @param wikiName name of the Wiki + * @return all the tags used in the wiki + */ + Tags getWikiTags(String wikiName)throws RestConnectorException; + + /** + * @param wikiName name of the Wiki + * @return lists all the classes in the specified Wiki + */ + Classes getWikiClasses(String wikiName)throws RestConnectorException; + + /** + * @param wikiName name of the Wiki + * @param classname name of the class + * @return Class of the provided classname in the specified Wiki + */ + Class getWikiClasses(String wikiName, String classname)throws RestConnectorException; + + /** + * @param wikiName name of the wiki + * @return list of spaces in the provided Wiki + */ + Spaces getSpaces(String wikiName)throws RestConnectorException; + + /** + * @param wikiName name of the wiki + * @param spaceName name of the space + * @return list of all the pages in specific Wiki and Space + */ + Pages getAllPages(String wikiName, String spaceName)throws RestConnectorException; + + /** + * @param wikiName name of the wiki + * @param spaceName name of the space + * @param pageName name of the page + * @return Page object according to the field values + */ + Page getPage(String wikiName, String spaceName, + String pageName)throws RestConnectorException; + + /** + * Add page to the server according to the provided field values + * + * @param wikiName name of the wiki + * @param spaceName name of the space + * @param pageName name of the page + * @param page Page object which is to be added + * @return status of the HTTP response + */ + String addPage(String wikiName, String spaceName, + String pageName, Page page)throws RestConnectorException; + + /** + * Delete page in the server + * + * @param wikiName name of the Wiki + * @param spaceName name of the space + * @param pageName name of the page + * @return status of the HTTP response + */ + String deletePage(String wikiName, String spaceName, + String pageName)throws RestConnectorException; + + /** + * Delete page translation + * + * @param wikiName name of the Wiki + * @param spaceName name of the space + * @param pageName name of the page + * @param language specific language to delete + * @return status of the HTTP response + */ + String deletePage(String wikiName, String spaceName, + String pageName, String language)throws RestConnectorException; + + /** + * @param wikiName name of the Wiki + * @param spaceName name of the space + * @param pageName name of the page + * @return history of the page according to the field values + */ + History getPageHistory(String wikiName, + String spaceName, String pageName)throws RestConnectorException; + + /** + * @param wikiName name of the Wiki + * @param spaceName name of the space + * @param pageName name of the page + * @param version version of the page + * @return Page of the specified version + */ + Page getPageInVersionHistory(String wikiName, + String spaceName, String pageName, String version)throws RestConnectorException; + + /** + * @param wikiName name of the Wiki + * @param spaceName name of the space + * @param pageName name of the page + * @return Children pages of the specific page + */ + Pages getPageChildren(String wikiName, + String spaceName, String pageName)throws RestConnectorException; + + /** + * @param wikiName name of the Wiki + * @param spaceName name of the space + * @param pageName name of the page + * @return Tags of the page + */ + Tags getPageTags(String wikiName, String spaceName, + String pageName)throws RestConnectorException; + + /** + * Adds page tag to the provided page + * + * @param wikiName name of the Wiki + * @param spaceName name of the space + * @param pageName name of the page + * @param tag tag to be added + * @return status of the HTTP response + */ + String addPageTag(String wikiName, String spaceName, + String pageName, Tag tag)throws RestConnectorException; + + /** + * @param wikiName name of the Wiki + * @param spaceName name of the space + * @param pageName name of the page + * @return all the comments in the specific page + */ + Comments getPageComments(String wikiName, + String spaceName, String pageName)throws RestConnectorException; + + /** + * Add comment to the page + * + * @param wikiName name of the Wiki + * @param spaceName name of the space + * @param pageName name of the page + * @param comment Comment object to be added + * @return status of the HTTP response + */ + String addPageComment(String wikiName, String spaceName, + String pageName, Comment comment)throws RestConnectorException; + + /** + * @param wikiName name of the Wiki + * @param spaceName name of the space + * @param pageName name of the page + * @param commentId ID of the comment + * @return page comment according to the comment ID + */ + Comment getPageComments(String wikiName, + String spaceName, String pageName, String commentId)throws RestConnectorException; + + /** + * @param wikiName name of the Wiki + * @param spaceName name of the space + * @param pageName name of the page + * @param version version of the page + * @return All the comments of the page specific version + */ + Comments getPageCommentsInHistory(String wikiName, + String spaceName, String pageName, String version)throws RestConnectorException; + + /** + * @param wikiName name of the Wiki + * @param spaceName name of the space + * @param pageName name of the page + * @param version version of the page + * @param commentId ID of the comment + * @return comments Comments of specific comment ID in specific page history version + */ + Comments getPageCommentsInHistory(String wikiName, + String spaceName, String pageName, String version, String commentId)throws RestConnectorException; + + /** + * @param wikiName name of the Wiki + * @param spaceName name of the space + * @param pageName name of the page + * @return list all the attachments in a specific page + */ + Attachments getAllPageAttachments(String wikiName, + String spaceName, String pageName)throws RestConnectorException; + + /** + * Gets a stream of data of a attachment + * + * @param wikiName name of the Wiki + * @param spaceName name of the space + * @param pageName name of the page + * @param attachmentName filename of the attachment. + * @return InputStream of the attachment raw data + */ + InputStream getPageAttachment(String wikiName, + String spaceName, String pageName, String attachmentName)throws RestConnectorException; + + /** + * Add attachment to a page + * + * @param wikiName name of the Wiki + * @param spaceName name of the space + * @param pageName name of the page + * @param filePath absolute path to the attachment in internal/external memory of the device + * @param attachmentName filename of the attachment + * @return status of the HTTP response + */ + String addPageAttachment(String wikiName, String spaceName, + String pageName, String filePath, String attachmentName)throws RestConnectorException; + + /** + * Delete the page attachment by its name + * + * @param wikiName name of the Wiki + * @param spaceName name of the space + * @param pageName name of the page + * @param attachmentName name of the attachment + * @return status of the HTTP response + */ + String deletePageAttachment(String wikiName, + String spaceName, String pageName, String attachmentName)throws RestConnectorException; + + /** + * @param wikiName name of the Wiki + * @param spaceName name of the space + * @param pageName name of the page + * @param pageVersion version of the page + * @return list of all attachments in the specified page history version + */ + Attachments getPageAttachmentsInHistory( + String wikiName, String spaceName, String pageName, + String pageVersion)throws RestConnectorException; + + /** + * @param wikiName name of the Wiki + * @param spaceName name of the space + * @param pageName name of the page + * @param pageVersion version of the page + * @param attachmentName filename of the attachment + * @return InputStream of attachment raw data in a specific page history version + */ + InputStream getPageAttachmentsInHistory( + String wikiName, String spaceName, String pageName, + String pageVersion, String attachmentName)throws RestConnectorException; + + /** + * @param wikiName name of the Wiki + * @param spaceName name of the space + * @param pageName name of the page + * @param attachmentName filename of the attachment + * @return list of attachment version history of a specific attachment + */ + Attachments getPageAttachmentsInAttachmentHistory( + String wikiName, String spaceName, String pageName, + String attachmentName)throws RestConnectorException; + + /** + * @param wikiName name of the Wiki + * @param spaceName name of the space + * @param pageName name of the page + * @param attachmentName filename of the attachment + * @param attachmentVersion version of the attachment + * @return Stream of attachment raw data in a specific attachment version of a specified page + */ + InputStream getPageAttachmentsInAttachmentHistory( + String wikiName, String spaceName, String pageName, + String attachmentName, String attachmentVersion)throws RestConnectorException; + + /** + * @param wikiName name of the Wiki + * @param spaceName name of the space + * @param pageName name of the page + * @return list all the Translations of a specific page + */ + Translations getAllPageTranslations(String wikiName, + String spaceName, String pageName)throws RestConnectorException; + + /** + * @param wikiName name of the Wiki + * @param spaceName name of the space + * @param pageName name of the page + * @param language language name of the page translations + * @return Page of the geted language + */ + Page getPageTranslation(String wikiName, + String spaceName, String pageName, String language)throws RestConnectorException; + + /** + * @param wikiName name of the Wiki + * @param spaceName name of the space + * @param pageName name of the page + * @param language language of the page + * @return Page history versions in a given language + */ + History getPageHistoryInLanguage(String wikiName, + String spaceName, String pageName, String language)throws RestConnectorException; + + /** + * @param wikiName name of the Wiki + * @param spaceName name of the space + * @param pageName name of the page + * @param language language of the page + * @param version version of the page + * @return Translated page of the given history version + */ + Page getPageTranslationInHistory(String wikiName, + String spaceName, String pageName, String language, String version)throws RestConnectorException; + + /** + * Adds provided object to the given page + * + * @param wikiName name of the Wiki + * @param spaceName name of the space + * @param pageName name of the page + * @param object Object to be added to page + * @return status of the HTTP response + */ + String addObject(String wikiName, String spaceName, + String pageName, Object object)throws RestConnectorException; + + /** + * @param wikiName name of the Wiki + * @param spaceName name of the space + * @param pageName name of the page + * @return All the objects of the specified page + */ + Objects getAllObjects(String wikiName, + String spaceName, String pageName)throws RestConnectorException; + + /** + * @param wikiName name of the Wiki + * @param spaceName name of the space + * @param pageName name of the page + * @param objectClassname class name of the objects + * @return All the objects which have given class name of the specified page + */ + Objects getObjectsInClass(String wikiName, + String spaceName, String pageName, String objectClassname)throws RestConnectorException; + + /** + * @param wikiName name of the Wiki + * @param spaceName name of the space + * @param pageName name of the page + * @param objectClassname class name of the objects + * @param objectNumber number of the object in the specific class + * @return Object of the given class name and object number of the specified page + */ + Object getObject(String wikiName, String spaceName, + String pageName, String objectClassname, String objectNumber)throws RestConnectorException; + + /** + * Deletes the given object. Object can be selected using class name and the object number + * + * @param wikiName name of the Wiki + * @param spaceName name of the space + * @param pageName name of the page + * @param objectClassname class name of the objects + * @param objectNumber number of the object in the specified class + * @return status of the HTTP response of the delete operation + */ + String deleteObject(String wikiName, String spaceName, + String pageName, String objectClassname, String objectNumber)throws RestConnectorException; + + /** + * @param wikiName name of the Wiki + * @param spaceName name of the space + * @param pageName name of the page + * @param objectClassname class name of the objects + * @param objectNumber number of the object in the specified class + * @return lists all the properties of a specific object + */ + Properties getObjectAllProperties(String wikiName, + String spaceName, String pageName, String objectClassname, + String objectNumber)throws RestConnectorException; + + /** + * @param wikiName name of the Wiki + * @param spaceName name of the space + * @param pageName name of the page + * @param objectClassname class name of objects + * @param objectNumber number of the object in the page + * @param propertyName name of the property in the object + * @return Property out of list of properties in a given object of a page + */ + Property getObjectProperty(String wikiName, + String spaceName, String pageName, String objectClassname, + String objectNumber, String propertyName)throws RestConnectorException; + + /** + * Adds the property to the object of a page + * + * @param wikiName name of the Wiki + * @param spaceName name of the space + * @param pageName name of the page + * @param objectClassname class name of the objects + * @param objectNumber number of the object + * @param property Property object to be added to the object in a page + * @return status of the HTTP response + */ + String addObjectProperty(String wikiName, String spaceName, + String pageName, String objectClassname, String objectNumber, + Property property)throws RestConnectorException; + +} \ No newline at end of file diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/rpc/AttachmentOperations.java b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/AttachmentOperations.java new file mode 100644 index 0000000..e259087 --- /dev/null +++ b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/AttachmentOperations.java @@ -0,0 +1,99 @@ +package org.xwiki.android.rest.rpc; + +import java.io.InputStream; + +import org.xwiki.android.resources.Attachments; +import org.xwiki.android.rest.RestConnectionException; +import org.xwiki.android.rest.RestException; + +public interface AttachmentOperations +{ + + /** + * Gets Attachments object according to the provided field values in constructor + * + * @return Attachments object acquired according to the wiki, space & page names + * @throws RestConnectionException + * @throws RestException + */ + public abstract Attachments getAllPageAttachments() throws RestConnectionException, RestException; + + /** + * Gets a stream data of the requested attachment + * + * @param attachmentName filename of the attachment in the page + * @return InputStream of the attachment data + * @throws RestConnectionException + * @throws RestException + */ + public abstract InputStream getPageAttachment(String attachmentName) throws RestConnectionException, RestException; + + /** + * Add file to the XWiki stored in the internal/external memory + * + * @param filePath absolute path of the file ex: "/sdcard/data/" + * @param attachmentName name of the file name + * @return status of the HTTP response + * @throws RestConnectionException + * @throws RestException + */ + public abstract String putPageAttachment(String filePath, String attachmentName) throws RestConnectionException, + RestException; + + /** + * Gets Attachments object in the provided version of page + * + * @param version version of the page + * @return Attachments object acquired according to the wiki, space & page names + * @throws RestConnectionException + * @throws RestException + */ + public abstract Attachments getPageAttachmentsInHistory(String version) throws RestConnectionException, + RestException; + + /** + * Gets a stream data of the requested attachment in the provided page version + * + * @param version version of the page + * @param attachmentName file name of the attachement + * @return InputStream of the attachment data in provided page version + * @throws RestConnectionException + * @throws RestException + */ + public abstract InputStream getPageAttachmentsInHistory(String version, String attachmentName) + throws RestConnectionException, RestException; + + /** + * Gets the history of the attachment + * + * @param attachmentName filename of the attachment + * @return Attachments object with the version details of the attachment + * @throws RestConnectionException + * @throws RestException + */ + public abstract Attachments getPageAttachmentsInAttachmentHistory(String attachmentName) + throws RestConnectionException, RestException; + + /** + * Gets the attachment of a specific attachment version + * + * @param attachmentName filename of the attachment + * @param attachmentVersion version of the attachment + * @return InputStream of the provided attachment version + * @throws RestConnectionException + * @throws RestException + */ + public abstract InputStream getPageAttachmentsInAttachmentHistory(String attachmentName, String attachmentVersion) + throws RestConnectionException, RestException; + + /** + * Deletes attachment file from the XWiki server + * + * @param attachmentName filename of the attachment + * @return Status code of the HTTP response + * @throws RestConnectionException + * @throws RestException + */ + public abstract String deletePageAttachment(String attachmentName) throws RestConnectionException, RestException; + +} diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/rpc/ClassOperations.java b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/ClassOperations.java new file mode 100644 index 0000000..f065086 --- /dev/null +++ b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/ClassOperations.java @@ -0,0 +1,26 @@ +package org.xwiki.android.rest.rpc; + +import org.xwiki.android.resources.Class; +import org.xwiki.android.resources.Classes; +import org.xwiki.android.rest.RestConnectionException; +import org.xwiki.android.rest.RestException; + +public interface ClassOperations +{ + + /** + * @return list of all the Classes in the Wiki + * @throws RestConnectionException + * @throws RestException + */ + public abstract Classes getWikiClasses() throws RestConnectionException, RestException; + + /** + * @param classname name of the Class + * @return Specific class with the provided class name + * @throws RestConnectionException + * @throws RestException + */ + public abstract Class getWikiClasses(String classname) throws RestConnectionException, RestException; + +} diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/rpc/CommentOperations.java b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/CommentOperations.java new file mode 100644 index 0000000..7267432 --- /dev/null +++ b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/CommentOperations.java @@ -0,0 +1,58 @@ +package org.xwiki.android.rest.rpc; + +import org.xwiki.android.resources.Comment; +import org.xwiki.android.resources.Comments; +import org.xwiki.android.rest.RestConnectionException; +import org.xwiki.android.rest.RestException; + +public interface CommentOperations +{ + + /** + * @return Comments object of the page + * @throws RestConnectionException + * @throws RestException + */ + public abstract Comments getPageComments() throws RestConnectionException, RestException; + + public abstract boolean exists(int commentId) throws RestConnectionException, RestException; + + /** + * @param commentId ID of the comment in the page + * @return comment of a page selected using comment ID + * @throws RestConnectionException + * @throws RestException + */ + public abstract Comment getPageComment(int commentId) throws RestConnectionException, RestException; + + /** + * @param version version of the page + * @return list of comments as a Comments object in a specific page history version + * @throws RestConnectionException + * @throws RestException + */ + public abstract Comments getPageCommentsInHistory(String version) throws RestConnectionException, RestException; + + /** + * @param version version of the page + * @param commentId ID of the comment in the page + * @return Comment in a specific page history version + * @throws RestConnectionException + * @throws RestException + */ + public abstract Comments getPageCommentsInHistory(String version, String commentId) throws RestConnectionException, + RestException; + + /** + * Adds comment to the page + * + * @param comment Comment object to be added + * @return comment id. + * @throws RestConnectionException + * @throws RestException + */ + public abstract int addPageComment(Comment comment) throws RestConnectionException, RestException; + + public abstract Comment addPageCommentForResource(Comment comment) throws RestConnectionException, RestException; + +} diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/rpc/HistoryOperations.java b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/HistoryOperations.java new file mode 100644 index 0000000..66d493e --- /dev/null +++ b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/HistoryOperations.java @@ -0,0 +1,25 @@ +package org.xwiki.android.rest.rpc; + +import org.xwiki.android.resources.History; +import org.xwiki.android.rest.RestConnectionException; +import org.xwiki.android.rest.RestException; + +public interface HistoryOperations +{ + + /** + * @return version details of the page as a History object + * @throws RestConnectionException + * @throws RestException + */ + public abstract History getPageHistory() throws RestConnectionException, RestException; + + /** + * @param language translation language name of the page + * @return page history of a page translation + * @throws RestConnectionException + * @throws RestException + */ + public abstract History getPageHistory(String language) throws RestConnectionException, RestException; + +} diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/rpc/ObjectOperations.java b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/ObjectOperations.java new file mode 100644 index 0000000..58eaee9 --- /dev/null +++ b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/ObjectOperations.java @@ -0,0 +1,110 @@ +package org.xwiki.android.rest.rpc; + +import org.xwiki.android.resources.Object; +import org.xwiki.android.resources.Objects; +import org.xwiki.android.resources.Properties; +import org.xwiki.android.resources.Property; +import org.xwiki.android.rest.RestConnectionException; +import org.xwiki.android.rest.RestException; + +public interface ObjectOperations +{ + + public abstract boolean exists(String objectClassname, String objectNumber) throws RestConnectionException, + RestException; + + /** + * @return list of all the Objects in a page + * @throws RestConnectionException + * @throws RestException + */ + public abstract Objects getAllObjects() throws RestConnectionException, RestException; + + /** + * Adds object to the page + * + * @param object Object object to be added to the page + * @return status of th HTTP post request + * @throws RestConnectionException + * @throws RestException + */ + public abstract String addObject(Object object) throws RestConnectionException, RestException; + + /** + * @param objectClassname name of the class + * @return list of objects in a specific class of a page + * @throws RestConnectionException + * @throws RestException + */ + public abstract Objects getObjectsInClassname(String objectClassname) throws RestConnectionException, RestException; + + /** + * @param objectClassname name of the class in the page + * @param objectNumber number of the object in the specified class + * @return selected Object object in the page + * @throws RestConnectionException + * @throws RestException + */ + public abstract Object getObject(String objectClassname, String objectNumber) throws RestConnectionException, + RestException; + + /** + * Update object in a page + * + * @param objectClassname name of the class of the object + * @param objectNumber number of the object in the class + * @param object Object object to be updated in the page + * @return status of the HTTP put request + * @throws RestConnectionException + * @throws RestException + */ + public abstract String updateObject(String objectClassname, String objectNumber, Object object) + throws RestConnectionException, RestException; + + /** + * Deletes the specified object in the page + * + * @param objectClassname name of the class in the page + * @param objectNumber number of the object in the class + * @return status of HTTP resonce in delete request + * @throws RestConnectionException + * @throws RestException + */ + public abstract String deleteObject(String objectClassname, String objectNumber) throws RestConnectionException, + RestException; + + /** + * @param objectClassname class name of the object in a page + * @param objectNumber number of the object in the class + * @return list of properties as a Properties object in a object + * @throws RestConnectionException + * @throws RestException + */ + public abstract Properties getObjectProperties(String objectClassname, String objectNumber) + throws RestConnectionException, RestException; + + /** + * Adds a property to a object in a page + * + * @param objectClassname class name of the object + * @param objectNumber number of the object in the class + * @param property Property object to be added to the Object + * @return status of the HTTP put request + * @throws RestConnectionException + * @throws RestException + */ + public abstract String addObjectProperty(String objectClassname, String objectNumber, Property property) + throws RestConnectionException, RestException; + + /** + * @param objectClassname class name of the objects + * @param objectNumber number of the object in the class + * @param propertyName name of the required property + * @return Specific property of a object in a page + * @throws RestConnectionException + * @throws RestException + */ + public abstract Property getObjectProperty(String objectClassname, String objectNumber, String propertyName) + throws RestConnectionException, RestException; + +} diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/rpc/PageOperations.java b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/PageOperations.java new file mode 100644 index 0000000..436b33f --- /dev/null +++ b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/PageOperations.java @@ -0,0 +1,110 @@ +package org.xwiki.android.rest.rpc; + +import org.xwiki.android.resources.Page; +import org.xwiki.android.resources.Pages; +import org.xwiki.android.rest.RestConnectionException; +import org.xwiki.android.rest.RestException; + +public interface PageOperations +{ + + /** + * @return all the pages as a Pages object in the specified space + * @throws RestConnectionException + * @throws RestException + */ + public abstract Pages getAllPages() throws RestConnectionException, RestException; + + public abstract boolean exists(String pageName) throws RestConnectionException, RestException; + + /** + * @param pageName name of the page + * @return requested page as a Page object + * @throws RestConnectionException + * @throws RestException + */ + public abstract Page getPage(String pageName) throws RestConnectionException, RestException; + + /** + * Adds or Modify the page + * + * @param page Page object to be added if not existing in the space or modified if it existing in the space + * @return status of the HTTP put request + * @throws RestConnectionException + * @throws RestException + */ + public abstract String addPage(Page page) throws RestConnectionException, RestException; + + /** + * Deletes the page by providing name of the page + * + * @param pageName name of the page + * @return status of the HTTP delete request + * @throws RestConnectionException + * @throws RestException + */ + public abstract String deletePage(String pageName) throws RestConnectionException, RestException; + + /** + * @param pageName name of the page + * @param version history version of the page + * @return requested version of the page + * @throws RestConnectionException + * @throws RestException + */ + public abstract Page getPageHistoryOnVersion(String pageName, String version) throws RestConnectionException, + RestException; + + /** + * @param pageName name of the page + * @return children of the page as a Pages object + * @throws RestConnectionException + * @throws RestException + */ + public abstract Pages getPageChildren(String pageName) throws RestConnectionException, RestException; + + /** + * @param pageName name of the page + * @param language language name of the page + * @return Translated page of the provided language + * @throws RestConnectionException + * @throws RestException + */ + public abstract Page getPageTranslation(String pageName, String language) throws RestConnectionException, + RestException; + + /** + * Adds page translation to XWiki + * + * @param page Page object of the new translation + * @param language translated language name of the page + * @return status of the HTTP put request + * @throws RestConnectionException + * @throws RestException + */ + public abstract String addPageTranslation(Page page, String language) throws RestConnectionException, RestException; + + /** + * Deletes specific translation page + * + * @param pageName name of the page + * @param language translated language name of the page + * @return status of the HTTP delete request + * @throws RestConnectionException + * @throws RestException + */ + public abstract String deletePageTranslation(String pageName, String language) throws RestConnectionException, + RestException; + + /** + * @param pageName name of the page + * @param language translated language name of the page + * @param version version of the page + * @return translated page of the spcific page history version + * @throws RestConnectionException + * @throws RestException + */ + public abstract Page getPageTranslation(String pageName, String language, String version) + throws RestConnectionException, RestException; + +} diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/rpc/README b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/README new file mode 100644 index 0000000..2c00157 --- /dev/null +++ b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/README @@ -0,0 +1,19 @@ +Under construction. +-------------------- +New requirements came as the RAL was under development. +* We must be able to process results from put post methods. + ex: we add a new comment to a page. We need to add a reply comment to that comment. We should have processed the resp for earlier + comment posting and extracted its id. +* there are a lot of repetitive code that can be reduced using generic code. (see how toXml, buileComment like methods in all *Resource classes was extracted to 1 single method in XmlRestClient) + + + +* Also the earlier implementation created a DefaultHttpClient for every single rpc call. +Here we set a single HttpClient with a pooled connection manager for each RestClient. The HttpClient must continue until the +RestClient shuts down. + +! after completion , Replace the XmlRestCient to be the rest client used by RestFulManger. +! then we can write ral.algo.---- classes for parallel uploads, downloads. + + +// Todo redefine add** , update** methods in each **Operations interface. \ No newline at end of file diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/rpc/RestClient.java b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/RestClient.java new file mode 100644 index 0000000..2a05eb2 --- /dev/null +++ b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/RestClient.java @@ -0,0 +1,22 @@ +package org.xwiki.android.rest.rpc; + + +public interface RestClient +{ + + XWikiAPI getBaseAPI(); + + public PageOperations pageOperations(String wikiName, String spaceName); + + public ObjectOperations objectOperations(String wikiName, String spaceName, String pageName); + + public CommentOperations commentOperations(String wikiName, String spaceName, String pageName); + + public TagOperations tagOperations(String wikiName, String spaceName, String pageName); + + public AttachmentOperations attachmentOperations(String wikiName, String spaceName, String pageName); + + public HistoryOperations historyOperations(String wikiName, String spaceName, String pageName); +} + + diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/rpc/SearchOperations.java b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/SearchOperations.java new file mode 100644 index 0000000..3bbaab6 --- /dev/null +++ b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/SearchOperations.java @@ -0,0 +1,31 @@ +package org.xwiki.android.rest.rpc; + +import org.xwiki.android.resources.SearchResults; +import org.xwiki.android.rest.RestConnectionException; +import org.xwiki.android.rest.RestException; + +public interface SearchOperations +{ + + /** + * @param wikiName name of the Wiki of space + * @param spaceName name of the space to search + * @param keyword searching keyword/text + * @return list of search results as a SearchResults object + * @throws RestConnectionException + * @throws RestException + */ + public abstract SearchResults doSpacesSearch(String wikiName, String spaceName, String keyword) + throws RestConnectionException, RestException; + + /** + * @param wikiName name of the Wik to search + * @param keyword searching keyword/text to search + * @return list of search results as a SearchResults object + * @throws RestConnectionException + * @throws RestException + */ + public abstract SearchResults doWikiSearch(String wikiName, String keyword) throws RestConnectionException, + RestException; + +} diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/rpc/SpaceOperations.java b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/SpaceOperations.java new file mode 100644 index 0000000..5ea3703 --- /dev/null +++ b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/SpaceOperations.java @@ -0,0 +1,21 @@ +package org.xwiki.android.rest.rpc; + +import org.xwiki.android.resources.Spaces; +import org.xwiki.android.rest.RestConnectionException; +import org.xwiki.android.rest.RestException; + +public interface SpaceOperations +{ + + /** + * @return list of spaces in the specified Wiki + * @throws RestConnectionException + * @throws RestException + */ + public abstract Spaces getSpaces() throws RestConnectionException, RestException; + +} + + + + diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/rpc/TagOperations.java b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/TagOperations.java new file mode 100644 index 0000000..a9c7f5f --- /dev/null +++ b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/TagOperations.java @@ -0,0 +1,33 @@ +package org.xwiki.android.rest.rpc; + +import org.xwiki.android.resources.Tag; +import org.xwiki.android.resources.Tags; +import org.xwiki.android.rest.RestConnectionException; +import org.xwiki.android.rest.RestException; + +public interface TagOperations +{ + + /** + * Gets all the tags either from wiki or from the page. If only the URL & Wiki name fields are provided then method + * will return wiki tags and if space name and page name is provided it will return page tags + * + * @return list of all tags as a Tags object + * @throws RestConnectionException + * @throws RestException + */ + public abstract Tags getTags() throws RestConnectionException, RestException; + + /** + * Adds tag to the wiki or the page depending on the fields provided in the constructor + * + * @param tag Tag object to be added + * @return statsu of the HTTP put request + * @throws RestConnectionException + * @throws RestException + */ + public abstract String addTag(Tag tag) throws RestConnectionException, RestException; + + public abstract String setTags(Tags tags) throws RestConnectionException, RestException; + +} diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/rpc/TranslationOperations.java b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/TranslationOperations.java new file mode 100644 index 0000000..b6c9b70 --- /dev/null +++ b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/TranslationOperations.java @@ -0,0 +1,17 @@ +package org.xwiki.android.rest.rpc; + +import org.xwiki.android.resources.Translations; +import org.xwiki.android.rest.RestConnectionException; +import org.xwiki.android.rest.RestException; + +public interface TranslationOperations +{ + + /** + * @return list of all the translations are included in Translations object + * @throws RestConnectionException + * @throws RestException + */ + public abstract Translations getAllTranslations() throws RestConnectionException, RestException; + +} diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/rpc/WikiOperations.java b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/WikiOperations.java new file mode 100644 index 0000000..a5d10ff --- /dev/null +++ b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/WikiOperations.java @@ -0,0 +1,17 @@ +package org.xwiki.android.rest.rpc; + +import org.xwiki.android.resources.Wikis; +import org.xwiki.android.rest.RestConnectionException; +import org.xwiki.android.rest.RestException; + +public interface WikiOperations +{ + + /** + * @return list of all the Wikis in the provided XWiki server hosted in XWiki URL + * @throws RestConnectionException + * @throws RestException + */ + public abstract Wikis getWikis() throws RestConnectionException, RestException; + +} diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/rpc/XWikiAPI.java b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/XWikiAPI.java new file mode 100644 index 0000000..ae22901 --- /dev/null +++ b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/XWikiAPI.java @@ -0,0 +1,662 @@ +package org.xwiki.android.rest.rpc; + +import java.io.InputStream; + +import org.xwiki.android.resources.Attachments; +import org.xwiki.android.resources.Class; +import org.xwiki.android.resources.Classes; +import org.xwiki.android.resources.Comment; +import org.xwiki.android.resources.Comments; +import org.xwiki.android.resources.History; +import org.xwiki.android.resources.Object; +import org.xwiki.android.resources.Objects; +import org.xwiki.android.resources.Page; +import org.xwiki.android.resources.Pages; +import org.xwiki.android.resources.Properties; +import org.xwiki.android.resources.Property; +import org.xwiki.android.resources.SearchResults; +import org.xwiki.android.resources.Spaces; +import org.xwiki.android.resources.Tag; +import org.xwiki.android.resources.Tags; +import org.xwiki.android.resources.Translations; +import org.xwiki.android.resources.Wikis; +import org.xwiki.android.rest.RestConnectionException; +import org.xwiki.android.rest.RestException; + +/** + * + * @author xwiki gsoc 2012 + * + */ +public interface XWikiAPI +{ + + /** + * Set the user credentials for accession + * + * @param username + * username of the user account in XWiki + * @param password + * password of the user account in XWiki + */ + void setAuthentication(String username, String password); + + /** + * @param wikiName + * name of the Wiki + * @param keyword + * text to search + * @return Search results of the searched keyword within Wiki contents + */ + SearchResults searchInWiki(String wikiName, String keyword) throws RestConnectionException, RestException, + RestException; + + /** + * @param wikiName + * name of the Wiki + * @param spaceName + * name of the space + * @param keyword + * text to search + * @return Search results of the searched keyword in provided space + */ + SearchResults searchInSpace(String wikiName, String spaceName, String keyword) throws RestConnectionException, + RestException, RestException; + + /** + * @return list of wikis in the provided XWiki URL domain + */ + Wikis getWikis() throws RestConnectionException, RestException, RestException; + + /** + * @param wikiName + * name of the Wiki + * @return all the tags used in the wiki + */ + Tags getWikiTags(String wikiName) throws RestConnectionException, RestException, RestException; + + /** + * @param wikiName + * name of the Wiki + * @return lists all the classes in the specified Wiki + */ + Classes getWikiClasses(String wikiName) throws RestConnectionException, RestException, RestException; + + /** + * @param wikiName + * name of the Wiki + * @param classname + * name of the class + * @return Class of the provided classname in the specified Wiki + */ + Class getWikiClasses(String wikiName, String classname) throws RestConnectionException, RestException, + RestException; + + /** + * @param wikiName + * name of the wiki + * @return list of spaces in the provided Wiki + */ + Spaces getSpaces(String wikiName) throws RestConnectionException, RestException; + + /** + * @param wikiName + * name of the wiki + * @param spaceName + * name of the space + * @return list of all the pages in specific Wiki and Space + */ + Pages getAllPages(String wikiName, String spaceName) throws RestConnectionException, RestException; + + boolean existsPage(String wikiName, String spaceName, String pageName) throws RestConnectionException,RestException; + + /** + * @param wikiName + * name of the wiki + * @param spaceName + * name of the space + * @param pageName + * name of the page + * @return Page object according to the field values + */ + Page getPage(String wikiName, String spaceName, String pageName) throws RestConnectionException, RestException; + + /** + * Add page to the server according to the provided field values + * + * @param wikiName + * name of the wiki + * @param spaceName + * name of the space + * @param pageName + * name of the page + * @param page + * Page object which is to be added + * @return status of the HTTP response + */ + String addPage(String wikiName, String spaceName, String pageName, Page page) throws RestConnectionException, + RestException; + + /** + * Delete page in the server + * + * @param wikiName + * name of the Wiki + * @param spaceName + * name of the space + * @param pageName + * name of the page + * @return status of the HTTP response + */ + String deletePage(String wikiName, String spaceName, String pageName) throws RestConnectionException, RestException; + + /** + * Delete page translation + * + * @param wikiName + * name of the Wiki + * @param spaceName + * name of the space + * @param pageName + * name of the page + * @param language + * specific language to delete + * @return status of the HTTP response + */ + String deletePage(String wikiName, String spaceName, String pageName, String language) + throws RestConnectionException, RestException; + + /** + * @param wikiName + * name of the Wiki + * @param spaceName + * name of the space + * @param pageName + * name of the page + * @return history of the page according to the field values + */ + History getPageHistory(String wikiName, String spaceName, String pageName) throws RestConnectionException, + RestException; + + /** + * @param wikiName + * name of the Wiki + * @param spaceName + * name of the space + * @param pageName + * name of the page + * @param version + * version of the page + * @return Page of the specified version + */ + Page getPageInVersionHistory(String wikiName, String spaceName, String pageName, String version) + throws RestConnectionException, RestException; + + /** + * @param wikiName + * name of the Wiki + * @param spaceName + * name of the space + * @param pageName + * name of the page + * @return Children pages of the specific page + */ + Pages getPageChildren(String wikiName, String spaceName, String pageName) throws RestConnectionException, + RestException; + + /** + * @param wikiName + * name of the Wiki + * @param spaceName + * name of the space + * @param pageName + * name of the page + * @return Tags of the page + */ + Tags getPageTags(String wikiName, String spaceName, String pageName) throws RestConnectionException, RestException; + + /** + * Adds page tag to the provided page + * + * @param wikiName + * name of the Wiki + * @param spaceName + * name of the space + * @param pageName + * name of the page + * @param tag + * tag to be added + * @return status of the HTTP response + */ + String addPageTag(String wikiName, String spaceName, String pageName, Tag tag) throws RestConnectionException, + RestException; + + /** + * + * @param wikiName + * @param spaceName + * @param pageName + * @param tags set of tags to replace with + * @return + * @throws RestConnectionException + * @throws RestException + */ + public String setTags(String wikiName, String spaceName, String pageName,Tags tags) throws RestConnectionException, RestException; + + /** + * get all comments in page + * @param wikiName + * name of the Wiki + * @param spaceName + * name of the space + * @param pageName + * name of the page + * @return all the comments in the specific page + */ + Comments getPageComments(String wikiName, String spaceName, String pageName) throws RestConnectionException, + RestException; + + /** + * check whether a comment exists for the given page. + * @param wikiName + * @param spaceName + * @param pageName + * @param commentId + * @return + * @throws RestConnectionException + * @throws RestException + */ + public boolean existsPageComment(String wikiName, String spaceName, String pageName,int commentId) throws RestConnectionException, RestException; + + /** + * get a comment. + * @param commentId ID of the comment in the page + * @return comment of a page selected using comment ID + * @throws RestConnectionException + * @throws RestException + */ + public Comment getPageComment(String wikiName, String spaceName, String pageName, int commentId) throws RestConnectionException, RestException; + + /** + * Add comment to the page + * + * @param wikiName + * name of the Wiki + * @param spaceName + * name of the space + * @param pageName + * name of the page + * @param comment + * Comment object to be added + * @return status of the HTTP response + */ + + String addPageComment(String wikiName, String spaceName, String pageName, Comment comment) + throws RestConnectionException, RestException; + + + /** + * @param wikiName + * name of the Wiki + * @param spaceName + * name of the space + * @param pageName + * name of the page + * @param version + * version of the page + * @return All the comments of the page specific version + */ + Comments getPageCommentsInHistory(String wikiName, String spaceName, String pageName, String version) + throws RestConnectionException, RestException; + + /** + * @param wikiName + * name of the Wiki + * @param spaceName + * name of the space + * @param pageName + * name of the page + * @param version + * version of the page + * @param commentId + * ID of the comment + * @return comments Comments of specific comment ID in specific page history + * version + */ + Comments getPageCommentsInHistory(String wikiName, String spaceName, String pageName, String version, + String commentId) throws RestConnectionException, RestException; + + /** + * @param wikiName + * name of the Wiki + * @param spaceName + * name of the space + * @param pageName + * name of the page + * @return list all the attachments in a specific page + */ + Attachments getAllPageAttachments(String wikiName, String spaceName, String pageName) + throws RestConnectionException, RestException; + + /** + * Gets a stream of data of a attachment + * + * @param wikiName + * name of the Wiki + * @param spaceName + * name of the space + * @param pageName + * name of the page + * @param attachmentName + * filename of the attachment. + * @return InputStream of the attachment raw data + */ + InputStream getPageAttachment(String wikiName, String spaceName, String pageName, String attachmentName) + throws RestConnectionException, RestException; + + /** + * Add attachment to a page + * + * @param wikiName + * name of the Wiki + * @param spaceName + * name of the space + * @param pageName + * name of the page + * @param filePath + * absolute path to the attachment in internal/external memory of + * the device + * @param attachmentName + * filename of the attachment + * @return status of the HTTP response + */ + String putPageAttachment(String wikiName, String spaceName, String pageName, String filePath, String attachmentName) + throws RestConnectionException, RestException; + + /** + * Delete the page attachment by its name + * + * @param wikiName + * name of the Wiki + * @param spaceName + * name of the space + * @param pageName + * name of the page + * @param attachmentName + * name of the attachment + * @return status of the HTTP response + */ + String deletePageAttachment(String wikiName, String spaceName, String pageName, String attachmentName) + throws RestConnectionException, RestException; + + /** + * @param wikiName + * name of the Wiki + * @param spaceName + * name of the space + * @param pageName + * name of the page + * @param pageVersion + * version of the page + * @return list of all attachments in the specified page history version + */ + Attachments getPageAttachmentsInHistory(String wikiName, String spaceName, String pageName, String pageVersion) + throws RestConnectionException, RestException; + + /** + * @param wikiName + * name of the Wiki + * @param spaceName + * name of the space + * @param pageName + * name of the page + * @param pageVersion + * version of the page + * @param attachmentName + * filename of the attachment + * @return InputStream of attachment raw data in a specific page history + * version + */ + InputStream getPageAttachmentsInHistory(String wikiName, String spaceName, String pageName, String pageVersion, + String attachmentName) throws RestConnectionException, RestException; + + /** + * @param wikiName + * name of the Wiki + * @param spaceName + * name of the space + * @param pageName + * name of the page + * @param attachmentName + * filename of the attachment + * @return list of attachment version history of a specific attachment + */ + Attachments getPageAttachmentsInAttachmentHistory(String wikiName, String spaceName, String pageName, + String attachmentName) throws RestConnectionException, RestException; + + /** + * @param wikiName + * name of the Wiki + * @param spaceName + * name of the space + * @param pageName + * name of the page + * @param attachmentName + * filename of the attachment + * @param attachmentVersion + * version of the attachment + * @return Stream of attachment raw data in a specific attachment version of + * a specified page + */ + InputStream getPageAttachmentsInAttachmentHistory(String wikiName, String spaceName, String pageName, + String attachmentName, String attachmentVersion) throws RestConnectionException, RestException; + + /** + * @param wikiName + * name of the Wiki + * @param spaceName + * name of the space + * @param pageName + * name of the page + * @return list all the Translations of a specific page + */ + Translations getAllPageTranslations(String wikiName, String spaceName, String pageName) + throws RestConnectionException, RestException; + + /** + * @param wikiName + * name of the Wiki + * @param spaceName + * name of the space + * @param pageName + * name of the page + * @param language + * language name of the page translations + * @return Page of the geted language + */ + Page getPageTranslation(String wikiName, String spaceName, String pageName, String language) + throws RestConnectionException, RestException; + + /** + * @param wikiName + * name of the Wiki + * @param spaceName + * name of the space + * @param pageName + * name of the page + * @param language + * language of the page + * @return Page history versions in a given language + */ + History getPageHistoryInLanguage(String wikiName, String spaceName, String pageName, String language) + throws RestConnectionException, RestException; + + /** + * @param wikiName + * name of the Wiki + * @param spaceName + * name of the space + * @param pageName + * name of the page + * @param language + * language of the page + * @param version + * version of the page + * @return Translated page of the given history version + */ + Page getPageTranslationInHistory(String wikiName, String spaceName, String pageName, String language, String version) + throws RestConnectionException, RestException; + + + boolean existsObject(String wikiName, String spaceName, String pageName, String objectClassname, + int objectNumber)throws RestConnectionException,RestException; + /** + * Adds provided object to the given page + * + * @param wikiName + * name of the Wiki + * @param spaceName + * name of the space + * @param pageName + * name of the page + * @param object + * Object to be added to page + * @return status of the HTTP response + */ + String addObject(String wikiName, String spaceName, String pageName, Object object) throws RestConnectionException, + RestException; + + /** + * Update object in a page + * + * @param objectClassname + * name of the class of the object + * @param objectNumber + * number of the object in the class + * @param object + * Object object to be updated in the page + * @return status of the HTTP put request + * @throws RestConnectionException + * @throws RestException + */ + public String updateObject(String wikiName, String spaceName, String pageName, String objectClassname, + int objectNumber, Object object) throws RestConnectionException, RestException; + + /** + * @param wikiName + * name of the Wiki + * @param spaceName + * name of the space + * @param pageName + * name of the page + * @return All the objects of the specified page + */ + Objects getAllObjects(String wikiName, String spaceName, String pageName) throws RestConnectionException, + RestException; + + /** + * @param wikiName + * name of the Wiki + * @param spaceName + * name of the space + * @param pageName + * name of the page + * @param objectClassname + * class name of the objects + * @return All the objects which have given class name of the specified page + */ + Objects getObjectsInClass(String wikiName, String spaceName, String pageName, String objectClassname) + throws RestConnectionException, RestException; + + /** + * @param wikiName + * name of the Wiki + * @param spaceName + * name of the space + * @param pageName + * name of the page + * @param objectClassname + * class name of the objects + * @param objectNumber + * number of the object in the specific class + * @return Object of the given class name and object number of the specified + * page + */ + Object getObject(String wikiName, String spaceName, String pageName, String objectClassname, int objectNumber) + throws RestConnectionException, RestException; + + /** + * Deletes the given object. Object can be selected using class name and the + * object number + * + * @param wikiName + * name of the Wiki + * @param spaceName + * name of the space + * @param pageName + * name of the page + * @param objectClassname + * class name of the objects + * @param objectNumber + * number of the object in the specified class + * @return status of the HTTP response of the delete operation + */ + String deleteObject(String wikiName, String spaceName, String pageName, String objectClassname, String objectNumber) + throws RestConnectionException, RestException; + + /** + * @param wikiName + * name of the Wiki + * @param spaceName + * name of the space + * @param pageName + * name of the page + * @param objectClassname + * class name of the objects + * @param objectNumber + * number of the object in the specified class + * @return lists all the properties of a specific object + */ + Properties getObjectAllProperties(String wikiName, String spaceName, String pageName, String objectClassname, + String objectNumber) throws RestConnectionException, RestException; + + /** + * @param wikiName + * name of the Wiki + * @param spaceName + * name of the space + * @param pageName + * name of the page + * @param objectClassname + * class name of objects + * @param objectNumber + * number of the object in the page + * @param propertyName + * name of the property in the object + * @return Property out of list of properties in a given object of a page + */ + Property getObjectProperty(String wikiName, String spaceName, String pageName, String objectClassname, + String objectNumber, String propertyName) throws RestConnectionException, RestException; + //TODO: refactor number to int + + /** + * Adds the property to the object of a page + * + * @param wikiName + * name of the Wiki + * @param spaceName + * name of the space + * @param pageName + * name of the page + * @param objectClassname + * class name of the objects + * @param objectNumber + * number of the object + * @param property + * Property object to be added to the object in a page + * @return status of the HTTP response + */ + String addObjectProperty(String wikiName, String spaceName, String pageName, String objectClassname, + String objectNumber, Property property) throws RestConnectionException, RestException; + +} \ No newline at end of file diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/rpc/XmlRestClient.java b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/XmlRestClient.java new file mode 100644 index 0000000..0627655 --- /dev/null +++ b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/XmlRestClient.java @@ -0,0 +1,518 @@ +package org.xwiki.android.rest.rpc; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.StringWriter; +import java.net.SocketTimeoutException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpException; +import org.apache.http.HttpHost; +import org.apache.http.HttpRequest; +import org.apache.http.HttpRequestInterceptor; +import org.apache.http.HttpResponse; +import org.apache.http.auth.AuthScope; +import org.apache.http.auth.AuthState; +import org.apache.http.auth.Credentials; +import org.apache.http.auth.UsernamePasswordCredentials; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.CredentialsProvider; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpDelete; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpHead; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpPut; +import org.apache.http.client.protocol.ClientContext; +import org.apache.http.entity.FileEntity; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.auth.BasicScheme; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.params.BasicHttpParams; +import org.apache.http.params.HttpConnectionParams; +import org.apache.http.params.HttpParams; +import org.apache.http.protocol.ExecutionContext; +import org.apache.http.protocol.HttpContext; +import org.apache.http.util.EntityUtils; +import org.simpleframework.xml.Serializer; +import org.simpleframework.xml.core.Persister; +import org.xwiki.android.resources.Resource; +import org.xwiki.android.rest.HttpConnector; +import org.xwiki.android.rest.RestBadRequestException; +import org.xwiki.android.rest.RestConnectionException; +import org.xwiki.android.rest.RestException; + +import android.util.Log; + +//TODO: under construction. +public class XmlRestClient implements RestClient +{ + + private static final String TAG = RestClient.class.getSimpleName(); + private static final String TAG2 = RestClient.class.getSimpleName() + "_ SimpleXML"; + + /** + * URI of the Remote XWiki instance i.e. host:port + */ + private String serverUrl; + + /** + * User credential details + */ + private String username, password; + + /** + * wether authentication enabled. + */ + private boolean isSecured = false; + + // /** + // * currently we use preemptive auth. Not a good choice to send username password every time. + // * This var is immutable. U have to change it internally because we will move away from pre emptive auth very + // soon. + // */ + // private boolean smartAuth =true; + + /** + * For executing http connection + */ + private DefaultHttpClient client; + + /** + * Sets user credentials of the XWiki user + * + * @param username username of the XWiki user account + * @param password password of the XWiki user account + */ + public void setAuthenticaion(String username, String password) + { + if (username != null && password != null && !username.equals("") && !password.equals("")) { + this.username = username; + this.password = password; + isSecured = true; + } else { + isSecured = false; + } + } + + /** + * @return gets whether connection should add user credentials + */ + public boolean isAuthenticated() + { + return isSecured; + } + + public int headForStatus(String Uri) throws RestConnectionException + { + return head(Uri).getStatusLine().getStatusCode(); + } + + public T getForResource(String uri, Class retType) throws RestConnectionException, + RestException + { + HttpResponse response = get(uri); + if (retType != null) { + return buildResource(retType, response.getEntity()); + } else { + return null; + } + } + + public T postForResource(String uri, Resource res, Class retType) + throws RestConnectionException, RestException + { + String content = toXmlString(res); + HttpResponse response = post(uri, content); + if (retType != null) { + return buildResource(retType, response.getEntity()); + } else { + return null; + } + } + + public T putForResource(String uri, Resource res, Class retType) + throws RestConnectionException, RestException + { + String content = toXmlString(res); + HttpResponse response = put(uri, content); + if (retType != null) { + return buildResource(retType, response.getEntity()); + } else { + return null; + } + } + + public boolean deleteResource(String uri) throws RestConnectionException, RestException + { + int code = delete(uri).getStatusLine().getStatusCode(); + return 204 == code; + } + + HttpResponse head(String uri) throws RestConnectionException + { + + HttpHead request = new HttpHead(); + URI requestUri; + try { + requestUri = new URI(uri); + request.setURI(requestUri); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + Log.d(TAG, "Request URL :" + uri); + + try { + HttpResponse response = client.execute(request); + Log.d(TAG, response.getStatusLine().toString()); + return response; + } catch (ClientProtocolException e) { + e.printStackTrace(); + return null; + } catch (IOException e) { + throw new RestConnectionException(e); + } + } + + /** + * Perform HTTP Get method execution and return the response as a String + * + * @param uri URL of XWiki RESTful API + * @return Response data of the HTTP connection as a String + */ + HttpResponse get(String uri) throws RestConnectionException, RestException + { + + HttpGet request = new HttpGet(); + + try { + URI requestUri = new URI(uri); + request.setURI(requestUri); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + Log.d(TAG, "GET URL :" + uri); + try { + HttpResponse response = client.execute(request); + Log.d(TAG, response.getStatusLine().toString()); + validate(response.getStatusLine().getStatusCode()); + return response; + } catch (ClientProtocolException e) { + e.printStackTrace(); + return null; + } catch (IOException e) { + throw new RestConnectionException(e); + } + } + + /** + * Perform HTTP Delete method execution and return its status + * + * @param uri URL of XWiki RESTful API + * @return status of the HTTP method execution + * @throws RestConnectionException + * @throws RestException + */ + HttpResponse delete(String uri) throws RestConnectionException, RestException + { + + HttpDelete request = null; + try { + URI requestUri = new URI(uri); + request = new HttpDelete(); + request.setURI(requestUri); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + Log.d(TAG, "DELETE URL :" + uri); + try { + HttpResponse response = client.execute(request); + Log.d(TAG, response.getStatusLine().toString()); + validate(response.getStatusLine().getStatusCode()); + return response; + } catch (ClientProtocolException e) { + e.printStackTrace(); + return null; + } catch (IOException e) { + throw new RestConnectionException(e); + } + } + + /** + * Perform HTTP Post method execution and return its response status + * + * @param uri URL of XWiki RESTful API + * @param content content to be posted to the server + * @return status code of the Post method execution + * @throws RestConnectionException + * @throws RestException + */ + HttpResponse post(String uri, String content) throws RestConnectionException, RestException + { + + HttpPost request = new HttpPost(); + + try { + URI requestUri = new URI(uri); + request.setURI(requestUri); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + + Log.d(TAG, "POST URL :" + uri); + + try { + Log.d("Post content", "content=" + content); + StringEntity se = new StringEntity(content, "UTF-8"); + + se.setContentType("application/xml"); + // se.setContentType("text/plain"); + request.setEntity(se); + request.setHeader("Content-Type", "application/xml;charset=UTF-8"); + + HttpResponse response = client.execute(request); + Log.d(TAG, response.getStatusLine().toString()); + + validate(response.getStatusLine().getStatusCode()); + return response; + + } catch (ClientProtocolException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + throw new RestConnectionException(e); + } + return null; + } + + /** + * Perform HTTP Put method execution and return its response status + * + * @param uri URL of XWiki RESTful API + * @param content content to be posted to the server + * @return status code of the Put method execution + * @throws RestConnectionException + * @throws RestException + */ + public HttpResponse put(String uri, String content) throws RestConnectionException, RestException + { + + HttpPut request = new HttpPut(); + + try { + Log.d(TAG, "Request URL :" + uri); + System.out.println(uri); + URI requestUri = new URI(uri); + request.setURI(requestUri); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + + try { + Log.d(TAG, "Put content=" + content); + StringEntity se = new StringEntity(content, "UTF-8"); + + se.setContentType("application/xml"); + // se.setContentType("text/plain"); + request.setEntity(se); + request.setHeader("Content-Type", "application/xml;charset=UTF-8"); + + HttpResponse response = client.execute(request); + Log.d(TAG, response.getStatusLine().toString()); + // close the stream to releas resources. //TODO: [ignore since test utils.]ideally this should be closed + // after content is read (if needed) by requester. So move it to PageOps etc. + validate(response.getStatusLine().getStatusCode()); + return response; + + } catch (ClientProtocolException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + throw new RestConnectionException(e); + } + + return null; + } + + /** + * Perform HTTP Put method with the raw data file + * + * @param uri URL of XWiki RESTful API + * @param file file to upload + * @return status of the HTTP Put method execution + * @throws RestConnectionException + * @throws RestException + */ + public HttpResponse put(String uri, File file) throws RestConnectionException, RestException + { + + HttpPut request = new HttpPut(); + try { + URI requestUri = new URI(uri); + request.setURI(requestUri); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + Log.d(TAG, "Request URL :" + uri); + try { + FileEntity fe = new FileEntity(file, "/"); + request.setEntity(fe); + // request.setHeader("Content-Type","application/xml;charset=UTF-8"); + HttpResponse response = client.execute(request); + Log.d(TAG, response.getStatusLine().toString()); + + validate(response.getStatusLine().getStatusCode()); + return response; + } catch (ClientProtocolException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RestConnectionException(e); + } + } + + @Override + public XWikiAPI getBaseAPI() + { + // TODO Auto-generated method stub + return null; + } + + public SpaceOperations spaceOperations(String wikiName) + { + return new _SpaceOperations(serverUrl, wikiName, this); + } + + @Override + public PageOperations pageOperations(String wikiName, String spaceName) + { + return new _PageOperations(serverUrl, wikiName, spaceName, this); + } + + @Override + public ObjectOperations objectOperations(String wikiName, String spaceName, String pageName) + { + return new _ObjectOperations(serverUrl, wikiName, spaceName, pageName, this); + } + + @Override + public CommentOperations commentOperations(String wikiName, String spaceName, String pageName) + { + return new _CommentOperations(serverUrl, wikiName, spaceName, pageName, this); + } + + @Override + public AttachmentOperations attachmentOperations(String wikiName, String spaceName, String pageName) + { + return new _AttachmentOperations(serverUrl, wikiName, spaceName, pageName, this); + } + + @Override + public TagOperations tagOperations(String wikiName, String spaceName, String pageName) + { + return new _TagOperations(serverUrl, wikiName, spaceName, pageName, this); + } + + @Override + public HistoryOperations historyOperations(String wikiName, String spaceName, String pageName) + { + // TODO Auto-generated method stub + return null; + } + + public void shutDown() + { + client.getConnectionManager().shutdown(); + } + + /** + * initializeHttpClient the general property fields + */ + private void initializeHttpClient() + { + client = new DefaultHttpClient(); + // set http params + HttpParams params = new BasicHttpParams(); + HttpConnectionParams.setConnectionTimeout(params, 10000);// try 10 seconds to get a socket connection + HttpConnectionParams.setSoTimeout(params, 20000);// wait 30 seconds waiting for data. then break connection. + client.setParams(params); + } + + /** + * set user credentials with manually developed preemtive Auth + */ + private void setCredentials() + { + // Setting preemtiveAuth manually since org.apache.http does not support it + HttpRequestInterceptor preemptiveAuth = new HttpRequestInterceptor() + { + @Override + public void process(HttpRequest request, HttpContext context) throws HttpException + { + AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE); + CredentialsProvider credsProvider = + (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER); + HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST); + + if (authState.getAuthScheme() == null) { + AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort()); + Credentials creds = credsProvider.getCredentials(authScope); + + if (creds != null) { + authState.setAuthScheme(new BasicScheme()); + authState.setCredentials(creds); + } + } + } + + }; + client.addRequestInterceptor(preemptiveAuth, 0); + Credentials defaultcreds = new UsernamePasswordCredentials(username, password); + client.getCredentialsProvider().setCredentials(new AuthScope(null, -1, AuthScope.ANY_REALM), defaultcreds); + + } + + private void validate(int code) throws RestException + { + if (400 <= code & code < 500) { + throw new RestException(code); + } else if (500 <= code & code < 600) { + throw new RuntimeException("server error : bad request. code:" + code); + } + } + + private String toXmlString(Resource res) + { + Serializer serializer = new Persister(); + StringWriter result = new StringWriter(); + + try { + serializer.write(res, result); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return result.toString(); + } + + private T buildResource(Class ofType, HttpEntity from) + { + Serializer serializer = new Persister(); + T res = null; + try { + res = serializer.read(ofType, EntityUtils.toString(from)); + from.consumeContent(); // from.finish(). + } catch (Exception e) { + Log.e(TAG2, e.getMessage()); + } + return res; + } + +} diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/rpc/_AttachmentOperations.java b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/_AttachmentOperations.java new file mode 100644 index 0000000..abe7d17 --- /dev/null +++ b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/_AttachmentOperations.java @@ -0,0 +1,114 @@ +package org.xwiki.android.rest.rpc; + +import java.io.InputStream; + +import org.xwiki.android.resources.Attachments; +import org.xwiki.android.rest.RestConnectionException; +import org.xwiki.android.rest.RestException; + + +class _AttachmentOperations implements AttachmentOperations +{ + +RestClient rpc; + + /** + * Path provided from XWiki RESTful API + */ + private final String PAGE_URL_PREFIX = "/xwiki/rest/wikis/"; + + /** + * URL of the XWiki domain + */ + private String URLprefix; + + /** + * Name of Wiki for acquiring attachment + */ + private String wikiName; + + /** + * Name of Space for acquiring attachment + */ + private String spaceName; + + /** + * Name of Page for acquiring attachment + */ + private String pageName; + + /** + * @param URLprefix XWiki URl ex:"www.xwiki.org" + * @param wikiName name of the wiki in UTF-8 format + * @param spaceName name of the space in UTF-8 format + * @param pageName name of the page in UTF-8 format + */ + _AttachmentOperations(String URLprefix, String wikiName, String spaceName, String pageName, RestClient rpc) { + this.URLprefix = URLprefix; + this.wikiName = wikiName; + this.spaceName = spaceName; + this.pageName = pageName; + this.rpc=rpc; + } + + @Override + public Attachments getAllPageAttachments() throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public InputStream getPageAttachment(String attachmentName) throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public String putPageAttachment(String filePath, String attachmentName) throws RestConnectionException, + RestException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public Attachments getPageAttachmentsInHistory(String version) throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public InputStream getPageAttachmentsInHistory(String version, String attachmentName) + throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public Attachments getPageAttachmentsInAttachmentHistory(String attachmentName) throws RestConnectionException, + RestException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public InputStream getPageAttachmentsInAttachmentHistory(String attachmentName, String attachmentVersion) + throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public String deletePageAttachment(String attachmentName) throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/rpc/_CommentOperations.java b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/_CommentOperations.java new file mode 100644 index 0000000..86b64d7 --- /dev/null +++ b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/_CommentOperations.java @@ -0,0 +1,104 @@ +package org.xwiki.android.rest.rpc; + +import org.xwiki.android.resources.Comment; +import org.xwiki.android.resources.Comments; +import org.xwiki.android.rest.RestConnectionException; +import org.xwiki.android.rest.RestException; + + +class _CommentOperations implements CommentOperations +{ + + /** + * Path provided from XWiki RESTful API + */ + private final String PAGE_URL_PREFIX = "/xwiki/rest/wikis/"; + + /** + * URL of the XWiki domain + */ + private String URLprefix; + + /** + * Name of Wiki for acquiring comments + */ + private String wikiName; + + /** + * Name of space for acquiring comments + */ + private String spaceName; + + /** + * Name of page for acquiring comments + */ + private String pageName; + private RestClient rpc; + + /** + * @param URLprefix XWiki URl ex:"www.xwiki.org" + * @param wikiName name of the wiki in UTF-8 format + * @param spaceName name of the space in UTF-8 format + * @param pageName name of the page in UTF-8 format + * @param rpc + */ + _CommentOperations(String URLprefix, String wikiName, String spaceName, String pageName, RestClient rpc) + { + this.URLprefix = URLprefix; + this.wikiName = wikiName; + this.spaceName = spaceName; + this.pageName = pageName; + this.rpc=rpc; + } + + @Override + public Comments getPageComments() throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean exists(int commentId) throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return false; + } + + @Override + public Comment getPageComment(int commentId) throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public Comments getPageCommentsInHistory(String version) throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public Comments getPageCommentsInHistory(String version, String commentId) throws RestConnectionException, + RestException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public int addPageComment(Comment comment) throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return 0; + } + + @Override + public Comment addPageCommentForResource(Comment comment) throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/rpc/_ObjectOperations.java b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/_ObjectOperations.java new file mode 100644 index 0000000..b22c2a8 --- /dev/null +++ b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/_ObjectOperations.java @@ -0,0 +1,131 @@ +package org.xwiki.android.rest.rpc; + +import org.xwiki.android.resources.Object; +import org.xwiki.android.resources.Objects; +import org.xwiki.android.resources.Properties; +import org.xwiki.android.resources.Property; +import org.xwiki.android.rest.RestConnectionException; +import org.xwiki.android.rest.RestException; + + +class _ObjectOperations implements ObjectOperations +{ + + /** + * Path provided from XWiki RESTful API + */ + private final String PAGE_URL_PREFIX = "/xwiki/rest/wikis/"; + + /** + * URL of the XWiki domain + */ + private String URLprefix; + + /** + * Name of Wiki for acquiring objects + */ + private String wikiName; + + /** + * Name of space for acquiring objects + */ + private String spaceName; + + /** + * Name of page for acquiring objects + */ + private String pageName; + private RestClient rpc; + + /** + * @param URLprefix XWiki URl ex:"www.xwiki.org" + * @param wikiName name of the wiki in UTF-8 format + * @param spaceName name of the space in UTF-8 format + * @param pageName name of the page in UTF-8 format + * @param rpc + */ + _ObjectOperations(String URLprefix, String wikiName, String spaceName, String pageName, RestClient rpc) + { + this.URLprefix = URLprefix; + this.wikiName = wikiName; + this.spaceName = spaceName; + this.pageName = pageName; + this.rpc=rpc; + } + + @Override + public boolean exists(String objectClassname, String objectNumber) throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return false; + } + + @Override + public Objects getAllObjects() throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public String addObject(Object object) throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public Objects getObjectsInClassname(String objectClassname) throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public Object getObject(String objectClassname, String objectNumber) throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public String updateObject(String objectClassname, String objectNumber, Object object) + throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public String deleteObject(String objectClassname, String objectNumber) throws RestConnectionException, + RestException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public Properties getObjectProperties(String objectClassname, String objectNumber) throws RestConnectionException, + RestException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public String addObjectProperty(String objectClassname, String objectNumber, Property property) + throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public Property getObjectProperty(String objectClassname, String objectNumber, String propertyName) + throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/rpc/_PageOperations.java b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/_PageOperations.java new file mode 100644 index 0000000..e062d0a --- /dev/null +++ b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/_PageOperations.java @@ -0,0 +1,132 @@ +package org.xwiki.android.rest.rpc; + +import org.xwiki.android.resources.Page; +import org.xwiki.android.resources.Pages; +import org.xwiki.android.rest.RestConnectionException; +import org.xwiki.android.rest.RestException; + + +class _PageOperations implements PageOperations +{ + + /** + * Path provided from XWiki RESTful API + */ + private final String PAGE_URL_PREFIX = "/xwiki/rest/wikis/"; + + /** + * Path provided from XWiki RESTful API for pages + */ + private final String PAGE_URL_SUFFIX = "/pages"; + + /** + * URL of the XWiki domain + */ + private String URLprefix; + + /** + * Name of Wiki for acquiring pages + */ + private String wikiName; + + /** + * Name of space for acquiring pages + */ + private String spaceName; + + private RestClient rpc; + + /** + * @param URLprefix XWiki URl ex:"www.xwiki.org" + * @param wikiName name of the wiki in UTF-8 format + * @param spaceName name of the space in UTF-8 format + * @param rpc + */ + _PageOperations(String URLprefix, String wikiName, String spaceName, RestClient rpc) + { + + this.URLprefix = URLprefix; + this.wikiName = wikiName; + this.spaceName = spaceName; + this.rpc=rpc; + } + + @Override + public Pages getAllPages() throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean exists(String pageName) throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return false; + } + + @Override + public Page getPage(String pageName) throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public String addPage(Page page) throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public String deletePage(String pageName) throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public Page getPageHistoryOnVersion(String pageName, String version) throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public Pages getPageChildren(String pageName) throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public Page getPageTranslation(String pageName, String language) throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public String addPageTranslation(Page page, String language) throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public String deletePageTranslation(String pageName, String language) throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public Page getPageTranslation(String pageName, String language, String version) throws RestConnectionException, + RestException + { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/rpc/_SpaceOperations.java b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/_SpaceOperations.java new file mode 100644 index 0000000..e4169c8 --- /dev/null +++ b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/_SpaceOperations.java @@ -0,0 +1,51 @@ +package org.xwiki.android.rest.rpc; + +import org.xwiki.android.resources.Spaces; +import org.xwiki.android.rest.RestConnectionException; +import org.xwiki.android.rest.RestException; +; + +class _SpaceOperations implements SpaceOperations +{ + + /** + * Path provided from XWiki RESTful API + */ + private final String SPACE_URL_PREFIX = "/xwiki/rest/wikis/"; + + /** + * Path provided from XWiki RESTful API for spaces + */ + private final String SPACE_URL_SUFFIX = "/spaces"; + + /** + * URL of the XWiki domain + */ + private String uRLprefix; + + /** + * Name of Wiki for acquiring pages + */ + private String wikiName; + private RestClient rpc; + + + /** + * @param URLprefix XWiki URl ex:"www.xwiki.org" + * @param wikiName name of the wiki in UTF-8 format + * @param rpc + */ + _SpaceOperations(String URLprefix, String wikiName, RestClient rpc) + { + this.uRLprefix = URLprefix; + this.wikiName = wikiName; + this.rpc=rpc; + } + @Override + public Spaces getSpaces() throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/rpc/_TagOperations.java b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/_TagOperations.java new file mode 100644 index 0000000..52a74ae --- /dev/null +++ b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/_TagOperations.java @@ -0,0 +1,94 @@ +package org.xwiki.android.rest.rpc; + +import org.xwiki.android.resources.Tag; +import org.xwiki.android.resources.Tags; +import org.xwiki.android.rest.RestConnectionException; +import org.xwiki.android.rest.RestException; + +class _TagOperations implements TagOperations +{ + + /** + * Path provided from XWiki RESTful API + */ + private final String PAGE_URL_PREFIX = "/xwiki/rest/wikis/"; + + /** + * URL of the XWiki domain + */ + private String URLprefix; + + /** + * Name of Wiki for acquiring tags + */ + private String wikiName; + + /** + * Name of space for acquiring tags + */ + private String spaceName; + + /** + * Name of page for acquiring tags + */ + private String pageName; + + /** + * Type of the tag. + *

+ * 0= Wiki tag 1=Page tag + */ + private int tagType; + + private RestClient rc; + + /** + * @param URLprefix XWiki URl ex:"www.xwiki.org" + * @param wikiName name of the wiki in UTF-8 format + */ + _TagOperations(String URLprefix, String wikiName, RestClient rc) + { + this.URLprefix = URLprefix; + this.wikiName = wikiName; + tagType = 0; + this.rc = rc; + } + + /** + * @param URLprefix XWiki URl ex:"www.xwiki.org" + * @param wikiName name of the wiki in UTF-8 format + * @param spaceName name of the space in UTF-8 format + * @param pageName name of the page in UTF-8 format + */ + _TagOperations(String URLprefix, String wikiName, String spaceName, String pageName, RestClient rc) + { + this.URLprefix = URLprefix; + this.wikiName = wikiName; + this.spaceName = spaceName; + this.pageName = pageName; + tagType = 1; + this.rc = rc; + } + + @Override + public Tags getTags() throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public String addTag(Tag tag) throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return null; + } + + @Override + public String setTags(Tags tags) throws RestConnectionException, RestException + { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/xwiki-android-rest/src/org/xwiki/android/rest/rpc/sample HttpClient with pooled connections b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/sample HttpClient with pooled connections new file mode 100644 index 0000000..9850c5e --- /dev/null +++ b/xwiki-android-rest/src/org/xwiki/android/rest/rpc/sample HttpClient with pooled connections @@ -0,0 +1,100 @@ +PoC. +We can achieve parellel http connections in this layer. +Use implementations of RestConnection to adjust params. +RestConnection.close() should shutdown the http connection manager of the http client. + +sample code// + +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.conn.ClientConnectionManager; +import org.apache.http.conn.scheme.PlainSocketFactory; +import org.apache.http.conn.scheme.Scheme; +import org.apache.http.conn.scheme.SchemeRegistry; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.impl.conn.PoolingClientConnectionManager; +import org.apache.http.protocol.BasicHttpContext; +import org.apache.http.protocol.HttpContext; +import org.apache.http.util.EntityUtils; + +import java.io.IOException; + +/** + * Created with IntelliJ IDEA. + * User: admin + * Date: 8/11/12 + * Time: 1:53 PM + * To change this template use File | Settings | File Templates. + */ +public class org.xwiki.android.test.org.xwiki.test.integration.Main { + + static DefaultHttpClient client; + public static void main(String[] args) throws IOException, InterruptedException { + + SchemeRegistry schemeRegistry = new SchemeRegistry(); + schemeRegistry.register( + new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); + + ClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry); + HttpClient httpClient = new DefaultHttpClient(cm); + +// URIs to perform GETs on + String[] urisToGet = { + "http://www.domain1.com/", + "http://www.domain2.com/", + "http://www.domain3.com/", + "http://www.domain4.com/" + }; + +// create a thread for each URI + GetThread[] threads = new GetThread[urisToGet.length]; + for (int i = 0; i < threads.length; i++) { + HttpGet httpget = new HttpGet(urisToGet[i]); + threads[i] = new GetThread(httpClient, httpget); + } + +// start the threads + for (int j = 0; j < threads.length; j++) { + threads[j].start(); + } + +// join the threads + for (int j = 0; j < threads.length; j++) { + threads[j].join(); + } + + } + + static class GetThread extends Thread { + + private final HttpClient httpClient; + private final HttpContext context; + private final HttpGet httpget; + + public GetThread(HttpClient httpClient, HttpGet httpget) { + this.httpClient = httpClient; + this.context = new BasicHttpContext(); + this.httpget = httpget; + } + + @Override + public void run() { + try { + HttpResponse response = this.httpClient.execute(this.httpget, this.context); + HttpEntity entity = response.getEntity(); + if (entity != null) { + // do something useful with the entity + } + // ensure the connection gets released to the manager + EntityUtils.consume(entity); + } catch (Exception ex) { + this.httpget.abort(); + } + } + + } + +} \ No newline at end of file diff --git a/xwiki-android-test-core/src/org/xwiki/android/core/test/properties/TestConstants.java b/xwiki-android-test-core/src/org/xwiki/android/core/test/properties/TestConstants.java new file mode 100644 index 0000000..b6aa3f4 --- /dev/null +++ b/xwiki-android-test-core/src/org/xwiki/android/core/test/properties/TestConstants.java @@ -0,0 +1,63 @@ +package org.xwiki.android.core.test.properties; + +public class TestConstants +{ + public static final int SERVER_INDEX; + public static final String HOST = "10.0.2.2"; + public static final int PORT = 8080; //actual port is port+server_index + public static final String SCHEME="http://"; + public static final String SERVER_URL; //SERVER NAME set in static block. + public static final String USERNAME = "Admin"; + public static final String PASSWORD = "admin"; + + //external test fixture. + + public static final String WIKI_NAME = "xwiki"; + public static final String SPACE_NAME = "Blog"; + public static final String PAGE_NAME = "test2"; + public static final String PAGE_VERSION = "1.1"; + public static final String CREATE_PAGE_NAME ="CreatePage"; //used for create method tests. because page needss to be deleted for creation test 01 will create CreatePage-1 + public static final String UPDATE_PAGE_NAME ="UpdatePage"; + + + public static final String COMMENT_ID = "0"; + public static final String COMMENT_TEXT = "hi"; + public static final String COMMENT_REPLY_ID = "1"; + public static final int COMMENT_REPLY_REPLY_TO = 0; + public static final String COMMENT_PAGE_HISTORY_VERSION="5.1"; + public static final String COMMENT_REPLY_TEXT = "huy"; + + + public static final String LANGUAGE = "fr"; + public static final String TRANSLATION_VERSION="2.1"; + + public static final String CLASS_NAME = "Blog.BlogPostClass"; + public static final int OBJECT_NUMBER = 0; + public static final String OBJECT_PROPERTY_NAME = "content"; + public static final String OBJECT_PROPERTY_VALUE = "test blog content"; + + public static final String SEARCH_KEWORD = "test"; + + public static final String TAG_WORD = "testTag"; + + public static final String ATTACHMENT_NAME = "a.png"; + public static final String ATTACHMENT_DEL_NAME = "del.png"; + public static final String ATTACHMENT_PATH = "./"; + public static final String ATTACHMENT_VERSION = "1.1"; + public static final String ATTACHMENT_PAGE_HISTORY_VERSION = "9.1"; + + static { + SERVER_INDEX = new Integer(System.getProperty("xwikiExecutionIndex", "0")); + SERVER_URL = HOST + ":" + (PORT + SERVER_INDEX); + if(HOST.contains("localhost")){ + System.err.println("localhost on android means devices interface card!!!"); + } + } + + + + + + + +} diff --git a/xwiki-rest-model/xwiki-rest-model-simplexml/src/org/xwiki/android/resources/Resource.java b/xwiki-rest-model/xwiki-rest-model-simplexml/src/org/xwiki/android/resources/Resource.java new file mode 100644 index 0000000..8b030e5 --- /dev/null +++ b/xwiki-rest-model/xwiki-rest-model-simplexml/src/org/xwiki/android/resources/Resource.java @@ -0,0 +1,11 @@ +package org.xwiki.android.resources; +/** + * marker interface + * @author xwiki gsoc 2012 + * + */ + +public interface Resource +{ + +}