a2923105c3ccd7be6ea5353cc70e8227f45216b5
[pub/Android/ownCloud.git] / oc_framework / src / com / owncloud / android / oc_framework / operations / ShareRemoteFile.java
1 /* ownCloud Android Library is available under MIT license
2 * Copyright (C) 2014 ownCloud (http://www.owncloud.org/)
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 * THE SOFTWARE.
22 *
23 */
24
25 package com.owncloud.android.oc_framework.operations;
26
27 import android.os.Parcel;
28 import android.os.Parcelable;
29 import android.util.Log;
30
31 import com.owncloud.android.oc_framework.network.webdav.WebdavEntry;
32 import com.owncloud.android.oc_framework.utils.FileUtils;
33
34 /**
35 * Contains the data of a Share Remote File from the Share API
36 *
37 * @author masensio
38 *
39 */
40 public class ShareRemoteFile extends RemoteFile {
41
42 /**
43 * Generated - should be refreshed every time the class changes!!
44 */
45 private static final long serialVersionUID = -5916376011588784325L;
46
47 private static final String TAG = ShareRemoteFile.class.getSimpleName();
48
49 private long mFileSource;
50 private long mItemSource;
51 private ShareType mShareType;
52 private String mShareWith;
53 private String mPath;
54 private int mPermissions;
55 private long mSharedDate;
56 private long mExpirationDate;
57 private String mToken;
58 private String mSharedWithDisplayName;
59 private boolean mIsDirectory;
60 private long mUserId;
61 private long mIdRemoteShared;
62
63
64 public ShareRemoteFile(String path) {
65 super(path);
66 resetData();
67 if (path == null || path.length() <= 0 || !path.startsWith(FileUtils.PATH_SEPARATOR)) {
68 Log.e(TAG, "Trying to create a OCShare with a non valid path");
69 throw new IllegalArgumentException("Trying to create a OCShare with a non valid path: " + path);
70 }
71 mPath = path;
72 }
73
74 public ShareRemoteFile(WebdavEntry we) {
75 super(we);
76 // TODO Auto-generated constructor stub
77 }
78
79 /**
80 * Used internally. Reset all file properties
81 */
82 private void resetData() {
83 mFileSource = 0;
84 mItemSource = 0;
85 mShareType = ShareType.NO_SHARED;
86 mShareWith = null;
87 mPath = null;
88 mPermissions = -1;
89 mSharedDate = 0;
90 mExpirationDate = 0;
91 mToken = null;
92 mSharedWithDisplayName = null;
93 mIsDirectory = false;
94 mUserId = -1;
95 mIdRemoteShared = -1;
96 }
97
98 /// Getters and Setters
99 public long getFileSource() {
100 return mFileSource;
101 }
102
103 public void setFileSource(long fileSource) {
104 this.mFileSource = fileSource;
105 }
106
107 public long getItemSource() {
108 return mItemSource;
109 }
110
111 public void setItemSource(long itemSource) {
112 this.mItemSource = itemSource;
113 }
114
115 public ShareType getShareType() {
116 return mShareType;
117 }
118
119 public void setShareType(ShareType shareType) {
120 this.mShareType = shareType;
121 }
122
123 public String getShareWith() {
124 return mShareWith;
125 }
126
127 public void setShareWith(String shareWith) {
128 this.mShareWith = shareWith;
129 }
130
131 public String getPath() {
132 return mPath;
133 }
134
135 public void setPath(String path) {
136 this.mPath = path;
137 }
138
139 public int getPermissions() {
140 return mPermissions;
141 }
142
143 public void setPermissions(int permissions) {
144 this.mPermissions = permissions;
145 }
146
147 public long getSharedDate() {
148 return mSharedDate;
149 }
150
151 public void setSharedDate(long sharedDate) {
152 this.mSharedDate = sharedDate;
153 }
154
155 public long getExpirationDate() {
156 return mExpirationDate;
157 }
158
159 public void setExpirationDate(long expirationDate) {
160 this.mExpirationDate = expirationDate;
161 }
162
163 public String getToken() {
164 return mToken;
165 }
166
167 public void setToken(String token) {
168 this.mToken = token;
169 }
170
171 public String getSharedWithDisplayName() {
172 return mSharedWithDisplayName;
173 }
174
175 public void setSharedWithDisplayName(String sharedWithDisplayName) {
176 this.mSharedWithDisplayName = sharedWithDisplayName;
177 }
178
179 public boolean isDirectory() {
180 return mIsDirectory;
181 }
182
183 public void setIsDirectory(boolean isDirectory) {
184 this.mIsDirectory = isDirectory;
185 }
186
187 public long getUserId() {
188 return mUserId;
189 }
190
191 public void setUserId(long userId) {
192 this.mUserId = userId;
193 }
194
195 public long getIdRemoteShared() {
196 return mIdRemoteShared;
197 }
198
199 public void setIdRemoteShared(long idRemoteShared) {
200 this.mIdRemoteShared = idRemoteShared;
201 }
202
203 /**
204 * Parcelable Methods
205 */
206 public static final Parcelable.Creator<ShareRemoteFile> CREATOR = new Parcelable.Creator<ShareRemoteFile>() {
207 @Override
208 public ShareRemoteFile createFromParcel(Parcel source) {
209 return new ShareRemoteFile(source);
210 }
211
212 @Override
213 public ShareRemoteFile[] newArray(int size) {
214 return new ShareRemoteFile[size];
215 }
216 };
217
218 /**
219 * Reconstruct from parcel
220 *
221 * @param source The source parcel
222 */
223 protected ShareRemoteFile(Parcel source) {
224 super(source);
225 }
226
227 public void readFromParcel(Parcel source) {
228 super.readFromParcel(source);
229
230 mFileSource = source.readLong();
231 mItemSource = source.readLong();
232 try {
233 mShareType = ShareType.valueOf(source.readString());
234 } catch (IllegalArgumentException x) {
235 mShareType = ShareType.NO_SHARED;
236 }
237 mShareWith = source.readString();
238 mPath = source.readString();
239 mPermissions = source.readInt();
240 mSharedDate = source.readLong();
241 mExpirationDate = source.readLong();
242 mToken = source.readString();
243 mSharedWithDisplayName = source.readString();
244 mIsDirectory = source.readInt() == 0;
245 mUserId = source.readLong();
246 mIdRemoteShared = source.readLong();
247 }
248
249
250 @Override
251 public void writeToParcel(Parcel dest, int flags) {
252 super.writeToParcel(dest, flags);
253
254 dest.writeLong(mFileSource);
255 dest.writeLong(mItemSource);
256 dest.writeString((mShareType == null) ? "" : mShareType.name());
257 dest.writeString(mShareWith);
258 dest.writeString(mPath);
259 dest.writeInt(mPermissions);
260 dest.writeLong(mSharedDate);
261 dest.writeLong(mExpirationDate);
262 dest.writeString(mToken);
263 dest.writeString(mSharedWithDisplayName);
264 dest.writeInt(mIsDirectory ? 1 : 0);
265 dest.writeLong(mUserId);
266 dest.writeLong(mIdRemoteShared);
267 }
268 }