9d0d61fe9a28952c14600dbc0bf51cc37c39de02
1 /* ownCloud Android Library is available under MIT license
2 * Copyright (C) 2014 ownCloud (http://www.owncloud.org/)
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 package com
.owncloud
.android
.oc_framework
.network
.webdav
;
27 import java
.util
.Date
;
29 import org
.apache
.jackrabbit
.webdav
.MultiStatusResponse
;
30 import org
.apache
.jackrabbit
.webdav
.property.DavProperty
;
31 import org
.apache
.jackrabbit
.webdav
.property.DavPropertyName
;
32 import org
.apache
.jackrabbit
.webdav
.property.DavPropertySet
;
36 import android
.net
.Uri
;
37 import android
.util
.Log
;
39 public class WebdavEntry
{
40 private String mName
, mPath
, mUri
, mContentType
, mEtag
;
41 private long mContentLength
, mCreateTimestamp
, mModifiedTimestamp
;
43 public WebdavEntry(MultiStatusResponse ms
, String splitElement
) {
45 if (ms
.getStatus().length
!= 0) {
48 mPath
= mUri
.split(splitElement
, 2)[1];
50 int status
= ms
.getStatus()[0].getStatusCode();
51 DavPropertySet propSet
= ms
.getProperties(status
);
52 @SuppressWarnings("rawtypes")
53 DavProperty prop
= propSet
.get(DavPropertyName
.DISPLAYNAME
);
55 mName
= (String
) prop
.getName().toString();
56 mName
= mName
.substring(1, mName
.length()-1);
59 String
[] tmp
= mPath
.split("/");
61 mName
= tmp
[tmp
.length
- 1];
64 // use unknown mimetype as default behavior
65 mContentType
= "application/octet-stream";
66 prop
= propSet
.get(DavPropertyName
.GETCONTENTTYPE
);
68 mContentType
= (String
) prop
.getValue();
69 // dvelasco: some builds of ownCloud server 4.0.x added a trailing ';' to the MIME type ; if looks fixed, but let's be cautious
70 if (mContentType
.indexOf(";") >= 0) {
71 mContentType
= mContentType
.substring(0, mContentType
.indexOf(";"));
75 // check if it's a folder in the standard way: see RFC2518 12.2 . RFC4918 14.3
76 prop
= propSet
.get(DavPropertyName
.RESOURCETYPE
);
78 Object value
= prop
.getValue();
80 mContentType
= "DIR"; // a specific attribute would be better, but this is enough; unless while we have no reason to distinguish MIME types for folders
84 prop
= propSet
.get(DavPropertyName
.GETCONTENTLENGTH
);
86 mContentLength
= Long
.parseLong((String
) prop
.getValue());
88 prop
= propSet
.get(DavPropertyName
.GETLASTMODIFIED
);
91 .parseResponseDate((String
) prop
.getValue());
92 mModifiedTimestamp
= (d
!= null
) ? d
.getTime() : 0;
95 prop
= propSet
.get(DavPropertyName
.CREATIONDATE
);
98 .parseResponseDate((String
) prop
.getValue());
99 mCreateTimestamp
= (d
!= null
) ? d
.getTime() : 0;
102 prop
= propSet
.get(DavPropertyName
.GETETAG
);
104 mEtag
= (String
) prop
.getValue();
105 mEtag
= mEtag
.substring(1, mEtag
.length()-1);
110 "General fuckup, no status for webdav response");
114 public String
path() {
118 public String
decodedPath() {
119 return Uri
.decode(mPath
);
122 public String
name() {
126 public boolean isDirectory() {
127 return mContentType
.equals("DIR");
130 public String
contentType() {
134 public String
uri() {
138 public long contentLength() {
139 return mContentLength
;
142 public long createTimestamp() {
143 return mCreateTimestamp
;
146 public long modifiedTimestamp() {
147 return mModifiedTimestamp
;
150 public String
etag() {
154 private void resetData() {
155 mName
= mUri
= mContentType
= null
;
156 mContentLength
= mCreateTimestamp
= mModifiedTimestamp
= 0;