mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 02:17:41 +00:00 
			
		
		
		
	Merge pull request #175 from owncloud/private_link_in_webdav
Add privatelink property support to processing of WebDAV responses
This commit is contained in:
		
						commit
						0e7fd8ee8f
					
				| @ -45,13 +45,14 @@ public class WebdavEntry { | ||||
|     public static final String EXTENDED_PROPERTY_NAME_PERMISSIONS = "permissions"; | ||||
|     public static final String EXTENDED_PROPERTY_NAME_REMOTE_ID = "id"; | ||||
|     public static final String EXTENDED_PROPERTY_NAME_SIZE = "size"; | ||||
|     public static final String EXTENDED_PROPERTY_NAME_PRIVATE_LINK = "privatelink"; | ||||
| 
 | ||||
|     public static final String PROPERTY_QUOTA_USED_BYTES = "quota-used-bytes"; | ||||
|     public static final String PROPERTY_QUOTA_AVAILABLE_BYTES = "quota-available-bytes"; | ||||
| 
 | ||||
|     private static final int CODE_PROP_NOT_FOUND = 404; | ||||
| 
 | ||||
| 	private String mName, mPath, mUri, mContentType, mEtag, mPermissions, mRemoteId; | ||||
|     private String mName, mPath, mUri, mContentType, mEtag, mPermissions, mRemoteId, mPrivateLink; | ||||
|     private long mContentLength, mCreateTimestamp, mModifiedTimestamp, mSize; | ||||
|     private BigDecimal mQuotaUsedBytes, mQuotaAvailableBytes; | ||||
| 
 | ||||
| @ -63,7 +64,7 @@ public class WebdavEntry { | ||||
|             mPath = mUri.split(splitElement, 2)[1]; | ||||
| 
 | ||||
|             int status = ms.getStatus()[0].getStatusCode(); | ||||
|             if ( status == CODE_PROP_NOT_FOUND ) { | ||||
|             if (status == CODE_PROP_NOT_FOUND) { | ||||
|                 status = ms.getStatus()[1].getStatusCode(); | ||||
|             } | ||||
|             DavPropertySet propSet = ms.getProperties(status); | ||||
| @ -71,9 +72,8 @@ public class WebdavEntry { | ||||
|             DavProperty prop = propSet.get(DavPropertyName.DISPLAYNAME); | ||||
|             if (prop != null) { | ||||
|                 mName = (String) prop.getName().toString(); | ||||
|                 mName = mName.substring(1, mName.length()-1); | ||||
|             } | ||||
|             else { | ||||
|                 mName = mName.substring(1, mName.length() - 1); | ||||
|             } else { | ||||
|                 String[] tmp = mPath.split("/"); | ||||
|                 if (tmp.length > 0) | ||||
|                     mName = tmp[tmp.length - 1]; | ||||
| @ -95,7 +95,7 @@ public class WebdavEntry { | ||||
|             // check if it's a folder in the standard way: see RFC2518 12.2 . RFC4918 14.3 | ||||
|             // {DAV:}resourcetype | ||||
|             prop = propSet.get(DavPropertyName.RESOURCETYPE); | ||||
|             if (prop!= null) { | ||||
|             if (prop != null) { | ||||
|                 Object value = prop.getValue(); | ||||
|                 if (value != null) { | ||||
|                     mContentType = "DIR";   // a specific attribute would be better, | ||||
| @ -140,10 +140,10 @@ public class WebdavEntry { | ||||
|                     mQuotaUsedBytes = new BigDecimal(quotaUsedBytesSt); | ||||
|                 } catch (NumberFormatException e) { | ||||
|                     Log_OC.w(TAG, "No value for QuotaUsedBytes - NumberFormatException"); | ||||
|                 } catch (NullPointerException e ){ | ||||
|                 } catch (NullPointerException e) { | ||||
|                     Log_OC.w(TAG, "No value for QuotaUsedBytes - NullPointerException"); | ||||
|                 } | ||||
|                 Log_OC.d(TAG , "QUOTA_USED_BYTES " + quotaUsedBytesSt ); | ||||
|                 Log_OC.d(TAG, "QUOTA_USED_BYTES " + quotaUsedBytesSt); | ||||
|             } | ||||
| 
 | ||||
|             // {DAV:}quota-available-bytes | ||||
| @ -154,10 +154,10 @@ public class WebdavEntry { | ||||
|                     mQuotaAvailableBytes = new BigDecimal(quotaAvailableBytesSt); | ||||
|                 } catch (NumberFormatException e) { | ||||
|                     Log_OC.w(TAG, "No value for QuotaAvailableBytes - NumberFormatException"); | ||||
|                 } catch (NullPointerException e ){ | ||||
|                 } catch (NullPointerException e) { | ||||
|                     Log_OC.w(TAG, "No value for QuotaAvailableBytes"); | ||||
|                 } | ||||
|                 Log_OC.d(TAG , "QUOTA_AVAILABLE_BYTES " + quotaAvailableBytesSt ); | ||||
|                 Log_OC.d(TAG, "QUOTA_AVAILABLE_BYTES " + quotaAvailableBytesSt); | ||||
|             } | ||||
| 
 | ||||
|             // OC permissions property <oc:permissions> | ||||
| @ -176,7 +176,6 @@ public class WebdavEntry { | ||||
|                 mRemoteId = prop.getValue().toString(); | ||||
|             } | ||||
| 
 | ||||
|             // TODO: is it necessary? | ||||
|             // OC size property <oc:size> | ||||
|             prop = propSet.get( | ||||
|                 EXTENDED_PROPERTY_NAME_SIZE, Namespace.getNamespace(NAMESPACE_OC) | ||||
| @ -185,6 +184,14 @@ public class WebdavEntry { | ||||
|                 mSize = Long.parseLong((String) prop.getValue()); | ||||
|             } | ||||
| 
 | ||||
|             // OC privatelink property <oc:privatelink> | ||||
|             prop = propSet.get( | ||||
|                 EXTENDED_PROPERTY_NAME_PRIVATE_LINK, Namespace.getNamespace(NAMESPACE_OC) | ||||
|             ); | ||||
|             if (prop != null) { | ||||
|                 mPrivateLink = prop.getValue().toString(); | ||||
|             } | ||||
| 
 | ||||
|         } else { | ||||
|             Log_OC.e("WebdavEntry", | ||||
|                 "General fuckup, no status for webdav response"); | ||||
| @ -239,7 +246,7 @@ public class WebdavEntry { | ||||
|         return mRemoteId; | ||||
|     } | ||||
| 
 | ||||
|     public long size(){ | ||||
|     public long size() { | ||||
|         return mSize; | ||||
|     } | ||||
| 
 | ||||
| @ -251,11 +258,17 @@ public class WebdavEntry { | ||||
|         return mQuotaAvailableBytes; | ||||
|     } | ||||
| 
 | ||||
|     public String privateLink() { | ||||
|         return mPrivateLink; | ||||
|     } | ||||
| 
 | ||||
|     private void resetData() { | ||||
|         mName = mUri = mContentType = mPermissions = null; mRemoteId = null; | ||||
|         mName = mUri = mContentType = mPermissions = null; | ||||
|         mRemoteId = null; | ||||
|         mContentLength = mCreateTimestamp = mModifiedTimestamp = 0; | ||||
|         mSize = 0; | ||||
|         mQuotaUsedBytes = null; | ||||
|         mQuotaAvailableBytes = null; | ||||
|         mPrivateLink = null; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -107,6 +107,8 @@ public class WebdavUtils { | ||||
|                 Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); | ||||
|         propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_SIZE, | ||||
|                 Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); | ||||
|         propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_PRIVATE_LINK, | ||||
|             Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); | ||||
| 
 | ||||
|         return propSet; | ||||
|     } | ||||
| @ -130,6 +132,10 @@ public class WebdavUtils { | ||||
|                 Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); | ||||
|         propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_SIZE, | ||||
|                 Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); | ||||
|         propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_SIZE, | ||||
|             Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); | ||||
|         propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_PRIVATE_LINK, | ||||
|             Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); | ||||
| 
 | ||||
|         return propSet; | ||||
|     } | ||||
|  | ||||
| @ -171,6 +171,7 @@ public class ReadRemoteFolderOperation extends RemoteOperation { | ||||
|         file.setSize(we.size()); | ||||
|         file.setQuotaUsedBytes(we.quotaUsedBytes()); | ||||
|         file.setQuotaAvailableBytes(we.quotaAvailableBytes()); | ||||
|         file.setPrivateLink(we.privateLink()); | ||||
|         return file; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -40,8 +40,10 @@ import com.owncloud.android.lib.common.network.WebdavEntry; | ||||
| 
 | ||||
| public class RemoteFile implements Parcelable, Serializable { | ||||
| 
 | ||||
|     /** Generated - should be refreshed every time the class changes!! */ | ||||
|     private static final long serialVersionUID = 3130865437811248451L; | ||||
|     /** | ||||
|      * Generated - should be refreshed every time the class changes!! | ||||
|      */ | ||||
|     private static final long serialVersionUID = -8965995357413958539L; | ||||
|      | ||||
|     private String mRemotePath; | ||||
|     private String mMimeType; | ||||
| @ -54,6 +56,7 @@ public class RemoteFile implements Parcelable, Serializable { | ||||
|     private long mSize; | ||||
|     private BigDecimal mQuotaUsedBytes; | ||||
|     private BigDecimal mQuotaAvailableBytes; | ||||
|     private String mPrivateLink; | ||||
| 
 | ||||
|     /** | ||||
|      * Getters and Setters | ||||
| @ -127,25 +130,33 @@ public class RemoteFile implements Parcelable, Serializable { | ||||
|         return mSize; | ||||
|     } | ||||
| 
 | ||||
|     public void setSize (long size){ | ||||
|     public void setSize(long size) { | ||||
|         mSize = size; | ||||
|     } | ||||
| 
 | ||||
|     public void setQuotaUsedBytes (BigDecimal quotaUsedBytes) { | ||||
|     public void setQuotaUsedBytes(BigDecimal quotaUsedBytes) { | ||||
|         mQuotaUsedBytes = quotaUsedBytes; | ||||
|     } | ||||
| 
 | ||||
|     public void setQuotaAvailableBytes (BigDecimal quotaAvailableBytes) { | ||||
|     public void setQuotaAvailableBytes(BigDecimal quotaAvailableBytes) { | ||||
|         mQuotaAvailableBytes = quotaAvailableBytes; | ||||
|     } | ||||
| 
 | ||||
|     public String getPrivateLink() { | ||||
|         return mPrivateLink; | ||||
|     } | ||||
| 
 | ||||
|     public void setPrivateLink(String privateLink) { | ||||
|         mPrivateLink = privateLink; | ||||
|     } | ||||
| 
 | ||||
|     public RemoteFile() { | ||||
|         resetData(); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Create new {@link RemoteFile} with given path. | ||||
|      *  | ||||
|      * <p> | ||||
|      * The path received must be URL-decoded. Path separator must be OCFile.PATH_SEPARATOR, and it must be the first character in 'path'. | ||||
|      * | ||||
|      * @param path The remote path of the file. | ||||
| @ -158,18 +169,19 @@ public class RemoteFile implements Parcelable, Serializable { | ||||
|         mRemotePath = path; | ||||
|     } | ||||
| 
 | ||||
| 	public RemoteFile(WebdavEntry we) { | ||||
|         this(we.decodedPath()); | ||||
|         this.setCreationTimestamp(we.createTimestamp()); | ||||
|         this.setLength(we.contentLength()); | ||||
|         this.setMimeType(we.contentType()); | ||||
|         this.setModifiedTimestamp(we.modifiedTimestamp()); | ||||
|         this.setEtag(we.etag()); | ||||
|         this.setPermissions(we.permissions()); | ||||
|         this.setRemoteId(we.remoteId()); | ||||
|         this.setSize(we.size()); | ||||
|         this.setQuotaUsedBytes(we.quotaUsedBytes()); | ||||
|         this.setQuotaAvailableBytes(we.quotaAvailableBytes()); | ||||
|     public RemoteFile(WebdavEntry webdavEntry) { | ||||
|         this(webdavEntry.decodedPath()); | ||||
|         this.setCreationTimestamp(webdavEntry.createTimestamp()); | ||||
|         this.setLength(webdavEntry.contentLength()); | ||||
|         this.setMimeType(webdavEntry.contentType()); | ||||
|         this.setModifiedTimestamp(webdavEntry.modifiedTimestamp()); | ||||
|         this.setEtag(webdavEntry.etag()); | ||||
|         this.setPermissions(webdavEntry.permissions()); | ||||
|         this.setRemoteId(webdavEntry.remoteId()); | ||||
|         this.setSize(webdavEntry.size()); | ||||
|         this.setQuotaUsedBytes(webdavEntry.quotaUsedBytes()); | ||||
|         this.setQuotaAvailableBytes(webdavEntry.quotaAvailableBytes()); | ||||
|         this.setPrivateLink(webdavEntry.privateLink()); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
| @ -187,6 +199,7 @@ public class RemoteFile implements Parcelable, Serializable { | ||||
|         mSize = 0; | ||||
|         mQuotaUsedBytes = null; | ||||
|         mQuotaAvailableBytes = null; | ||||
|         mPrivateLink = null; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
| @ -214,18 +227,19 @@ public class RemoteFile implements Parcelable, Serializable { | ||||
|         readFromParcel(source); | ||||
|     } | ||||
| 
 | ||||
|     public void readFromParcel (Parcel source) { | ||||
|     public void readFromParcel(Parcel source) { | ||||
|         mRemotePath = source.readString(); | ||||
|         mMimeType = source.readString(); | ||||
|         mLength = source.readLong(); | ||||
|         mCreationTimestamp = source.readLong(); | ||||
|         mModifiedTimestamp = source.readLong(); | ||||
|         mEtag = source.readString(); | ||||
|         mPermissions= source.readString(); | ||||
|         mPermissions = source.readString(); | ||||
|         mRemoteId = source.readString(); | ||||
|         mSize = source.readLong(); | ||||
|         mQuotaUsedBytes = (BigDecimal) source.readSerializable(); | ||||
|         mQuotaAvailableBytes = (BigDecimal) source.readSerializable(); | ||||
|         mPrivateLink = source.readString(); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
| @ -246,6 +260,7 @@ public class RemoteFile implements Parcelable, Serializable { | ||||
|         dest.writeLong(mSize); | ||||
|         dest.writeSerializable(mQuotaUsedBytes); | ||||
|         dest.writeSerializable(mQuotaAvailableBytes); | ||||
|         dest.writeString(mPrivateLink); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user