07f45b7b502ef8bf19c61b67561cdfd05ab1e3c6
[pub/Android/ownCloud.git] / oc_framework / src / com / owncloud / android / oc_framework / operations / RemoteFile.java
1 /* ownCloud Android client application
2 * Copyright (C) 2012-2013 ownCloud Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18 package com.owncloud.android.oc_framework.operations;
19
20 import java.io.Serializable;
21
22 import android.os.Parcel;
23 import android.os.Parcelable;
24
25 import com.owncloud.android.oc_framework.utils.FileUtils;
26
27 /**
28 * Contains the data of a Remote File from a WebDavEntry
29 *
30 * @author masensio
31 */
32
33 public class RemoteFile implements Parcelable, Serializable {
34
35 /** Generated - should be refreshed every time the class changes!! */
36 private static final long serialVersionUID = 7256606476031992757L;
37
38 private String mRemotePath;
39 private String mMimeType;
40 private long mLength;
41 private long mCreationTimestamp;
42 private long mModifiedTimestamp;
43 private String mEtag;
44
45 /**
46 * Getters and Setters
47 */
48
49 public String getRemotePath() {
50 return mRemotePath;
51 }
52
53 public void setRemotePath(String remotePath) {
54 this.mRemotePath = remotePath;
55 }
56
57 public String getMimeType() {
58 return mMimeType;
59 }
60
61 public void setMimeType(String mimeType) {
62 this.mMimeType = mimeType;
63 }
64
65 public long getLength() {
66 return mLength;
67 }
68
69 public void setLength(long length) {
70 this.mLength = length;
71 }
72
73 public long getCreationTimestamp() {
74 return mCreationTimestamp;
75 }
76
77 public void setCreationTimestamp(long creationTimestamp) {
78 this.mCreationTimestamp = creationTimestamp;
79 }
80
81 public long getModifiedTimestamp() {
82 return mModifiedTimestamp;
83 }
84
85 public void setModifiedTimestamp(long modifiedTimestamp) {
86 this.mModifiedTimestamp = modifiedTimestamp;
87 }
88
89 public String getEtag() {
90 return mEtag;
91 }
92
93 public void setEtag(String etag) {
94 this.mEtag = etag;
95 }
96
97 /**
98 * Create new {@link RemoteFile} with given path.
99 *
100 * The path received must be URL-decoded. Path separator must be OCFile.PATH_SEPARATOR, and it must be the first character in 'path'.
101 *
102 * @param path The remote path of the file.
103 */
104 public RemoteFile(String path) {
105 resetData();
106 if (path == null || path.length() <= 0 || !path.startsWith(FileUtils.PATH_SEPARATOR)) {
107 throw new IllegalArgumentException("Trying to create a OCFile with a non valid remote path: " + path);
108 }
109 mRemotePath = path;
110 }
111
112 /**
113 * Used internally. Reset all file properties
114 */
115 private void resetData() {
116 mRemotePath = null;
117 mMimeType = null;
118 mLength = 0;
119 mCreationTimestamp = 0;
120 mModifiedTimestamp = 0;
121 mEtag = null;
122 }
123
124 /**
125 * Parcelable Methods
126 */
127 public static final Parcelable.Creator<RemoteFile> CREATOR = new Parcelable.Creator<RemoteFile>() {
128 @Override
129 public RemoteFile createFromParcel(Parcel source) {
130 return new RemoteFile(source);
131 }
132
133 @Override
134 public RemoteFile[] newArray(int size) {
135 return new RemoteFile[size];
136 }
137 };
138
139
140 /**
141 * Reconstruct from parcel
142 *
143 * @param source The source parcel
144 */
145 private RemoteFile(Parcel source) {
146 mRemotePath = source.readString();
147 mMimeType = source.readString();
148 mLength = source.readLong();
149 mCreationTimestamp = source.readLong();
150 mModifiedTimestamp = source.readLong();
151 mEtag = source.readString();
152 }
153
154 @Override
155 public int describeContents() {
156 return this.hashCode();
157 }
158
159 @Override
160 public void writeToParcel(Parcel dest, int flags) {
161 dest.writeString(mRemotePath);
162 dest.writeString(mMimeType);
163 dest.writeLong(mLength);
164 dest.writeLong(mCreationTimestamp);
165 dest.writeLong(mModifiedTimestamp);
166 dest.writeString(mEtag);
167 }
168
169
170 }