Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
dkocher committed Jan 10, 2025
2 parents dbb117e + d17b2e0 commit e2b5e01
Show file tree
Hide file tree
Showing 12 changed files with 353 additions and 66 deletions.
41 changes: 38 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<groupId>com.github.lookfirst</groupId>
<artifactId>sardine</artifactId>
<packaging>jar</packaging>
<version>5.13-SNAPSHOT</version>
<version>5.14-SNAPSHOT</version>
<description>An easy to use WebDAV client for Java</description>
<name>Sardine WebDAV client</name>
<url>https://github.com/lookfirst/sardine</url>
Expand Down Expand Up @@ -53,6 +53,18 @@
</extensions>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.3.0</version>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>extra-enforcer-rules</artifactId>
<version>1.7.0</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand Down Expand Up @@ -121,6 +133,29 @@
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>enforce-bytecode-version</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<enforceBytecodeVersion>
<maxJdkVersion>${maven.compiler.target}</maxJdkVersion>
<ignoredScopes>
<ignoreScope>test</ignoreScope>
</ignoredScopes>
</enforceBytecodeVersion>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand Down Expand Up @@ -260,8 +295,8 @@
</profile>
</profiles>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<!-- Skip integration tests by default with failsafe plugin -->
<skipITs>false</skipITs>
<httpclient.version>4.5.14</httpclient.version>
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/github/sardine/DavResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@ public DavResource(Response response) throws URISyntaxException
*/
private int getStatusCode(Response response)
{
List<Propstat> list = response.getPropstat();
for(Propstat propstat : list) {
if(propstat.getStatus() != null) {
try {
return BasicLineParser.parseStatusLine(propstat.getStatus(), null).getStatusCode();
}
catch(ParseException e) {
log.warning(String.format("Failed to parse status line: %s", propstat.getStatus()));
return -1;
}
}
}
String status = response.getStatus();
if (status == null || status.isEmpty())
{
Expand Down
69 changes: 69 additions & 0 deletions src/main/java/com/github/sardine/Sardine.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,37 @@ public interface Sardine
*/
List<DavResource> list(String url, int depth, boolean allProp) throws IOException;

/**
* Gets versions listing of resource.
*
* @param url Path to the resource including protocol and hostname
* @throws IOException I/O error or HTTP response validation failure
*/
List<DavResource> versionsList(String url) throws IOException;

/**
* Gets versions listing of resource.
*
* @param url Path to the resource including protocol and hostname
* @param depth The depth to look at (use 0 for single resource, 1 for directory listing,
* -1 for infinite recursion)
* @throws IOException I/O error or HTTP response validation failure
*
*/
List<DavResource> versionsList(String url, int depth) throws IOException;

/**
* Gets versions listing of resource.
*
* @param url Path to the resource including protocol and hostname
* @param depth The depth to look at (use 0 for single resource, 1 for directory listing,
* -1 for infinite recursion)
* @param props Set of properties to be requested
* @throws IOException I/O error or HTTP response validation failure
*
*/
List<DavResource> versionsList(String url, int depth, Set<QName> props) throws IOException;

/**
* Fetches a resource using WebDAV <code>PROPFIND</code>. Only the specified properties
* are retrieved.
Expand Down Expand Up @@ -180,6 +211,17 @@ public interface Sardine
*/
InputStream get(String url) throws IOException;

/**
* Uses HTTP <code>GET</code> to download specific version of data from a server.
* The stream must be closed after reading.
*
* @param url Path to the resource including protocol and hostname
* @param version version of resource
* @return Data stream to read from
* @throws IOException I/O error or HTTP response validation failure
*/
InputStream get(String url, String version) throws IOException;

/**
* Uses HTTP <code>GET</code> to download data from a server. The stream must be closed after reading.
*
Expand Down Expand Up @@ -432,6 +474,33 @@ public interface Sardine
*/
void unlock(String url, String token) throws IOException;

/**
* Put the resource under version control.
*
* @param url Path to the resource including protocol and hostname
* @throws IOException I/O error or HTTP response validation failure
*/
void addToVersionControl(String url) throws IOException;

/**
* CHECKOUT request can be applied only to a checked-in version-controlled resource
* to allow modifications to the content and properties of that version-controlled resource.
*
* @param url Path to the <b>checked-in, version-controlled</b> resource including protocol and hostname
* @throws IOException I/O error or HTTP response validation failure
*/
void checkout(String url) throws IOException;

/**
* CHECKIN request can be applied to a checked-out version-controlled
* resource to produce a new version whose content and properties
* are copied from the checked-out resource.
*
* @param url Path to the <b>checked-out, version-controlled</b> resource including protocol and hostname
* @throws IOException I/O error or HTTP response validation failure
*/
void checkin(String url) throws IOException;

/**
* Read access control list for resource
*
Expand Down
107 changes: 46 additions & 61 deletions src/main/java/com/github/sardine/impl/SardineImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,64 +16,19 @@

package com.github.sardine.impl;

import com.github.sardine.DavAce;
import com.github.sardine.DavAcl;
import com.github.sardine.DavPrincipal;
import com.github.sardine.DavQuota;
import com.github.sardine.DavResource;
import com.github.sardine.Sardine;
import com.github.sardine.Version;
import com.github.sardine.*;
import com.github.sardine.impl.handler.ExistsResponseHandler;
import com.github.sardine.impl.handler.LockResponseHandler;
import com.github.sardine.impl.handler.MultiStatusResponseHandler;
import com.github.sardine.impl.handler.VoidResponseHandler;
import com.github.sardine.impl.io.ContentLengthInputStream;
import com.github.sardine.impl.io.HttpMethodReleaseInputStream;
import com.github.sardine.impl.methods.HttpAcl;
import com.github.sardine.impl.methods.HttpCopy;
import com.github.sardine.impl.methods.HttpLock;
import com.github.sardine.impl.methods.HttpMkCol;
import com.github.sardine.impl.methods.HttpMove;
import com.github.sardine.impl.methods.HttpPropFind;
import com.github.sardine.impl.methods.HttpPropPatch;
import com.github.sardine.impl.methods.HttpReport;
import com.github.sardine.impl.methods.HttpSearch;
import com.github.sardine.impl.methods.HttpUnlock;
import com.github.sardine.model.Ace;
import com.github.sardine.model.Acl;
import com.github.sardine.model.Allprop;
import com.github.sardine.model.Displayname;
import com.github.sardine.model.Exclusive;
import com.github.sardine.model.Group;
import com.github.sardine.model.Lockinfo;
import com.github.sardine.model.Lockscope;
import com.github.sardine.model.Locktype;
import com.github.sardine.model.Multistatus;
import com.github.sardine.model.ObjectFactory;
import com.github.sardine.model.Owner;
import com.github.sardine.model.PrincipalCollectionSet;
import com.github.sardine.model.PrincipalURL;
import com.github.sardine.model.Prop;
import com.github.sardine.model.Propertyupdate;
import com.github.sardine.model.Propfind;
import com.github.sardine.model.Propstat;
import com.github.sardine.model.QuotaAvailableBytes;
import com.github.sardine.model.QuotaUsedBytes;
import com.github.sardine.model.Remove;
import com.github.sardine.model.Resourcetype;
import com.github.sardine.model.Response;
import com.github.sardine.model.SearchRequest;
import com.github.sardine.model.Set;
import com.github.sardine.model.Write;
import com.github.sardine.impl.methods.*;
import com.github.sardine.model.*;
import com.github.sardine.report.SardineReport;
import com.github.sardine.report.VersionTreeReport;
import com.github.sardine.util.SardineUtil;
import org.apache.http.Consts;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.*;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.AuthState;
import org.apache.http.auth.NTCredentials;
Expand All @@ -84,12 +39,7 @@
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.config.AuthSchemes;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.methods.*;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.client.protocol.RequestAcceptEncoding;
import org.apache.http.client.protocol.ResponseContentEncoding;
Expand All @@ -108,11 +58,7 @@
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.impl.client.BasicAuthCache;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.client.*;
import org.apache.http.impl.conn.DefaultSchemePortResolver;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.impl.conn.SystemDefaultRoutePlanner;
Expand All @@ -139,6 +85,8 @@
import java.util.Map.Entry;
import java.util.logging.Logger;

import static com.github.sardine.util.SardineUtil.createQNameWithDefaultNamespace;

/**
* Implementation of the Sardine interface. This is where the meat of the Sardine library lives.
*
Expand Down Expand Up @@ -414,6 +362,21 @@ public List<DavResource> list(String url, int depth, boolean allProp) throws IOE
}
}

@Override
public List<DavResource> versionsList(String url) throws IOException {
return versionsList(url, 0);
}

@Override
public List<DavResource> versionsList(String url, int depth) throws IOException {
return versionsList(url, depth, Collections.<QName>emptySet());
}

@Override
public List<DavResource> versionsList(String url, int depth, java.util.Set<QName> props) throws IOException {
return report(url, depth, new VersionTreeReport(props));
}

@Override
public List<DavResource> list(String url, int depth, java.util.Set<QName> props) throws IOException
{
Expand Down Expand Up @@ -643,6 +606,21 @@ public void unlock(String url, String token) throws IOException
this.execute(entity, new VoidResponseHandler());
}

@Override
public void addToVersionControl(String url) throws IOException {
this.execute(new HttpVersionControl(url), new VoidResponseHandler());
}

@Override
public void checkout(String url) throws IOException {
this.execute(new HttpCheckout(url), new VoidResponseHandler());
}

@Override
public void checkin(String url) throws IOException {
this.execute(new HttpCheckin(url), new VoidResponseHandler());
}

@Override
public void setAcl(String url, List<DavAce> aces) throws IOException
{
Expand Down Expand Up @@ -806,6 +784,13 @@ public ContentLengthInputStream get(String url) throws IOException
return this.get(url, Collections.<String, String>emptyMap());
}

@Override
public ContentLengthInputStream get(String url, String version) throws IOException {
List<DavResource> versionHistory = propfind(url, 0, Collections.singleton(createQNameWithDefaultNamespace("version-history")));
String storageUrl = versionHistory.get(0).getCustomProps().get("version-history");
return this.get(storageUrl + version);
}

@Override
public ContentLengthInputStream get(String url, Map<String, String> headers) throws IOException
{
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/com/github/sardine/impl/methods/HttpCheckin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.github.sardine.impl.methods;

import org.apache.http.client.methods.HttpRequestBase;

import java.net.URI;

/**
* Simple class for making WebDAV <code>CHECKIN</code> requests.
*/
public class HttpCheckin extends HttpRequestBase {

public static final String METHOD_NAME = "CHECKIN";

public HttpCheckin(String uri) {
this(URI.create(uri));
}

public HttpCheckin(URI uri) {
this.setURI(uri);
}

@Override
public String getMethod() {
return METHOD_NAME;
}
}
26 changes: 26 additions & 0 deletions src/main/java/com/github/sardine/impl/methods/HttpCheckout.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.github.sardine.impl.methods;

import org.apache.http.client.methods.HttpRequestBase;

import java.net.URI;

/**
* Simple class for making WebDAV <code>CHECKOUT</code> requests.
*/
public class HttpCheckout extends HttpRequestBase {

public static final String METHOD_NAME = "CHECKOUT";

public HttpCheckout(String uri) {
this(URI.create(uri));
}

public HttpCheckout(URI uri) {
this.setURI(uri);
}

@Override
public String getMethod() {
return METHOD_NAME;
}
}
Loading

0 comments on commit e2b5e01

Please sign in to comment.