1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
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/>.
19 package eu
.alefzero
.webdav
;
21 import java
.io
.IOException
;
22 import java
.io
.InputStream
;
23 import java
.text
.ParseException
;
24 import java
.text
.SimpleDateFormat
;
25 import java
.util
.Date
;
26 import java
.util
.LinkedList
;
27 import java
.util
.List
;
28 import java
.util
.Locale
;
30 import javax
.xml
.parsers
.DocumentBuilder
;
31 import javax
.xml
.parsers
.DocumentBuilderFactory
;
32 import javax
.xml
.parsers
.ParserConfigurationException
;
34 import org
.w3c
.dom
.Document
;
35 import org
.w3c
.dom
.Element
;
36 import org
.w3c
.dom
.Node
;
37 import org
.w3c
.dom
.NodeList
;
38 import org
.xml
.sax
.SAXException
;
40 import android
.util
.Log
;
42 public class WebdavUtils
{
44 public static final String RESPONSE
= "response";
45 public static final String HREF
= "href";
46 public static final String IS_HIDDEN
= "ishidden";
47 public static final String RESOURCE_TYPE
= "resourcetype";
48 public static final String CONTENT_TYPE
= "getcontenttype";
49 public static final String CONTENT_LENGTH
= "getcontentlength";
50 public static final String LAST_MODIFIED
= "getlastmodified";
51 public static final String LAST_ACCESS
= "lastaccessed";
52 public static final String CREATE_DATE
= "creationdate";
54 public static final String PROPSTAT
= "propstat";
55 public static final String STATUS
= "status";
56 public static final String PROP
= "prop";
58 private static final String DAV_NAMESPACE_PREFIX
= "DAV:";
60 public static final SimpleDateFormat DISPLAY_DATE_FORMAT
= new SimpleDateFormat("dd.MM.yyyy hh:mm");
61 private static final SimpleDateFormat DATETIME_FORMATS
[] = {
62 new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale
.US
),
63 new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale
.US
),
64 new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.sss'Z'", Locale
.US
),
65 new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale
.US
),
66 new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale
.US
),
67 new SimpleDateFormat("EEEEEE, dd-MMM-yy HH:mm:ss zzz", Locale
.US
),
68 new SimpleDateFormat("EEE MMMM d HH:mm:ss yyyy", Locale
.US
)};
70 public static String
prepareXmlForPropFind() {
71 String ret
= "<?xml version=\"1.0\" ?><D:propfind xmlns:D=\"DAV:\"><D:allprop/></D:propfind>";
75 public static String
prepareXmlForPatch() {
76 return "<?xml version=\"1.0\" ?><D:propertyupdate xmlns:D=\"DAV:\"></D:propertyupdate>";
79 public static Date
parseResponseDate(String date
) {
80 Date returnDate
= null
;
81 for (int i
= 0; i
< DATETIME_FORMATS
.length
; ++i
) {
83 returnDate
= DATETIME_FORMATS
[i
].parse(date
);
85 } catch (ParseException e
) {}
90 private static String
determineDAVPrefix(Element e
) {
91 for (int i
= 0; i
< e
.getAttributes().getLength(); ++i
) {
92 String attrName
= e
.getAttributes().item(i
).getNodeName();
93 if (e
.getAttribute(attrName
).equals(DAV_NAMESPACE_PREFIX
)) {
94 return attrName
.substring(attrName
.lastIndexOf(':')+1) + ":";