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 version 2,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package eu
.alefzero
.webdav
;
19 import java
.util
.Date
;
21 import org
.apache
.jackrabbit
.webdav
.MultiStatusResponse
;
22 import org
.apache
.jackrabbit
.webdav
.property.DavProperty
;
23 import org
.apache
.jackrabbit
.webdav
.property.DavPropertyName
;
24 import org
.apache
.jackrabbit
.webdav
.property.DavPropertySet
;
26 import com
.owncloud
.android
.Log_OC
;
29 import android
.net
.Uri
;
31 public class WebdavEntry
{
32 private String mName
, mPath
, mUri
, mContentType
;
33 private long mContentLength
, mCreateTimestamp
, mModifiedTimestamp
;
35 public WebdavEntry(MultiStatusResponse ms
, String splitElement
) {
37 if (ms
.getStatus().length
!= 0) {
40 mPath
= mUri
.split(splitElement
, 2)[1];
42 int status
= ms
.getStatus()[0].getStatusCode();
43 DavPropertySet propSet
= ms
.getProperties(status
);
44 @SuppressWarnings("rawtypes")
45 DavProperty prop
= propSet
.get(DavPropertyName
.DISPLAYNAME
);
47 mName
= (String
) prop
.getName().toString();
49 String
[] tmp
= mPath
.split("/");
51 mName
= tmp
[tmp
.length
- 1];
54 // use unknown mimetype as default behavior
55 mContentType
= "application/octet-stream";
56 prop
= propSet
.get(DavPropertyName
.GETCONTENTTYPE
);
58 mContentType
= (String
) prop
.getValue();
59 // dvelasco: some builds of ownCloud server 4.0.x added a trailing ';' to the MIME type ; if looks fixed, but let's be cautious
60 if (mContentType
.indexOf(";") >= 0) {
61 mContentType
= mContentType
.substring(0, mContentType
.indexOf(";"));
65 // check if it's a folder in the standard way: see RFC2518 12.2 . RFC4918 14.3
66 prop
= propSet
.get(DavPropertyName
.RESOURCETYPE
);
68 Object value
= prop
.getValue();
70 mContentType
= "DIR"; // a specific attribute would be better, but this is enough; unless while we have no reason to distinguish MIME types for folders
74 prop
= propSet
.get(DavPropertyName
.GETCONTENTLENGTH
);
76 mContentLength
= Long
.parseLong((String
) prop
.getValue());
78 prop
= propSet
.get(DavPropertyName
.GETLASTMODIFIED
);
81 .parseResponseDate((String
) prop
.getValue());
82 mModifiedTimestamp
= (d
!= null
) ? d
.getTime() : 0;
85 prop
= propSet
.get(DavPropertyName
.CREATIONDATE
);
88 .parseResponseDate((String
) prop
.getValue());
89 mCreateTimestamp
= (d
!= null
) ? d
.getTime() : 0;
93 Log_OC
.e("WebdavEntry",
94 "General fuckup, no status for webdav response");
98 public String
path() {
102 public String
decodedPath() {
103 return Uri
.decode(mPath
);
106 public String
name() {
110 public boolean isDirectory() {
111 return mContentType
.equals("DIR");
114 public String
contentType() {
118 public String
uri() {
122 public long contentLength() {
123 return mContentLength
;
126 public long createTimestamp() {
127 return mCreateTimestamp
;
130 public long modifiedTimestamp() {
131 return mModifiedTimestamp
;
134 private void resetData() {
135 mName
= mUri
= mContentType
= null
;
136 mContentLength
= mCreateTimestamp
= mModifiedTimestamp
= 0;