c2e9712fff5f1bd338d8946d96025124f81d88af
[pub/Android/ownCloud.git] / src / eu / alefzero / webdav / WebdavEntry.java
1 /* ownCloud Android client application
2 * Copyright (C) 2012 ownCloud
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18 package eu.alefzero.webdav;
19
20 import java.util.Date;
21
22 import org.apache.jackrabbit.webdav.MultiStatusResponse;
23 import org.apache.jackrabbit.webdav.property.DavProperty;
24 import org.apache.jackrabbit.webdav.property.DavPropertyName;
25 import org.apache.jackrabbit.webdav.property.DavPropertySet;
26
27 import android.util.Log;
28
29 public class WebdavEntry {
30 private String mName, mPath, mUri, mContentType;
31 private long mContentLength, mCreateTimestamp, mModifiedTimestamp;
32
33 public WebdavEntry(MultiStatusResponse ms) {
34 resetData();
35 if (ms.getStatus().length != 0) {
36 mUri = ms.getHref();
37
38 mPath = mUri.split("webdav.php", 2)[1];
39
40 int status = ms.getStatus()[0].getStatusCode();
41 DavPropertySet propSet = ms.getProperties(status);
42 @SuppressWarnings("rawtypes")
43 DavProperty prop = propSet.get(DavPropertyName.DISPLAYNAME);
44 if (prop != null) mName = (String) prop.getName().toString();
45 else {
46 String[] tmp = mPath.split("/");
47 if (tmp.length > 0)
48 mName = tmp[tmp.length-1];
49 }
50
51 prop = propSet.get(DavPropertyName.GETCONTENTTYPE);
52 if (prop != null) {
53 mContentType = (String) prop.getValue();
54 } else {
55 mContentType = "DIR";
56 /*prop = propSet.get(DavPropertyName.ISCOLLECTION);
57 if (prop != null && Boolean.parseBoolean((String) prop.getValue()))
58 mContentType = "DIR";*/
59 }
60
61 prop = propSet.get(DavPropertyName.GETCONTENTLENGTH);
62 if (prop != null)
63 mContentLength = Long.parseLong((String) prop.getValue());
64
65 prop = propSet.get(DavPropertyName.GETLASTMODIFIED);
66 if (prop != null) {
67 Date d = WebdavUtils.parseResponseDate((String)prop.getValue());
68 mModifiedTimestamp = (d != null) ? d.getTime() : 0;
69 }
70
71 prop = propSet.get(DavPropertyName.CREATIONDATE);
72 if (prop != null) {
73 Date d = WebdavUtils.parseResponseDate((String)prop.getValue());
74 mCreateTimestamp = (d != null) ? d.getTime() : 0;
75 }
76
77 } else {
78 Log.e("WebdavEntry", "General fuckup, no status for webdav response");
79 }
80 }
81
82 public String path() {
83 return mPath;
84 }
85
86 public String name() {
87 return mName;
88 }
89
90 public boolean isDirectory() {
91 return mContentType.equals("DIR");
92 }
93
94 public String contentType() {
95 return mContentType;
96 }
97
98 public String uri() {
99 return mUri;
100 }
101
102 public long contentLength() {
103 return mContentLength;
104 }
105
106 public long createTimestamp() {
107 return mCreateTimestamp;
108 }
109
110 public long modifiedTimesamp() {
111 return mModifiedTimestamp;
112 }
113
114 private void resetData() {
115 mName = mUri = mContentType = null;
116 mContentLength = mCreateTimestamp = mModifiedTimestamp = 0;
117 }
118 }