OCFile stores again decoded remote paths; WebdavUtils.encode(...) added; fixed space...
[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.net.Uri;
28 import android.util.Log;
29
30 public class WebdavEntry {
31 private String mName, mPath, mUri, mContentType;
32 private long mContentLength, mCreateTimestamp, mModifiedTimestamp;
33
34 public WebdavEntry(MultiStatusResponse ms, String splitElement) {
35 resetData();
36 if (ms.getStatus().length != 0) {
37 mUri = ms.getHref();
38
39 mPath = mUri.split(splitElement, 2)[1];
40
41 int status = ms.getStatus()[0].getStatusCode();
42 DavPropertySet propSet = ms.getProperties(status);
43 @SuppressWarnings("rawtypes")
44 DavProperty prop = propSet.get(DavPropertyName.DISPLAYNAME);
45 if (prop != null)
46 mName = (String) prop.getName().toString();
47 else {
48 String[] tmp = mPath.split("/");
49 if (tmp.length > 0)
50 mName = tmp[tmp.length - 1];
51 }
52
53 prop = propSet.get(DavPropertyName.GETCONTENTTYPE);
54 if (prop != null) {
55 mContentType = (String) prop.getValue();
56 // dvelasco: some builds of ownCloud server 4.0.x added a trailing ';' to the MIME type ; if looks fixed, but let's be cautious
57 if (mContentType.indexOf(";") >= 0) {
58 mContentType = mContentType.substring(0, mContentType.indexOf(";"));
59 }
60 } else {
61 mContentType = "DIR";
62 /*
63 * prop = propSet.get(DavPropertyName.ISCOLLECTION); if (prop !=
64 * null && Boolean.parseBoolean((String) prop.getValue()))
65 * mContentType = "DIR";
66 */
67 }
68
69 prop = propSet.get(DavPropertyName.GETCONTENTLENGTH);
70 if (prop != null)
71 mContentLength = Long.parseLong((String) prop.getValue());
72
73 prop = propSet.get(DavPropertyName.GETLASTMODIFIED);
74 if (prop != null) {
75 Date d = WebdavUtils
76 .parseResponseDate((String) prop.getValue());
77 mModifiedTimestamp = (d != null) ? d.getTime() : 0;
78 }
79
80 prop = propSet.get(DavPropertyName.CREATIONDATE);
81 if (prop != null) {
82 Date d = WebdavUtils
83 .parseResponseDate((String) prop.getValue());
84 mCreateTimestamp = (d != null) ? d.getTime() : 0;
85 }
86
87 } else {
88 Log.e("WebdavEntry",
89 "General fuckup, no status for webdav response");
90 }
91 }
92
93 public String path() {
94 return mPath;
95 }
96
97 public String decodedPath() {
98 return Uri.decode(mPath);
99 }
100
101 public String name() {
102 return mName;
103 }
104
105 public boolean isDirectory() {
106 return mContentType.equals("DIR");
107 }
108
109 public String contentType() {
110 return mContentType;
111 }
112
113 public String uri() {
114 return mUri;
115 }
116
117 public long contentLength() {
118 return mContentLength;
119 }
120
121 public long createTimestamp() {
122 return mCreateTimestamp;
123 }
124
125 public long modifiedTimesamp() {
126 return mModifiedTimestamp;
127 }
128
129 private void resetData() {
130 mName = mUri = mContentType = null;
131 mContentLength = mCreateTimestamp = mModifiedTimestamp = 0;
132 }
133 }