00001 00020 #ifndef INCL_VIRTUAL_OBJECT 00021 #define INCL_VIRTUAL_OBJECT 00022 00024 #include "VProperty.h" 00025 00026 00027 00028 /* 00029 * ************************************* Class VObject ********************************************* 00030 * ************************************************************************************************* 00031 * A VObject object rapresents an item that can be a vCard, a vCalendar or vTodo. 00032 * A VObject contains an array of VProperty, each one rapresents a property. 00033 * A property is the definition of an individual attribute describing the vCard/vCal/vTodo. 00034 * Each property has a name, an array of parameters and an array of values, 00035 * for example, the property: 00036 * 00037 * TEL;HOME:+1-919-555-1234 00038 * 00039 * has name 'TEL', one parameter 'HOME' and one value '+1-919-555-1234' 00040 * 00041 * Some properties have more than one parameter, each parameter is a pair: (name, value). 00042 * Use VProperty::add/getParameter() methods to access them. 00043 * 00044 * Some properties have more than one value, each value is a string of text. 00045 * Values MUST be inserted in the right order (as vCard specific). 00046 * Use VProperty::add/getValue() methods to access them. 00047 * Note: 00048 * If one of these value is not present, it must be inserted however as 00049 * an empty string, to make sure the right order is respected. 00050 * 00051 * 00052 * Properties with more than one value are: 00053 * 00054 * Property name 1^value 2^value 3^value 4^value 5^value 6^value 7^value 00055 * ---------------------------------------------------------------------------------------------------------------------------------- 00056 * Name -> N: <LastName> <FirstName> <MiddleName> <Title> <Suffix> 00057 * Address -> ADR: <Post Office> <Extended Addr> <Street> <City> <State> <PostalCode> <Country> 00058 * Audio Alarm -> AALARM: <RunTime> <Snooze Time> <Repeat Count> <Audio Content> 00059 * 00060 * 00061 * Property values should be added as simple text, Quoted-Printable and BASE64 encodings are 00062 * automatically managed inside VObject. Also the escaping of special chars is 00063 * automatically managed inside VObject. 00064 * Escaped chars for v.2.1: ";" "\" 00065 * Escaped chars for v.3.0: ";" "\" "," 00066 * Use VObject::toString() method to obtain the correspondent vCard/vCal/vTodo. 00067 * 00068 * 00069 * To set Quoted-Printable / Base64 encoding for a property: 00070 * ========================================================= 00071 * QP and B64 encodings are automatically managed inside VObject. This means that 00072 * data conversion is performed inside VObject, to force data encoding 00073 * just add the encoding parameter to the VProperty, calling: 00074 * 00075 * for QP: VProperty->addParameter(TEXT("ENCODING"), TEXT("QUOTED-PRINTABLE")) 00076 * for B64: VProperty->addParameter(TEXT("ENCODING"), TEXT("b")) 00077 * 00078 * Note that QP encoding is used only for vCard v.2.1 (not allowed in v.3.0). 00079 * If a property contains characters that cannot be managed with the default 00080 * 7bit encoding, it is encoded automatically with QP (v.2.1) or B64 (v.3.0). 00081 * 00082 */ 00083 00084 00085 class VObject { 00086 00087 private: 00088 00089 WCHAR* version; 00090 WCHAR* productID; 00091 ArrayList* properties; 00092 void set(WCHAR**, const WCHAR*); 00093 00094 public: 00095 00096 VObject(); 00097 VObject(const WCHAR* prodID, const WCHAR* ver); 00098 ~VObject(); 00099 void setVersion (const WCHAR* ver); 00100 void setProdID (const WCHAR* prodID); 00101 WCHAR* getVersion(); 00102 WCHAR* getProdID(); 00103 void addProperty(VProperty* property); 00104 void addFirstProperty(VProperty* property); 00105 void insertProperty(VProperty* property); 00106 bool removeProperty(int index); 00107 void removeProperty(WCHAR* propName); 00108 void removeAllProperies(WCHAR* propName); 00109 //removes all properties having name - propName; 00110 bool containsProperty(const WCHAR* propName); 00111 int propertiesCount(); 00112 VProperty* getProperty(int index); 00113 VProperty* getProperty(const WCHAR* propName); 00114 WCHAR* toString(); 00115 00116 #ifdef VOCL_ENCODING_FIX 00117 00118 // Patrick Ohly: 00119 // 00120 // Normally the class does not change the encoding 00121 // of properties. That means that users of this class 00122 // have to be prepared to handle e.g. quoted-printable 00123 // encoding of non-ASCII characters or \n as line break 00124 // in vCard 3.0. 00125 // 00126 // This function decodes all property strings into the 00127 // native format. It supports: 00128 // - decoding quoted-printable characters if 00129 // ENCODING=QUOTED-PRINTABLE 00130 // - replacement of \n with a line break and \, with 00131 // single comma if version is 3.0 00132 // 00133 // It does not support charset conversions, so everything 00134 // has to be UTF-8 to work correctly. 00135 // 00136 // This function does not modify the property parameters, 00137 // so one could convert back into the original format. 00138 // 00139 // Consider this function a hack: at this time it is not 00140 // clear how the class is supposed to handle different 00141 // encodings, but I needed a solution, so here it is. 00142 // 00143 void toNativeEncoding(); 00144 00145 // 00146 // Converts properties in native format according to 00147 // their parameters. 00148 // 00149 // It only supports: 00150 // - replacement of line breaks and commas (if 3.0) 00151 // 00152 // It does not support any charsets or encoding. 00153 // ENCODING=QUOTED-PRINTABLE will be removed because 00154 // it no longer applies when toNativeEncoding() was 00155 // used before, but the other parameters are preserved: 00156 // this might be good enough to recreate the original 00157 // object. 00158 // 00159 void fromNativeEncoding(); 00160 00162 #endif 00163 00164 }; 00165 00166 00168 #endif