Force spaces in eclipse via project specifc settings
[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)
45 mName = (String) prop.getName().toString();
46 else {
47 String[] tmp = mPath.split("/");
48 if (tmp.length > 0)
49 mName = tmp[tmp.length - 1];
50 }
51
52 prop = propSet.get(DavPropertyName.GETCONTENTTYPE);
53 if (prop != null) {
54 mContentType = (String) prop.getValue();
55 } else {
56 mContentType = "DIR";
57 /*
58 * prop = propSet.get(DavPropertyName.ISCOLLECTION); if (prop !=
59 * null && Boolean.parseBoolean((String) prop.getValue()))
60 * mContentType = "DIR";
61 */
62 }
63
64 prop = propSet.get(DavPropertyName.GETCONTENTLENGTH);
65 if (prop != null)
66 mContentLength = Long.parseLong((String) prop.getValue());
67
68 prop = propSet.get(DavPropertyName.GETLASTMODIFIED);
69 if (prop != null) {
70 Date d = WebdavUtils
71 .parseResponseDate((String) prop.getValue());
72 mModifiedTimestamp = (d != null) ? d.getTime() : 0;
73 }
74
75 prop = propSet.get(DavPropertyName.CREATIONDATE);
76 if (prop != null) {
77 Date d = WebdavUtils
78 .parseResponseDate((String) prop.getValue());
79 mCreateTimestamp = (d != null) ? d.getTime() : 0;
80 }
81
82 } else {
83 Log.e("WebdavEntry",
84 "General fuckup, no status for webdav response");
85 }
86 }
87
88 public String path() {
89 return mPath;
90 }
91
92 public String name() {
93 return mName;
94 }
95
96 public boolean isDirectory() {
97 return mContentType.equals("DIR");
98 }
99
100 public String contentType() {
101 return mContentType;
102 }
103
104 public String uri() {
105 return mUri;
106 }
107
108 public long contentLength() {
109 return mContentLength;
110 }
111
112 public long createTimestamp() {
113 return mCreateTimestamp;
114 }
115
116 public long modifiedTimesamp() {
117 return mModifiedTimestamp;
118 }
119
120 private void resetData() {
121 mName = mUri = mContentType = null;
122 mContentLength = mCreateTimestamp = mModifiedTimestamp = 0;
123 }
124 }