|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2011-04-19 17:49:53
|
Revision: 252
http://sword-app.svn.sourceforge.net/sword-app/?rev=252&view=rev
Author: richard-jones
Date: 2011-04-19 17:49:46 +0000 (Tue, 19 Apr 2011)
Log Message:
-----------
partial Java client for the SWORD 2.0 implementation; covers Create and some of Retrieve
Added Paths:
-----------
JavaClient2.0/pom.xml
JavaClient2.0/src/
JavaClient2.0/src/main/
JavaClient2.0/src/main/java/
JavaClient2.0/src/main/java/org/
JavaClient2.0/src/main/java/org/swordapp/
JavaClient2.0/src/main/java/org/swordapp/client/
JavaClient2.0/src/main/java/org/swordapp/client/AuthCredentials.java
JavaClient2.0/src/main/java/org/swordapp/client/ClientConfiguration.java
JavaClient2.0/src/main/java/org/swordapp/client/CollectionEntries.java
JavaClient2.0/src/main/java/org/swordapp/client/Content.java
JavaClient2.0/src/main/java/org/swordapp/client/Deposit.java
JavaClient2.0/src/main/java/org/swordapp/client/DepositReceipt.java
JavaClient2.0/src/main/java/org/swordapp/client/EntryPart.java
JavaClient2.0/src/main/java/org/swordapp/client/HttpHeaders.java
JavaClient2.0/src/main/java/org/swordapp/client/ProtocolViolationException.java
JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java
JavaClient2.0/src/main/java/org/swordapp/client/SWORDClientException.java
JavaClient2.0/src/main/java/org/swordapp/client/SWORDCollection.java
JavaClient2.0/src/main/java/org/swordapp/client/SWORDError.java
JavaClient2.0/src/main/java/org/swordapp/client/SWORDMultipartRequestEntity.java
JavaClient2.0/src/main/java/org/swordapp/client/SWORDWorkspace.java
JavaClient2.0/src/main/java/org/swordapp/client/ServiceDocument.java
JavaClient2.0/src/main/java/org/swordapp/client/Statement.java
JavaClient2.0/src/main/java/org/swordapp/client/SwordCli.java
JavaClient2.0/src/main/java/org/swordapp/client/UriRegistry.java
JavaClient2.0/src/test/
JavaClient2.0/src/test/java/
JavaClient2.0/src/test/java/org/
JavaClient2.0/src/test/java/org/swordapp/
JavaClient2.0/src/test/java/org/swordapp/client/
JavaClient2.0/src/test/java/org/swordapp/client/test/
JavaClient2.0/src/test/java/org/swordapp/client/test/ClientTests.java
Added: JavaClient2.0/pom.xml
===================================================================
--- JavaClient2.0/pom.xml (rev 0)
+++ JavaClient2.0/pom.xml 2011-04-19 17:49:46 UTC (rev 252)
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.swordapp</groupId>
+ <artifactId>sword-client</artifactId>
+ <version>2.0</version>
+
+ <dependencies>
+ <dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ <version>3.1</version>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.15</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.abdera</groupId>
+ <artifactId>abdera-client</artifactId>
+ <version>1.1.1</version>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
Added: JavaClient2.0/src/main/java/org/swordapp/client/AuthCredentials.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/AuthCredentials.java (rev 0)
+++ JavaClient2.0/src/main/java/org/swordapp/client/AuthCredentials.java 2011-04-19 17:49:46 UTC (rev 252)
@@ -0,0 +1,70 @@
+package org.swordapp.client;
+
+public class AuthCredentials
+{
+ private String username;
+ private String password;
+ private String onBehalfOf;
+ private String target = null;
+ private String realm = null;
+
+ public AuthCredentials(String username, String password, String onBehalfOf, String target, String realm)
+ {
+ this.username = username;
+ this.password = password;
+ this.onBehalfOf = onBehalfOf;
+ this.target = target;
+ this.realm = realm;
+ }
+
+ public AuthCredentials(String username, String password, String target, String realm)
+ {
+ this.username = username;
+ this.password = password;
+ this.target = target;
+ this.realm = realm;
+ }
+
+ public AuthCredentials(String username, String password, String onBehalfOf)
+ {
+ this.username = username;
+ this.password = password;
+ this.onBehalfOf = onBehalfOf;
+ }
+
+ public AuthCredentials(String username, String password)
+ {
+ this.username = username;
+ this.password = password;
+ }
+
+ public AuthCredentials(String onBehalfOf)
+ {
+ this.onBehalfOf = onBehalfOf;
+ }
+
+ public String getUsername()
+ {
+ return username;
+ }
+
+ public String getPassword()
+ {
+ return password;
+ }
+
+ public String getOnBehalfOf()
+ {
+ return onBehalfOf;
+ }
+
+ public String getTarget()
+ {
+ return target;
+ }
+
+ public String getRealm()
+ {
+ return realm;
+ }
+}
Added: JavaClient2.0/src/main/java/org/swordapp/client/ClientConfiguration.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/ClientConfiguration.java (rev 0)
+++ JavaClient2.0/src/main/java/org/swordapp/client/ClientConfiguration.java 2011-04-19 17:49:46 UTC (rev 252)
@@ -0,0 +1,27 @@
+package org.swordapp.client;
+
+public class ClientConfiguration
+{
+ private String userAgent = "SWORD Client 2.0";
+ private boolean returnDepositReceipt = true;
+
+ public String getUserAgent()
+ {
+ return userAgent;
+ }
+
+ public void setUserAgent(String userAgent)
+ {
+ this.userAgent = userAgent;
+ }
+
+ public boolean returnDepositReceipt()
+ {
+ return returnDepositReceipt;
+ }
+
+ public void setReturnDepositReceipt(boolean returnDepositReceipt)
+ {
+ this.returnDepositReceipt = returnDepositReceipt;
+ }
+}
Added: JavaClient2.0/src/main/java/org/swordapp/client/CollectionEntries.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/CollectionEntries.java (rev 0)
+++ JavaClient2.0/src/main/java/org/swordapp/client/CollectionEntries.java 2011-04-19 17:49:46 UTC (rev 252)
@@ -0,0 +1,31 @@
+package org.swordapp.client;
+
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+
+import java.util.List;
+
+public class CollectionEntries
+{
+ private Feed feed;
+
+ public CollectionEntries(Feed feed)
+ {
+ this.feed = feed;
+ }
+
+ public Feed getFeed()
+ {
+ return feed;
+ }
+
+ public List<Entry> getEntries()
+ {
+ return this.feed.getEntries();
+ }
+
+ public Entry getEntry(String s)
+ {
+ return this.feed.getEntry(s);
+ }
+}
Added: JavaClient2.0/src/main/java/org/swordapp/client/Content.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/Content.java (rev 0)
+++ JavaClient2.0/src/main/java/org/swordapp/client/Content.java 2011-04-19 17:49:46 UTC (rev 252)
@@ -0,0 +1,54 @@
+package org.swordapp.client;
+
+import org.apache.abdera.model.Feed;
+
+import javax.activation.MimeType;
+import java.io.InputStream;
+
+public class Content
+{
+ private MimeType mimeType;
+ private String packaging;
+ private InputStream inputStream;
+ private Feed feed;
+
+ public MimeType getMimeType()
+ {
+ return mimeType;
+ }
+
+ public void setMimeType(MimeType mimeType)
+ {
+ this.mimeType = mimeType;
+ }
+
+ public String getPackaging()
+ {
+ return packaging;
+ }
+
+ public void setPackaging(String packaging)
+ {
+ this.packaging = packaging;
+ }
+
+ public InputStream getInputStream()
+ {
+ return inputStream;
+ }
+
+ public void setInputStream(InputStream inputStream)
+ {
+ this.inputStream = inputStream;
+ }
+
+ public Feed getFeed()
+ {
+ return feed;
+ }
+
+ public void setFeed(Feed feed)
+ {
+ this.feed = feed;
+ }
+}
Added: JavaClient2.0/src/main/java/org/swordapp/client/Deposit.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/Deposit.java (rev 0)
+++ JavaClient2.0/src/main/java/org/swordapp/client/Deposit.java 2011-04-19 17:49:46 UTC (rev 252)
@@ -0,0 +1,167 @@
+package org.swordapp.client;
+
+import java.io.InputStream;
+
+public class Deposit
+{
+ private EntryPart entryPart = null;
+ private InputStream file = null;
+ private String filename;
+ private String mimeType;
+ private String slug = null;
+ private String md5 = null;
+ private String packaging;
+ private boolean inProgress = false;
+ private boolean suppressMetadata = false;
+
+ public Deposit(EntryPart entryPart)
+ {
+ this(entryPart, null, false, false);
+ }
+
+ public Deposit(EntryPart entryPart, String slug, boolean inProgress, boolean suppressMetadata)
+ {
+ this.entryPart = entryPart;
+ this.slug = slug;
+ this.inProgress = inProgress;
+ this.suppressMetadata = suppressMetadata;
+ }
+
+ public Deposit(InputStream file, String filename, String mimeType, String packaging)
+ {
+ this.file = file;
+ this.filename = filename;
+ this.mimeType = mimeType;
+ this.packaging = packaging;
+ }
+
+ public Deposit(EntryPart entryPart, InputStream file, String filename, String mimeType, String packaging)
+ {
+ this.entryPart = entryPart;
+ this.file = file;
+ this.filename = filename;
+ this.mimeType = mimeType;
+ this.packaging = packaging;
+
+ // now, since we have got an EntryPart and an InputStream, we need to set the content src of the EntryPart
+ this.entryPart.referenceMediaPart(mimeType);
+ }
+
+ public Deposit(InputStream file, String filename, String mimeType, String packaging,
+ String slug, String md5, boolean inProgress, boolean suppressMetadata)
+ {
+ this.file = file;
+ this.filename = filename;
+ this.mimeType = mimeType;
+ this.packaging = packaging;
+ this.slug = slug;
+ this.md5 = md5;
+ this.inProgress = inProgress;
+ this.suppressMetadata = suppressMetadata;
+ }
+
+ public boolean isEntryOnly()
+ {
+ return this.entryPart != null && this.file == null;
+ }
+
+ public boolean isMultipart()
+ {
+ return this.entryPart != null && this.file != null;
+ }
+
+ public boolean isBinaryOnly()
+ {
+ return this.entryPart == null && this.file != null;
+ }
+
+ public EntryPart getEntryPart()
+ {
+ return entryPart;
+ }
+
+ public void setEntryPart(EntryPart entryPart)
+ {
+ this.entryPart = entryPart;
+ }
+
+ public InputStream getFile()
+ {
+ return file;
+ }
+
+ public void setFile(InputStream file)
+ {
+ this.file = file;
+ }
+
+ public String getFilename()
+ {
+ return filename;
+ }
+
+ public void setFilename(String filename)
+ {
+ this.filename = filename;
+ }
+
+ public String getMimeType()
+ {
+ return mimeType;
+ }
+
+ public void setMimeType(String mimeType)
+ {
+ this.mimeType = mimeType;
+ }
+
+ public String getSlug()
+ {
+ return slug;
+ }
+
+ public void setSlug(String slug)
+ {
+ this.slug = slug;
+ }
+
+ public String getMd5()
+ {
+ return md5;
+ }
+
+ public void setMd5(String md5)
+ {
+ this.md5 = md5;
+ }
+
+ public String getPackaging()
+ {
+ return packaging;
+ }
+
+ public void setPackaging(String packaging)
+ {
+ this.packaging = packaging;
+ }
+
+ public boolean isInProgress()
+ {
+ return inProgress;
+ }
+
+ public void setInProgress(boolean inProgress)
+ {
+ this.inProgress = inProgress;
+ }
+
+ public boolean isSuppressMetadata()
+ {
+ return suppressMetadata;
+ }
+
+ public void setSuppressMetadata(boolean suppressMetadata)
+ {
+ this.suppressMetadata = suppressMetadata;
+ }
+}
Added: JavaClient2.0/src/main/java/org/swordapp/client/DepositReceipt.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/DepositReceipt.java (rev 0)
+++ JavaClient2.0/src/main/java/org/swordapp/client/DepositReceipt.java 2011-04-19 17:49:46 UTC (rev 252)
@@ -0,0 +1,42 @@
+package org.swordapp.client;
+
+import org.apache.abdera.i18n.iri.IRI;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Link;
+
+import javax.activation.MimeType;
+
+public class DepositReceipt
+{
+ private Entry entry;
+
+ public DepositReceipt(Entry entry)
+ {
+ this.entry = entry;
+ }
+
+ public Entry getEntry()
+ {
+ return entry;
+ }
+
+ public IRI getContentSrc()
+ {
+ return this.entry.getContentSrc();
+ }
+
+ public MimeType getContentMimeType()
+ {
+ return this.entry.getContentMimeType();
+ }
+
+ public Link getEditMediaLink(String type)
+ {
+ return this.getEditMediaLink(type, null);
+ }
+
+ public Link getEditMediaLink(String type, String hreflang)
+ {
+ return this.entry.getEditMediaLink(type, hreflang);
+ }
+}
Added: JavaClient2.0/src/main/java/org/swordapp/client/EntryPart.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/EntryPart.java (rev 0)
+++ JavaClient2.0/src/main/java/org/swordapp/client/EntryPart.java 2011-04-19 17:49:46 UTC (rev 252)
@@ -0,0 +1,48 @@
+package org.swordapp.client;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.i18n.iri.IRI;
+import org.apache.abdera.model.Element;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.ExtensibleElement;
+
+import javax.xml.namespace.QName;
+import java.util.UUID;
+
+public class EntryPart
+{
+ private Entry entry;
+
+ public EntryPart()
+ {
+ Abdera ab = new Abdera();
+ this.entry = ab.newEntry();
+ }
+
+ public Entry getEntry()
+ {
+ return entry;
+ }
+
+ public void referenceMediaPart(String mimeType)
+ {
+ String uuid = UUID.randomUUID().toString();
+ this.entry.setContent(new IRI("cid:" + uuid), mimeType);
+ }
+
+ public Element addDublinCore(String field, String value)
+ {
+ QName term = new QName(UriRegistry.DC_NAMESPACE, field);
+ return this.entry.addSimpleExtension(term, value);
+ }
+
+ public Element addSimpleExtension(QName qName, String s)
+ {
+ return this.entry.addSimpleExtension(qName, s);
+ }
+
+ public <T extends ExtensibleElement> T addExtension(Element element)
+ {
+ return this.entry.addExtension(element);
+ }
+}
Added: JavaClient2.0/src/main/java/org/swordapp/client/HttpHeaders.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/HttpHeaders.java (rev 0)
+++ JavaClient2.0/src/main/java/org/swordapp/client/HttpHeaders.java 2011-04-19 17:49:46 UTC (rev 252)
@@ -0,0 +1,121 @@
+package org.swordapp.client;
+
+import org.apache.abdera.protocol.client.ClientResponse;
+import org.apache.abdera.protocol.client.RequestOptions;
+import org.apache.log4j.Logger;
+
+public class HttpHeaders
+{
+ private static Logger log = Logger.getLogger(HttpHeaders.class);
+
+ public void addContentDisposition(RequestOptions options, String filename)
+ throws SWORDClientException
+ {
+ if (filename == null || "".equals(filename))
+ {
+ log.error("No filename has been specified for the Content-Disposition, but this is a required field; throwing Exception");
+ throw new SWORDClientException("No filename has been specified for the Content-Disposition, but this is a required field");
+ }
+ options.addHeader("Content-Disposition", "attachment; filename=" + filename);
+ }
+
+ public void addContentMd5(RequestOptions options, String checksum)
+ {
+ if (checksum != null && !"".equals(checksum))
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("Adding HTTP Header to RequestOptions; Content-MD5: " + checksum);
+ }
+ options.addHeader("Content-MD5", checksum);
+ }
+ }
+
+ public void addPackaging(RequestOptions options, String packaging)
+ {
+ if (packaging != null && !"".equals(packaging))
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("Adding HTTP Header to RequestOptions; Packaging: " + packaging);
+ }
+ options.addHeader("Packaging", packaging);
+ }
+ }
+
+ public void addAcceptPackaging(RequestOptions options, String packaging)
+ {
+ if (packaging != null && !"".equals(packaging))
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("Adding HTTP Header to RequestOptions; Accept-Packaging: " + packaging);
+ }
+ options.addHeader("Accept-Packaging", packaging);
+ }
+ }
+
+ public void addAccept(RequestOptions options, String mimeType)
+ {
+ if (mimeType != null && !"".equals(mimeType))
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("Adding HTTP Header to RequestOptions; Accept: " + mimeType);
+ }
+ options.addHeader("Accept", mimeType);
+ }
+ }
+
+ public void addInProgress(RequestOptions options, boolean inProgress)
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("Adding HTTP Header to RequestOptions; In-Progress: " + (inProgress ? "true" : "false"));
+ }
+ options.addHeader("In-Progress", inProgress ? "true" : "false");
+ }
+
+ public void addSuppressMetadata(RequestOptions options, boolean suppressMetadata)
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("Adding HTTP Header to RequestOptions; Suppress-Metadata: " + (suppressMetadata ? "true" : "false"));
+ }
+ options.addHeader("Suppress-Metadata", suppressMetadata ? "true" : "false");
+ }
+
+ public void addSlug(RequestOptions options, String slug)
+ {
+ if (slug != null && !"".equals(slug))
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("Adding HTTP Header to RequestOptions; Slug: " + slug);
+ }
+ options.addHeader("Slug", slug);
+ }
+ }
+
+ public void addOnBehalfOf(RequestOptions options, String username)
+ {
+ if (username != null && !"".equals(username))
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("Adding HTTP Header to RequestOptions; On-Behalf-Of: " + username);
+ }
+ options.addHeader("On-Behalf_of", username);
+ }
+ }
+
+ public String getLocation(ClientResponse resp)
+ {
+ return resp.getHeader("Location");
+ }
+
+ public String getPackaging(ClientResponse resp)
+ {
+ return resp.getHeader("Packaging");
+ }
+}
Added: JavaClient2.0/src/main/java/org/swordapp/client/ProtocolViolationException.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/ProtocolViolationException.java (rev 0)
+++ JavaClient2.0/src/main/java/org/swordapp/client/ProtocolViolationException.java 2011-04-19 17:49:46 UTC (rev 252)
@@ -0,0 +1,24 @@
+package org.swordapp.client;
+
+public class ProtocolViolationException extends Exception
+{
+ public ProtocolViolationException()
+ {
+ super();
+ }
+
+ public ProtocolViolationException(String message)
+ {
+ super(message);
+ }
+
+ public ProtocolViolationException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public ProtocolViolationException(Throwable cause)
+ {
+ super(cause);
+ }
+}
Added: JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java (rev 0)
+++ JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java 2011-04-19 17:49:46 UTC (rev 252)
@@ -0,0 +1,584 @@
+package org.swordapp.client;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+import org.apache.abdera.model.Service;
+import org.apache.abdera.protocol.Response;
+import org.apache.abdera.protocol.client.AbderaClient;
+import org.apache.abdera.protocol.client.ClientResponse;
+import org.apache.abdera.protocol.client.RequestOptions;
+import org.apache.abdera.protocol.client.util.MultipartRelatedRequestEntity;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
+import org.apache.log4j.Logger;
+
+import javax.activation.MimeType;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+public class SWORDClient
+{
+ private static Logger log = Logger.getLogger(SWORDClient.class);
+
+ private ClientConfiguration config;
+
+ private Abdera abdera;
+
+ public SWORDClient()
+ {
+ this(new ClientConfiguration());
+ }
+
+ public SWORDClient(ClientConfiguration config)
+ {
+ this.config = config;
+ this.abdera = new Abdera();
+ }
+
+ public ServiceDocument getServiceDocument(String sdURL)
+ throws SWORDClientException, ProtocolViolationException
+ {
+ return this.getServiceDocument(sdURL, null);
+ }
+
+ public ServiceDocument getServiceDocument(String sdURL, AuthCredentials auth)
+ throws SWORDClientException, ProtocolViolationException
+ {
+ // do some error checking and validations
+ if (sdURL == null)
+ {
+ log.error("Null string passed in to getServiceDocument; returning null");
+ return null;
+ }
+ if (log.isDebugEnabled())
+ {
+ log.debug("getting service document from " + sdURL);
+ }
+
+ AbderaClient client = new AbderaClient(this.abdera);
+ RequestOptions options = this.getDefaultRequestOptions();
+
+ // prepare the bits of the request
+
+ // ensure that the URL is valid
+ URL url = this.formaliseURL(sdURL);
+ if (log.isDebugEnabled())
+ {
+ log.debug("Formalised Service Document URL to " + url.toString());
+ }
+
+ // sort out the HTTP basic authentication credentials
+ this.prepAuth(auth, client, options);
+
+ // log the request
+ this.logGetRequest(auth, url.toString(), "Service Document");
+
+ // make the request for the service document
+ if (log.isDebugEnabled())
+ {
+ log.debug("Connecting to Server to retrieve Service Document from " + url.toString() + " ...");
+ }
+ ClientResponse resp = client.get(url.toString(), options);
+ if (log.isDebugEnabled())
+ {
+ log.debug("Successfully retrieved Service Document from " + url.toString());
+ }
+
+ // if the response is successful, get the service document out of the response,
+ // and wrap it in the SWORD ServiceDocument class
+ if (resp.getType() == Response.ResponseType.SUCCESS)
+ {
+ log.info("Retrieved Service Document from " + url.toString() + " with HTTP success code");
+ Document<Service> doc = resp.getDocument();
+ Service sd = doc.getRoot();
+ ServiceDocument ssd = new ServiceDocument(sd);
+ return ssd;
+ }
+
+ // if we don't get anything respond with null
+ log.warn("Unable to retrieve service document from " + url.toString() + "; responded with " + resp.getStatus()
+ + ". Possible problem with SWORD server, or URL");
+ return null;
+ }
+
+ public CollectionEntries listCollection(SWORDCollection collection)
+ throws SWORDClientException, ProtocolViolationException
+ {
+ return this.listCollection(collection.getHref().toString(), null);
+ }
+
+ public CollectionEntries listCollection(String colURL)
+ throws SWORDClientException, ProtocolViolationException
+ {
+ return this.listCollection(colURL, null);
+ }
+
+ public CollectionEntries listCollection(SWORDCollection collection, AuthCredentials auth)
+ throws SWORDClientException, ProtocolViolationException
+ {
+ return this.listCollection(collection.getHref().toString(), auth);
+ }
+
+ public CollectionEntries listCollection(String colURL, AuthCredentials auth)
+ throws SWORDClientException, ProtocolViolationException
+ {
+ // do some error checking and validation
+ if (colURL == null)
+ {
+ log.error("Null URL passed in to listCollection; returning null");
+ return null;
+ }
+ if (log.isDebugEnabled())
+ {
+ log.debug("listing collection contents from " + colURL);
+ }
+
+ AbderaClient client = new AbderaClient(this.abdera);
+ RequestOptions options = this.getDefaultRequestOptions();
+
+ // ensure that the URL is valid
+ URL url = this.formaliseURL(colURL);
+ if (log.isDebugEnabled())
+ {
+ log.debug("Formalised Collection URL to " + url.toString());
+ }
+
+ // sort out the HTTP basic authentication credentials
+ this.prepAuth(auth, client, options);
+
+ // log the request
+ this.logGetRequest(auth, colURL, "Collection Entry List");
+
+ // make the request for the service document
+ if (log.isDebugEnabled())
+ {
+ log.debug("Connecting to Server to list contents of Collection " + url.toString() + " ...");
+ }
+ ClientResponse resp = client.get(url.toString(), options);
+ if (log.isDebugEnabled())
+ {
+ log.debug("Successfully retrieved Collection contents list from " + url.toString());
+ }
+
+ // if the response is successful, get the service document out of the response,
+ // and wrap it in the SWORD ServiceDocument class
+ if (resp.getType() == Response.ResponseType.SUCCESS)
+ {
+ log.info("Successfully retrieved Collection Entry List from " + url.toString());
+ Document<Feed> doc = resp.getDocument();
+ Feed feed = doc.getRoot();
+ CollectionEntries ce = new CollectionEntries(feed);
+ return ce;
+ }
+
+ // if we don't get anything respond with null
+ log.warn("Unable to retrieve collection entry list from " + url.toString() + "; responded with " + resp.getStatus()
+ + ". Possible problem with SWORD server, or URL");
+ return null;
+ }
+
+ public DepositReceipt getDepositReceipt(String editURL)
+ throws SWORDClientException
+ {
+ return null;
+ }
+
+ public Statement getStatement()
+ throws SWORDClientException
+ {
+ return null;
+ }
+
+ public DepositReceipt deposit(SWORDCollection collection, Deposit deposit)
+ throws SWORDClientException, SWORDError, ProtocolViolationException
+ {
+ return this.deposit(collection.getHref().toString(), deposit, null);
+ }
+
+ public DepositReceipt deposit(String targetURL, Deposit deposit)
+ throws SWORDClientException, SWORDError, ProtocolViolationException
+ {
+ return this.deposit(targetURL, deposit, null);
+ }
+
+ public DepositReceipt deposit(SWORDCollection collection, Deposit deposit, AuthCredentials auth)
+ throws SWORDClientException, SWORDError, ProtocolViolationException
+ {
+ return this.deposit(collection.getHref().toString(), deposit, auth);
+ }
+
+ public DepositReceipt deposit(String targetURL, Deposit deposit, AuthCredentials auth)
+ throws SWORDClientException, SWORDError, ProtocolViolationException
+ {
+ // some initial error checking and validation
+ if (targetURL == null)
+ {
+ log.error("Null URL passed into deposit method");
+ throw new SWORDClientException("Null URL passed into deposit method");
+ }
+ if (deposit == null)
+ {
+ log.error("Null Deposit Object passed into deposit method");
+ throw new SWORDClientException("Null Deposit Object passed into deposit method");
+ }
+ if (log.isDebugEnabled())
+ {
+ log.debug("beginning deposit on Collection url " + targetURL);
+ }
+
+ AbderaClient client = new AbderaClient(this.abdera);
+ RequestOptions options = this.getDefaultRequestOptions();
+ HttpHeaders http = new HttpHeaders();
+
+ // ensure that the URL is valid
+ URL url = this.formaliseURL(targetURL);
+ if (log.isDebugEnabled())
+ {
+ log.debug("Formalised Collection URL to " + url.toString());
+ ...
[truncated message content] |
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2011-05-09 12:58:58
|
Revision: 283
http://sword-app.svn.sourceforge.net/sword-app/?rev=283&view=rev
Author: richard-jones
Date: 2011-05-09 12:58:52 +0000 (Mon, 09 May 2011)
Log Message:
-----------
fix http header adding bugs, which results in what appears to be a working content retrieve process
Modified Paths:
--------------
JavaClient2.0/src/main/java/org/swordapp/client/HttpHeaders.java
JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java
Added Paths:
-----------
JavaClient2.0/sword-client.iml
Modified: JavaClient2.0/src/main/java/org/swordapp/client/HttpHeaders.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/HttpHeaders.java 2011-05-09 12:57:39 UTC (rev 282)
+++ JavaClient2.0/src/main/java/org/swordapp/client/HttpHeaders.java 2011-05-09 12:58:52 UTC (rev 283)
@@ -8,7 +8,7 @@
{
private static Logger log = Logger.getLogger(HttpHeaders.class);
- public RequestOptions addContentDisposition(RequestOptions options, String filename)
+ public void addContentDisposition(RequestOptions options, String filename)
throws SWORDClientException
{
if (filename == null || "".equals(filename))
@@ -16,11 +16,10 @@
log.error("No filename has been specified for the Content-Disposition, but this is a required field; throwing Exception");
throw new SWORDClientException("No filename has been specified for the Content-Disposition, but this is a required field");
}
- options.addHeader("Content-Disposition", "attachment; filename=" + filename);
- return options;
+ options.setHeader("Content-Disposition", "attachment; filename=" + filename);
}
- public RequestOptions addContentMd5(RequestOptions options, String checksum)
+ public void addContentMd5(RequestOptions options, String checksum)
{
if (checksum != null && !"".equals(checksum))
{
@@ -28,12 +27,11 @@
{
log.debug("Adding HTTP Header to RequestOptions; Content-MD5: " + checksum);
}
- options.addHeader("Content-MD5", checksum);
+ options.setHeader("Content-MD5", checksum);
}
- return options;
}
- public RequestOptions addPackaging(RequestOptions options, String packaging)
+ public void addPackaging(RequestOptions options, String packaging)
{
if (packaging != null && !"".equals(packaging))
{
@@ -41,12 +39,11 @@
{
log.debug("Adding HTTP Header to RequestOptions; Packaging: " + packaging);
}
- options.addHeader("Packaging", packaging);
+ options.setHeader("Packaging", packaging);
}
- return options;
}
- public RequestOptions addAcceptPackaging(RequestOptions options, String packaging)
+ public void addAcceptPackaging(RequestOptions options, String packaging)
{
if (packaging != null && !"".equals(packaging))
{
@@ -54,13 +51,11 @@
{
log.debug("Adding HTTP Header to RequestOptions; Accept-Packaging: " + packaging);
}
- options.addHeader("Accept-Packaging", packaging);
- System.out.println("whatever");
+ options.setHeader("Accept-Packaging", packaging);
}
- return options;
}
- public RequestOptions addAccept(RequestOptions options, String mimeType)
+ public void addAccept(RequestOptions options, String mimeType)
{
if (mimeType != null && !"".equals(mimeType))
{
@@ -68,32 +63,29 @@
{
log.debug("Adding HTTP Header to RequestOptions; Accept: " + mimeType);
}
- options.addHeader("Accept", mimeType);
+ options.setHeader("Accept", mimeType);
}
- return options;
}
- public RequestOptions addInProgress(RequestOptions options, boolean inProgress)
+ public void addInProgress(RequestOptions options, boolean inProgress)
{
if (log.isDebugEnabled())
{
log.debug("Adding HTTP Header to RequestOptions; In-Progress: " + (inProgress ? "true" : "false"));
}
- options.addHeader("In-Progress", inProgress ? "true" : "false");
- return options;
+ options.setHeader("In-Progress", inProgress ? "true" : "false");
}
- public RequestOptions addSuppressMetadata(RequestOptions options, boolean suppressMetadata)
+ public void addMetadataRelevant(RequestOptions options, boolean suppressMetadata)
{
if (log.isDebugEnabled())
{
- log.debug("Adding HTTP Header to RequestOptions; Suppress-Metadata: " + (suppressMetadata ? "true" : "false"));
+ log.debug("Adding HTTP Header to RequestOptions; Metadata-Relevant: " + (suppressMetadata ? "true" : "false"));
}
- options.addHeader("Suppress-Metadata", suppressMetadata ? "true" : "false");
- return options;
+ options.setHeader("Metadata-Relevant", suppressMetadata ? "true" : "false");
}
- public RequestOptions addSlug(RequestOptions options, String slug)
+ public void addSlug(RequestOptions options, String slug)
{
if (slug != null && !"".equals(slug))
{
@@ -101,12 +93,11 @@
{
log.debug("Adding HTTP Header to RequestOptions; Slug: " + slug);
}
- options.addHeader("Slug", slug);
+ options.setHeader("Slug", slug);
}
- return options;
}
- public RequestOptions addOnBehalfOf(RequestOptions options, String username)
+ public void addOnBehalfOf(RequestOptions options, String username)
{
if (username != null && !"".equals(username))
{
@@ -114,9 +105,8 @@
{
log.debug("Adding HTTP Header to RequestOptions; On-Behalf-Of: " + username);
}
- options.addHeader("On-Behalf_of", username);
+ options.setHeader("On-Behalf-Of", username);
}
- return options;
}
public String getLocation(ClientResponse resp)
Modified: JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java 2011-05-09 12:57:39 UTC (rev 282)
+++ JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java 2011-05-09 12:58:52 UTC (rev 283)
@@ -250,7 +250,6 @@
// prepare the common HTTP headers (other than the auth ones)
http.addInProgress(options, deposit.isInProgress());
- http.addSuppressMetadata(options, deposit.isSuppressMetadata());
http.addSlug(options, deposit.getSlug());
ClientResponse resp;
@@ -387,8 +386,8 @@
this.logGetRequest(auth, contentURL, "Content");
// add the Accept-Packaging header
- options = http.addAcceptPackaging(options, packaging);
- options = http.addAccept(options, mimeType);
+ http.addAcceptPackaging(options, packaging);
+ http.addAccept(options, mimeType);
// make the request for the service document
if (log.isDebugEnabled())
Added: JavaClient2.0/sword-client.iml
===================================================================
--- JavaClient2.0/sword-client.iml (rev 0)
+++ JavaClient2.0/sword-client.iml 2011-05-09 12:58:52 UTC (rev 283)
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
+ <component name="NewModuleRootManager" inherit-compiler-output="false">
+ <output url="file://$MODULE_DIR$/target/classes" />
+ <output-test url="file://$MODULE_DIR$/target/test-classes" />
+ <exclude-output />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
+ <excludeFolder url="file://$MODULE_DIR$/target" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="library" name="Maven: commons-httpclient:commons-httpclient:3.1" level="project" />
+ <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.0.4" level="project" />
+ <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.2" level="project" />
+ <orderEntry type="library" name="Maven: log4j:log4j:1.2.15" level="project" />
+ <orderEntry type="library" name="Maven: org.apache.abdera:abdera-client:1.1.1" level="project" />
+ <orderEntry type="library" name="Maven: org.apache.abdera:abdera-core:1.1.1" level="project" />
+ <orderEntry type="library" name="Maven: org.apache.abdera:abdera-i18n:1.1.1" level="project" />
+ <orderEntry type="library" name="Maven: org.apache.geronimo.specs:geronimo-activation_1.0.2_spec:1.1" level="project" />
+ <orderEntry type="library" name="Maven: org.apache.geronimo.specs:geronimo-stax-api_1.0_spec:1.0.1" level="project" />
+ <orderEntry type="library" name="Maven: org.apache.abdera:abdera-parser:1.1.1" level="project" />
+ <orderEntry type="library" name="Maven: org.apache.ws.commons.axiom:axiom-impl:1.2.10" level="project" />
+ <orderEntry type="library" name="Maven: org.apache.ws.commons.axiom:axiom-api:1.2.10" level="project" />
+ <orderEntry type="library" name="Maven: org.apache.geronimo.specs:geronimo-activation_1.1_spec:1.0.2" level="project" />
+ <orderEntry type="library" name="Maven: org.apache.geronimo.specs:geronimo-javamail_1.4_spec:1.6" level="project" />
+ <orderEntry type="library" name="Maven: jaxen:jaxen:1.1.1" level="project" />
+ <orderEntry type="library" name="Maven: org.codehaus.woodstox:wstx-asl:3.2.6" level="project" />
+ <orderEntry type="library" name="Maven: xml-apis:xml-apis:1.3.02" level="project" />
+ <orderEntry type="library" name="Maven: xerces:xercesImpl:2.6.2" level="project" />
+ </component>
+</module>
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2011-05-14 09:58:27
|
Revision: 314
http://sword-app.svn.sourceforge.net/sword-app/?rev=314&view=rev
Author: richard-jones
Date: 2011-05-14 09:58:20 +0000 (Sat, 14 May 2011)
Log Message:
-----------
full support for protocol operations and packaging terms (sections 6 and 7)
Modified Paths:
--------------
JavaClient2.0/pom.xml
JavaClient2.0/src/main/java/org/swordapp/client/DepositReceipt.java
JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java
JavaClient2.0/src/main/java/org/swordapp/client/SWORDCollection.java
JavaClient2.0/src/main/java/org/swordapp/client/Statement.java
JavaClient2.0/src/main/java/org/swordapp/client/SwordCli.java
JavaClient2.0/src/main/java/org/swordapp/client/UriRegistry.java
JavaClient2.0/sword-client.iml
Added Paths:
-----------
JavaClient2.0/src/main/java/org/swordapp/client/AtomStatement.java
JavaClient2.0/src/main/java/org/swordapp/client/OreStatement.java
JavaClient2.0/src/main/java/org/swordapp/client/StatementParseException.java
Removed Paths:
-------------
JavaClient2.0/src/main/java/org/swordapp/client/XMLResponse.java
Modified: JavaClient2.0/pom.xml
===================================================================
--- JavaClient2.0/pom.xml 2011-05-12 15:24:12 UTC (rev 313)
+++ JavaClient2.0/pom.xml 2011-05-14 09:58:20 UTC (rev 314)
@@ -1,45 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
- <groupId>org.swordapp</groupId>
- <artifactId>sword-client</artifactId>
- <version>2.0</version>
+ <groupId>org.swordapp</groupId>
+ <artifactId>sword-client</artifactId>
+ <version>2.0</version>
- <dependencies>
- <dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- <version>3.1</version>
- </dependency>
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- <version>1.2.15</version>
- <exclusions>
- <exclusion>
- <groupId>javax.mail</groupId>
- <artifactId>mail</artifactId>
- </exclusion>
- <exclusion>
- <groupId>javax.jms</groupId>
- <artifactId>jms</artifactId>
- </exclusion>
- <exclusion>
- <groupId>com.sun.jdmk</groupId>
- <artifactId>jmxtools</artifactId>
- </exclusion>
- <exclusion>
- <groupId>com.sun.jmx</groupId>
- <artifactId>jmxri</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.apache.abdera</groupId>
- <artifactId>abdera-client</artifactId>
- <version>1.1.1</version>
- </dependency>
- </dependencies>
+ <dependencies>
+ <dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ <version>3.1</version>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.15</version>
+ <exclusions>
+ <exclusion>
+ <groupId>javax.mail</groupId>
+ <artifactId>mail</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>javax.jms</groupId>
+ <artifactId>jms</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.sun.jdmk</groupId>
+ <artifactId>jmxtools</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.sun.jmx</groupId>
+ <artifactId>jmxri</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.abdera</groupId>
+ <artifactId>abdera-client</artifactId>
+ <version>1.1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.dspace</groupId>
+ <artifactId>foresite</artifactId>
+ <version>0.9</version>
+ </dependency>
+ </dependencies>
</project>
\ No newline at end of file
Added: JavaClient2.0/src/main/java/org/swordapp/client/AtomStatement.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/AtomStatement.java (rev 0)
+++ JavaClient2.0/src/main/java/org/swordapp/client/AtomStatement.java 2011-05-14 09:58:20 UTC (rev 314)
@@ -0,0 +1,40 @@
+package org.swordapp.client;
+
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+import org.apache.abdera.protocol.client.ClientResponse;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+public class AtomStatement implements Statement
+{
+ private Feed feed;
+
+ public void parse(ClientResponse resp)
+ throws SWORDClientException, StatementParseException
+ {
+ Document<Feed> doc = resp.getDocument();
+ this.feed = doc.getRoot();
+ }
+
+ public String getMimeType()
+ {
+ return "application/atom+xml;type=feed";
+ }
+
+ public String toString()
+ {
+ try
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ this.feed.writeTo(baos);
+ return baos.toString();
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+}
Modified: JavaClient2.0/src/main/java/org/swordapp/client/DepositReceipt.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/DepositReceipt.java 2011-05-12 15:24:12 UTC (rev 313)
+++ JavaClient2.0/src/main/java/org/swordapp/client/DepositReceipt.java 2011-05-14 09:58:20 UTC (rev 314)
@@ -1,10 +1,14 @@
package org.swordapp.client;
import org.apache.abdera.i18n.iri.IRI;
+import org.apache.abdera.model.Element;
import org.apache.abdera.model.Entry;
import org.apache.abdera.model.Link;
import javax.activation.MimeType;
+import javax.activation.MimeTypeParseException;
+import java.util.ArrayList;
+import java.util.List;
public class DepositReceipt extends SwordResponse
{
@@ -55,11 +59,66 @@
public Link getEditMediaLink(String type, String hreflang)
{
- // type and hreflang can be: null, "*", or a value
- if ("*".equals(type))
- {
-
- }
return this.entry.getEditMediaLink(type, hreflang);
}
+
+ public List<String> getPackaging()
+ {
+ List<Element> packagings = this.entry.getExtensions(UriRegistry.SWORD_PACKAGING);
+ List<String> packages = new ArrayList<String>();
+ for (Element element : packagings)
+ {
+ packages.add(element.getText());
+ }
+
+ // now deal with the default case
+ if (packages.size() == 0)
+ {
+ // add the simple zip
+ packages.add(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ }
+
+ return packages;
+ }
+
+ public Link getStatementLink(String type)
+ throws SWORDClientException
+ {
+ try
+ {
+ String statementRel = UriRegistry.REL_STATEMENT;
+ MimeType mt = new MimeType(type);
+ for (Link link : this.entry.getLinks())
+ {
+ if (statementRel.equals(link.getRel()) &&
+ link.getMimeType().toString().equals(mt.toString()))
+ {
+ return link;
+ }
+ }
+ return null;
+ }
+ catch (MimeTypeParseException e)
+ {
+ throw new SWORDClientException(e);
+ }
+ }
+
+ public Link getOREStatementLink()
+ throws SWORDClientException
+ {
+ return this.getStatementLink("application/rdf+xml");
+ }
+
+ public Link getAtomStatementLink()
+ throws SWORDClientException
+ {
+ Link stmt = this.getStatementLink("application/atom+xml;type=feed");
+ if (stmt == null)
+ {
+ // try an alternative mimetype
+ stmt = this.getStatementLink("application/atom+xml");
+ }
+ return stmt;
+ }
}
Added: JavaClient2.0/src/main/java/org/swordapp/client/OreStatement.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/OreStatement.java (rev 0)
+++ JavaClient2.0/src/main/java/org/swordapp/client/OreStatement.java 2011-05-14 09:58:20 UTC (rev 314)
@@ -0,0 +1,60 @@
+package org.swordapp.client;
+
+import org.apache.abdera.protocol.client.ClientResponse;
+import org.dspace.foresite.OREParser;
+import org.dspace.foresite.OREParserException;
+import org.dspace.foresite.OREParserFactory;
+import org.dspace.foresite.ORESerialiser;
+import org.dspace.foresite.ORESerialiserException;
+import org.dspace.foresite.ORESerialiserFactory;
+import org.dspace.foresite.ResourceMap;
+import org.dspace.foresite.ResourceMapDocument;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class OreStatement implements Statement
+{
+ private ResourceMap rem;
+
+ public void parse(ClientResponse resp)
+ throws SWORDClientException, StatementParseException
+ {
+ try
+ {
+ InputStream is = resp.getInputStream();
+ if (is != null)
+ {
+ OREParser parser = OREParserFactory.getInstance("RDF/XML");
+ this.rem = parser.parse(is);
+ }
+ }
+ catch (IOException e)
+ {
+ throw new SWORDClientException(e);
+ }
+ catch (OREParserException e)
+ {
+ throw new StatementParseException(e);
+ }
+ }
+
+ public String getMimeType()
+ {
+ return "application/rdf+xml";
+ }
+
+ public String toString()
+ {
+ try
+ {
+ ORESerialiser s = ORESerialiserFactory.getInstance("RDF/XML");
+ ResourceMapDocument rmd = s.serialise(rem);
+ return rmd.toString();
+ }
+ catch (ORESerialiserException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+}
Modified: JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java 2011-05-12 15:24:12 UTC (rev 313)
+++ JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java 2011-05-14 09:58:20 UTC (rev 314)
@@ -543,7 +543,7 @@
URL url = this.formaliseURL(deleteUrl);
if (log.isDebugEnabled())
{
- log.debug("Formalised Edit URL to " + url.toString());
+ log.debug("Formalised URL to " + url.toString());
}
// sort out the HTTP basic authentication credentials
@@ -636,40 +636,23 @@
// if there was a success response...
if (status >= 200 && status < 300)
{
- Document doc = resp.getDocument();
- if (doc != null)
+ // we don't know what is returned, so we just sidestep the whole issue and give
+ // the client an inputstream
+ try
{
- // this means we found an XML document, but is it atom or is it something else
- Element element = doc.getRoot();
-
- // is it an entry? If so we treat it like a deposit receipt
- if (element instanceof Entry)
+ InputStream is = resp.getInputStream();
+ if (is == null)
{
- receipt = new DepositReceipt(status, location, (Entry) element);
+ receipt = new SwordResponse(status, location);
}
else
{
- receipt = new XMLResponse(status, location, element);
+ receipt = new BinaryResponse(status, location, is);
}
}
- else
+ catch (IOException e)
{
- try
- {
- InputStream is = resp.getInputStream();
- if (is == null)
- {
- receipt = new SwordResponse(status, location);
- }
- else
- {
- receipt = new BinaryResponse(status, location, is);
- }
- }
- catch (IOException e)
- {
- throw new SWORDClientException(e);
- }
+ throw new SWORDClientException(e);
}
}
else if (status >= 400)
@@ -822,9 +805,53 @@
return null;
}
- public Statement getStatement()
- throws SWORDClientException
+ public Statement getStatement(String statementUrl, Statement statementShell, AuthCredentials auth)
+ throws SWORDClientException, StatementParseException
{
+ // some initial error checking and validation
+ if (statementUrl == null)
+ {
+ log.error("Null URL passed into getStatement method");
+ throw new SWORDClientException("Null URL passed into getStatement method");
+ }
+ if (log.isDebugEnabled())
+ {
+ log.debug("beginning retrieve on statement url " + statementUrl);
+ }
+
+ AbderaClient client = new AbderaClient(this.abdera);
+ RequestOptions options = this.getDefaultRequestOptions();
+ HttpHeaders http = new HttpHeaders();
+
+ // we add accept headers in case content negotiation is required
+ http.addAccept(options, statementShell.getMimeType());
+
+ // ensure that the URL is valid
+ URL url = this.formaliseURL(statementUrl);
+ if (log.isDebugEnabled())
+ {
+ log.debug("Formalised Statement URL to " + url.toString());
+ }
+
+ // sort out the HTTP basic authentication credentials
+ this.prepAuth(auth, client, options);
+
+ ClientResponse resp = client.get(url.toString(), options);
+
+ // is this an atom feed or an oai-ore doc or something else
+ int status = resp.getStatus();
+ if (status == 200)
+ {
+ statementShell.parse(resp);
+ return statementShell;
+ }
+ else
+ {
+ // FIXME: this needs to handle all the other possible response codes
+ this.handleError();
+ }
+
+ // FIXME: we might want to error out here if we haven't already returned
return null;
}
@@ -929,7 +956,9 @@
}
else if (resp.getStatus() == 406)
{
- // this means that the Accept/Accept-Packaging header supplied an unacceptable type/packaging format
+ // FIXME: this needs to handle all the other possible response codes
+ log.info("Deposit request on " + url.toString() + " return HTTP status " + resp.getStatus());
+ this.handleError();
}
// if we don't get anything respond with null
Modified: JavaClient2.0/src/main/java/org/swordapp/client/SWORDCollection.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/SWORDCollection.java 2011-05-12 15:24:12 UTC (rev 313)
+++ JavaClient2.0/src/main/java/org/swordapp/client/SWORDCollection.java 2011-05-14 09:58:20 UTC (rev 314)
@@ -73,7 +73,18 @@
}
}
- public List<String> getPackaging()
+ public String getAbstract()
+ {
+ // there ought to be only one abstract, but just in case let's just return the first one
+ List<Element> abstracts = this.collection.getExtensions(UriRegistry.DC_ABSTRACT);
+ for (Element ab : abstracts)
+ {
+ return ab.getText();
+ }
+ return null;
+ }
+
+ public List<String> getAcceptPackaging()
{
List<String> packaging = new ArrayList<String>();
List<Element> acceptPackagings = this.collection.getExtensions(UriRegistry.SWORD_ACCEPT_PACKAGING);
Modified: JavaClient2.0/src/main/java/org/swordapp/client/Statement.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/Statement.java 2011-05-12 15:24:12 UTC (rev 313)
+++ JavaClient2.0/src/main/java/org/swordapp/client/Statement.java 2011-05-14 09:58:20 UTC (rev 314)
@@ -1,6 +1,10 @@
package org.swordapp.client;
-public class Statement
+import org.apache.abdera.protocol.client.ClientResponse;
+
+public interface Statement
{
+ public void parse(ClientResponse resp) throws SWORDClientException, StatementParseException;
+ public String getMimeType();
}
Added: JavaClient2.0/src/main/java/org/swordapp/client/StatementParseException.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/StatementParseException.java (rev 0)
+++ JavaClient2.0/src/main/java/org/swordapp/client/StatementParseException.java 2011-05-14 09:58:20 UTC (rev 314)
@@ -0,0 +1,24 @@
+package org.swordapp.client;
+
+public class StatementParseException extends Exception
+{
+ public StatementParseException()
+ {
+ super();
+ }
+
+ public StatementParseException(String message)
+ {
+ super(message);
+ }
+
+ public StatementParseException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public StatementParseException(Throwable cause)
+ {
+ super(cause);
+ }
+}
Modified: JavaClient2.0/src/main/java/org/swordapp/client/SwordCli.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/SwordCli.java 2011-05-12 15:24:12 UTC (rev 313)
+++ JavaClient2.0/src/main/java/org/swordapp/client/SwordCli.java 2011-05-14 09:58:20 UTC (rev 314)
@@ -23,9 +23,85 @@
throws Exception
{
SwordCli cli = new SwordCli();
- cli.tryAddMetadataAndPackage();
+ cli.tryStatement();
}
+ private void tryStatement()
+ throws Exception
+ {
+ // first we need to put some content in
+ SWORDClient client = new SWORDClient();
+ InputStream is = new FileInputStream(new File(exampleZip));
+ DepositFactory factory = new DepositFactory();
+ Deposit deposit = factory.newBinaryOnly(is, "example.zip", "application/zip", UriRegistry.PACKAGE_SIMPLE_ZIP);
+ AuthCredentials auth = new AuthCredentials("sword", "sword", "obo");
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, auth);
+ DepositReceipt receipt = null;
+ List<SWORDWorkspace> ws = sd.getWorkspaces();
+ for (SWORDWorkspace w : ws)
+ {
+ List<SWORDCollection> collections = w.getCollections();
+ for (SWORDCollection c : collections)
+ {
+ // do the deposit to the first collection we find
+ receipt = client.deposit(c, deposit, auth);
+ break;
+ }
+ }
+
+ Link oreStatementLink = receipt.getStatementLink("application/rdf+xml");
+ String oreUri = oreStatementLink.getHref().toString();
+ Link feedStatementLink = receipt.getStatementLink("application/atom+xml;type=feed");
+ String feedUri = feedStatementLink.getHref().toString();
+
+ Statement oreStmt = client.getStatement(oreUri, new OreStatement(), auth);
+ Statement feedStmt = client.getStatement(feedUri, new AtomStatement(), auth);
+
+ System.out.println(oreStmt.toString());
+ System.out.println(feedStmt.toString());
+
+ System.out.println("---- and now with content negotiation ---");
+
+ Link editlink = receipt.getEntry().getEditLink();
+ String editiri = editlink.getHref().toString();
+
+ Statement oreStmtCN = client.getStatement(editiri, new OreStatement(), auth);
+ Statement feedStmtCN = client.getStatement(editiri, new AtomStatement(), auth);
+
+ System.out.println(oreStmtCN.toString());
+ System.out.println(feedStmtCN.toString());
+ }
+
+ private void tryDelete()
+ throws Exception
+ {
+ // first we need to put some content in
+ SWORDClient client = new SWORDClient();
+ InputStream is = new FileInputStream(new File(exampleZip));
+ DepositFactory factory = new DepositFactory();
+ Deposit deposit = factory.newBinaryOnly(is, "example.zip", "application/zip", UriRegistry.PACKAGE_SIMPLE_ZIP);
+ AuthCredentials auth = new AuthCredentials("sword", "sword", "obo");
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, auth);
+ DepositReceipt receipt = null;
+ List<SWORDWorkspace> ws = sd.getWorkspaces();
+ for (SWORDWorkspace w : ws)
+ {
+ List<SWORDCollection> collections = w.getCollections();
+ for (SWORDCollection c : collections)
+ {
+ // do the deposit to the first collection we find
+ receipt = client.deposit(c, deposit, auth);
+ break;
+ }
+ }
+
+ Link editlink = receipt.getEntry().getEditLink();
+ String editiri = editlink.getHref().toString();
+
+ SwordResponse resp = client.delete(editiri, auth);
+ System.out.println(resp.getStatusCode());
+ }
+
private void tryAddMetadataAndPackage()
throws Exception
{
@@ -514,7 +590,7 @@
System.out.println("\t\tURI (Resolved): " + c.getResolvedHref());
System.out.println("\t\tMediation Allowed: " + c.allowsMediation());
- List<String> packaging = c.getPackaging();
+ List<String> packaging = c.getAcceptPackaging();
for (String pack : packaging)
{
System.out.println("\t\tAccepts Packaging: " + pack);
Modified: JavaClient2.0/src/main/java/org/swordapp/client/UriRegistry.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/UriRegistry.java 2011-05-12 15:24:12 UTC (rev 313)
+++ JavaClient2.0/src/main/java/org/swordapp/client/UriRegistry.java 2011-05-14 09:58:20 UTC (rev 314)
@@ -17,7 +17,12 @@
public static QName SWORD_TREATMENT = new QName(SWORD_TERMS_NAMESPACE, "treatment");
public static QName SWORD_ACCEPT_PACKAGING = new QName(SWORD_TERMS_NAMESPACE, "acceptPackaging");
public static QName SWORD_SERVICE = new QName(SWORD_TERMS_NAMESPACE, "service");
+ public static QName SWORD_PACKAGING = new QName(SWORD_TERMS_NAMESPACE, "packaging");
+ public static QName DC_ABSTRACT = new QName(DC_NAMESPACE, "abstract");
+ // rel values
+ public static String REL_STATEMENT = SWORD_TERMS_NAMESPACE + "statement";
+
// Package Formats
public static String PACKAGE_SIMPLE_ZIP = "http://purl.org/net/sword/package/SimpleZip";
public static String PACKAGE_BINARY = "http://purl.org/net/sword/package/Binary";
Deleted: JavaClient2.0/src/main/java/org/swordapp/client/XMLResponse.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/XMLResponse.java 2011-05-12 15:24:12 UTC (rev 313)
+++ JavaClient2.0/src/main/java/org/swordapp/client/XMLResponse.java 2011-05-14 09:58:20 UTC (rev 314)
@@ -1,19 +0,0 @@
-package org.swordapp.client;
-
-import org.apache.abdera.model.Element;
-
-public class XMLResponse extends SwordResponse
-{
- private Element element;
-
- public XMLResponse(int statusCode, String location, Element element)
- {
- super(statusCode, location);
- this.element = element;
- }
-
- public Element getElement()
- {
- return element;
- }
-}
Modified: JavaClient2.0/sword-client.iml
===================================================================
--- JavaClient2.0/sword-client.iml 2011-05-12 15:24:12 UTC (rev 313)
+++ JavaClient2.0/sword-client.iml 2011-05-14 09:58:20 UTC (rev 314)
@@ -3,7 +3,6 @@
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
- <exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
@@ -26,9 +25,29 @@
<orderEntry type="library" name="Maven: org.apache.geronimo.specs:geronimo-activation_1.1_spec:1.0.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.geronimo.specs:geronimo-javamail_1.4_spec:1.6" level="project" />
<orderEntry type="library" name="Maven: jaxen:jaxen:1.1.1" level="project" />
- <orderEntry type="library" name="Maven: org.codehaus.woodstox:wstx-asl:3.2.6" level="project" />
- <orderEntry type="library" name="Maven: xml-apis:xml-apis:1.3.02" level="project" />
- <orderEntry type="library" name="Maven: xerces:xercesImpl:2.6.2" level="project" />
+ <orderEntry type="library" name="Maven: org.codehaus.woodstox:wstx-asl:3.0.0" level="project" />
+ <orderEntry type="library" name="Maven: xml-apis:xml-apis:1.0.b2" level="project" />
+ <orderEntry type="library" name="Maven: xerces:xercesImpl:2.7.1" level="project" />
+ <orderEntry type="library" name="Maven: org.dspace:foresite:0.9" level="project" />
+ <orderEntry type="library" name="Maven: com.hp.hpl.jena:jena:2.5.5" level="project" />
+ <orderEntry type="library" name="Maven: com.hp.hpl.jena:arq:2.2" level="project" />
+ <orderEntry type="library" name="Maven: org.apache.lucene:lucene-core:2.2.0" level="project" />
+ <orderEntry type="library" name="Maven: com.hp.hpl.jena:arq-extra:2.2" level="project" />
+ <orderEntry type="library" name="Maven: com.hp.hpl.jena:jenatest:2.5.5" level="project" />
+ <orderEntry type="library" name="Maven: com.hp.hpl.jena:iri:0.5" level="project" />
+ <orderEntry type="library" name="Maven: com.ibm.icu:icu4j:3.4.4" level="project" />
+ <orderEntry type="library" name="Maven: antlr:antlr:2.7.5" level="project" />
+ <orderEntry type="library" name="Maven: com.hp.hpl.jena:concurrent-jena:1.3.2" level="project" />
+ <orderEntry type="library" name="Maven: com.hp.hpl.jena:json-jena:1.0" level="project" />
+ <orderEntry type="library" name="Maven: stax:stax-api:1.0" level="project" />
+ <orderEntry type="library" name="Maven: xerces:xmlParserAPIs:2.0.2" level="project" />
+ <orderEntry type="library" name="Maven: rome:rome:0.9" level="project" />
+ <orderEntry type="library" name="Maven: jdom:jdom:1.0" level="project" />
+ <orderEntry type="library" name="Maven: xalan:xalan:2.7.0" level="project" />
+ <orderEntry type="library" name="Maven: commons-cli:commons-cli:1.0" level="project" />
+ <orderEntry type="library" name="Maven: commons-lang:commons-lang:1.0" level="project" />
+ <orderEntry type="library" name="Maven: junit:junit:3.7" level="project" />
+ <orderEntry type="library" name="Maven: joda-time:joda-time:1.6" level="project" />
</component>
</module>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2011-05-22 17:01:56
|
Revision: 324
http://sword-app.svn.sourceforge.net/sword-app/?rev=324&view=rev
Author: richard-jones
Date: 2011-05-22 17:01:50 +0000 (Sun, 22 May 2011)
Log Message:
-----------
fix build process to accurately reflect java version
Modified Paths:
--------------
JavaClient2.0/pom.xml
JavaClient2.0/src/main/java/org/swordapp/client/EntryPart.java
JavaClient2.0/sword-client.iml
Modified: JavaClient2.0/pom.xml
===================================================================
--- JavaClient2.0/pom.xml 2011-05-22 10:59:38 UTC (rev 323)
+++ JavaClient2.0/pom.xml 2011-05-22 17:01:50 UTC (rev 324)
@@ -1,50 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
- <groupId>org.swordapp</groupId>
- <artifactId>sword-client</artifactId>
- <version>2.0</version>
+ <groupId>org.swordapp</groupId>
+ <artifactId>sword-client</artifactId>
+ <version>2.0</version>
- <dependencies>
- <dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- <version>3.1</version>
- </dependency>
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- <version>1.2.15</version>
- <exclusions>
- <exclusion>
- <groupId>javax.mail</groupId>
- <artifactId>mail</artifactId>
- </exclusion>
- <exclusion>
- <groupId>javax.jms</groupId>
- <artifactId>jms</artifactId>
- </exclusion>
- <exclusion>
- <groupId>com.sun.jdmk</groupId>
- <artifactId>jmxtools</artifactId>
- </exclusion>
- <exclusion>
- <groupId>com.sun.jmx</groupId>
- <artifactId>jmxri</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.apache.abdera</groupId>
- <artifactId>abdera-client</artifactId>
- <version>1.1.1</version>
- </dependency>
- <dependency>
- <groupId>org.dspace</groupId>
- <artifactId>foresite</artifactId>
- <version>0.9</version>
- </dependency>
- </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>6</source>
+ <target>6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ <version>3.1</version>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.15</version>
+ <exclusions>
+ <exclusion>
+ <groupId>javax.mail</groupId>
+ <artifactId>mail</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>javax.jms</groupId>
+ <artifactId>jms</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.sun.jdmk</groupId>
+ <artifactId>jmxtools</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.sun.jmx</groupId>
+ <artifactId>jmxri</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.abdera</groupId>
+ <artifactId>abdera-client</artifactId>
+ <version>1.1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.dspace</groupId>
+ <artifactId>foresite</artifactId>
+ <version>0.9</version>
+ </dependency>
+ </dependencies>
</project>
\ No newline at end of file
Modified: JavaClient2.0/src/main/java/org/swordapp/client/EntryPart.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/EntryPart.java 2011-05-22 10:59:38 UTC (rev 323)
+++ JavaClient2.0/src/main/java/org/swordapp/client/EntryPart.java 2011-05-22 17:01:50 UTC (rev 324)
@@ -40,9 +40,4 @@
{
return this.entry.addSimpleExtension(qName, s);
}
-
- public <T extends ExtensibleElement> T addExtension(Element element)
- {
- return this.entry.addExtension(element);
- }
}
Modified: JavaClient2.0/sword-client.iml
===================================================================
--- JavaClient2.0/sword-client.iml 2011-05-22 10:59:38 UTC (rev 323)
+++ JavaClient2.0/sword-client.iml 2011-05-22 17:01:50 UTC (rev 324)
@@ -6,7 +6,11 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
- <excludeFolder url="file://$MODULE_DIR$/target" />
+ <sourceFolder url="file://$MODULE_DIR$/target/generated-sources/test-annotations" isTestSource="true" />
+ <sourceFolder url="file://$MODULE_DIR$/target/generated-sources/annotations" isTestSource="false" />
+ <excludeFolder url="file://$MODULE_DIR$/target/classes" />
+ <excludeFolder url="file://$MODULE_DIR$/target/maven-archiver" />
+ <excludeFolder url="file://$MODULE_DIR$/target/test-classes" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2011-05-23 15:54:01
|
Revision: 328
http://sword-app.svn.sourceforge.net/sword-app/?rev=328&view=rev
Author: richard-jones
Date: 2011-05-23 15:53:55 +0000 (Mon, 23 May 2011)
Log Message:
-----------
full support for errors and error documents; this makes the client effectively fully compliant with the sword spec, notwithstanding documentation and refactoring to come
Modified Paths:
--------------
JavaClient2.0/pom.xml
JavaClient2.0/src/main/java/org/swordapp/client/ErrorHandler.java
JavaClient2.0/src/main/java/org/swordapp/client/SWORDError.java
JavaClient2.0/src/main/java/org/swordapp/client/UriRegistry.java
JavaClient2.0/sword-client.iml
Modified: JavaClient2.0/pom.xml
===================================================================
--- JavaClient2.0/pom.xml 2011-05-23 12:39:12 UTC (rev 327)
+++ JavaClient2.0/pom.xml 2011-05-23 15:53:55 UTC (rev 328)
@@ -60,5 +60,10 @@
<artifactId>foresite</artifactId>
<version>0.9</version>
</dependency>
+ <dependency>
+ <groupId>xom</groupId>
+ <artifactId>xom</artifactId>
+ <version>1.2.5</version>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
Modified: JavaClient2.0/src/main/java/org/swordapp/client/ErrorHandler.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/ErrorHandler.java 2011-05-23 12:39:12 UTC (rev 327)
+++ JavaClient2.0/src/main/java/org/swordapp/client/ErrorHandler.java 2011-05-23 15:53:55 UTC (rev 328)
@@ -1,30 +1,36 @@
package org.swordapp.client;
+import nu.xom.Builder;
+import nu.xom.Document;
+import nu.xom.ParsingException;
import org.apache.abdera.protocol.client.ClientResponse;
+import java.io.IOException;
+import java.io.InputStream;
+
public class ErrorHandler
{
public SWORDError handleError(ClientResponse resp)
+ throws SWORDClientException
{
- // find out what kind of error we got
- int status = resp.getStatus();
+ try
+ {
+ // get hold of the XML content of the response if available
+ InputStream inputStream = resp.getInputStream();
+ Builder parser = new Builder();
+ Document doc = parser.build(inputStream);
- switch (status)
- {
- case 401 : this.authorisationError(resp);
- case 403 : this.forbidden(resp);
- }
+ int status = resp.getStatus();
- return null;
- }
-
- public void authorisationError(ClientResponse resp)
- {
-
- }
-
- public void forbidden(ClientResponse resp)
- {
-
- }
+ return new SWORDError(status, doc);
+ }
+ catch (IOException e)
+ {
+ throw new SWORDClientException(e);
+ }
+ catch (ParsingException e)
+ {
+ throw new SWORDClientException(e);
+ }
+ }
}
Modified: JavaClient2.0/src/main/java/org/swordapp/client/SWORDError.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/SWORDError.java 2011-05-23 12:39:12 UTC (rev 327)
+++ JavaClient2.0/src/main/java/org/swordapp/client/SWORDError.java 2011-05-23 15:53:55 UTC (rev 328)
@@ -1,6 +1,60 @@
package org.swordapp.client;
+import nu.xom.Document;
+import nu.xom.Element;
+import nu.xom.Elements;
+
public class SWORDError extends Exception
{
+ private int status;
+ private Document errorDoc;
+
+ SWORDError(int status, Document errorDoc)
+ {
+ this.status = status;
+ this.errorDoc = errorDoc;
+ }
+ public int getStatus()
+ {
+ return status;
+ }
+
+ public Document getErrorDoc()
+ {
+ return errorDoc;
+ }
+
+ public String getErrorURI()
+ {
+ Element root = this.errorDoc.getRootElement();
+ return root.getAttributeValue("href");
+ }
+
+ public String getSummary()
+ {
+ Element root = this.errorDoc.getRootElement();
+ Elements elements = root.getChildElements("summary", UriRegistry.ATOM_NAMESPACE);
+ if (elements.size() > 0)
+ {
+ return elements.get(0).getValue();
+ }
+ return null;
+ }
+
+ public String getVerboseDescription()
+ {
+ Element root = this.errorDoc.getRootElement();
+ Elements elements = root.getChildElements("verboseDescription", UriRegistry.SWORD_TERMS_NAMESPACE);
+ if (elements.size() > 0)
+ {
+ return elements.get(0).getValue();
+ }
+ return null;
+ }
+
+ public String toString()
+ {
+ return this.errorDoc.toXML();
+ }
}
Modified: JavaClient2.0/src/main/java/org/swordapp/client/UriRegistry.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/UriRegistry.java 2011-05-23 12:39:12 UTC (rev 327)
+++ JavaClient2.0/src/main/java/org/swordapp/client/UriRegistry.java 2011-05-23 15:53:55 UTC (rev 328)
@@ -8,6 +8,8 @@
public static String SWORD_TERMS_NAMESPACE = "http://purl.org/net/sword/terms/";
public static String APP_NAMESPACE = "http://www.w3.org/2007/app";
public static String DC_NAMESPACE = "http://purl.org/dc/terms/";
+ public static String ERROR_NAMESPACE = "http://purl.org/net/sword/error/";
+ public static String ATOM_NAMESPACE = "http://www.w3.org/2005/Atom";
// QNames for Extension Elements
public static QName SWORD_VERSION = new QName(SWORD_TERMS_NAMESPACE, "version");
@@ -36,4 +38,13 @@
// Package Formats
public static String PACKAGE_SIMPLE_ZIP = "http://purl.org/net/sword/package/SimpleZip";
public static String PACKAGE_BINARY = "http://purl.org/net/sword/package/Binary";
+
+ // errors
+ public static String ERROR_CONTENT = ERROR_NAMESPACE + "ErrorContent";
+ public static String ERROR_CHECKSUM_MISMATCH = ERROR_NAMESPACE + "ErrorChecksumMismatch";
+ public static String ERROR_BAD_REQUEST = ERROR_NAMESPACE + "ErrorBadRequest";
+ public static String ERROR_TARGET_OWNER_UNKNOWN = ERROR_NAMESPACE + "TargetOwnerUnknown";
+ public static String ERROR_MEDIATION_NOT_ALLOWED = ERROR_NAMESPACE + "MediationNotAllowed";
+ public static String ERROR_METHOD_NOT_ALLOWED = ERROR_NAMESPACE + "MethodNotAllowed";
+ public static String ERROR_MAX_UPLOAD_SIZE_EXCEEDED = ERROR_NAMESPACE + "MaxUploadSizeExceeded";
}
Modified: JavaClient2.0/sword-client.iml
===================================================================
--- JavaClient2.0/sword-client.iml 2011-05-23 12:39:12 UTC (rev 327)
+++ JavaClient2.0/sword-client.iml 2011-05-23 15:53:55 UTC (rev 328)
@@ -30,8 +30,8 @@
<orderEntry type="library" name="Maven: org.apache.geronimo.specs:geronimo-javamail_1.4_spec:1.6" level="project" />
<orderEntry type="library" name="Maven: jaxen:jaxen:1.1.1" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.woodstox:wstx-asl:3.0.0" level="project" />
- <orderEntry type="library" name="Maven: xml-apis:xml-apis:1.0.b2" level="project" />
- <orderEntry type="library" name="Maven: xerces:xercesImpl:2.7.1" level="project" />
+ <orderEntry type="library" name="Maven: xml-apis:xml-apis:1.3.03" level="project" />
+ <orderEntry type="library" name="Maven: xerces:xercesImpl:2.8.0" level="project" />
<orderEntry type="library" name="Maven: org.dspace:foresite:0.9" level="project" />
<orderEntry type="library" name="Maven: com.hp.hpl.jena:jena:2.5.5" level="project" />
<orderEntry type="library" name="Maven: com.hp.hpl.jena:arq:2.2" level="project" />
@@ -52,6 +52,7 @@
<orderEntry type="library" name="Maven: commons-lang:commons-lang:1.0" level="project" />
<orderEntry type="library" name="Maven: junit:junit:3.7" level="project" />
<orderEntry type="library" name="Maven: joda-time:joda-time:1.6" level="project" />
+ <orderEntry type="library" name="Maven: xom:xom:1.2.5" level="project" />
</component>
</module>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2011-05-25 10:48:25
|
Revision: 329
http://sword-app.svn.sourceforge.net/sword-app/?rev=329&view=rev
Author: richard-jones
Date: 2011-05-25 10:48:18 +0000 (Wed, 25 May 2011)
Log Message:
-----------
documentation for some of the codebase, plus stubs for a potential web interface
Modified Paths:
--------------
JavaClient2.0/pom.xml
JavaClient2.0/src/main/java/org/swordapp/client/AtomStatement.java
JavaClient2.0/src/main/java/org/swordapp/client/AuthCredentials.java
JavaClient2.0/src/main/java/org/swordapp/client/BinaryResponse.java
JavaClient2.0/src/main/java/org/swordapp/client/ClientConfiguration.java
JavaClient2.0/src/main/java/org/swordapp/client/CollectionEntries.java
JavaClient2.0/src/main/java/org/swordapp/client/Content.java
JavaClient2.0/src/main/java/org/swordapp/client/DepositFactory.java
JavaClient2.0/sword-client.iml
Added Paths:
-----------
JavaClient2.0/src/main/java/org/swordapp/client/webui/
JavaClient2.0/src/main/java/org/swordapp/client/webui/ClientServlet.java
JavaClient2.0/src/main/java/org/swordapp/client/webui/SwordServlet.java
JavaClient2.0/src/main/webapp/
JavaClient2.0/src/main/webapp/WEB-INF/
JavaClient2.0/src/main/webapp/WEB-INF/web.xml
Modified: JavaClient2.0/pom.xml
===================================================================
--- JavaClient2.0/pom.xml 2011-05-23 15:53:55 UTC (rev 328)
+++ JavaClient2.0/pom.xml 2011-05-25 10:48:18 UTC (rev 329)
@@ -65,5 +65,10 @@
<artifactId>xom</artifactId>
<version>1.2.5</version>
</dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.4</version>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
Modified: JavaClient2.0/src/main/java/org/swordapp/client/AtomStatement.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/AtomStatement.java 2011-05-23 15:53:55 UTC (rev 328)
+++ JavaClient2.0/src/main/java/org/swordapp/client/AtomStatement.java 2011-05-25 10:48:18 UTC (rev 329)
@@ -1,3 +1,30 @@
+/*
+ * Copyright (c) 2011, Richard Jones, Cottage Labs
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the <organization> nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
package org.swordapp.client;
import org.apache.abdera.i18n.iri.IRI;
@@ -17,10 +44,23 @@
import java.util.Date;
import java.util.List;
+/**
+ * An implementation of the Statement interface for representing a SWORD Statement
+ * document serialised as an Atom Feed.
+ */
public class AtomStatement implements Statement
{
private Feed feed;
+ /**
+ * Parse the Abdera ClientResponse object and populate this object with the
+ * data found therein
+ *
+ * @param resp
+ * @throws SWORDClientException
+ * @throws StatementParseException
+ */
+ @Override
public void parse(ClientResponse resp)
throws SWORDClientException, StatementParseException
{
@@ -28,11 +68,23 @@
this.feed = doc.getRoot();
}
+ /**
+ * The mimetype of an Atom formatted Statement
+ *
+ * @return
+ */
+ @Override
public String getMimeType()
{
return "application/atom+xml;type=feed";
}
+ /**
+ * List all the parts of the item as described in the Statement
+ *
+ * @return
+ * @throws SWORDClientException
+ */
@Override
public List<ServerResource> getParts()
throws SWORDClientException
@@ -85,6 +137,13 @@
}
}
+ /**
+ * List all the parts of the item as represented by the statement which have been
+ * marked as Original Deposits
+ *
+ * @return
+ * @throws SWORDClientException
+ */
@Override
public List<ServerResource> getOriginalDeposits() throws SWORDClientException
{
@@ -151,6 +210,12 @@
}
}
+ /**
+ * Get a list of state objects which represent the item
+ *
+ * @return
+ * @throws SWORDClientException
+ */
@Override
public List<ResourceState> getState() throws SWORDClientException
{
@@ -169,11 +234,22 @@
return states;
}
+ /**
+ * Get the Abdera Feed object which forms the core of this object
+ *
+ * @return
+ */
public Feed getFeed()
{
return this.feed;
}
+ /**
+ * Nice string representation of the feed - a fully pretty printed
+ * XML dump
+ *
+ * @return
+ */
public String toString()
{
try
Modified: JavaClient2.0/src/main/java/org/swordapp/client/AuthCredentials.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/AuthCredentials.java 2011-05-23 15:53:55 UTC (rev 328)
+++ JavaClient2.0/src/main/java/org/swordapp/client/AuthCredentials.java 2011-05-25 10:48:18 UTC (rev 329)
@@ -1,5 +1,37 @@
+/*
+ * Copyright (c) 2011, Richard Jones, Cottage Labs
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the <organization> nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
package org.swordapp.client;
+/**
+ * Entity class representing the Authentication Credentials which can be used by
+ * SWORD to do HTTP Basic authentication and also to supply the On-Behalf-Of
+ * header
+ */
public class AuthCredentials
{
private String username;
Modified: JavaClient2.0/src/main/java/org/swordapp/client/BinaryResponse.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/BinaryResponse.java 2011-05-23 15:53:55 UTC (rev 328)
+++ JavaClient2.0/src/main/java/org/swordapp/client/BinaryResponse.java 2011-05-25 10:48:18 UTC (rev 329)
@@ -1,3 +1,30 @@
+/*
+ * Copyright (c) 2011, Richard Jones, Cottage Labs
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the <organization> nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
package org.swordapp.client;
import java.io.InputStream;
@@ -2,2 +29,9 @@
+/**
+ * SwordResponse which can also hold an input stream. For use in
+ * requests which result in response objects which are not part of the
+ * spec. In these cases the client implementers should hopefully know
+ * what they are expecting from their server, and can parse the input
+ * stream appropriately.
+ */
public class BinaryResponse extends SwordResponse
@@ -12,6 +46,11 @@
this.inputStream = stream;
}
+ /**
+ * Get the input stream which was supplied in the response body
+ *
+ * @return
+ */
public InputStream getInputStream()
{
return inputStream;
Modified: JavaClient2.0/src/main/java/org/swordapp/client/ClientConfiguration.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/ClientConfiguration.java 2011-05-23 15:53:55 UTC (rev 328)
+++ JavaClient2.0/src/main/java/org/swordapp/client/ClientConfiguration.java 2011-05-25 10:48:18 UTC (rev 329)
@@ -1,5 +1,36 @@
+/*
+ * Copyright (c) 2011, Richard Jones, Cottage Labs
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the <organization> nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
package org.swordapp.client;
+/**
+ * Configuration class allowing the client environment to be
+ * tailored to the implementers requirements
+ */
public class ClientConfiguration
{
private String userAgent = "SWORD Client 2.0";
@@ -20,6 +51,15 @@
return returnDepositReceipt;
}
+ /**
+ * Setting the deposit receipt to be returned means that whether the
+ * server returns the deposit receipt or not in its response, the
+ * client will ensure that a deposit receipt is acquired. If the
+ * server returns the deposit receipt it will be used, if not it will
+ * be retrieved from the Location header and used.
+ *
+ * @param returnDepositReceipt
+ */
public void setReturnDepositReceipt(boolean returnDepositReceipt)
{
this.returnDepositReceipt = returnDepositReceipt;
Modified: JavaClient2.0/src/main/java/org/swordapp/client/CollectionEntries.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/CollectionEntries.java 2011-05-23 15:53:55 UTC (rev 328)
+++ JavaClient2.0/src/main/java/org/swordapp/client/CollectionEntries.java 2011-05-25 10:48:18 UTC (rev 329)
@@ -1,3 +1,30 @@
+/*
+ * Copyright (c) 2011, Richard Jones, Cottage Labs
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the <organization> nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
package org.swordapp.client;
import org.apache.abdera.model.Entry;
@@ -5,6 +32,9 @@
import java.util.List;
+/**
+ * Class representing a list of entries in a collection on the server
+ */
public class CollectionEntries
{
private Feed feed;
@@ -14,6 +44,11 @@
this.feed = feed;
}
+ /**
+ * Get the Abdera feed object wrapped by this class
+ *
+ * @return
+ */
public Feed getFeed()
{
return feed;
Modified: JavaClient2.0/src/main/java/org/swordapp/client/Content.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/Content.java 2011-05-23 15:53:55 UTC (rev 328)
+++ JavaClient2.0/src/main/java/org/swordapp/client/Content.java 2011-05-25 10:48:18 UTC (rev 329)
@@ -1,3 +1,30 @@
+/*
+ * Copyright (c) 2011, Richard Jones, Cottage Labs
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the <organization> nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
package org.swordapp.client;
import org.apache.abdera.model.Feed;
@@ -5,6 +32,9 @@
import javax.activation.MimeType;
import java.io.InputStream;
+/**
+ * Class representing a content retrieval request from the server
+ */
public class Content
{
private MimeType mimeType;
Modified: JavaClient2.0/src/main/java/org/swordapp/client/DepositFactory.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/DepositFactory.java 2011-05-23 15:53:55 UTC (rev 328)
+++ JavaClient2.0/src/main/java/org/swordapp/client/DepositFactory.java 2011-05-25 10:48:18 UTC (rev 329)
@@ -1,3 +1,30 @@
+/*
+ * Copyright (c) 2011, Richard Jones, Cottage Labs
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the <organization> nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
package org.swordapp.client;
import java.io.InputStream;
@@ -2,6 +29,21 @@
+/**
+ * This is a convenience class to allow you to construct Deposit objects for the
+ * various deposit operations which only take the arguments which are relevant to
+ * that operation. It's just Syntactic Sugar, you don't have to use it.
+ */
public class DepositFactory
{
// Deposit(EntryPart entryPart, InputStream file, String filename, String mimeType, String packaging,
- // String slug, String md5, boolean inProgress, boolean metadataRelevant)
+ // String slug, String md5, boolean inProgress, boolean metadataRelevant)
+
+ /**
+ * Create a Deposit object for creating a new object by placing just an Entry/Metadata
+ * document on the server
+ *
+ * @param entryPart
+ * @param slug
+ * @param inProgress
+ * @return
+ */
public Deposit newMetadataOnly(EntryPart entryPart, String slug, boolean inProgress)
@@ -11,46 +53,133 @@
return new Deposit(entryPart, null, null, null, null, slug, null, inProgress, false);
}
+ /**
+ * Create a Deposit object for creating a new object by placing just an Entry/Metadata
+ * document on the server
+ *
+ * @param entryPart
+ * @return
+ */
public Deposit newMetadataOnly(EntryPart entryPart)
{
return this.newMetadataOnly(entryPart, null, false);
}
+ /**
+ * Create a Deposit object for creating a new object by placing a binary package
+ * onto the server
+ *
+ * @param file
+ * @param filename
+ * @param mimeType
+ * @param packaging
+ * @param slug
+ * @param md5
+ * @param inProgress
+ * @return
+ */
public Deposit newBinaryOnly(InputStream file, String filename, String mimeType, String packaging, String slug, String md5, boolean inProgress)
{
return new Deposit(null, file, filename, mimeType, packaging, slug, md5, inProgress, false);
}
+ /**
+ * Create a Deposit object for creating a new object by placing a binary package
+ * onto the server
+ *
+ * @param file
+ * @param filename
+ * @param mimeType
+ * @return
+ */
public Deposit newBinaryOnly(InputStream file, String filename, String mimeType)
{
return this.newBinaryOnly(file, filename, mimeType, null, null, null, false);
}
+ /**
+ * Create a Deposit object for creating a new object by placing a binary package
+ * onto the server
+ *
+ * @param file
+ * @param filename
+ * @param mimeType
+ * @param packaging
+ * @return
+ */
public Deposit newBinaryOnly(InputStream file, String filename, String mimeType, String packaging)
{
return this.newBinaryOnly(file, filename, mimeType, packaging, null, null, false);
}
+ /**
+ * Create a Deposit object for creating a new object by placing both metadata and
+ * binary content (multipart) onto the server
+ *
+ * @param entryPart
+ * @param file
+ * @param filename
+ * @param mimeType
+ * @param packaging
+ * @param slug
+ * @param md5
+ * @param inProgress
+ * @return
+ */
public Deposit newMultipart(EntryPart entryPart, InputStream file, String filename, String mimeType, String packaging, String slug, String md5, boolean inProgress)
{
return new Deposit(entryPart, file, filename, mimeType, packaging, slug, md5, inProgress, false);
}
+ /**
+ * Create a Deposit object for creating a new object by placing both metadata and
+ * binary content (multipart) onto the server
+ *
+ * @param entryPart
+ * @param file
+ * @param filename
+ * @param mimeType
+ * @return
+ */
public Deposit newMultipart(EntryPart entryPart, InputStream file, String filename, String mimeType)
{
return this.newMultipart(entryPart, file, filename, mimeType, null, null, null, false);
}
+ /**
+ * Create a Deposit object for creating a new object by placing both metadata and
+ * binary content (multipart) onto the server
+ *
+ * @param entryPart
+ * @param file
+ * @param filename
+ * @param mimeType
+ * @param packaging
+ * @return
+ */
public Deposit newMultipart(EntryPart entryPart, InputStream file, String filename, String mimeType, String packaging)
{
return this.newMultipart(entryPart, file, filename, mimeType, packaging, null, null, false);
}
+ /**
+ * Create a Deposit object for replacing the metadata of an item
+ *
+ * @param entryPart
+ * @param inProgress
+ * @return
+ */
public Deposit replaceMetadata(EntryPart entryPart, boolean inProgress)
{
return new Deposit(entryPart, null, null, null, null, null, null, inProgress, false);
}
+ /**
+ * Create a Deposit object for replacing the metadata of an item
+ *
+ * @param entryPart
+ * @return
+ */
public Deposit replaceMetadata(EntryPart entryPart)
{
return this.replaceMetadata(entryPart, false);
Added: JavaClient2.0/src/main/java/org/swordapp/client/webui/ClientServlet.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/webui/ClientServlet.java (rev 0)
+++ JavaClient2.0/src/main/java/org/swordapp/client/webui/ClientServlet.java 2011-05-25 10:48:18 UTC (rev 329)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2011, Richard Jones, Cottage Labs
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the <organization> nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.swordapp.client.webui;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+public class ClientServlet extends SwordServlet
+{
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException
+ {
+
+ }
+}
Added: JavaClient2.0/src/main/java/org/swordapp/client/webui/SwordServlet.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/webui/SwordServlet.java (rev 0)
+++ JavaClient2.0/src/main/java/org/swordapp/client/webui/SwordServlet.java 2011-05-25 10:48:18 UTC (rev 329)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2011, Richard Jones, Cottage Labs
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the <organization> nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.swordapp.client.webui;
+
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+public class SwordServlet extends HttpServlet
+{
+ public void show(HttpServletRequest...
[truncated message content] |
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2011-05-27 11:07:12
|
Revision: 333
http://sword-app.svn.sourceforge.net/sword-app/?rev=333&view=rev
Author: richard-jones
Date: 2011-05-27 11:07:05 +0000 (Fri, 27 May 2011)
Log Message:
-----------
full support for binary deposit, tested against DSpace
Modified Paths:
--------------
JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java
JavaClient2.0/src/main/java/org/swordapp/client/SwordCli.java
JavaClient2.0/sword-client.iml
Modified: JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java 2011-05-27 00:15:07 UTC (rev 332)
+++ JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java 2011-05-27 11:07:05 UTC (rev 333)
@@ -7,6 +7,7 @@
import org.apache.abdera.model.Feed;
import org.apache.abdera.model.Link;
import org.apache.abdera.model.Service;
+import org.apache.abdera.parser.ParseException;
import org.apache.abdera.protocol.Response;
import org.apache.abdera.protocol.client.AbderaClient;
import org.apache.abdera.protocol.client.ClientResponse;
@@ -975,25 +976,35 @@
{
DepositReceipt receipt;
HttpHeaders http = new HttpHeaders();
- Document<Entry> doc = resp.getDocument();
+
+ // we have to do this rather annoying thing to determine if the receipt is included
+ boolean receiptIncluded = true;
+ Document<Entry> doc = null;
+ try
+ {
+ doc = resp.getDocument();
+ }
+ catch (ParseException e)
+ {
+ receiptIncluded = false;
+ }
+
String location = http.getLocation(resp);
// it is possible that the doc will be null
// if there is no doc and no location header this is broken
- if (doc == null && (location == null || "".equals(location)))
+ if (!receiptIncluded && (location == null || "".equals(location)))
{
throw new ProtocolViolationException("SWORD Server responded " + resp.getStatus() + " but failed to provide a deposit receipt or a Location header");
}
-
-
// if there is no doc, we need to see what the configuration asks us to do about getting it
- if (doc == null && this.config.returnDepositReceipt())
+ if (!receiptIncluded && this.config.returnDepositReceipt())
{
// load the deposit receipt from the location
receipt = this.getDepositReceipt(location, auth);
}
- else if (doc == null)
+ else if (!receiptIncluded)
{
receipt = new DepositReceipt(resp.getStatus(), location);
}
Modified: JavaClient2.0/src/main/java/org/swordapp/client/SwordCli.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/SwordCli.java 2011-05-27 00:15:07 UTC (rev 332)
+++ JavaClient2.0/src/main/java/org/swordapp/client/SwordCli.java 2011-05-27 11:07:05 UTC (rev 333)
@@ -15,9 +15,12 @@
public class SwordCli
{
- private String exampleZip = "/Users/richard/Code/External/SSS/example.zip";
+ private String exampleZip = "/home/richard/Code/External/SSS/example.zip";
//private String sdIRI = "http://localhost:8080/sd-uri";
- private String sdIRI = "http://localhost/sss/sd-uri";
+ private String sdIRI = "http://localhost:8080/sword2/servicedocument";
+ private String user = "richard";
+ private String pass = "dspace";
+ private String obo = null;
public static void main(String[] args)
throws Exception
@@ -26,8 +29,8 @@
// cli.tryServiceDocument();
// cli.trySwordServiceDocument();
// cli.tryCollectionEntries();
-// cli.tryBinaryDeposit();
- cli.tryMultipartDeposit();
+ cli.tryBinaryDeposit();
+// cli.tryMultipartDeposit();
// cli.tryEntryDeposit();
// cli.tryContentRetrieve();
// cli.tryFeedRetrieve();
@@ -564,7 +567,7 @@
InputStream is = new FileInputStream(new File(exampleZip));
DepositFactory factory = new DepositFactory();
Deposit deposit = factory.newBinaryOnly(is, "example.zip", "application/zip", UriRegistry.PACKAGE_SIMPLE_ZIP);
- AuthCredentials auth = new AuthCredentials("sword", "sword", "obo");
+ AuthCredentials auth = new AuthCredentials(this.user, this.pass, this.obo);
ServiceDocument sd = client.getServiceDocument(this.sdIRI, auth);
DepositReceipt receipt = null;
List<SWORDWorkspace> ws = sd.getWorkspaces();
@@ -611,7 +614,7 @@
{
System.out.println("trySwordServiceDocument");
SWORDClient client = new SWORDClient();
- ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials("sword", "sword", "obo"));
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass, this.obo));
System.out.println("Version: " + sd.getVersion());
System.out.println("Max Upload Size: " + Long.toString(sd.getMaxUploadSize()));
List<SWORDWorkspace> sws = sd.getWorkspaces();
Modified: JavaClient2.0/sword-client.iml
===================================================================
--- JavaClient2.0/sword-client.iml 2011-05-27 00:15:07 UTC (rev 332)
+++ JavaClient2.0/sword-client.iml 2011-05-27 11:07:05 UTC (rev 333)
@@ -4,16 +4,19 @@
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/target/generated-sources/test-annotations" isTestSource="true" />
+ <sourceFolder url="file://$MODULE_DIR$/target/generated-sources/annotations" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
- <sourceFolder url="file://$MODULE_DIR$/target/generated-sources/test-annotations" isTestSource="true" />
- <sourceFolder url="file://$MODULE_DIR$/target/generated-sources/annotations" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target/classes" />
- <excludeFolder url="file://$MODULE_DIR$/target/maven-archiver" />
<excludeFolder url="file://$MODULE_DIR$/target/test-classes" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="library" name="Maven: xml-apis:xml-apis:1.3.03" level="project" />
+ <orderEntry type="library" name="Maven: xerces:xercesImpl:2.8.0" level="project" />
+ <orderEntry type="library" name="Maven: xom:xom:1.2.5" level="project" />
+ <orderEntry type="library" name="Maven: javax.servlet:servlet-api:2.4" level="project" />
<orderEntry type="library" name="Maven: commons-httpclient:commons-httpclient:3.1" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.0.4" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.2" level="project" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-03-12 14:20:30
|
Revision: 469
http://sword-app.svn.sourceforge.net/sword-app/?rev=469&view=rev
Author: richard-jones
Date: 2012-03-12 14:20:19 +0000 (Mon, 12 Mar 2012)
Log Message:
-----------
various minor additions to testing code
Modified Paths:
--------------
JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java
JavaClient2.0/src/main/java/org/swordapp/client/SwordCli.java
JavaClient2.0/sword-client.iml
Modified: JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java 2012-02-28 12:17:46 UTC (rev 468)
+++ JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java 2012-03-12 14:20:19 UTC (rev 469)
@@ -686,7 +686,7 @@
ResponseStatus rs = rcm.addToMediaResource(status);
if (rs.isCorrect() || rs.isIncorrectButAllowed())
{
- log.info("Delete request on " + url.toString() + " returned HTTP status " + status + "; SUCCESS");
+ log.info("Add request on " + url.toString() + " returned HTTP status " + status + "; SUCCESS");
if (rs.isIncorrectButAllowed())
{
Modified: JavaClient2.0/src/main/java/org/swordapp/client/SwordCli.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/SwordCli.java 2012-02-28 12:17:46 UTC (rev 468)
+++ JavaClient2.0/src/main/java/org/swordapp/client/SwordCli.java 2012-03-12 14:20:19 UTC (rev 469)
@@ -19,11 +19,13 @@
private String exampleZip = "/Users/richard/Code/External/SSS/example.zip";
private String image = "/Users/richard/Code/Internal/DepositMO/Dome_sm.jpg";
private String docx = "/Users/richard/Code/Internal/DepositMO/hy.docx";
+ private String bagit = "/Users/richard/Dropbox/Documents/DUO/BagIt.zip";
//private String sdIRI = "http://localhost:8080/sd-uri";
- private String sdIRI = "http://localhost:8080/sword2/servicedocument";
+ private String sdIRI = "http://localhost:8080/swordv2/servicedocument";
private String user = "richard";
private String pass = "dspace";
private String obo = null;
+ private String mediaUri = "http://localhost:8080/swordv2/edit-media/34";
public static void main(String[] args)
throws Exception
@@ -32,7 +34,7 @@
// cli.trySwordServiceDocument();
// cli.tryCollectionEntries();
// cli.tryBinaryDeposit();
-// cli.tryEntryDeposit();
+// cli.tryEntryDeposit();
// cli.tryMultipartDeposit();
// cli.tryContentRetrieve();
// cli.tryFeedRetrieve();
@@ -49,9 +51,37 @@
// cli.tryContinuedDeposit();
// cli.tryImage();
// cli.tryDocument();
- cli.tryFileReplace();
+// cli.tryFileReplace();
+// cli.tryAddToMediaResource();
+ cli.tryFSDeposit();
}
+ private void tryFSDeposit()
+ throws Exception
+ {
+ System.out.println("tryFSDeposit");
+ SWORDClient client = new SWORDClient();
+ InputStream is = new FileInputStream(new File(bagit));
+ DepositFactory factory = new DepositFactory();
+ Deposit deposit = factory.newBinaryOnly(is, "bagit.zip", "application/zip", "http://duo.uio.no/terms/package/FSBagIt", null, null, true);
+ AuthCredentials auth = new AuthCredentials(this.user, this.pass, this.obo);
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, auth);
+ DepositReceipt receipt = null;
+ List<SWORDWorkspace> ws = sd.getWorkspaces();
+ for (SWORDWorkspace w : ws)
+ {
+ List<SWORDCollection> collections = w.getCollections();
+ for (SWORDCollection c : collections)
+ {
+ // do the deposit to the first collection we find
+ receipt = client.deposit(c, deposit, auth);
+ break;
+ }
+ }
+ System.out.println(receipt.getEditLink().getHref().toString());
+ receipt.getEntry().writeTo(System.out);
+ }
+
private void tryContinuedDeposit()
throws Exception
{
@@ -333,6 +363,36 @@
content.getFeed().writeTo(System.out);
}
+ private void tryAddToMediaResource()
+ throws Exception
+ {
+ System.out.println("tryAddToContainer");
+ // first we need to put some content in
+ SWORDClient client = new SWORDClient();
+ DepositFactory factory = new DepositFactory();
+ AuthCredentials auth = new AuthCredentials(this.user, this.pass, this.obo);
+
+ InputStream is2 = new FileInputStream(new File(exampleZip));
+ Deposit updateDeposit = factory.addMediaResource(is2, "example2.zip", "application/zip");
+ SwordResponse resp = client.addToMediaResource(mediaUri, updateDeposit, auth);
+ System.out.println(resp.getStatusCode());
+
+ if (resp instanceof DepositReceipt)
+ {
+ ((DepositReceipt) resp).getEntry().writeTo(System.out);
+ }
+ else
+ {
+ System.out.println("Response was NOT a deposit receipt");
+ }
+
+ // now we need to get the content out as an atom feed to see the multiple files
+ Content content = client.getContent(mediaUri, "application/atom+xml;type=feed", null, auth);
+
+ // prove that we got a feed
+ content.getFeed().writeTo(System.out);
+ }
+
private void tryDeleteContent()
throws Exception
{
@@ -555,7 +615,7 @@
ep.addDublinCore("title", "Richard Woz Ere");
ep.addDublinCore("bibliographicCitation", "this is my citation");
DepositFactory factory = new DepositFactory();
- Deposit deposit = factory.newMetadataOnly(ep);
+ Deposit deposit = factory.newMetadataOnly(ep, null, true);
AuthCredentials auth = new AuthCredentials(this.user, this.pass, this.obo);
ServiceDocument sd = client.getServiceDocument(this.sdIRI, auth);
DepositReceipt receipt = null;
Modified: JavaClient2.0/sword-client.iml
===================================================================
--- JavaClient2.0/sword-client.iml 2012-02-28 12:17:46 UTC (rev 468)
+++ JavaClient2.0/sword-client.iml 2012-03-12 14:20:19 UTC (rev 469)
@@ -4,11 +4,12 @@
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources/test-annotations" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources/annotations" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target/classes" />
+ <excludeFolder url="file://$MODULE_DIR$/target/maven-archiver" />
<excludeFolder url="file://$MODULE_DIR$/target/test-classes" />
</content>
<orderEntry type="inheritedJdk" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-03-12 15:16:53
|
Revision: 470
http://sword-app.svn.sourceforge.net/sword-app/?rev=470&view=rev
Author: richard-jones
Date: 2012-03-12 15:16:42 +0000 (Mon, 12 Mar 2012)
Log Message:
-----------
add basic junit test
Modified Paths:
--------------
JavaClient2.0/pom.xml
JavaClient2.0/src/test/java/org/swordapp/client/test/ClientTests.java
JavaClient2.0/sword-client.iml
Modified: JavaClient2.0/pom.xml
===================================================================
--- JavaClient2.0/pom.xml 2012-03-12 14:20:19 UTC (rev 469)
+++ JavaClient2.0/pom.xml 2012-03-12 15:16:42 UTC (rev 470)
@@ -70,5 +70,10 @@
<artifactId>servlet-api</artifactId>
<version>2.4</version>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.4</version>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
Modified: JavaClient2.0/src/test/java/org/swordapp/client/test/ClientTests.java
===================================================================
--- JavaClient2.0/src/test/java/org/swordapp/client/test/ClientTests.java 2012-03-12 14:20:19 UTC (rev 469)
+++ JavaClient2.0/src/test/java/org/swordapp/client/test/ClientTests.java 2012-03-12 15:16:42 UTC (rev 470)
@@ -1,6 +1,18 @@
package org.swordapp.client.test;
+import org.junit.*;
+import org.swordapp.client.ClientConfiguration;
+import org.swordapp.client.SWORDClient;
+
public class ClientTests
{
-
+ @Test
+ public void simpleClientInit()
+ {
+ // construct without arguments
+ SWORDClient client1 = new SWORDClient();
+
+ // construct with a default ClientConfiguration
+ SWORDClient client2 = new SWORDClient(new ClientConfiguration());
+ }
}
Modified: JavaClient2.0/sword-client.iml
===================================================================
--- JavaClient2.0/sword-client.iml 2012-03-12 14:20:19 UTC (rev 469)
+++ JavaClient2.0/sword-client.iml 2012-03-12 15:16:42 UTC (rev 470)
@@ -4,8 +4,6 @@
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
- <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources/test-annotations" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources/annotations" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target/classes" />
@@ -14,10 +12,6 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
- <orderEntry type="library" name="Maven: xml-apis:xml-apis:1.3.03" level="project" />
- <orderEntry type="library" name="Maven: xerces:xercesImpl:2.8.0" level="project" />
- <orderEntry type="library" name="Maven: xom:xom:1.2.5" level="project" />
- <orderEntry type="library" name="Maven: javax.servlet:servlet-api:2.4" level="project" />
<orderEntry type="library" name="Maven: commons-httpclient:commons-httpclient:3.1" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.0.4" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.2" level="project" />
@@ -54,7 +48,7 @@
<orderEntry type="library" name="Maven: xalan:xalan:2.7.0" level="project" />
<orderEntry type="library" name="Maven: commons-cli:commons-cli:1.0" level="project" />
<orderEntry type="library" name="Maven: commons-lang:commons-lang:1.0" level="project" />
- <orderEntry type="library" name="Maven: junit:junit:3.7" level="project" />
+ <orderEntry type="library" name="Maven: junit:junit:4.4" level="project" />
<orderEntry type="library" name="Maven: joda-time:joda-time:1.6" level="project" />
<orderEntry type="library" name="Maven: xom:xom:1.2.5" level="project" />
<orderEntry type="library" name="Maven: javax.servlet:servlet-api:2.4" level="project" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-03-16 11:55:03
|
Revision: 472
http://sword-app.svn.sourceforge.net/sword-app/?rev=472&view=rev
Author: richard-jones
Date: 2012-03-16 11:54:51 +0000 (Fri, 16 Mar 2012)
Log Message:
-----------
add new class with spec tests; this is being set up to mimic the python client for consistency
Modified Paths:
--------------
JavaClient2.0/sword-client.iml
Added Paths:
-----------
JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java
Added: JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java
===================================================================
--- JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java (rev 0)
+++ JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java 2012-03-16 11:54:51 UTC (rev 472)
@@ -0,0 +1,889 @@
+package org.swordapp.client.test;
+
+import org.junit.Test;
+import org.junit.Before;
+import static org.junit.Assert.*;
+import org.swordapp.client.AuthCredentials;
+import org.swordapp.client.ClientConfiguration;
+import org.swordapp.client.SWORDClient;
+import org.swordapp.client.ServiceDocument;
+
+public class SpecTests
+{
+ private String sdIRI = null;
+ private String user = null;
+ private String pass = null;
+ private String obo = null;
+
+ @Before
+ public void setUp()
+ {
+ this.sdIRI = "http://localhost:8080/sd-uri";
+ this.user = "sword";
+ this.pass = "sword";
+ this.obo = "obo";
+ }
+
+ @Test
+ public void getServiceDocument()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass));
+
+ // verify that the service document contains the sorts of things we are expecting
+ assertTrue(sd.getService() != null);
+ assertEquals(sd.getVersion(), "2.0");
+ }
+
+ @Test
+ public void getServiceDocumentOBO()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass, this.obo));
+
+ // verify that the service document contains the sorts of things we are expecting
+ assertTrue(sd.getService() != null);
+ assertEquals(sd.getVersion(), "2.0");
+ }
+
+ /* Python tests to mimic
+
+ def test_03_basic_create_resource_with_package(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip')
+
+ assert receipt.code == 201
+ assert receipt.location != None
+
+ # these last two assertions are contingent on if we actually get a
+ # receipt back from the server (which we might not legitimately get)
+ assert receipt.dom is None or receipt.parsed == True
+ assert receipt.dom is None or receipt.valid == True
+
+ def test_04_advanced_create_resource_with_package(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip',
+ in_progress = True,
+ suggested_identifier = "abcdefghijklmnop")
+
+ assert receipt.code == 201
+ assert receipt.location != None
+
+ # these last two assertions are contingent on if we actually get a
+ # receipt back from the server (which we might not legitimately get)
+ assert receipt.dom is None or receipt.parsed == True
+ assert receipt.dom is None or receipt.valid == True
+
+ def test_05_basic_create_resource_with_multipart(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ e = Entry(title="Foo", id="asidjasidj", dcterms_abstract="abstract", dcterms_title="my title")
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ metadata_entry = e,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip')
+
+ assert receipt.code == 201
+ assert receipt.location != None
+
+ # these last two assertions are contingent on if we actually get a
+ # receipt back from the server (which we might not legitimately get)
+ assert receipt.dom is None or receipt.parsed == True
+ assert receipt.dom is None or receipt.valid == True
+
+ def test_06_advanced_create_resource_with_multipart(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ e = Entry(title="Foo", id="asidjasidj", dcterms_abstract="abstract", dcterms_title="my title")
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ metadata_entry = e,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip',
+ in_progress = True,
+ suggested_identifier = "zyxwvutsrq")
+
+ assert receipt.code == 201
+ assert receipt.location != None
+
+ # these last two assertions are contingent on if we actually get a
+ # receipt back from the server (which we might not legitimately get)
+ assert receipt.dom is None or receipt.parsed == True
+ assert receipt.dom is None or receipt.valid == True
+
+ def test_07_basic_create_resource_with_entry(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ e = Entry(title="An entry only deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
+ receipt = conn.create(col_iri = col.href,
+ metadata_entry = e)
+
+ assert receipt.code == 201
+ assert receipt.location != None
+
+ # these last two assertions are contingent on if we actually get a
+ # receipt back from the server (which we might not legitimately get)
+ assert receipt.dom is None or receipt.parsed == True
+ assert receipt.dom is None or receipt.valid == True
+
+ def test_08_advanced_create_resource_with_entry(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ e = Entry(title="An entry only deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
+ receipt = conn.create(col_iri = col.href,
+ metadata_entry = e,
+ in_progress = True,
+ suggested_identifier = "1234567890")
+
+ assert receipt.code == 201
+ assert receipt.location != None
+
+ # these last two assertions are contingent on if we actually get a
+ # receipt back from the server (which we might not legitimately get)
+ assert receipt.dom is None or receipt.parsed == True
+ assert receipt.dom is None or receipt.valid == True
+
+ def test_09_basic_retrieve_deposit_receipt(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip')
+
+ # we're going to work with the location
+ assert receipt.location != None
+
+ new_receipt = conn.get_deposit_receipt(receipt.location)
+
+ assert new_receipt.code == 200
+ assert new_receipt.parsed == True
+ assert new_receipt.valid == True
+
+ def test_10_advanced_retrieve_deposit_receipt(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip',
+ in_progress = True,
+ suggested_identifier = "0987654321")
+
+ # we're going to work with the location
+ assert receipt.location != None
+
+ new_receipt = conn.get_deposit_receipt(receipt.location)
+
+ assert new_receipt.code == 200
+ assert new_receipt.parsed == True
+ assert new_receipt.valid == True
+
+ def test_11_basic_retrieve_content_cont_iri(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging='http://purl.org/net/sword/package/SimpleZip')
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ # we're going to work with the cont_iri
+ assert receipt.cont_iri is not None
+
+ resource = conn.get_resource(content_iri=receipt.cont_iri)
+
+ assert resource.code == 200
+ assert resource.content is not None
+
+ def test_12_basic_retrieve_content_em_iri(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging='http://purl.org/net/sword/package/SimpleZip')
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ # we're going to work with the edit_media iri
+ assert receipt.edit_media is not None
+
+ resource = conn.get_resource(content_iri=receipt.edit_media)
+
+ assert resource.code == 200
+ assert resource.content is not None
+
+ def test_13_advanced_retrieve_content_em_iri(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging='http://purl.org/net/sword/package/SimpleZip')
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ packaging = 'http://purl.org/net/sword/package/SimpleZip'
+ if receipt.packaging is not None and len(receipt.packaging) > 0:
+ packaging = receipt.packaging[0]
+
+ resource = conn.get_resource(content_iri=receipt.edit_media, packaging=packaging, on_behalf_of=SSS_OBO)
+
+ assert resource.code == 200
+ assert resource.content is not None
+
+ def test_14_error_retrieve_content_em_iri(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW,
+ error_response_raises_exceptions=False)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging='http://purl.org/net/sword/package/SimpleZip')
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ error = 'http://purl.org/net/sword/package/IJustMadeThisUp'
+ response = conn.get_resource(content_iri=receipt.edit_media, packaging=error)
+
+ assert response.code == 406
+ assert isinstance(response, Error_Document)
+ assert response.error_href == "http://purl.org/net/sword/error/ErrorContent"
+
+ def test_15_retrieve_content_em_iri_as_feed(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging='http://purl.org/net/sword/package/SimpleZip')
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ # we're going to work with the edit_media_feed iri
+ assert receipt.edit_media_feed is not None
+
+ response = conn.get_resource(content_iri=receipt.edit_media_feed)
+
+ assert response.code == 200
+ assert response.content is not None
+
+ # the response should be an xml document, so let's see if we can parse
+ # it. This should give us an exception which will fail the test if not
+ dom = etree.fromstring(response.content)
+
+ def test_16_basic_replace_file_content(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging='http://purl.org/net/sword/package/SimpleZip')
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ # now do the replace
+ with open(PACKAGE) as pkg:
+ new_receipt = conn.update(dr = receipt,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="update.zip",
+ packaging='http://purl.org/net/sword/package/SimpleZip')
+
+ assert new_receipt.code == 204
+ assert new_receipt.dom is None
+
+ def test_17_advanced_replace_file_content(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging='http://purl.org/net/sword/package/SimpleZip')
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ # now do the replace
+ with open(PACKAGE) as pkg:
+ new_receipt = conn.update(dr = receipt,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="update.zip",
+ packaging='http://purl.org/net/sword/package/SimpleZip',
+ metadata_relevant=True)
+
+ assert new_receipt.code == 204
+ assert new_receipt.dom is None
+
+ def test_18_basic_replace_metadata(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ e = Entry(title="An entry only deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
+ receipt = conn.create(col_iri = col.href, metadata_entry = e)
+
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ # now do the replace
+ ne = Entry(title="A metadata update", id="asidjasidj", dcterms_abstract="new abstract", dcterms_identifier="http://elsewhere/")
+ new_receipt = conn.update(dr=receipt, metadata_entry=ne)
+
+ assert new_receipt.code == 204 or new_receipt.code == 200
+ if new_receipt.code == 204:
+ assert new_receipt.dom is None
+ if new_receipt.code == 200:
+ assert new_receipt.parsed == True
+ assert new_receipt.valid == True
+
+ def test_19_advanced_replace_metadata(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ e = Entry(title="An entry only deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
+ receipt = conn.create(col_iri = col.href, metadata_entry = e)
+
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ # now do the replace
+ ne = Entry(title="A metadata update", id="asidjasidj", dcterms_abstract="new abstract", dcterms_identifier="http://elsewhere/")
+ new_receipt = conn.update(dr=receipt, metadata_entry=ne, in_progress=True)
+
+ assert new_receipt.code == 204 or new_receipt.code == 200
+ if new_receipt.code == 204:
+ assert new_receipt.dom is None
+ if new_receipt.code == 200:
+ assert new_receipt.parsed == True
+ assert new_receipt.valid == True
+
+ def test_20_basic_replace_with_multipart(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ metadata_entry = e,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip')
+
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ # now do the replace
+ ne = Entry(title="A multipart update", id="asidjasidj", dcterms_abstract="new abstract", dcterms_identifier="http://elsewhere/")
+ with open(PACKAGE) as pkg:
+ new_receipt = conn.update(dr = receipt,
+ metadata_entry = ne,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="update.zip",
+ packaging='http://purl.org/net/sword/package/SimpleZip')
+
+ assert new_receipt.code == 204 or new_receipt.code == 200
+ if new_receipt.code == 204:
+ assert new_receipt.dom is None
+ if new_receipt.code == 200:
+ assert new_receipt.parsed == True
+ assert new_receipt.valid == True
+
+ def test_21_advanced_replace_with_multipart(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ metadata_entry = e,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip')
+
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ # now do the replace
+ ne = Entry(title="A multipart update", id="asidjasidj", dcterms_abstract="new abstract", dcterms_identifier="http://elsewhere/")
+ with open(PACKAGE) as pkg:
+ new_receipt = conn.update(dr = receipt,
+ metadata_entry = ne,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="update.zip",
+ packaging='http://purl.org/net/sword/package/SimpleZip',
+ in_progress=True)
+
+ assert new_receipt.code == 204 or new_receipt.code == 200
+ if new_receipt.code == 204:
+ assert new_receipt.dom is None
+ if new_receipt.code == 200:
+ assert new_receipt.parsed == True
+ assert new_receipt.valid == True
+
+ def test_22_delete_content(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ metadata_entry = e,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip')
+
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ # now delete the content but not the container
+ new_receipt = conn.delete_content_of_resource(dr=receipt)
+
+ assert new_receipt.code == 204
+ assert new_receipt.dom is None
+
+ def test_23_basic_add_content_to_resource_single_file(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip')
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ with open(PACKAGE) as pkg:
+ new_receipt = conn.add_file_to_resource(receipt.edit_media, pkg, "addition.zip", mimetype=PACKAGE_MIME)
+
+ assert new_receipt.code >= 200 and new_receipt.code < 400
+ assert new_receipt.location is not None
+ assert new_receipt.location != receipt.edit_media
+
+ def test_24_advanced_add_content_to_resource_single_file(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip')
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ with open(PACKAGE) as pkg:
+ new_receipt = conn.add_file_to_resource(receipt.edit_media, pkg, "addition.zip",
+ mimetype=PACKAGE_MIME,
+ metadata_relevant=True)
+
+ assert new_receipt.code >= 200 and new_receipt.code < 400
+ assert new_receipt.location is not None
+ assert new_receipt.location != receipt.edit_media
+
+ def test_25_basic_add_content_to_resource_package(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip')
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ with open(PACKAGE) as pkg:
+ new_receipt = conn.add_file_to_resource(receipt.edit_media, pkg, "addition.zip",
+ mimetype=PACKAGE_MIME,
+ packaging="http://purl.org/net/sword/package/SimpleZip")
+
+ assert new_receipt.code >= 200 and new_receipt.code < 400
+ assert new_receipt.location is not None
+ assert new_receipt.location == receipt.edit_media
+
+ def test_26_advanced_add_content_to_resource_package(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip')
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ with open(PACKAGE) as pkg:
+ new_receipt = conn.add_file_to_resource(receipt.edit_media, pkg, "addition.zip",
+ mimetype=PACKAGE_MIME,
+ packaging="http://purl.org/net/sword/package/SimpleZip",
+ metadata_relevant=True)
+
+ assert new_receipt.code >= 200 and new_receipt.code < 400
+ assert new_receipt.location is not None
+ assert new_receipt.location == receipt.edit_media
+
+ def test_27_basic_add_metadata(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ metadata_entry = e,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip')
+
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ ne = Entry(title="Multipart deposit", id="asidjasidj", dcterms_identifier="http://another/",
+ dcterms_creator="Me!", dcterms_rights="CC0")
+ new_receipt = conn.append(dr=receipt, metadata_entry=ne)
+
+ assert new_receipt.code == 200
+
+ def test_28_advanced_add_metadata(self):
+ conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
+ conn.get_service_document()
+ col = conn.sd.workspaces[0][1][0]
+ e = Entry(title="Multipart deposit", id="asidjasidj", dcterms_abstract="abstract", dcterms_identifier="http://whatever/")
+ with open(PACKAGE) as pkg:
+ receipt = conn.create(col_iri = col.href,
+ metadata_entry = e,
+ payload=pkg,
+ mimetype=PACKAGE_MIME,
+ filename="example.zip",
+ packaging = 'http://purl.org/net/sword/package/SimpleZip')
+
+ # ensure that we have a receipt (the server may not give us one
+ # by default)
+ receipt = conn.get_deposit_receipt(receipt.location)
+
+ ne = Entry(title="Multipart deposit", id="asidjasidj", dcterms_identif...
[truncated message content] |
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-03-16 15:02:18
|
Revision: 474
http://sword-app.svn.sourceforge.net/sword-app/?rev=474&view=rev
Author: richard-jones
Date: 2012-03-16 15:02:07 +0000 (Fri, 16 Mar 2012)
Log Message:
-----------
add binary deposit test cases and add extra method to the deposit object to be in-line with the python client
Modified Paths:
--------------
JavaClient2.0/pom.xml
JavaClient2.0/src/main/java/org/swordapp/client/Deposit.java
JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java
JavaClient2.0/sword-client.iml
Added Paths:
-----------
JavaClient2.0/src/test/resources/
JavaClient2.0/src/test/resources/example.zip
Modified: JavaClient2.0/pom.xml
===================================================================
--- JavaClient2.0/pom.xml 2012-03-16 13:26:52 UTC (rev 473)
+++ JavaClient2.0/pom.xml 2012-03-16 15:02:07 UTC (rev 474)
@@ -75,5 +75,10 @@
<artifactId>junit</artifactId>
<version>4.4</version>
</dependency>
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>1.4</version>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
Modified: JavaClient2.0/src/main/java/org/swordapp/client/Deposit.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/Deposit.java 2012-03-16 13:26:52 UTC (rev 473)
+++ JavaClient2.0/src/main/java/org/swordapp/client/Deposit.java 2012-03-16 15:02:07 UTC (rev 474)
@@ -101,6 +101,16 @@
this.mimeType = mimeType;
}
+ public void setSuggestedIdentifier(String slug)
+ {
+ this.setSlug(slug);
+ }
+
+ public String getSuggestedIdentifier()
+ {
+ return this.getSlug();
+ }
+
public String getSlug()
{
return slug;
Modified: JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java
===================================================================
--- JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java 2012-03-16 13:26:52 UTC (rev 473)
+++ JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java 2012-03-16 15:02:07 UTC (rev 474)
@@ -1,27 +1,42 @@
package org.swordapp.client.test;
+import org.apache.commons.codec.digest.DigestUtils;
import org.junit.Test;
import org.junit.Before;
import static org.junit.Assert.*;
import org.swordapp.client.AuthCredentials;
import org.swordapp.client.ClientConfiguration;
+import org.swordapp.client.Deposit;
+import org.swordapp.client.DepositReceipt;
import org.swordapp.client.SWORDClient;
+import org.swordapp.client.SWORDCollection;
import org.swordapp.client.ServiceDocument;
+import org.swordapp.client.UriRegistry;
+import java.io.FileInputStream;
+
public class SpecTests
{
private String sdIRI = null;
private String user = null;
private String pass = null;
private String obo = null;
+ private String file = null;
+ private String fileMd5 = null;
@Before
public void setUp()
+ throws Exception
{
+ // FIXME: should read this all from some test config, or try to auto-locate
+ // resources (particularly the file)
this.sdIRI = "http://localhost:8080/sd-uri";
this.user = "sword";
this.pass = "sword";
this.obo = "obo";
+ this.file = "/home/richard/Code/External/JavaClient2.0/src/test/resources/example.zip";
+
+ this.fileMd5 = DigestUtils.md5Hex(new FileInputStream(this.file));
}
@Test
@@ -48,27 +63,50 @@
assertEquals(sd.getVersion(), "2.0");
}
- /* Python tests to mimic
+ @Test
+ public void basicCreateResourceWithPackage()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
- def test_03_basic_create_resource_with_package(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- with open(PACKAGE) as pkg:
- receipt = conn.create(col_iri = col.href,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="example.zip",
- packaging = 'http://purl.org/net/sword/package/SimpleZip')
+ Deposit deposit = new Deposit();
+ deposit.setFile(new FileInputStream(this.file));
+ deposit.setMimeType("application/zip");
+ deposit.setFilename("example.zip");
+ deposit.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ deposit.setMd5(this.fileMd5);
- assert receipt.code == 201
- assert receipt.location != None
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass));
+ assertEquals(receipt.getStatusCode(), 201);
+ assertTrue(receipt.getLocation() != null);
+ }
- # these last two assertions are contingent on if we actually get a
- # receipt back from the server (which we might not legitimately get)
- assert receipt.dom is None or receipt.parsed == True
- assert receipt.dom is None or receipt.valid == True
+ @Test
+ public void advancedCreateResourceWithPackage()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass, this.obo));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
+ Deposit deposit = new Deposit();
+ deposit.setFile(new FileInputStream(this.file));
+ deposit.setMimeType("application/zip");
+ deposit.setFilename("example.zip");
+ deposit.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ deposit.setMd5(this.fileMd5);
+ deposit.setInProgress(true);
+ deposit.setSuggestedIdentifier("abcdefg");
+
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass, this.obo));
+ assertEquals(receipt.getStatusCode(), 201);
+ assertTrue(receipt.getLocation() != null);
+ }
+
+ /* Python tests to mimic
+
def test_04_advanced_create_resource_with_package(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
conn.get_service_document()
Added: JavaClient2.0/src/test/resources/example.zip
===================================================================
(Binary files differ)
Property changes on: JavaClient2.0/src/test/resources/example.zip
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified: JavaClient2.0/sword-client.iml
===================================================================
--- JavaClient2.0/sword-client.iml 2012-03-16 13:26:52 UTC (rev 473)
+++ JavaClient2.0/sword-client.iml 2012-03-16 15:02:07 UTC (rev 474)
@@ -8,15 +8,15 @@
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources/annotations" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
+ <sourceFolder url="file://$MODULE_DIR$/src/test/resources" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target/classes" />
<excludeFolder url="file://$MODULE_DIR$/target/test-classes" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
- <orderEntry type="library" name="Maven: junit:junit:4.4" level="project" />
<orderEntry type="library" name="Maven: commons-httpclient:commons-httpclient:3.1" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.0.4" level="project" />
- <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.2" level="project" />
+ <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.4" level="project" />
<orderEntry type="library" name="Maven: log4j:log4j:1.2.15" level="project" />
<orderEntry type="library" name="Maven: org.apache.abdera:abdera-client:1.1.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.abdera:abdera-core:1.1.1" level="project" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-03-16 16:23:41
|
Revision: 476
http://sword-app.svn.sourceforge.net/sword-app/?rev=476&view=rev
Author: richard-jones
Date: 2012-03-16 16:23:32 +0000 (Fri, 16 Mar 2012)
Log Message:
-----------
add unused tests for multipart deposit, and add notes on why multipart doesn't work and a todo file to remind us
Modified Paths:
--------------
JavaClient2.0/src/main/java/org/swordapp/client/SWORDMultipartRequestEntity.java
JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java
Added Paths:
-----------
JavaClient2.0/TODO
Added: JavaClient2.0/TODO
===================================================================
--- JavaClient2.0/TODO (rev 0)
+++ JavaClient2.0/TODO 2012-03-16 16:23:32 UTC (rev 476)
@@ -0,0 +1,24 @@
+TODO List
+=========
+
+This is a register of some things that still need to be adequately handled in this code library
+
+1/ Multipart does not work.
+
+This occurs when a 401 Unauthorised challenge is received. In making the initial request, the library
+reads all of the data from the input stream to be delivered, and therefore cannot re-deliver it once
+authentication has taken place.
+
+
+Notes
+-----
+
+- Create mechanism for handling arbitrary response codes (might act on response codes that we understand, like
+302, etc); possible value in a response code handler with default behaviour that can be customised per-request
+
+- documentation
+
+- logging
+
+- modify foresite to allow namespace prefixes to be passed in
+
Modified: JavaClient2.0/src/main/java/org/swordapp/client/SWORDMultipartRequestEntity.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/SWORDMultipartRequestEntity.java 2012-03-16 15:57:39 UTC (rev 475)
+++ JavaClient2.0/src/main/java/org/swordapp/client/SWORDMultipartRequestEntity.java 2012-03-16 16:23:32 UTC (rev 476)
@@ -55,6 +55,8 @@
out.writeBytes("\r\n--" + this.boundary + "\r\n");
}
+ // FIXME: this fails if we receive an authentication request, because it has
+ // already burned through the input stream on the first attempt
private void writeInput(DataOutputStream out) throws IOException
{
if (this.contentType == null)
Modified: JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java
===================================================================
--- JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java 2012-03-16 15:57:39 UTC (rev 475)
+++ JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java 2012-03-16 16:23:32 UTC (rev 476)
@@ -8,6 +8,7 @@
import org.swordapp.client.ClientConfiguration;
import org.swordapp.client.Deposit;
import org.swordapp.client.DepositReceipt;
+import org.swordapp.client.EntryPart;
import org.swordapp.client.SWORDClient;
import org.swordapp.client.SWORDCollection;
import org.swordapp.client.ServiceDocument;
@@ -77,6 +78,8 @@
deposit.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
deposit.setMd5(this.fileMd5);
+ assertTrue(deposit.isBinaryOnly());
+
DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass));
assertEquals(receipt.getStatusCode(), 201);
assertTrue(receipt.getLocation() != null);
@@ -104,52 +107,64 @@
assertTrue(receipt.getLocation() != null);
}
- /* Python tests to mimic
+ /* FIXME: multipart is not currently functional ...
+ @Test
+ public void basicCreateResourceWithMutlipart()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
- def test_05_basic_create_resource_with_multipart(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- e = Entry(title="Foo", id="asidjasidj", dcterms_abstract="abstract", dcterms_title="my title")
- with open(PACKAGE) as pkg:
- receipt = conn.create(col_iri = col.href,
- metadata_entry = e,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="example.zip",
- packaging = 'http://purl.org/net/sword/package/SimpleZip')
+ EntryPart ep = new EntryPart();
+ ep.addDublinCore("title", "My Title");
- assert receipt.code == 201
- assert receipt.location != None
+ Deposit deposit = new Deposit();
+ deposit.setEntryPart(ep);
+ deposit.setFile(new FileInputStream(this.file));
+ deposit.setMimeType("application/zip");
+ deposit.setFilename("example.zip");
+ deposit.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ deposit.setMd5(this.fileMd5);
- # these last two assertions are contingent on if we actually get a
- # receipt back from the server (which we might not legitimately get)
- assert receipt.dom is None or receipt.parsed == True
- assert receipt.dom is None or receipt.valid == True
+ assertTrue(deposit.isMultipart());
- def test_06_advanced_create_resource_with_multipart(self):
- conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW, on_behalf_of=SSS_OBO)
- conn.get_service_document()
- col = conn.sd.workspaces[0][1][0]
- e = Entry(title="Foo", id="asidjasidj", dcterms_abstract="abstract", dcterms_title="my title")
- with open(PACKAGE) as pkg:
- receipt = conn.create(col_iri = col.href,
- metadata_entry = e,
- payload=pkg,
- mimetype=PACKAGE_MIME,
- filename="example.zip",
- packaging = 'http://purl.org/net/sword/package/SimpleZip',
- in_progress = True,
- suggested_identifier = "zyxwvutsrq")
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass));
+ assertEquals(receipt.getStatusCode(), 201);
+ assertTrue(receipt.getLocation() != null);
+ }
- assert receipt.code == 201
- assert receipt.location != None
+ @Test
+ public void advancedCreateResourceWithMutlipart()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ ServiceDocument sd = client.getServiceDocument(this.sdIRI, new AuthCredentials(this.user, this.pass, this.obo));
+ SWORDCollection col = sd.getWorkspaces().get(0).getCollections().get(0);
- # these last two assertions are contingent on if we actually get a
- # receipt back from the server (which we might not legitimately get)
- assert receipt.dom is None or receipt.parsed == True
- assert receipt.dom is None or receipt.valid == True
+ EntryPart ep = new EntryPart();
+ ep.addDublinCore("title", "My Title");
+ Deposit deposit = new Deposit();
+ deposit.setEntryPart(ep);
+ deposit.setFile(new FileInputStream(this.file));
+ deposit.setMimeType("application/zip");
+ deposit.setFilename("example.zip");
+ deposit.setPackaging(UriRegistry.PACKAGE_SIMPLE_ZIP);
+ deposit.setMd5(this.fileMd5);
+ deposit.setInProgress(true);
+ deposit.setSuggestedIdentifier("abcdefg");
+
+ assertTrue(deposit.isMultipart());
+
+ DepositReceipt receipt = client.deposit(col, deposit, new AuthCredentials(this.user, this.pass, this.obo));
+ assertEquals(receipt.getStatusCode(), 201);
+ assertTrue(receipt.getLocation() != null);
+ }
+ */
+
+ /* Python tests to mimic
+
def test_07_basic_create_resource_with_entry(self):
conn = Connection(SSS_URL, user_name=SSS_UN, user_pass=SSS_PW)
conn.get_service_document()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-03-25 17:40:58
|
Revision: 489
http://sword-app.svn.sourceforge.net/sword-app/?rev=489&view=rev
Author: richard-jones
Date: 2012-03-25 17:40:48 +0000 (Sun, 25 Mar 2012)
Log Message:
-----------
add auto-discovery service to client, and associated tests
Modified Paths:
--------------
JavaClient2.0/pom.xml
JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java
JavaClient2.0/src/main/java/org/swordapp/client/UriRegistry.java
JavaClient2.0/src/test/java/org/swordapp/client/test/SSSSemiUnits.java
JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java
JavaClient2.0/sword-client.iml
Added Paths:
-----------
JavaClient2.0/src/main/java/org/swordapp/client/Endpoints.java
Modified: JavaClient2.0/pom.xml
===================================================================
--- JavaClient2.0/pom.xml 2012-03-25 16:17:58 UTC (rev 488)
+++ JavaClient2.0/pom.xml 2012-03-25 17:40:48 UTC (rev 489)
@@ -80,5 +80,10 @@
<artifactId>commons-codec</artifactId>
<version>1.4</version>
</dependency>
+ <dependency>
+ <groupId>org.jsoup</groupId>
+ <artifactId>jsoup</artifactId>
+ <version>1.6.1</version>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
Added: JavaClient2.0/src/main/java/org/swordapp/client/Endpoints.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/Endpoints.java (rev 0)
+++ JavaClient2.0/src/main/java/org/swordapp/client/Endpoints.java 2012-03-25 17:40:48 UTC (rev 489)
@@ -0,0 +1,71 @@
+package org.swordapp.client;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class Endpoints
+{
+ private String serviceDocument = null;
+ private String collection = null;
+ private String edit = null;
+ private Map<String, String> statements = new HashMap<String, String>();
+
+ public Endpoints() {}
+
+ public Endpoints(String serviceDocument, String collection, String edit, Map<String, String> statements)
+ {
+ this.serviceDocument = serviceDocument;
+ this.collection = collection;
+ this.edit = edit;
+ this.statements = statements;
+ }
+
+ public String getServiceDocument()
+ {
+ return serviceDocument;
+ }
+
+ public void setServiceDocument(String serviceDocument)
+ {
+ this.serviceDocument = serviceDocument;
+ }
+
+ public String getCollection()
+ {
+ return collection;
+ }
+
+ public void setCollection(String collection)
+ {
+ this.collection = collection;
+ }
+
+ public String getEdit()
+ {
+ return edit;
+ }
+
+ public void setEdit(String edit)
+ {
+ this.edit = edit;
+ }
+
+ public Map<String, String> getStatements()
+ {
+ if (statements.size() == 0)
+ {
+ return null;
+ }
+ return statements;
+ }
+
+ public void setStatements(Map<String, String> statements)
+ {
+ this.statements = statements;
+ }
+
+ public void addStatement(String url, String type)
+ {
+ this.statements.put(url, type);
+ }
+}
Modified: JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java 2012-03-25 16:17:58 UTC (rev 488)
+++ JavaClient2.0/src/main/java/org/swordapp/client/SWORDClient.java 2012-03-25 17:40:48 UTC (rev 489)
@@ -1,26 +1,24 @@
package org.swordapp.client;
import org.apache.abdera.Abdera;
-import org.apache.abdera.i18n.iri.IRI;
import org.apache.abdera.model.Document;
-import org.apache.abdera.model.Element;
import org.apache.abdera.model.Entry;
import org.apache.abdera.model.Feed;
-import org.apache.abdera.model.Link;
import org.apache.abdera.model.Service;
import org.apache.abdera.parser.ParseException;
import org.apache.abdera.protocol.Response;
import org.apache.abdera.protocol.client.AbderaClient;
import org.apache.abdera.protocol.client.ClientResponse;
import org.apache.abdera.protocol.client.RequestOptions;
-import org.apache.abdera.protocol.client.util.MultipartRelatedRequestEntity;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
import org.apache.log4j.Logger;
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Element;
+import org.jsoup.select.Elements;
import javax.activation.MimeType;
import javax.activation.MimeTypeParseException;
-import java.awt.print.PrinterException;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
@@ -47,6 +45,51 @@
this.abdera = new Abdera();
}
+ public Endpoints autoDiscover(String url)
+ throws SWORDClientException
+ {
+ try
+ {
+ org.jsoup.nodes.Document doc = Jsoup.connect(url).get();
+ Elements links = doc.select("link[rel]");
+ Endpoints endpoints = new Endpoints();
+
+ for (int i = 0; i < links.size(); i++)
+ {
+ Element element = links.get(i);
+ String rel = element.attr("rel");
+ if (rel == null)
+ {
+ continue;
+ }
+ rel = rel.toLowerCase();
+
+ if (rel.equals("sword") || rel.equals(UriRegistry.REL_SERVICE_DOCUMENT))
+ {
+ endpoints.setServiceDocument(element.attr("href"));
+ }
+ else if (rel.equals(UriRegistry.REL_DEPOSIT))
+ {
+ endpoints.setCollection(element.attr("href"));
+ }
+ else if (rel.equals(UriRegistry.REL_EDIT))
+ {
+ endpoints.setEdit(element.attr("href"));
+ }
+ else if (rel.equals(UriRegistry.REL_STATEMENT))
+ {
+ endpoints.addStatement(element.attr("href"), element.attr("type"));
+ }
+ }
+
+ return endpoints;
+ }
+ catch (IOException e)
+ {
+ throw new SWORDClientException(e);
+ }
+ }
+
public ServiceDocument getServiceDocument(String sdURL)
throws SWORDClientException, ProtocolViolationException
{
Modified: JavaClient2.0/src/main/java/org/swordapp/client/UriRegistry.java
===================================================================
--- JavaClient2.0/src/main/java/org/swordapp/client/UriRegistry.java 2012-03-25 16:17:58 UTC (rev 488)
+++ JavaClient2.0/src/main/java/org/swordapp/client/UriRegistry.java 2012-03-25 17:40:48 UTC (rev 489)
@@ -28,6 +28,9 @@
public static SQName SWORD_STATE_DESCRIPTION = new SQName(SWORD_TERMS_NAMESPACE, "stateDescription");
// rel values
+ public static String REL_SERVICE_DOCUMENT = "http://purl.org/net/sword/discovery/service-document";
+ public static String REL_DEPOSIT = SWORD_TERMS_NAMESPACE + "deposit";
+ public static String REL_EDIT = SWORD_TERMS_NAMESPACE + "edit";
public static String REL_STATEMENT = SWORD_TERMS_NAMESPACE + "statement";
public static String REL_SWORD_EDIT = SWORD_TERMS_NAMESPACE + "add";
public static String REL_ORIGINAL_DEPOSIT = SWORD_TERMS_NAMESPACE + "originalDeposit";
Modified: JavaClient2.0/src/test/java/org/swordapp/client/test/SSSSemiUnits.java
===================================================================
--- JavaClient2.0/src/test/java/org/swordapp/client/test/SSSSemiUnits.java 2012-03-25 16:17:58 UTC (rev 488)
+++ JavaClient2.0/src/test/java/org/swordapp/client/test/SSSSemiUnits.java 2012-03-25 17:40:48 UTC (rev 489)
@@ -9,6 +9,7 @@
import org.swordapp.client.ClientConfiguration;
import org.swordapp.client.Deposit;
import org.swordapp.client.DepositReceipt;
+import org.swordapp.client.Endpoints;
import org.swordapp.client.EntryPart;
import org.swordapp.client.OreStatement;
import org.swordapp.client.ResourceState;
@@ -24,8 +25,10 @@
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
/**
* This class uses explicit knowledge of the SSS test server configuration
@@ -37,6 +40,9 @@
*/
public class SSSSemiUnits
{
+ private String homePage = null;
+ private String depositPage = null;
+ private String resourcePage = null;
private String sdIRI = null;
private String user = null;
private String pass = null;
@@ -48,6 +54,9 @@
public void setUp()
throws Exception
{
+ this.homePage = "http://localhost:8080/";
+ this.depositPage = "http://localhost:8080/html/ded3c328-d8f0-4307-8b86-086cf46a953c";
+ this.resourcePage = "http://localhost:8080/html/ded3c328-d8f0-4307-8b86-086cf46a953c/f2966e10-c6a0-40ab-90ad-6fc90d5b8bd3";
this.sdIRI = "http://localhost:8080/sd-uri";
this.user = "sword";
this.pass = "sword";
@@ -308,4 +317,49 @@
}
assertTrue(checked);
}
+
+ @Test
+ public void autoDiscoverService()
+ throws Exception
+ {
+ SWORDClient client = new SWORDClient(new ClientConfiguration());
+ Endpoints endpoints = client.autoDiscover(this.homePage);
+
+ assertEquals(endpoints.getServiceDocument(), this.sdIRI);
+ assertNull(endpoints.getCollection());
+ assertNull(endpoints.getEdit());
+ assertNull(endpoints.getStatements());
+
+ endpoints = client.autoDiscover(this.depositPage);
+
+ assertNull(endpoints.getServiceDocument());
+ assertEquals(endpoints.getCollection(), "http://localhost:8080/col-uri/ded3c328-d8f0-4307-8b86-086cf46a953c");
+ assertNull(endpoints.getEdit());
+ assertNull(endpoints.getStatements());
+
+ endpoints = client.autoDiscover(this.resourcePage);
+
+ assertNull(endpoints.getServiceDocument());
+ assertNull(endpoints.getCollection());
+ assertEquals(endpoints.getEdit(), "http://localhost:8080/edit-uri/ded3c328-d8f0-4307-8b86-086cf46a953c/f2966e10-c6a0-40ab-90ad-6fc90d5b8bd3");
+
+ Map<String, String> statements = endpoints.getStatements();
+ int count = 0;
+ for (String url : statements.keySet())
+ {
+ String type = statements.get(url);
+
+ if (type.equals("application/atom+xml") || type.equals("application/atom+xml;type=feed"))
+ {
+ assertEquals(url, "http://localhost:8080/state-uri/ded3c328-d8f0-4307-8b86-086cf46a953c/f2966e10-c6a0-40ab-90ad-6fc90d5b8bd3.atom");
+ count++;
+ }
+ else if (type.equals("application/rdf+xml"))
+ {
+ assertEquals(url, "http://localhost:8080/state-uri/ded3c328-d8f0-4307-8b86-086cf46a953c/f2966e10-c6a0-40ab-90ad-6fc90d5b8bd3.rdf");
+ count++;
+ }
+ }
+ assertEquals(count, 2);
+ }
}
Modified: JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java
===================================================================
--- JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java 2012-03-25 16:17:58 UTC (rev 488)
+++ JavaClient2.0/src/test/java/org/swordapp/client/test/SpecTests.java 2012-03-25 17:40:48 UTC (rev 489)
@@ -12,6 +12,7 @@
import org.swordapp.client.Content;
import org.swordapp.client.Deposit;
import org.swordapp.client.DepositReceipt;
+import org.swordapp.client.Endpoints;
import org.swordapp.client.EntryPart;
import org.swordapp.client.OreStatement;
import org.swordapp.client.SWORDClient;
@@ -25,7 +26,12 @@
import java.io.FileInputStream;
import java.util.List;
+import java.util.Map;
+// FIXME: these tests rely on a hard-coded set of fixtures to do with my local
+// set up. This means anyone else trying to run these tests will need to reconfigure
+// and recompile. Sorry.
+
public class SpecTests
{
private String sdIRI = null;
Modified: JavaClient2.0/sword-client.iml
===================================================================
--- JavaClient2.0/sword-client.iml 2012-03-25 16:17:58 UTC (rev 488)
+++ JavaClient2.0/sword-client.iml 2012-03-25 17:40:48 UTC (rev 489)
@@ -54,6 +54,7 @@
<orderEntry type="library" name="Maven: joda-time:joda-time:1.6" level="project" />
<orderEntry type="library" name="Maven: xom:xom:1.2.5" level="project" />
<orderEntry type="library" name="Maven: javax.servlet:servlet-api:2.4" level="project" />
+ <orderEntry type="library" name="Maven: org.jsoup:jsoup:1.6.1" level="project" />
</component>
</module>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-03-26 13:01:54
|
Revision: 491
http://sword-app.svn.sourceforge.net/sword-app/?rev=491&view=rev
Author: richard-jones
Date: 2012-03-26 13:01:45 +0000 (Mon, 26 Mar 2012)
Log Message:
-----------
add directory structure for proper branches/tags/trunk layout
Added Paths:
-----------
JavaClient2.0/branches/
JavaClient2.0/tags/
JavaClient2.0/trunk/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: SVN c. m. f. t. SWORD-A. p. <swo...@li...> - 2012-03-26 13:22:42
|
Revision: 492
http://sword-app.svn.sourceforge.net/sword-app/?rev=492&view=rev
Author: richard-jones
Date: 2012-03-26 13:22:32 +0000 (Mon, 26 Mar 2012)
Log Message:
-----------
move main code into trunk directory
Added Paths:
-----------
JavaClient2.0/trunk/TODO
JavaClient2.0/trunk/pom.xml
JavaClient2.0/trunk/src/
JavaClient2.0/trunk/sword-client.iml
Removed Paths:
-------------
JavaClient2.0/TODO
JavaClient2.0/pom.xml
JavaClient2.0/src/
JavaClient2.0/sword-client.iml
Deleted: JavaClient2.0/TODO
===================================================================
--- JavaClient2.0/TODO 2012-03-26 13:01:45 UTC (rev 491)
+++ JavaClient2.0/TODO 2012-03-26 13:22:32 UTC (rev 492)
@@ -1,24 +0,0 @@
-TODO List
-=========
-
-This is a register of some things that still need to be adequately handled in this code library
-
-1/ Multipart does not work.
-
-This occurs when a 401 Unauthorised challenge is received. In making the initial request, the library
-reads all of the data from the input stream to be delivered, and therefore cannot re-deliver it once
-authentication has taken place.
-
-
-Notes
------
-
-- Create mechanism for handling arbitrary response codes (might act on response codes that we understand, like
-302, etc); possible value in a response code handler with default behaviour that can be customised per-request
-
-- documentation
-
-- logging
-
-- modify foresite to allow namespace prefixes to be passed in
-
Deleted: JavaClient2.0/pom.xml
===================================================================
--- JavaClient2.0/pom.xml 2012-03-26 13:01:45 UTC (rev 491)
+++ JavaClient2.0/pom.xml 2012-03-26 13:22:32 UTC (rev 492)
@@ -1,89 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <groupId>org.swordapp</groupId>
- <artifactId>sword-client</artifactId>
- <version>2.0</version>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>2.3.2</version>
- <configuration>
- <source>6</source>
- <target>6</target>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- <dependencies>
- <dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- <version>3.1</version>
- </dependency>
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- <version>1.2.15</version>
- <exclusions>
- <exclusion>
- <groupId>javax.mail</groupId>
- <artifactId>mail</artifactId>
- </exclusion>
- <exclusion>
- <groupId>javax.jms</groupId>
- <artifactId>jms</artifactId>
- </exclusion>
- <exclusion>
- <groupId>com.sun.jdmk</groupId>
- <artifactId>jmxtools</artifactId>
- </exclusion>
- <exclusion>
- <groupId>com.sun.jmx</groupId>
- <artifactId>jmxri</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.apache.abdera</groupId>
- <artifactId>abdera-client</artifactId>
- <version>1.1.1</version>
- </dependency>
- <dependency>
- <groupId>org.dspace</groupId>
- <artifactId>foresite</artifactId>
- <version>0.9</version>
- </dependency>
- <dependency>
- <groupId>xom</groupId>
- <artifactId>xom</artifactId>
- <version>1.2.5</version>
- </dependency>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- <version>2.4</version>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.4</version>
- </dependency>
- <dependency>
- <groupId>commons-codec</groupId>
- <artifactId>commons-codec</artifactId>
- <version>1.4</version>
- </dependency>
- <dependency>
- <groupId>org.jsoup</groupId>
- <artifactId>jsoup</artifactId>
- <version>1.6.1</version>
- </dependency>
- </dependencies>
-</project>
\ No newline at end of file
Deleted: JavaClient2.0/sword-client.iml
===================================================================
--- JavaClient2.0/sword-client.iml 2012-03-26 13:01:45 UTC (rev 491)
+++ JavaClient2.0/sword-client.iml 2012-03-26 13:22:32 UTC (rev 492)
@@ -1,60 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
- <component name="NewModuleRootManager" inherit-compiler-output="false">
- <output url="file://$MODULE_DIR$/target/classes" />
- <output-test url="file://$MODULE_DIR$/target/test-classes" />
- <content url="file://$MODULE_DIR$">
- <sourceFolder url="file://$MODULE_DIR$/target/generated-sources/test-annotations" isTestSource="true" />
- <sourceFolder url="file://$MODULE_DIR$/target/generated-sources/annotations" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
- <sourceFolder url="file://$MODULE_DIR$/src/test/resources" isTestSource="true" />
- <excludeFolder url="file://$MODULE_DIR$/target/classes" />
- <excludeFolder url="file://$MODULE_DIR$/target/test-classes" />
- </content>
- <orderEntry type="inheritedJdk" />
- <orderEntry type="sourceFolder" forTests="false" />
- <orderEntry type="library" name="Maven: commons-httpclient:commons-httpclient:3.1" level="project" />
- <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.0.4" level="project" />
- <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.4" level="project" />
- <orderEntry type="library" name="Maven: log4j:log4j:1.2.15" level="project" />
- <orderEntry type="library" name="Maven: org.apache.abdera:abdera-client:1.1.1" level="project" />
- <orderEntry type="library" name="Maven: org.apache.abdera:abdera-core:1.1.1" level="project" />
- <orderEntry type="library" name="Maven: org.apache.abdera:abdera-i18n:1.1.1" level="project" />
- <orderEntry type="library" name="Maven: org.apache.geronimo.specs:geronimo-activation_1.0.2_spec:1.1" level="project" />
- <orderEntry type="library" name="Maven: org.apache.geronimo.specs:geronimo-stax-api_1.0_spec:1.0.1" level="project" />
- <orderEntry type="library" name="Maven: org.apache.abdera:abdera-parser:1.1.1" level="project" />
- <orderEntry type="library" name="Maven: org.apache.ws.commons.axiom:axiom-impl:1.2.10" level="project" />
- <orderEntry type="library" name="Maven: org.apache.ws.commons.axiom:axiom-api:1.2.10" level="project" />
- <orderEntry type="library" name="Maven: org.apache.geronimo.specs:geronimo-activation_1.1_spec:1.0.2" level="project" />
- <orderEntry type="library" name="Maven: org.apache.geronimo.specs:geronimo-javamail_1.4_spec:1.6" level="project" />
- <orderEntry type="library" name="Maven: jaxen:jaxen:1.1.1" level="project" />
- <orderEntry type="library" name="Maven: org.codehaus.woodstox:wstx-asl:3.0.0" level="project" />
- <orderEntry type="library" name="Maven: xml-apis:xml-apis:1.3.03" level="project" />
- <orderEntry type="library" name="Maven: xerces:xercesImpl:2.8.0" level="project" />
- <orderEntry type="library" name="Maven: org.dspace:foresite:0.9" level="project" />
- <orderEntry type="library" name="Maven: com.hp.hpl.jena:jena:2.5.5" level="project" />
- <orderEntry type="library" name="Maven: com.hp.hpl.jena:arq:2.2" level="project" />
- <orderEntry type="library" name="Maven: org.apache.lucene:lucene-core:2.2.0" level="project" />
- <orderEntry type="library" name="Maven: com.hp.hpl.jena:arq-extra:2.2" level="project" />
- <orderEntry type="library" name="Maven: com.hp.hpl.jena:jenatest:2.5.5" level="project" />
- <orderEntry type="library" name="Maven: com.hp.hpl.jena:iri:0.5" level="project" />
- <orderEntry type="library" name="Maven: com.ibm.icu:icu4j:3.4.4" level="project" />
- <orderEntry type="library" name="Maven: antlr:antlr:2.7.5" level="project" />
- <orderEntry type="library" name="Maven: com.hp.hpl.jena:concurrent-jena:1.3.2" level="project" />
- <orderEntry type="library" name="Maven: com.hp.hpl.jena:json-jena:1.0" level="project" />
- <orderEntry type="library" name="Maven: stax:stax-api:1.0" level="project" />
- <orderEntry type="library" name="Maven: xerces:xmlParserAPIs:2.0.2" level="project" />
- <orderEntry type="library" name="Maven: rome:rome:0.9" level="project" />
- <orderEntry type="library" name="Maven: jdom:jdom:1.0" level="project" />
- <orderEntry type="library" name="Maven: xalan:xalan:2.7.0" level="project" />
- <orderEntry type="library" name="Maven: commons-cli:commons-cli:1.0" level="project" />
- <orderEntry type="library" name="Maven: commons-lang:commons-lang:1.0" level="project" />
- <orderEntry type="library" name="Maven: junit:junit:4.4" level="project" />
- <orderEntry type="library" name="Maven: joda-time:joda-time:1.6" level="project" />
- <orderEntry type="library" name="Maven: xom:xom:1.2.5" level="project" />
- <orderEntry type="library" name="Maven: javax.servlet:servlet-api:2.4" level="project" />
- <orderEntry type="library" name="Maven: org.jsoup:jsoup:1.6.1" level="project" />
- </component>
-</module>
-
Copied: JavaClient2.0/trunk/TODO (from rev 491, JavaClient2.0/TODO)
===================================================================
--- JavaClient2.0/trunk/TODO (rev 0)
+++ JavaClient2.0/trunk/TODO 2012-03-26 13:22:32 UTC (rev 492)
@@ -0,0 +1,24 @@
+TODO List
+=========
+
+This is a register of some things that still need to be adequately handled in this code library
+
+1/ Multipart does not work.
+
+This occurs when a 401 Unauthorised challenge is received. In making the initial request, the library
+reads all of the data from the input stream to be delivered, and therefore cannot re-deliver it once
+authentication has taken place.
+
+
+Notes
+-----
+
+- Create mechanism for handling arbitrary response codes (might act on response codes that we understand, like
+302, etc); possible value in a response code handler with default behaviour that can be customised per-request
+
+- documentation
+
+- logging
+
+- modify foresite to allow namespace prefixes to be passed in
+
Copied: JavaClient2.0/trunk/pom.xml (from rev 491, JavaClient2.0/pom.xml)
===================================================================
--- JavaClient2.0/trunk/pom.xml (rev 0)
+++ JavaClient2.0/trunk/pom.xml 2012-03-26 13:22:32 UTC (rev 492)
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.swordapp</groupId>
+ <artifactId>sword-client</artifactId>
+ <version>2.0</version>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>6</source>
+ <target>6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ <version>3.1</version>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.15</version>
+ <exclusions>
+ <exclusion>
+ <groupId>javax.mail</groupId>
+ <artifactId>mail</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>javax.jms</groupId>
+ <artifactId>jms</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.sun.jdmk</groupId>
+ <artifactId>jmxtools</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.sun.jmx</groupId>
+ <artifactId>jmxri</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.abdera</groupId>
+ <artifactId>abdera-client</artifactId>
+ <version>1.1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.dspace</groupId>
+ <artifactId>foresite</artifactId>
+ <version>0.9</version>
+ </dependency>
+ <dependency>
+ <groupId>xom</groupId>
+ <artifactId>xom</artifactId>
+ <version>1.2.5</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.4</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.4</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>1.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jsoup</groupId>
+ <artifactId>jsoup</artifactId>
+ <version>1.6.1</version>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
Copied: JavaClient2.0/trunk/sword-client.iml (from rev 491, JavaClient2.0/sword-client.iml)
===================================================================
--- JavaClient2.0/trunk/sword-client.iml (rev 0)
+++ JavaClient2.0/trunk/sword-client.iml 2012-03-26 13:22:32 UTC (rev 492)
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
+ <component name="NewModuleRootManager" inherit-compiler-output="false">
+ <output url="file://$MODULE_DIR$/target/classes" />
+ <output-test url="file://$MODULE_DIR$/target/test-classes" />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/target/generated-sources/test-annotations" isTestSource="true" />
+ <sourceFolder url="file://$MODULE_DIR$/target/generated-sources/annotations" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
+ <sourceFolder url="file://$MODULE_DIR$/src/test/resources" isTestSource="true" />
+ <excludeFolder url="file://$MODULE_DIR$/target/classes" />
+ <excludeFolder url="file://$MODULE_DIR$/target/test-classes" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="library" name="Maven: commons-httpclient:commons-httpclient:3.1" level="project" />
+ <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.0.4" level="project" />
+ <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.4" level="project" />
+ <orderEntry type="library" name="Maven: log4j:log4j:1.2.15" level="project" />
+ <orderEntry type="library" name="Maven: org.apache.abdera:abdera-client:1.1.1" level="project" />
+ <orderEntry type="library" name="Maven: org.apache.abdera:abdera-core:1.1.1" level="project" />
+ <orderEntry type="library" name="Maven: org.apache.abdera:abdera-i18n:1.1.1" level="project" />
+ <orderEntry type="library" name="Maven: org.apache.geronimo.specs:geronimo-activation_1.0.2_spec:1.1" level="project" />
+ <orderEntry type="library" name="Maven: org.apache.geronimo.specs:geronimo-stax-api_1.0_spec:1.0.1" level="project" />
+ <orderEntry type="library" name="Maven: org.apache.abdera:abdera-parser:1.1.1" level="project" />
+ <orderEntry type="library" name="Maven: org.apache.ws.commons.axiom:axiom-impl:1.2.10" level="project" />
+ <orderEntry type="library" name="Maven: org.apache.ws.commons.axiom:axiom-api:1.2.10" level="project" />
+ <orderEntry type="library" name="Maven: org.apache.geronimo.specs:geronimo-activation_1.1_spec:1.0.2" level="project" />
+ <orderEntry type="library" name="Maven: org.apache.geronimo.specs:geronimo-javamail_1.4_spec:1.6" level="project" />
+ <orderEntry type="library" name="Maven: jaxen:jaxen:1.1.1" level="project" />
+ <orderEntry type="library" name="Maven: org.codehaus.woodstox:wstx-asl:3.0.0" level="project" />
+ <orderEntry type="library" name="Maven: xml-apis:xml-apis:1.3.03" level="project" />
+ <orderEntry type="library" name="Maven: xerces:xercesImpl:2.8.0" level="project" />
+ <orderEntry type="library" name="Maven: org.dspace:foresite:0.9" level="project" />
+ <orderEntry type="library" name="Maven: com.hp.hpl.jena:jena:2.5.5" level="project" />
+ <orderEntry type="library" name="Maven: com.hp.hpl.jena:arq:2.2" level="project" />
+ <orderEntry type="library" name="Maven: org.apache.lucene:lucene-core:2.2.0" level="project" />
+ <orderEntry type="library" name="Maven: com.hp.hpl.jena:arq-extra:2.2" level="project" />
+ <orderEntry type="library" name="Maven: com.hp.hpl.jena:jenatest:2.5.5" level="project" />
+ <orderEntry type="library" name="Maven: com.hp.hpl.jena:iri:0.5" level="project" />
+ <orderEntry type="library" name="Maven: com.ibm.icu:icu4j:3.4.4" level="project" />
+ <orderEntry type="library" name="Maven: antlr:antlr:2.7.5" level="project" />
+ <orderEntry type="library" name="Maven: com.hp.hpl.jena:concurrent-jena:1.3.2" level="project" />
+ <orderEntry type="library" name="Maven: com.hp.hpl.jena:json-jena:1.0" level="project" />
+ <orderEntry type="library" name="Maven: stax:stax-api:1.0" level="project" />
+ <orderEntry type="library" name="Maven: xerces:xmlParserAPIs:2.0.2" level="project" />
+ <orderEntry type="library" name="Maven: rome:rome:0.9" level="project" />
+ <orderEntry type="library" name="Maven: jdom:jdom:1.0" level="project" />
+ <orderEntry type="library" name="Maven: xalan:xalan:2.7.0" level="project" />
+ <orderEntry type="library" name="Maven: commons-cli:commons-cli:1.0" level="project" />
+ <orderEntry type="library" name="Maven: commons-lang:commons-lang:1.0" level="project" />
+ <orderEntry type="library" name="Maven: junit:junit:4.4" level="project" />
+ <orderEntry type="library" name="Maven: joda-time:joda-time:1.6" level="project" />
+ <orderEntry type="library" name="Maven: xom:xom:1.2.5" level="project" />
+ <orderEntry type="library" name="Maven: javax.servlet:servlet-api:2.4" level="project" />
+ <orderEntry type="library" name="Maven: org.jsoup:jsoup:1.6.1" level="project" />
+ </component>
+</module>
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|