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 2 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 com
.owncloud
.android
.Log_OC
;
29 import android
.net
.Uri
;
30 import android
.util
.Log
;
32 public class WebdavEntry
{
33 private String mName
, mPath
, mUri
, mContentType
;
34 private long mContentLength
, mCreateTimestamp
, mModifiedTimestamp
;
36 public WebdavEntry(MultiStatusResponse ms
, String splitElement
) {
38 if (ms
.getStatus().length
!= 0) {
41 mPath
= mUri
.split(splitElement
, 2)[1];
43 int status
= ms
.getStatus()[0].getStatusCode();
44 DavPropertySet propSet
= ms
.getProperties(status
);
45 @SuppressWarnings("rawtypes")
46 DavProperty prop
= propSet
.get(DavPropertyName
.DISPLAYNAME
);
48 mName
= (String
) prop
.getName().toString();
50 String
[] tmp
= mPath
.split("/");
52 mName
= tmp
[tmp
.length
- 1];
55 // use unknown mimetype as default behavior
56 mContentType
= "application/octet-stream";
57 prop
= propSet
.get(DavPropertyName
.GETCONTENTTYPE
);
59 mContentType
= (String
) prop
.getValue();
60 // dvelasco: some builds of ownCloud server 4.0.x added a trailing ';' to the MIME type ; if looks fixed, but let's be cautious
61 if (mContentType
.indexOf(";") >= 0) {
62 mContentType
= mContentType
.substring(0, mContentType
.indexOf(";"));
66 // check if it's a folder in the standard way: see RFC2518 12.2 , or RFC4918 14.3
67 prop
= propSet
.get(DavPropertyName
.RESOURCETYPE
);
69 Object value
= prop
.getValue();
71 mContentType
= "DIR"; // a specific attribute would be better, but this is enough; unless while we have no reason to distinguish MIME types for folders
75 prop
= propSet
.get(DavPropertyName
.GETCONTENTLENGTH
);
77 mContentLength
= Long
.parseLong((String
) prop
.getValue());
79 prop
= propSet
.get(DavPropertyName
.GETLASTMODIFIED
);
82 .parseResponseDate((String
) prop
.getValue());
83 mModifiedTimestamp
= (d
!= null
) ? d
.getTime() : 0;
86 prop
= propSet
.get(DavPropertyName
.CREATIONDATE
);
89 .parseResponseDate((String
) prop
.getValue());
90 mCreateTimestamp
= (d
!= null
) ? d
.getTime() : 0;
94 Log_OC
.e("WebdavEntry",
95 "General fuckup, no status for webdav response");
99 public String
path() {
103 public String
decodedPath() {
104 return Uri
.decode(mPath
);
107 public String
name() {
111 public boolean isDirectory() {
112 return mContentType
.equals("DIR");
115 public String
contentType() {
119 public String
uri() {
123 public long contentLength() {
124 return mContentLength
;
127 public long createTimestamp() {
128 return mCreateTimestamp
;
131 public long modifiedTimestamp() {
132 return mModifiedTimestamp
;
135 private void resetData() {
136 mName
= mUri
= mContentType
= null
;
137 mContentLength
= mCreateTimestamp
= mModifiedTimestamp
= 0;