Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Replaced unit tests for LOCATION with ORGANIZER for ContactJournalObject.
[xestiacalendar/.git] / source / objects / calendarjournal / CalendarJournal.cpp
1 #include "CalendarJournal.h"
3 using namespace std;
5 CalendarObjectValidResult CalendarJournalObject::ValidObject(){
7         bool ValidBegin = false;
8         bool ValidEnd = false;
9         bool ValidDateTimeStamp = false;
10         bool ValidUniqueID = false;
11         int SeekCount = 0;
12         string PropertyName;
13         
14         // Look for BEGIN:VJOURNAL.
15         
16         for (vector<string>::iterator iter = ObjectName.begin();
17                 iter != ObjectName.end(); iter++){
18         
19                 if (ObjectName[SeekCount] == "BEGIN" &&
20                         ObjectData[SeekCount] == "VJOURNAL"){
21                         
22                         if (ValidBegin == false){
23                                 ValidBegin = true;
24                         } else {
25                                 return CALENDAROBJECTVALID_INVALIDFORMAT;
26                         }
27                                 
28                 }
29                 
30                 if (ObjectName[SeekCount] == "END" &&
31                         ObjectData[SeekCount] == "VJOURNAL" &&
32                         ValidBegin == false){
33                 
34                         return CALENDAROBJECTVALID_INVALIDFORMAT;
35                                 
36                 }
37                 
38                 SeekCount++;
39                         
40         }
41         
42         SeekCount = 0;
43         
44         // Look for DTSTAMP.
45         
46         for (vector<string>::iterator iter = ObjectName.begin();
47                 iter != ObjectName.end(); iter++){
48                         
49                 try{
50                         PropertyName = ObjectName[SeekCount].substr(0,7);
51                 }
52                         
53                 catch(const out_of_range& oor){
54                         continue;
55                 }
56                 
57                 if (PropertyName == "DTSTAMP"){
58                         
59                         if (ValidDateTimeStamp == false){
60                                 ValidDateTimeStamp = true;
61                         } else {
62                                 return CALENDAROBJECTVALID_INVALIDFORMAT;
63                         }
64                                 
65                 }
66                         
67                 SeekCount++;
69         }
70         
71         SeekCount = 0;
72         
73         // Look for UID.
74         
75         for (vector<string>::iterator iter = ObjectName.begin();
76                 iter != ObjectName.end(); iter++){
77         
78                 try{
79                         PropertyName = ObjectName[SeekCount].substr(0,3);
80                 }
81                 
82                 catch(const out_of_range& oor){
83                         continue;
84                 }
85                         
86                 if (PropertyName == "UID"){
87                         
88                         if (ValidUniqueID == false){
89                                 ValidUniqueID = true;
90                         } else {
91                                 return CALENDAROBJECTVALID_INVALIDFORMAT;
92                         }
93                                 
94                 }
95                         
96                 SeekCount++;
97                         
98         }
99         
100         SeekCount = 0;
101                 
102         // Look for END:VJOURNAL.
103         
104         for (vector<string>::iterator iter = ObjectName.begin();
105                 iter != ObjectName.end(); iter++){
106         
107                 if (ObjectName[SeekCount] == "END" &&
108                         ObjectData[SeekCount] == "VJOURNAL"){
109                         
110                         if (ValidEnd == false){
111                                 ValidEnd = true;
112                         } else {
113                                 return CALENDAROBJECTVALID_INVALIDFORMAT;
114                         }
115                                 
116                 }
117                         
118                 SeekCount++;
119                         
120         }
121         
122         // Check if the VJOURNAL is valid.
123         
124         if (ValidBegin == true && 
125                 ValidEnd == true && 
126                 ValidDateTimeStamp == true &&
127                 ValidUniqueID == true){
128                         
129                 return CALENDAROBJECTVALID_OK;
130                         
131         } else {
132                 
133                 return CALENDAROBJECTVALID_INVALIDFORMAT;
134                 
135         }
136         
139 void CalendarJournalObject::ProcessData(){
141         // Process the data.
142         
143         multimap<string,string> DataReceived;
144         map<string,string> PropertyData;
145         string *PropertyNameData = nullptr;
146         int ObjectSeekCount = 0;
148         // Get the Date Time Stamp (DTSTAMP).
149         
150         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "DTSTAMP");
151         
152         // Process the data from DTSTAMP.
153         
154         if (DataReceived.begin() != DataReceived.end()){
155         
156                 try {
157                         DateTimeStampTokens = DataReceived.begin()->first.substr(8);
158                 }
159                 
160                 catch(const out_of_range &oor){
161                         // Do nothing as there is no data.
162                 }               
163                 
164                 DateTimeStampData = DataReceived.begin()->second;
165                 
166         }
167         
168         // Get the Unique ID (UID).
169         
170         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "UID");
171         
172         // Process the data from UID.
173         
174         if (DataReceived.begin() != DataReceived.end()){
175         
176                 try {
177                         UniqueIDTokens = DataReceived.begin()->first.substr(4);
178                 }
179                 
180                 catch(const out_of_range &oor){
181                         // Do nothing as there is no data.
182                 }               
183                 
184                 UniqueID = DataReceived.begin()->second;
185                 
186         }
187         
188         // Process the data from CLASS.
189         
190         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "CLASS");
191         
192         if (DataReceived.begin() != DataReceived.end()){
193         
194                 try {
195                         ClassDataTokens = DataReceived.begin()->first.substr(6);
196                 }
197                 
198                 catch(const out_of_range &oor){
199                         // Do nothing as there is no data.
200                 }               
201                 
202                 ClassData = DataReceived.begin()->second;
203                 
204         }
205         
206         // Get the Date Time Start value.
207         
208         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "DTSTART");
209         
210         // Process the data from DTSTART.
211         
212         if (DataReceived.begin() != DataReceived.end()){
213         
214                 bool TokenData = false;
215                 string PropertyTokens;
216                 
217                 PropertyNameData = (string*)&DataReceived.begin()->first;
218                 
219                 PropertyData = SplitValues(*PropertyNameData);
220                 
221                 for(map<string,string>::iterator iter = PropertyData.begin();
222                         iter != PropertyData.end(); iter++){
223                         
224                         if (iter->first == "VALUE"){
225                                 
226                                 DateTimeStartDataValue = iter->second;
227                                 
228                         } else if (iter->first == "TZID"){
229                                 
230                                 DateTimeStartDataTimeZoneID = iter->second;
231                                 
232                         } else {
233                                 
234                                 if (TokenData == false){
235                                         TokenData = true;
236                                 } else {
237                                         PropertyTokens += ";";
238                                 }
239                                 
240                                 PropertyTokens += iter->first;
241                                 PropertyTokens += "=";
242                                 PropertyTokens += iter->second;
243                                 
244                         }
245                                 
246                 }
247                 
248                 if (PropertyTokens.size() > 0){
249                         DateTimeStartDataTokens = PropertyTokens;
250                 }
251                 
252                 DateTimeStartData = DataReceived.begin()->second;
253                 
254         }
255         
256         // Process the data from LAST-MODIFIED.
257         
258         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "LAST-MODIFIED");
259         
260         if (DataReceived.begin() != DataReceived.end()){
261         
262                 try {
263                         LastModifiedTokens = DataReceived.begin()->first.substr(14);
264                 }
265                 
266                 catch(const out_of_range &oor){
267                         // Do nothing as there is no data.
268                 }               
269                 
270                 LastModifiedData = DataReceived.begin()->second;
271                 
272         }
273         
274         // Process the data from ORGANIZER.
275         
276         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "ORGANIZER");
277         
278         if (DataReceived.begin() != DataReceived.end()){
279         
280                 bool TokenData = false;
281                 string PropertyTokens;
282                 
283                 PropertyNameData = (string*)&DataReceived.begin()->first;
284                 
285                 PropertyData = SplitValues(*PropertyNameData);
286                 
287                 for(map<string,string>::iterator iter = PropertyData.begin();
288                         iter != PropertyData.end(); iter++){
289                         
290                         if (iter->first == "CN"){
291                                 
292                                 OrganiserDataCommonName = iter->second;
293                                 
294                         } else if (iter->first == "DIR"){
295                                 
296                                 OrganiserDataDirectoryEntry = iter->second;
297                                 
298                         } else if (iter->first == "SENT-BY"){
299                                 
300                                 OrganiserDataSentByParam = iter->second;
301                                 
302                         } else if (iter->first == "LANGUAGE"){
303                                 
304                                 OrganiserDataLanguage = iter->second;
305                                 
306                         } else {
307                                 
308                                 if (TokenData == false){
309                                         TokenData = true;
310                                 } else {
311                                         PropertyTokens += ";";
312                                 }
313                                 
314                                 PropertyTokens += iter->first;
315                                 PropertyTokens += "=";
316                                 PropertyTokens += iter->second;
317                                 
318                         }
319                                 
320                 }
321                 
322                 if (PropertyTokens.size() > 0){
323                         
324                         OrganiserDataTokens = PropertyTokens;
325                         
326                 }
327                 
328                 OrganiserData = DataReceived.begin()->second;
329                 
330         }
331         
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy