You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:36:54 UTC
[sling-org-apache-sling-hapi-client] 18/24: SLING-5880 Fixed
service interface
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.hapi.client-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-hapi-client.git
commit b1f1fc445f08f7c887328386b6c2186fd6a58f4b
Author: Andrei Dulvac <du...@apache.org>
AuthorDate: Wed Aug 10 11:38:38 2016 +0000
SLING-5880 Fixed service interface
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/hapi/client@1755727 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 1 +
.../org/apache/sling/hapi/client/Document.java | 30 +++++++++++++++++++++-
.../sling/hapi/client/HtmlClientService.java | 26 +++++++++++++++++++
.../java/org/apache/sling/hapi/client/Item.java | 15 ++++++-----
.../hapi/client/impl/HtmlClientServiceImpl.java | 4 ++-
5 files changed, 67 insertions(+), 9 deletions(-)
diff --git a/pom.xml b/pom.xml
index 2bc1c2d..58c22b9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -61,6 +61,7 @@
<configuration>
<instructions>
<Bundle-Category>sling</Bundle-Category>
+ <Private-Package>org.apache.sling.hapi.client.forms</Private-Package>
<Sling-Initial-Content>SLING-INF;overwrite=true</Sling-Initial-Content>
<Embed-Dependency>groupId=org.jsoup</Embed-Dependency>
</instructions>
diff --git a/src/main/java/org/apache/sling/hapi/client/Document.java b/src/main/java/org/apache/sling/hapi/client/Document.java
index 9344e5d..3da16ba 100644
--- a/src/main/java/org/apache/sling/hapi/client/Document.java
+++ b/src/main/java/org/apache/sling/hapi/client/Document.java
@@ -19,11 +19,39 @@
package org.apache.sling.hapi.client;
/**
- * An HTML document representation
+ * A hapi representation of an HTML document, backed by HTML markup.
+ * The Document provides a structure, accessible through the {@link #item(String)} and {@link #items()} methods
+ * and a way to use the hypermedia controls through the {@link #link(String)} and {@link #form(String)} methods
*/
public interface Document {
+ /**
+ * Get all the {@link Document}'s link items. These Items should normally be backed by HTML <i>anchors</i> and <i>links</i>.
+ * @param rel An identifier that groups all the <i>link</i> Items for this Document
+ * @return all the link Items for this Document, that have the given relation
+ * @throws ClientException
+ */
Items link(String rel) throws ClientException;
+
+ /**
+ * Get all the {@link Document}'s form items. These Items should normally be backed by the HTML <i>form</i> element
+ * @param rel An identifier that groups all the <i>form</i> Items for this Document
+ * @return all the form Items for this Document, that have the given relation
+ * @throws ClientException
+ */
Items form(String rel) throws ClientException;
+
+ /**
+ * Get all the {@link Document}'s items. These Items are backed by any HTML element
+ * @param rel An identifier that groups all the Items for this Document
+ * @return all the Items for this Document, that have the given relation
+ * @throws ClientException
+ */
Items item(String rel) throws ClientException;
+
+ /**
+ * Get all the {@link Document}'s items. These Items are backed by any HTML element
+ * @return all the Items for this Document
+ * @throws ClientException
+ */
Items items() throws ClientException;
}
diff --git a/src/main/java/org/apache/sling/hapi/client/HtmlClientService.java b/src/main/java/org/apache/sling/hapi/client/HtmlClientService.java
index bedf01d..fa39f28 100644
--- a/src/main/java/org/apache/sling/hapi/client/HtmlClientService.java
+++ b/src/main/java/org/apache/sling/hapi/client/HtmlClientService.java
@@ -18,6 +18,32 @@
******************************************************************************/
package org.apache.sling.hapi.client;
+import org.apache.http.impl.client.CloseableHttpClient;
+
public interface HtmlClientService {
+ /**
+ * Get an HtmlClient that internally uses a CloseableHttpClient
+ * @param client the inner {@link CloseableHttpClient}. The client should take care of any timeouts, authentication, pre/post
+ * processing, etc.
+ * @param baseUrl The address prefix to all the http requests (e.g. http://localhost:8080/myapp/)
+ * @return
+ */
+ HtmlClient getClient(CloseableHttpClient client, String baseUrl);
+
+ /**
+ * Get an HtmlClient.
+ * @param baseUrl The address prefix to all the http requests (e.g. http://localhost:8080/myapp/)
+ * @return
+ */
+ HtmlClient getClient(String baseUrl);
+
+ /**
+ * Get an HtmlClient that uses BasicAuth for all requests
+ * @param baseUrl The address prefix to all the http requests (e.g. http://localhost:8080/myapp/)
+ * @param user The username for BasicAuth
+ * @param password The password for BasicAuth
+ * @return
+ */
+ HtmlClient getClient(String baseUrl, String user, String password);
}
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/hapi/client/Item.java b/src/main/java/org/apache/sling/hapi/client/Item.java
index fa74107..8eba400 100644
--- a/src/main/java/org/apache/sling/hapi/client/Item.java
+++ b/src/main/java/org/apache/sling/hapi/client/Item.java
@@ -20,21 +20,22 @@ package org.apache.sling.hapi.client;
******************************************************************************/
import org.apache.http.NameValuePair;
-
-import java.util.List;
import java.util.Set;
/**
- *
+ * An HTML item representation. This maps to an html element and contains all the child elements.
+ * The child <i>semantic</i> elements (properties, links, forms) and the Item's metadata (src, href, value)
+ * are accessible through the dedicated methods
*/
public interface Item {
/**
- * Returns the property of the item having the given name.
+ * Returns the property of the item having the given name. The property is a child Item.
*/
Items prop(String name) throws ClientException;
/**
- * Return a List of all the properties of this item
+ * Return a List of all the properties of this item.
+ * The returned Strings are names that can be used for {@link #prop(String)}
*/
Set<String> props() throws ClientException;
@@ -81,12 +82,12 @@ public interface Item {
String src();
/**
- * Follow a hyperlink and get a new {@see Document} representation
+ * Follow a hyperlink and get a new {@link Document} representation
*/
Document follow() throws ClientException;
/**
- * Submits this form item and returns a new {@see Document} representation
+ * Submits this form item and returns a new {@link Document} representation
*/
Document submit(Iterable<NameValuePair> data) throws ClientException;
}
diff --git a/src/main/java/org/apache/sling/hapi/client/impl/HtmlClientServiceImpl.java b/src/main/java/org/apache/sling/hapi/client/impl/HtmlClientServiceImpl.java
index a684d1d..623c47d 100644
--- a/src/main/java/org/apache/sling/hapi/client/impl/HtmlClientServiceImpl.java
+++ b/src/main/java/org/apache/sling/hapi/client/impl/HtmlClientServiceImpl.java
@@ -32,7 +32,6 @@ import java.net.URISyntaxException;
@Component(metatype = false)
@Service(value = HtmlClientService.class)
public class HtmlClientServiceImpl implements HtmlClientService {
-
private final Logger LOG = LoggerFactory.getLogger(HtmlClientService.class);
/**
@@ -41,6 +40,7 @@ public class HtmlClientServiceImpl implements HtmlClientService {
* @param baseUrl the base URL as String
* @return the HtmlClient or null if there was an error
*/
+ @Override
public HtmlClient getClient(CloseableHttpClient client, String baseUrl) {
try {
return new MicrodataHtmlClient(client, baseUrl);
@@ -55,6 +55,7 @@ public class HtmlClientServiceImpl implements HtmlClientService {
* @param baseUrl the base URL as String
* @return the HtmlClient or null if there was an error
*/
+ @Override
public HtmlClient getClient(String baseUrl) {
try {
return new MicrodataHtmlClient(baseUrl);
@@ -71,6 +72,7 @@ public class HtmlClientServiceImpl implements HtmlClientService {
* @param password the password to be used for basic auth
* @return the HtmlClient or null if there was an error
*/
+ @Override
public HtmlClient getClient(String baseUrl, String user, String password) {
try {
return new MicrodataHtmlClient(baseUrl, user, password);
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.