dc407b0a58145eb1b879847c8043ebe60178f8f7
[pub/Android/ownCloud.git] / src / eu / alefzero / webdav / WebdavUtils.java
1 /* ownCloud Android client application
2 * Copyright (C) 2012 Bartek Przybylski
3 *
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.
8 *
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.
13 *
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/>.
16 *
17 */
18
19 package eu.alefzero.webdav;
20
21 import java.text.ParseException;
22 import java.text.SimpleDateFormat;
23 import java.util.Date;
24 import java.util.Locale;
25
26 public class WebdavUtils {
27 public static final SimpleDateFormat DISPLAY_DATE_FORMAT = new SimpleDateFormat(
28 "dd.MM.yyyy hh:mm");
29 private static final SimpleDateFormat DATETIME_FORMATS[] = {
30 new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US),
31 new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US),
32 new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.sss'Z'", Locale.US),
33 new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.US),
34 new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US),
35 new SimpleDateFormat("EEEEEE, dd-MMM-yy HH:mm:ss zzz", Locale.US),
36 new SimpleDateFormat("EEE MMMM d HH:mm:ss yyyy", Locale.US) };
37
38 public static String prepareXmlForPropFind() {
39 String ret = "<?xml version=\"1.0\" ?><D:propfind xmlns:D=\"DAV:\"><D:allprop/></D:propfind>";
40 return ret;
41 }
42
43 public static String prepareXmlForPatch() {
44 return "<?xml version=\"1.0\" ?><D:propertyupdate xmlns:D=\"DAV:\"></D:propertyupdate>";
45 }
46
47 public static Date parseResponseDate(String date) {
48 Date returnDate = null;
49 for (int i = 0; i < DATETIME_FORMATS.length; ++i) {
50 try {
51 returnDate = DATETIME_FORMATS[i].parse(date);
52 return returnDate;
53 } catch (ParseException e) {
54 }
55 }
56 return null;
57 }
58 }