Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions src/de/aflx/sardine/DavResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,24 @@ private String getContentType(Response response)
*/
private long getContentLength(Response response)
{
// Propstat list = response.getPropstat();
// if(list.equals("") || null == list) {
// return null;
// }
// Getcontentlength gcl = list.getProp().ge;

Propstat list = response.getPropstat();
if(list.equals("") || null == list) {
return DEFAULT_CONTENT_LENGTH;
}

return -1;
String gcl = list.getProp().getGetcontentlength();
if ((gcl != null) && (!gcl.isEmpty()))
{
try
{
return Long.parseLong(gcl);
} catch (NumberFormatException e)
{
log.warn(String.format("Failed to parse content length %s", gcl));
}
}
return DEFAULT_CONTENT_LENGTH;
/*List<Propstat> list = response.getPropstat();
if (list.isEmpty()) {
return DEFAULT_CONTENT_LENGTH;
Expand Down
13 changes: 13 additions & 0 deletions src/de/aflx/sardine/Sardine.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ public interface Sardine
*/
List<DavResource> list(String url, int depth) throws IOException;

/**
* Gets a directory listing using WebDAV <code>PROPFIND</code>.
*
* @param url Path to the resource including protocol and hostname
* @param depth The depth to look at (use 0 for single ressource, 1 for directory listing)
* @param allProp If allprop should be used, which can be inefficient sometimes;
* warning: no allprop does not retrieve custom props, just the basic ones
* @return List of resources for this URI including the parent resource itself
* @throws IOException I/O error or HTTP response validation failure
*/
List<DavResource> list(String url, int depth, boolean allProp)
throws IOException;

/**
* @see #patch(String, java.util.Map, java.util.List)
*/
Expand Down
21 changes: 15 additions & 6 deletions src/de/aflx/sardine/impl/SardineImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,11 @@
import de.aflx.sardine.impl.methods.HttpMove;
import de.aflx.sardine.impl.methods.HttpPropFind;
import de.aflx.sardine.impl.methods.HttpUnlock;
import de.aflx.sardine.model.Allprop;
import de.aflx.sardine.model.Exclusive;
import de.aflx.sardine.model.Lockinfo;
import de.aflx.sardine.model.Lockscope;
import de.aflx.sardine.model.Locktype;
import de.aflx.sardine.model.Multistatus;
import de.aflx.sardine.model.Propfind;
import de.aflx.sardine.model.Response;
import de.aflx.sardine.model.Write;
import de.aflx.sardine.util.Logger;
Expand Down Expand Up @@ -390,14 +388,25 @@ public List<DavResource> list(String url) throws IOException {
*
* @see de.aflx.sardine.Sardine#list(java.lang.String)
*/
public List<DavResource> list(String url, int depth) throws IOException {
@Override
public List<DavResource> list(String url, int depth) throws IOException
{
return list(url, depth, true);
}

@Override
public List<DavResource> list(String url, int depth, boolean allProp) throws IOException
{
log.warn("list");
HttpPropFind entity = new HttpPropFind(url);
entity.setDepth(Integer.toString(depth));
Propfind body = new Propfind();
body.setAllprop(new Allprop());
// Propfind body = new Propfind();
if (allProp)
entity.setEntity(new StringEntity("<?xml version=\"1.0\" encoding=\"utf-8\" ?><D:propfind xmlns:D=\"DAV:\"> <D:allprop/></D:propfind>", UTF_8));
else
entity.setEntity(new StringEntity("<?xml version=\"1.0\" encoding=\"utf-8\" ?><D:propfind xmlns:D=\"DAV:\"> <D:prop> <D:creationdate/><D:displayname/><D:resourcetype/><D:getcontentlength/><D:getlastmodified/> </D:prop></D:propfind>", UTF_8));

// entity.setEntity(new StringEntity(SardineUtil.toXml(body), UTF_8));
entity.setEntity(new StringEntity("<?xml version=\"1.0\" encoding=\"utf-8\" ?><D:propfind xmlns:D=\"DAV:\"> <D:allprop/></D:propfind>", UTF_8));
Multistatus multistatus = this.execute(entity,
new MultiStatusResponseHandler());
List<Response> responses = multistatus.getResponse();
Expand Down
16 changes: 11 additions & 5 deletions src/de/aflx/sardine/model/Prop.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,16 @@ public class Prop {

@Element
private Resourcetype resourcetype;
@Element
@Element (required = false)
private String creationdate;
@Element
@Element (required = false)
private String getlastmodified;
@Element
@Element (required = false)
private String getetag;
@Element (required = false)
private String getcontenttype;
@Element (required = false)
private String getcontentlength;

public Resourcetype getResourcetype() {
return resourcetype;
Expand All @@ -85,9 +87,13 @@ public String getGetetag() {
public String getGetcontenttype() {
return getcontenttype;
}


/*protected Creationdate creationdate;
public String getGetcontentlength() {
return getcontentlength;
}


/*protected Creationdate creationdate;
protected Displayname displayname;
protected Getcontentlanguage getcontentlanguage;
protected Getcontentlength getcontentlength;
Expand Down