1 /* ownCloud Android client application
2 * Copyright (C) 2012 ownCloud
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.
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.
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/>.
18 package eu
.alefzero
.webdav
;
20 import java
.util
.Date
;
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
;
27 import android
.net
.Uri
;
28 import android
.util
.Log
;
30 public class WebdavEntry
{
31 private String mName
, mPath
, mUri
, mContentType
;
32 private long mContentLength
, mCreateTimestamp
, mModifiedTimestamp
;
34 public WebdavEntry(MultiStatusResponse ms
, String splitElement
) {
36 if (ms
.getStatus().length
!= 0) {
39 mPath
= mUri
.split(splitElement
, 2)[1];
41 int status
= ms
.getStatus()[0].getStatusCode();
42 DavPropertySet propSet
= ms
.getProperties(status
);
43 @SuppressWarnings("rawtypes")
44 DavProperty prop
= propSet
.get(DavPropertyName
.DISPLAYNAME
);
46 mName
= (String
) prop
.getName().toString();
48 String
[] tmp
= mPath
.split("/");
50 mName
= tmp
[tmp
.length
- 1];
53 prop
= propSet
.get(DavPropertyName
.GETCONTENTTYPE
);
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(";"));
62 // check if it's a folder in the standard way: see RFC2518 12.2 , or RFC4918 14.3
63 prop
= propSet
.get(DavPropertyName
.RESOURCETYPE
);
65 Object value
= prop
.getValue();
67 mContentType
= "DIR"; // a specific attribute would be better, but this is enough; unless while we have no reason to distinguish MIME types for folders
71 prop
= propSet
.get(DavPropertyName
.GETCONTENTLENGTH
);
73 mContentLength
= Long
.parseLong((String
) prop
.getValue());
75 prop
= propSet
.get(DavPropertyName
.GETLASTMODIFIED
);
78 .parseResponseDate((String
) prop
.getValue());
79 mModifiedTimestamp
= (d
!= null
) ? d
.getTime() : 0;
82 prop
= propSet
.get(DavPropertyName
.CREATIONDATE
);
85 .parseResponseDate((String
) prop
.getValue());
86 mCreateTimestamp
= (d
!= null
) ? d
.getTime() : 0;
91 "General fuckup, no status for webdav response");
95 public String
path() {
99 public String
decodedPath() {
100 return Uri
.decode(mPath
);
103 public String
name() {
107 public boolean isDirectory() {
108 return mContentType
.equals("DIR");
111 public String
contentType() {
115 public String
uri() {
119 public long contentLength() {
120 return mContentLength
;
123 public long createTimestamp() {
124 return mCreateTimestamp
;
127 public long modifiedTimesamp() {
128 return mModifiedTimestamp
;
131 private void resetData() {
132 mName
= mUri
= mContentType
= null
;
133 mContentLength
= mCreateTimestamp
= mModifiedTimestamp
= 0;