1 /* ownCloud Android client application 
   2  *   Copyright (C) 2012  Bartek Przybylski 
   3  *   Copyright (C) 2012-2013 ownCloud Inc. 
   5  *   This program is free software: you can redistribute it and/or modify 
   6  *   it under the terms of the GNU General Public License version 2, 
   7  *   as published by the Free Software Foundation. 
   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
.text
.ParseException
; 
  22 import java
.text
.SimpleDateFormat
; 
  23 import java
.util
.Date
; 
  24 import java
.util
.Locale
; 
  26 import android
.net
.Uri
; 
  28 public class WebdavUtils 
{ 
  29     public static final SimpleDateFormat DISPLAY_DATE_FORMAT 
= new SimpleDateFormat( 
  31     private static final SimpleDateFormat DATETIME_FORMATS
[] = { 
  32             new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale
.US
), 
  33             new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale
.US
), 
  34             new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.sss'Z'", Locale
.US
), 
  35             new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale
.US
), 
  36             new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale
.US
), 
  37             new SimpleDateFormat("EEEEEE, dd-MMM-yy HH:mm:ss zzz", Locale
.US
), 
  38             new SimpleDateFormat("EEE MMMM d HH:mm:ss yyyy", Locale
.US
) }; 
  40     public static String 
prepareXmlForPropFind() { 
  41         String ret 
= "<?xml version=\"1.0\" ?><D:propfind xmlns:D=\"DAV:\"><D:allprop/></D:propfind>"; 
  45     public static String 
prepareXmlForPatch() { 
  46         return "<?xml version=\"1.0\" ?><D:propertyupdate xmlns:D=\"DAV:\"></D:propertyupdate>"; 
  49     public static Date 
parseResponseDate(String date
) { 
  50         Date returnDate 
= null
; 
  51         for (int i 
= 0; i 
< DATETIME_FORMATS
.length
; ++i
) { 
  53                 returnDate 
= DATETIME_FORMATS
[i
].parse(date
); 
  55             } catch (ParseException e
) { 
  62      * Encodes a path according to URI RFC 2396.  
  64      * If the received path doesn't start with "/", the method adds it. 
  66      * @param remoteFilePath    Path 
  67      * @return                  Encoded path according to RFC 2396, always starting with "/" 
  69     public static String 
encodePath(String remoteFilePath
) { 
  70         String encodedPath 
= Uri
.encode(remoteFilePath
, "/"); 
  71         if (!encodedPath
.startsWith("/")) 
  72             encodedPath 
= "/" + encodedPath
;