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