1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.exoplatform.model;
20
21 import java.util.List;
22 import java.util.Locale;
23
24 import android.os.Parcel;
25 import android.os.Parcelable;
26
27 public class ExoFile implements Parcelable {
28
29
30
31
32 public String path;
33
34
35
36
37 public boolean isFolder;
38
39
40
41
42 public boolean canRemove;
43
44
45
46
47 public String name;
48
49
50
51
52 public String currentFolder;
53
54
55
56
57 public String driveName;
58
59
60
61
62 public String workspaceName;
63
64
65
66
67 public String nodeType;
68
69
70
71
72
73
74 private String naturalName;
75
76
77
78
79 public List<ExoFile> children;
80
81
82 public ExoFile() {
83 path = "";
84 isFolder = true;
85 canRemove = false;
86 name = "";
87 currentFolder = "";
88 driveName = "";
89 workspaceName = "";
90 nodeType = "";
91 naturalName = "";
92 children = null;
93 }
94
95 public ExoFile(String driverName) {
96 path = "";
97 isFolder = true;
98 canRemove = false;
99 name = "";
100 currentFolder = "";
101 this.driveName = driverName;
102 workspaceName = "";
103 nodeType = "";
104 naturalName = "";
105 children = null;
106 }
107
108 private ExoFile(Parcel in) {
109 readFromParcel(in);
110 }
111
112
113
114
115
116
117
118 public String getName() {
119 if (naturalName == null || "".equals(naturalName))
120 return name;
121 else
122 return naturalName;
123 }
124
125
126
127
128
129
130
131
132
133
134
135
136
137 public void createNaturalName() {
138 StringBuilder sb = new StringBuilder();
139
140 String tmpName = name.replace('_', '.');
141 tmpName = tmpName.replace('-', '.');
142
143 if (tmpName.startsWith(".spaces."))
144 tmpName = tmpName.substring(".spaces.".length());
145
146 String[] words = tmpName.split("\\.");
147 for (String word : words) {
148 if ("exo".equals(word)) {
149 sb.append("eXo ");
150 continue;
151 }
152
153 sb.append(toCapitalCase(word)).append(" ");
154 }
155 naturalName = sb.toString().trim();
156 }
157
158
159
160
161
162
163
164
165 private String toCapitalCase(String word) {
166 if (word == null || word.length() == 0)
167 return "";
168 String initial = String.valueOf(word.charAt(0)).toUpperCase(Locale.US);
169 String remainder = word.substring(1).toLowerCase(Locale.US);
170 return initial + remainder;
171 }
172
173 private void readFromParcel(Parcel in) {
174 path = in.readString();
175 isFolder = (Boolean) in.readValue(null);
176 canRemove = (Boolean) in.readValue(null);
177 name = in.readString();
178 currentFolder = in.readString();
179 driveName = in.readString();
180 workspaceName = in.readString();
181 nodeType = in.readString();
182 naturalName = in.readString();
183 in.readList(children, this.getClass().getClassLoader());
184 }
185
186 public static final Parcelable.Creator<ExoFile> CREATOR = new Parcelable.Creator<ExoFile>() {
187 public ExoFile createFromParcel(Parcel in) {
188 return new ExoFile(in);
189 }
190
191 public ExoFile[] newArray(int size) {
192 return new ExoFile[size];
193 }
194 };
195
196
197
198
199
200 @Override
201 public int describeContents() {
202 return 0;
203 }
204
205
206
207
208
209 @Override
210 public void writeToParcel(Parcel par, int flags) {
211 par.writeString(path);
212 par.writeValue(isFolder);
213 par.writeValue(canRemove);
214 par.writeString(name);
215 par.writeString(currentFolder);
216 par.writeString(driveName);
217 par.writeString(workspaceName);
218 par.writeString(nodeType);
219 par.writeString(naturalName);
220 par.writeList(children);
221 }
222 }