1 #include "CalendarJournal.h"
5 CalendarObjectValidResult CalendarJournalObject::ValidObject(){
7 bool ValidBegin = false;
9 bool ValidDateTimeStamp = false;
10 bool ValidUniqueID = false;
14 // Look for BEGIN:VJOURNAL.
16 for (vector<string>::iterator iter = ObjectName.begin();
17 iter != ObjectName.end(); iter++){
19 if (ObjectName[SeekCount] == "BEGIN" &&
20 ObjectData[SeekCount] == "VJOURNAL"){
22 if (ValidBegin == false){
25 return CALENDAROBJECTVALID_INVALIDFORMAT;
30 if (ObjectName[SeekCount] == "END" &&
31 ObjectData[SeekCount] == "VJOURNAL" &&
34 return CALENDAROBJECTVALID_INVALIDFORMAT;
46 for (vector<string>::iterator iter = ObjectName.begin();
47 iter != ObjectName.end(); iter++){
50 PropertyName = ObjectName[SeekCount].substr(0,7);
53 catch(const out_of_range& oor){
57 if (PropertyName == "DTSTAMP"){
59 if (ValidDateTimeStamp == false){
60 ValidDateTimeStamp = true;
62 return CALENDAROBJECTVALID_INVALIDFORMAT;
75 for (vector<string>::iterator iter = ObjectName.begin();
76 iter != ObjectName.end(); iter++){
79 PropertyName = ObjectName[SeekCount].substr(0,3);
82 catch(const out_of_range& oor){
86 if (PropertyName == "UID"){
88 if (ValidUniqueID == false){
91 return CALENDAROBJECTVALID_INVALIDFORMAT;
102 // Look for END:VJOURNAL.
104 for (vector<string>::iterator iter = ObjectName.begin();
105 iter != ObjectName.end(); iter++){
107 if (ObjectName[SeekCount] == "END" &&
108 ObjectData[SeekCount] == "VJOURNAL"){
110 if (ValidEnd == false){
113 return CALENDAROBJECTVALID_INVALIDFORMAT;
122 // Check if the VJOURNAL is valid.
124 if (ValidBegin == true &&
126 ValidDateTimeStamp == true &&
127 ValidUniqueID == true){
129 return CALENDAROBJECTVALID_OK;
133 return CALENDAROBJECTVALID_INVALIDFORMAT;
139 void CalendarJournalObject::ProcessData(){
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).
150 DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "DTSTAMP");
152 // Process the data from DTSTAMP.
154 if (DataReceived.begin() != DataReceived.end()){
157 DateTimeStampTokens = DataReceived.begin()->first.substr(8);
160 catch(const out_of_range &oor){
161 // Do nothing as there is no data.
164 DateTimeStampData = DataReceived.begin()->second;
168 // Get the Unique ID (UID).
170 DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "UID");
172 // Process the data from UID.
174 if (DataReceived.begin() != DataReceived.end()){
177 UniqueIDTokens = DataReceived.begin()->first.substr(4);
180 catch(const out_of_range &oor){
181 // Do nothing as there is no data.
184 UniqueID = DataReceived.begin()->second;
188 // Process the data from CLASS.
190 DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "CLASS");
192 if (DataReceived.begin() != DataReceived.end()){
195 ClassDataTokens = DataReceived.begin()->first.substr(6);
198 catch(const out_of_range &oor){
199 // Do nothing as there is no data.
202 ClassData = DataReceived.begin()->second;
206 // Get the Date Time Start value.
208 DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "DTSTART");
210 // Process the data from DTSTART.
212 if (DataReceived.begin() != DataReceived.end()){
214 bool TokenData = false;
215 string PropertyTokens;
217 PropertyNameData = (string*)&DataReceived.begin()->first;
219 PropertyData = SplitValues(*PropertyNameData);
221 for(map<string,string>::iterator iter = PropertyData.begin();
222 iter != PropertyData.end(); iter++){
224 if (iter->first == "VALUE"){
226 DateTimeStartDataValue = iter->second;
228 } else if (iter->first == "TZID"){
230 DateTimeStartDataTimeZoneID = iter->second;
234 if (TokenData == false){
237 PropertyTokens += ";";
240 PropertyTokens += iter->first;
241 PropertyTokens += "=";
242 PropertyTokens += iter->second;
248 if (PropertyTokens.size() > 0){
249 DateTimeStartDataTokens = PropertyTokens;
252 DateTimeStartData = DataReceived.begin()->second;
256 // Process the data from LAST-MODIFIED.
258 DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "LAST-MODIFIED");
260 if (DataReceived.begin() != DataReceived.end()){
263 LastModifiedTokens = DataReceived.begin()->first.substr(14);
266 catch(const out_of_range &oor){
267 // Do nothing as there is no data.
270 LastModifiedData = DataReceived.begin()->second;
274 // Process the data from ORGANIZER.
276 DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "ORGANIZER");
278 if (DataReceived.begin() != DataReceived.end()){
280 bool TokenData = false;
281 string PropertyTokens;
283 PropertyNameData = (string*)&DataReceived.begin()->first;
285 PropertyData = SplitValues(*PropertyNameData);
287 for(map<string,string>::iterator iter = PropertyData.begin();
288 iter != PropertyData.end(); iter++){
290 if (iter->first == "CN"){
292 OrganiserDataCommonName = iter->second;
294 } else if (iter->first == "DIR"){
296 OrganiserDataDirectoryEntry = iter->second;
298 } else if (iter->first == "SENT-BY"){
300 OrganiserDataSentByParam = iter->second;
302 } else if (iter->first == "LANGUAGE"){
304 OrganiserDataLanguage = iter->second;
308 if (TokenData == false){
311 PropertyTokens += ";";
314 PropertyTokens += iter->first;
315 PropertyTokens += "=";
316 PropertyTokens += iter->second;
322 if (PropertyTokens.size() > 0){
324 OrganiserDataTokens = PropertyTokens;
328 OrganiserData = DataReceived.begin()->second;