forked from owncloud/android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWebdavEntry.java
150 lines (123 loc) · 4.89 KB
/
WebdavEntry.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/* ownCloud Android client application
* Copyright (C) 2012 ownCloud
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package eu.alefzero.webdav;
import java.util.Date;
import org.apache.jackrabbit.webdav.MultiStatusResponse;
import org.apache.jackrabbit.webdav.property.DavProperty;
import org.apache.jackrabbit.webdav.property.DavPropertyName;
import org.apache.jackrabbit.webdav.property.DavPropertySet;
import com.owncloud.android.Log_OC;
import android.net.Uri;
public class WebdavEntry {
private String mName, mPath, mUri, mContentType, mEtag;
private long mContentLength, mCreateTimestamp, mModifiedTimestamp;
public WebdavEntry(MultiStatusResponse ms, String splitElement) {
resetData();
if (ms.getStatus().length != 0) {
mUri = ms.getHref();
mPath = mUri.split(splitElement, 2)[1];
int status = ms.getStatus()[0].getStatusCode();
DavPropertySet propSet = ms.getProperties(status);
@SuppressWarnings("rawtypes")
DavProperty prop = propSet.get(DavPropertyName.DISPLAYNAME);
if (prop != null) {
mName = (String) prop.getName().toString();
mName = mName.substring(1, mName.length()-1);
}
else {
String[] tmp = mPath.split("/");
if (tmp.length > 0)
mName = tmp[tmp.length - 1];
}
// use unknown mimetype as default behavior
mContentType = "application/octet-stream";
prop = propSet.get(DavPropertyName.GETCONTENTTYPE);
if (prop != null) {
mContentType = (String) prop.getValue();
// dvelasco: some builds of ownCloud server 4.0.x added a trailing ';' to the MIME type ; if looks fixed, but let's be cautious
if (mContentType.indexOf(";") >= 0) {
mContentType = mContentType.substring(0, mContentType.indexOf(";"));
}
}
// check if it's a folder in the standard way: see RFC2518 12.2 . RFC4918 14.3
prop = propSet.get(DavPropertyName.RESOURCETYPE);
if (prop!= null) {
Object value = prop.getValue();
if (value != null) {
mContentType = "DIR"; // a specific attribute would be better, but this is enough; unless while we have no reason to distinguish MIME types for folders
}
}
prop = propSet.get(DavPropertyName.GETCONTENTLENGTH);
if (prop != null)
mContentLength = Long.parseLong((String) prop.getValue());
prop = propSet.get(DavPropertyName.GETLASTMODIFIED);
if (prop != null) {
Date d = WebdavUtils
.parseResponseDate((String) prop.getValue());
mModifiedTimestamp = (d != null) ? d.getTime() : 0;
}
prop = propSet.get(DavPropertyName.CREATIONDATE);
if (prop != null) {
Date d = WebdavUtils
.parseResponseDate((String) prop.getValue());
mCreateTimestamp = (d != null) ? d.getTime() : 0;
}
prop = propSet.get(DavPropertyName.GETETAG);
if (prop != null) {
mEtag = (String) prop.getValue();
mEtag = mEtag.substring(1, mEtag.length()-1);
}
} else {
Log_OC.e("WebdavEntry",
"General fuckup, no status for webdav response");
}
}
public String path() {
return mPath;
}
public String decodedPath() {
return Uri.decode(mPath);
}
public String name() {
return mName;
}
public boolean isDirectory() {
return mContentType.equals("DIR");
}
public String contentType() {
return mContentType;
}
public String uri() {
return mUri;
}
public long contentLength() {
return mContentLength;
}
public long createTimestamp() {
return mCreateTimestamp;
}
public long modifiedTimestamp() {
return mModifiedTimestamp;
}
public String etag() {
return mEtag;
}
private void resetData() {
mName = mUri = mContentType = null;
mContentLength = mCreateTimestamp = mModifiedTimestamp = 0;
}
}