70c9dc1ba8dfab3c967f1230f653debeeb536e13
[pub/Android/ownCloud.git] / oc_framework / src / com / owncloud / android / oc_framework / operations / RemoteFile.java
1 /* ownCloud webDAV Library for Android 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 java.io.Serializable;
28
29 import android.os.Parcel;
30 import android.os.Parcelable;
31
32 import com.owncloud.android.oc_framework.network.webdav.WebdavEntry;
33 import com.owncloud.android.oc_framework.utils.FileUtils;
34
35 /**
36 * Contains the data of a Remote File from a WebDavEntry
37 *
38 * @author masensio
39 */
40
41 public class RemoteFile implements Parcelable, Serializable {
42
43 /** Generated - should be refreshed every time the class changes!! */
44 private static final long serialVersionUID = 532139091191390616L;
45
46 private String mRemotePath;
47 private String mMimeType;
48 private long mLength;
49 private long mCreationTimestamp;
50 private long mModifiedTimestamp;
51 private String mEtag;
52
53 /**
54 * Getters and Setters
55 */
56
57 public String getRemotePath() {
58 return mRemotePath;
59 }
60
61 public void setRemotePath(String remotePath) {
62 this.mRemotePath = remotePath;
63 }
64
65 public String getMimeType() {
66 return mMimeType;
67 }
68
69 public void setMimeType(String mimeType) {
70 this.mMimeType = mimeType;
71 }
72
73 public long getLength() {
74 return mLength;
75 }
76
77 public void setLength(long length) {
78 this.mLength = length;
79 }
80
81 public long getCreationTimestamp() {
82 return mCreationTimestamp;
83 }
84
85 public void setCreationTimestamp(long creationTimestamp) {
86 this.mCreationTimestamp = creationTimestamp;
87 }
88
89 public long getModifiedTimestamp() {
90 return mModifiedTimestamp;
91 }
92
93 public void setModifiedTimestamp(long modifiedTimestamp) {
94 this.mModifiedTimestamp = modifiedTimestamp;
95 }
96
97 public String getEtag() {
98 return mEtag;
99 }
100
101 public void setEtag(String etag) {
102 this.mEtag = etag;
103 }
104
105 /**
106 * Create new {@link RemoteFile} with given path.
107 *
108 * The path received must be URL-decoded. Path separator must be OCFile.PATH_SEPARATOR, and it must be the first character in 'path'.
109 *
110 * @param path The remote path of the file.
111 */
112 public RemoteFile(String path) {
113 resetData();
114 if (path == null || path.length() <= 0 || !path.startsWith(FileUtils.PATH_SEPARATOR)) {
115 throw new IllegalArgumentException("Trying to create a OCFile with a non valid remote path: " + path);
116 }
117 mRemotePath = path;
118 }
119
120 public RemoteFile(WebdavEntry we) {
121 this(we.decodedPath());
122 this.setCreationTimestamp(we.createTimestamp());
123 this.setLength(we.contentLength());
124 this.setMimeType(we.contentType());
125 this.setModifiedTimestamp(we.modifiedTimestamp());
126 this.setEtag(we.etag());
127 }
128
129 /**
130 * Used internally. Reset all file properties
131 */
132 private void resetData() {
133 mRemotePath = null;
134 mMimeType = null;
135 mLength = 0;
136 mCreationTimestamp = 0;
137 mModifiedTimestamp = 0;
138 mEtag = null;
139 }
140
141 /**
142 * Parcelable Methods
143 */
144 public static final Parcelable.Creator<RemoteFile> CREATOR = new Parcelable.Creator<RemoteFile>() {
145 @Override
146 public RemoteFile createFromParcel(Parcel source) {
147 return new RemoteFile(source);
148 }
149
150 @Override
151 public RemoteFile[] newArray(int size) {
152 return new RemoteFile[size];
153 }
154 };
155
156
157 /**
158 * Reconstruct from parcel
159 *
160 * @param source The source parcel
161 */
162 private RemoteFile(Parcel source) {
163 mRemotePath = source.readString();
164 mMimeType = source.readString();
165 mLength = source.readLong();
166 mCreationTimestamp = source.readLong();
167 mModifiedTimestamp = source.readLong();
168 mEtag = source.readString();
169 }
170
171 @Override
172 public int describeContents() {
173 return this.hashCode();
174 }
175
176 @Override
177 public void writeToParcel(Parcel dest, int flags) {
178 dest.writeString(mRemotePath);
179 dest.writeString(mMimeType);
180 dest.writeLong(mLength);
181 dest.writeLong(mCreationTimestamp);
182 dest.writeLong(mModifiedTimestamp);
183 dest.writeString(mEtag);
184 }
185
186
187 }