3bcfa36a788c8647b2daec5f3cb4c28a489a13f0
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 com
.owncloud
.android
.oc_framework
.network
.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
;
28 import android
.net
.Uri
;
29 import android
.util
.Log
;
31 public class WebdavEntry
{
32 private String mName
, mPath
, mUri
, mContentType
, mEtag
;
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();
48 mName
= mName
.substring(1, mName
.length()-1);
51 String
[] tmp
= mPath
.split("/");
53 mName
= tmp
[tmp
.length
- 1];
56 // use unknown mimetype as default behavior
57 mContentType
= "application/octet-stream";
58 prop
= propSet
.get(DavPropertyName
.GETCONTENTTYPE
);
60 mContentType
= (String
) prop
.getValue();
61 // dvelasco: some builds of ownCloud server 4.0.x added a trailing ';' to the MIME type ; if looks fixed, but let's be cautious
62 if (mContentType
.indexOf(";") >= 0) {
63 mContentType
= mContentType
.substring(0, mContentType
.indexOf(";"));
67 // check if it's a folder in the standard way: see RFC2518 12.2 . RFC4918 14.3
68 prop
= propSet
.get(DavPropertyName
.RESOURCETYPE
);
70 Object value
= prop
.getValue();
72 mContentType
= "DIR"; // a specific attribute would be better, but this is enough; unless while we have no reason to distinguish MIME types for folders
76 prop
= propSet
.get(DavPropertyName
.GETCONTENTLENGTH
);
78 mContentLength
= Long
.parseLong((String
) prop
.getValue());
80 prop
= propSet
.get(DavPropertyName
.GETLASTMODIFIED
);
83 .parseResponseDate((String
) prop
.getValue());
84 mModifiedTimestamp
= (d
!= null
) ? d
.getTime() : 0;
87 prop
= propSet
.get(DavPropertyName
.CREATIONDATE
);
90 .parseResponseDate((String
) prop
.getValue());
91 mCreateTimestamp
= (d
!= null
) ? d
.getTime() : 0;
94 prop
= propSet
.get(DavPropertyName
.GETETAG
);
96 mEtag
= (String
) prop
.getValue();
97 mEtag
= mEtag
.substring(1, mEtag
.length()-1);
102 "General fuckup, no status for webdav response");
106 public String
path() {
110 public String
decodedPath() {
111 return Uri
.decode(mPath
);
114 public String
name() {
118 public boolean isDirectory() {
119 return mContentType
.equals("DIR");
122 public String
contentType() {
126 public String
uri() {
130 public long contentLength() {
131 return mContentLength
;
134 public long createTimestamp() {
135 return mCreateTimestamp
;
138 public long modifiedTimestamp() {
139 return mModifiedTimestamp
;
142 public String
etag() {
146 private void resetData() {
147 mName
= mUri
= mContentType
= null
;
148 mContentLength
= mCreateTimestamp
= mModifiedTimestamp
= 0;