1 #include "CalendarEvent.h"
5 CalendarObjectValidResult CalendarEventObject::ValidObject(){
7 bool ValidBegin = false;
9 bool ValidDateTimeStamp = false;
10 bool ValidUniqueID = false;
11 bool ValidDateTimeStart = false;
15 // Look for BEGIN:VEVENT.
17 for (vector<string>::iterator iter = ObjectName.begin();
18 iter != ObjectName.end(); iter++){
20 if (ObjectName[SeekCount] == "BEGIN" &&
21 ObjectData[SeekCount] == "VEVENT"){
23 if (ValidBegin == false){
26 return CALENDAROBJECTVALID_INVALIDFORMAT;
31 if (ObjectName[SeekCount] == "END" &&
32 ObjectData[SeekCount] == "VEVENT" &&
35 return CALENDAROBJECTVALID_INVALIDFORMAT;
47 for (vector<string>::iterator iter = ObjectName.begin();
48 iter != ObjectName.end(); iter++){
51 PropertyName = ObjectName[SeekCount].substr(0,7);
54 catch(const out_of_range& oor){
58 if (PropertyName == "DTSTAMP"){
60 if (ValidDateTimeStamp == false){
61 ValidDateTimeStamp = true;
63 return CALENDAROBJECTVALID_INVALIDFORMAT;
76 for (vector<string>::iterator iter = ObjectName.begin();
77 iter != ObjectName.end(); iter++){
80 PropertyName = ObjectName[SeekCount].substr(0,3);
83 catch(const out_of_range& oor){
87 if (PropertyName == "UID"){
89 if (ValidUniqueID == false){
92 return CALENDAROBJECTVALID_INVALIDFORMAT;
103 // Look for DTSTART if nothing is set for METHOD..
105 if (MethodData.size() == 0){
107 for (vector<string>::iterator iter = ObjectName.begin();
108 iter != ObjectName.end(); iter++){
111 PropertyName = ObjectName[SeekCount].substr(0,7);
114 catch(const out_of_range& oor){
118 if (PropertyName == "DTSTART"){
120 if (ValidDateTimeStart == false){
121 ValidDateTimeStart = true;
123 return CALENDAROBJECTVALID_INVALIDFORMAT;
133 ValidDateTimeStart = true;
138 // Look for END:VEVENT.
140 for (vector<string>::iterator iter = ObjectName.begin();
141 iter != ObjectName.end(); iter++){
143 if (ObjectName[SeekCount] == "END" &&
144 ObjectData[SeekCount] == "VEVENT"){
146 if (ValidEnd == false){
149 return CALENDAROBJECTVALID_INVALIDFORMAT;
158 // Check if the VEVENT is valid.
160 if (ValidBegin == true &&
162 ValidDateTimeStamp == true &&
163 ValidDateTimeStart == true &&
164 ValidUniqueID == true){
166 return CALENDAROBJECTVALID_OK;
170 return CALENDAROBJECTVALID_INVALIDFORMAT;
176 void CalendarEventObject::ProcessData(){
180 multimap<string,string> DataReceived;
181 map<string,string> PropertyData;
182 string *PropertyNameData = nullptr;
184 // Get the Date Time Stamp (DTSTAMP).
186 DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "DTSTAMP");
188 // Process the data from DTSTAMP.
190 if (DataReceived.begin() != DataReceived.end()){
193 DateTimeStampTokens = DataReceived.begin()->first.substr(8);
196 catch(const out_of_range &oor){
197 // Do nothing as there is no data.
200 DateTimeStampData = DataReceived.begin()->second;
204 // Get the Unique ID (UID).
206 DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "UID");
208 // Process the data from UID.
210 if (DataReceived.begin() != DataReceived.end()){
213 UniqueIDTokens = DataReceived.begin()->first.substr(4);
216 catch(const out_of_range &oor){
217 // Do nothing as there is no data.
220 UniqueID = DataReceived.begin()->second;
224 // Get the Date Time Start value.
226 DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "DTSTART");
228 // Process the data from DTSTART.
230 if (DataReceived.begin() != DataReceived.end()){
232 bool TokenData = false;
233 string PropertyTokens;
235 PropertyNameData = (string*)&DataReceived.begin()->first;
237 PropertyData = SplitValues(*PropertyNameData);
239 for(map<string,string>::iterator iter = PropertyData.begin();
240 iter != PropertyData.end(); iter++){
242 if (iter->first == "VALUE"){
244 DateTimeStartDataValue = iter->second;
246 } else if (iter->first == "TZID"){
248 DateTimeStartDataTimeZoneID = iter->second;
252 if (TokenData == false){
255 PropertyTokens += ";";
258 PropertyTokens += iter->first;
259 PropertyTokens += "=";
260 PropertyTokens += iter->second;
266 if (PropertyTokens.size() > 0){
267 DateTimeStartDataTokens = PropertyTokens;
270 DateTimeStartData = DataReceived.begin()->second;
274 // Process the data from CLASS.
276 DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "CLASS");
278 if (DataReceived.begin() != DataReceived.end()){
281 ClassDataTokens = DataReceived.begin()->first.substr(6);
284 catch(const out_of_range &oor){
285 // Do nothing as there is no data.
288 ClassData = DataReceived.begin()->second;
292 // Process the data from CREATED.
294 DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "CREATED");
296 if (DataReceived.begin() != DataReceived.end()){
299 DateTimeCreatedTokens = DataReceived.begin()->first.substr(8);
302 catch(const out_of_range &oor){
303 // Do nothing as there is no data.
306 DateTimeCreatedData = DataReceived.begin()->second;
310 // Process the data from DESCRIPTION.
312 DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "DESCRIPTION");
314 if (DataReceived.begin() != DataReceived.end()){
316 bool TokenData = false;
317 string PropertyTokens;
319 PropertyNameData = (string*)&DataReceived.begin()->first;
321 PropertyData = SplitValues(*PropertyNameData);
323 for(map<string,string>::iterator iter = PropertyData.begin();
324 iter != PropertyData.end(); iter++){
326 if (iter->first == "ALTREP"){
328 DescriptionListAltRep.clear();
329 DescriptionListAltRep.push_back(iter->second);
331 } else if (iter->first == "LANGUAGE"){
333 DescriptionListLanguage.clear();
334 DescriptionListLanguage.push_back(iter->second);
338 if (TokenData == false){
341 PropertyTokens += ";";
344 PropertyTokens += iter->first;
345 PropertyTokens += "=";
346 PropertyTokens += iter->second;
352 if (PropertyTokens.size() > 0){
353 DescriptionListTokens.clear();
354 DescriptionListTokens.push_back(PropertyTokens);
357 DescriptionList.clear();
358 DescriptionList.push_back(DataReceived.begin()->second);
362 // Process the data from GEO.
364 DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "GEO");
366 if (DataReceived.begin() != DataReceived.end()){
369 GeographicTokens = DataReceived.begin()->first.substr(4);
372 catch(const out_of_range &oor){
373 // Do nothing as there is no data.
376 GeographicData = DataReceived.begin()->second;