f599028c1a83203ead6a260b7fda51d530a7df4c
[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 public class ShareRemoteFile extends RemoteFile {
35
36 /**
37 * Generated - should be refreshed every time the class changes!!
38 */
39 private static final long serialVersionUID = -5916376011588784325L;
40
41 private static final String TAG = ShareRemoteFile.class.getSimpleName();
42
43 private long mFileSource;
44 private long mItemSource;
45 private ShareType mShareType;
46 private String mShareWith;
47 private String mPath;
48 private int mPermissions;
49 private long mSharedDate;
50 private long mExpirationDate;
51 private String mToken;
52 private String mSharedWithDisplayName;
53 private boolean mIsDirectory;
54 private long mUserId;
55 private long mIdRemoteShared;
56
57
58 public ShareRemoteFile(String path) {
59 super(path);
60 resetData();
61 if (path == null || path.length() <= 0 || !path.startsWith(FileUtils.PATH_SEPARATOR)) {
62 Log.e(TAG, "Trying to create a OCShare with a non valid path");
63 throw new IllegalArgumentException("Trying to create a OCShare with a non valid path: " + path);
64 }
65 mPath = path;
66 }
67
68 public ShareRemoteFile(WebdavEntry we) {
69 super(we);
70 // TODO Auto-generated constructor stub
71 }
72
73 /**
74 * Used internally. Reset all file properties
75 */
76 private void resetData() {
77 mFileSource = 0;
78 mItemSource = 0;
79 mShareType = ShareType.NO_SHARED;
80 mShareWith = null;
81 mPath = null;
82 mPermissions = -1;
83 mSharedDate = 0;
84 mExpirationDate = 0;
85 mToken = null;
86 mSharedWithDisplayName = null;
87 mIsDirectory = false;
88 mUserId = -1;
89 mIdRemoteShared = -1;
90 }
91
92 /// Getters and Setters
93 public long getFileSource() {
94 return mFileSource;
95 }
96
97 public void setFileSource(long fileSource) {
98 this.mFileSource = fileSource;
99 }
100
101 public long getItemSource() {
102 return mItemSource;
103 }
104
105 public void setItemSource(long itemSource) {
106 this.mItemSource = itemSource;
107 }
108
109 public ShareType getShareType() {
110 return mShareType;
111 }
112
113 public void setShareType(ShareType shareType) {
114 this.mShareType = shareType;
115 }
116
117 public String getShareWith() {
118 return mShareWith;
119 }
120
121 public void setShareWith(String shareWith) {
122 this.mShareWith = shareWith;
123 }
124
125 public String getPath() {
126 return mPath;
127 }
128
129 public void setPath(String path) {
130 this.mPath = path;
131 }
132
133 public int getPermissions() {
134 return mPermissions;
135 }
136
137 public void setPermissions(int permissions) {
138 this.mPermissions = permissions;
139 }
140
141 public long getSharedDate() {
142 return mSharedDate;
143 }
144
145 public void setSharedDate(long sharedDate) {
146 this.mSharedDate = sharedDate;
147 }
148
149 public long getExpirationDate() {
150 return mExpirationDate;
151 }
152
153 public void setExpirationDate(long expirationDate) {
154 this.mExpirationDate = expirationDate;
155 }
156
157 public String getToken() {
158 return mToken;
159 }
160
161 public void setToken(String token) {
162 this.mToken = token;
163 }
164
165 public String getSharedWithDisplayName() {
166 return mSharedWithDisplayName;
167 }
168
169 public void setSharedWithDisplayName(String sharedWithDisplayName) {
170 this.mSharedWithDisplayName = sharedWithDisplayName;
171 }
172
173 public boolean isDirectory() {
174 return mIsDirectory;
175 }
176
177 public void setIsDirectory(boolean isDirectory) {
178 this.mIsDirectory = isDirectory;
179 }
180
181 public long getUserId() {
182 return mUserId;
183 }
184
185 public void setUserId(long userId) {
186 this.mUserId = userId;
187 }
188
189 public long getIdRemoteShared() {
190 return mIdRemoteShared;
191 }
192
193 public void setIdRemoteShared(long idRemoteShared) {
194 this.mIdRemoteShared = idRemoteShared;
195 }
196
197 /**
198 * Parcelable Methods
199 */
200 public static final Parcelable.Creator<ShareRemoteFile> CREATOR = new Parcelable.Creator<ShareRemoteFile>() {
201 @Override
202 public ShareRemoteFile createFromParcel(Parcel source) {
203 return new ShareRemoteFile(source);
204 }
205
206 @Override
207 public ShareRemoteFile[] newArray(int size) {
208 return new ShareRemoteFile[size];
209 }
210 };
211
212 /**
213 * Reconstruct from parcel
214 *
215 * @param source The source parcel
216 */
217 protected ShareRemoteFile(Parcel source) {
218 super(source);
219 }
220
221 public void readFromParcel(Parcel source) {
222 super.readFromParcel(source);
223
224 mFileSource = source.readLong();
225 mItemSource = source.readLong();
226 try {
227 mShareType = ShareType.valueOf(source.readString());
228 } catch (IllegalArgumentException x) {
229 mShareType = ShareType.NO_SHARED;
230 }
231 mShareWith = source.readString();
232 mPath = source.readString();
233 mPermissions = source.readInt();
234 mSharedDate = source.readLong();
235 mExpirationDate = source.readLong();
236 mToken = source.readString();
237 mSharedWithDisplayName = source.readString();
238 mIsDirectory = source.readInt() == 0;
239 mUserId = source.readLong();
240 mIdRemoteShared = source.readLong();
241 }
242
243
244 @Override
245 public void writeToParcel(Parcel dest, int flags) {
246 super.writeToParcel(dest, flags);
247
248 dest.writeLong(mFileSource);
249 dest.writeLong(mItemSource);
250 dest.writeString((mShareType == null) ? "" : mShareType.name());
251 dest.writeString(mShareWith);
252 dest.writeString(mPath);
253 dest.writeInt(mPermissions);
254 dest.writeLong(mSharedDate);
255 dest.writeLong(mExpirationDate);
256 dest.writeString(mToken);
257 dest.writeString(mSharedWithDisplayName);
258 dest.writeInt(mIsDirectory ? 1 : 0);
259 dest.writeLong(mUserId);
260 dest.writeLong(mIdRemoteShared);
261 }
262 }