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.ArrayList;
22 import java.util.HashMap;
23 import java.util.List;
24 import java.util.Map;
25
26 import org.exoplatform.shareextension.service.ShareService.UploadInfo;
27 import org.exoplatform.utils.ExoConstants;
28 import org.exoplatform.utils.Utils;
29
30 import android.os.Parcel;
31 import android.os.Parcelable;
32
33
34
35
36
37
38
39 public class SocialPostInfo implements Parcelable {
40
41 public final static String TYPE_DEFAULT = "activity_default";
42
43 public final static String TYPE_DOC = "activity_doc";
44
45 public final static String TYPE_LINK = "activity_link";
46
47 public ExoAccount ownerAccount;
48
49 public String postMessage;
50
51 public List<String> postAttachedFiles;
52
53 public SocialSpaceInfo destinationSpace;
54
55 public Map<String, String> templateParams;
56
57 public String activityType = TYPE_DEFAULT;
58
59 public SocialPostInfo() {
60 }
61
62 private SocialPostInfo(Parcel in) {
63 readFromParcel(in);
64 }
65
66 public static final Parcelable.Creator<SocialPostInfo> CREATOR = new Parcelable.Creator<SocialPostInfo>() {
67 public SocialPostInfo createFromParcel(Parcel in) {
68 return new SocialPostInfo(in);
69 }
70
71 public SocialPostInfo[] newArray(int size) {
72 return new SocialPostInfo[size];
73 }
74 };
75
76 @Override
77 public int describeContents() {
78 return 0;
79 }
80
81 @Override
82 public void writeToParcel(Parcel out, int flags) {
83 out.writeParcelable(ownerAccount, flags);
84 out.writeString(postMessage);
85 out.writeStringList(postAttachedFiles);
86 out.writeParcelable(destinationSpace, flags);
87 out.writeMap(templateParams);
88 out.writeString(activityType);
89
90 }
91
92 public void readFromParcel(Parcel in) {
93 ownerAccount = in.readParcelable(SocialPostInfo.class.getClassLoader());
94 postMessage = in.readString();
95 postAttachedFiles = new ArrayList<String>();
96 in.readStringList(postAttachedFiles);
97 destinationSpace = in.readParcelable(SocialPostInfo.class.getClassLoader());
98 in.readMap(templateParams, SocialPostInfo.class.getClassLoader());
99 activityType = in.readString();
100 }
101
102
103
104
105
106
107
108
109
110 public boolean isPublic() {
111 return (destinationSpace == null || "".equals(destinationSpace));
112 }
113
114
115
116
117 public boolean hasAttachment() {
118 return Utils.notEmpty(postAttachedFiles);
119 }
120
121
122
123
124
125
126
127
128 public void addTemplateParam(String name, String value) {
129 if (templateParams == null)
130 templateParams = new HashMap<String, String>(1);
131 templateParams.put(name, value);
132 }
133
134
135
136
137
138
139
140
141 public String getTemplateParam(String name) {
142 if (templateParams == null)
143 return null;
144 return templateParams.get(name);
145 }
146
147
148
149
150
151 public void buildTemplateParams(UploadInfo uploadInfo) {
152 String docUrl = uploadInfo.getUploadedUrl();
153 templateParams = new HashMap<String, String>();
154 templateParams.put("WORKSPACE", uploadInfo.workspace);
155 templateParams.put("REPOSITORY", uploadInfo.repository);
156 String docLink = docUrl.substring(ownerAccount.serverUrl.length());
157 templateParams.put("DOCLINK", docLink);
158 StringBuffer beginPath = new StringBuffer(ExoConstants.DOCUMENT_JCR_PATH).append("/")
159 .append(uploadInfo.repository)
160 .append("/")
161 .append(uploadInfo.workspace);
162 String docPath = docLink.substring(beginPath.length());
163 templateParams.put("DOCPATH", docPath);
164 templateParams.put("DOCNAME", uploadInfo.fileToUpload.documentName);
165 String mimeType = uploadInfo.fileToUpload.documentMimeType;
166 if (mimeType != null && !mimeType.trim().isEmpty()) {
167 templateParams.put("mimeType", uploadInfo.fileToUpload.documentMimeType);
168 }
169 }
170
171 }