1 #ifndef __XMPMeta_hpp__ 2 #define __XMPMeta_hpp__ 3 4 // ================================================================================================= 5 // Copyright 2003 Adobe Systems Incorporated 6 // All Rights Reserved. 7 // 8 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the terms 9 // of the Adobe license agreement accompanying it. 10 // ================================================================================================= 11 12 #include "public/include/XMP_Environment.h" 13 #include "public/include/XMP_Const.h" 14 #include "XMPCore/source/XMPCore_Impl.hpp" 15 #include "source/XMLParserAdapter.hpp" 16 17 // ------------------------------------------------------------------------------------------------- 18 19 #ifndef DumpXMLParseTree 20 #define DumpXMLParseTree 0 21 #endif 22 23 extern XMP_VarString * xdefaultName; // Needed in XMPMeta-Parse.cpp, MoveExplicitAliases. 24 25 class XMPIterator; 26 class XMPUtils; 27 28 // ------------------------------------------------------------------------------------------------- 29 30 class XMPMeta { 31 public: 32 33 static void 34 GetVersionInfo ( XMP_VersionInfo * info ); 35 36 static bool 37 Initialize(); 38 static void 39 Terminate() RELEASE_NO_THROW; 40 41 // --------------------------------------------------------------------------------------------- 42 43 XMPMeta(); 44 45 virtual ~XMPMeta() RELEASE_NO_THROW; 46 47 // --------------------------------------------------------------------------------------------- 48 49 static XMP_OptionBits 50 GetGlobalOptions(); 51 52 static void 53 SetGlobalOptions ( XMP_OptionBits options ); 54 55 // --------------------------------------------------------------------------------------------- 56 57 static XMP_Status 58 DumpNamespaces ( XMP_TextOutputProc outProc, 59 void * refCon ); 60 61 // --------------------------------------------------------------------------------------------- 62 63 static bool 64 RegisterNamespace ( XMP_StringPtr namespaceURI, 65 XMP_StringPtr suggestedPrefix, 66 XMP_StringPtr * registeredPrefix, 67 XMP_StringLen * prefixSize ); 68 69 static bool 70 GetNamespacePrefix ( XMP_StringPtr namespaceURI, 71 XMP_StringPtr * namespacePrefix, 72 XMP_StringLen * prefixSize ); 73 74 static bool 75 GetNamespaceURI ( XMP_StringPtr namespacePrefix, 76 XMP_StringPtr * namespaceURI, 77 XMP_StringLen * uriSize ); 78 79 static void 80 DeleteNamespace ( XMP_StringPtr namespaceURI ); 81 82 // --------------------------------------------------------------------------------------------- 83 84 virtual bool 85 GetProperty ( XMP_StringPtr schemaNS, 86 XMP_StringPtr propName, 87 XMP_StringPtr * propValue, 88 XMP_StringLen * valueSize, 89 XMP_OptionBits * options ) const; 90 91 virtual bool 92 GetArrayItem ( XMP_StringPtr schemaNS, 93 XMP_StringPtr arrayName, 94 XMP_Index itemIndex, 95 XMP_StringPtr * itemValue, 96 XMP_StringLen * valueSize, 97 XMP_OptionBits * options ) const; 98 99 virtual bool 100 GetStructField ( XMP_StringPtr schemaNS, 101 XMP_StringPtr structName, 102 XMP_StringPtr fieldNS, 103 XMP_StringPtr fieldName, 104 XMP_StringPtr * fieldValue, 105 XMP_StringLen * valueSize, 106 XMP_OptionBits * options ) const; 107 108 virtual bool 109 GetQualifier ( XMP_StringPtr schemaNS, 110 XMP_StringPtr propName, 111 XMP_StringPtr qualNS, 112 XMP_StringPtr qualName, 113 XMP_StringPtr * qualValue, 114 XMP_StringLen * valueSize, 115 XMP_OptionBits * options ) const; 116 117 // --------------------------------------------------------------------------------------------- 118 119 virtual void 120 SetProperty ( XMP_StringPtr schemaNS, 121 XMP_StringPtr propName, 122 XMP_StringPtr propValue, 123 XMP_OptionBits options ); 124 125 virtual void 126 SetArrayItem ( XMP_StringPtr schemaNS, 127 XMP_StringPtr arrayName, 128 XMP_Index itemIndex, 129 XMP_StringPtr itemValue, 130 XMP_OptionBits options ); 131 132 virtual void 133 AppendArrayItem ( XMP_StringPtr schemaNS, 134 XMP_StringPtr arrayName, 135 XMP_OptionBits arrayOptions, 136 XMP_StringPtr itemValue, 137 XMP_OptionBits options ); 138 139 void 140 SetStructField ( XMP_StringPtr schemaNS, 141 XMP_StringPtr structName, 142 XMP_StringPtr fieldNS, 143 XMP_StringPtr fieldName, 144 XMP_StringPtr fieldValue, 145 XMP_OptionBits options ); 146 147 virtual void 148 SetQualifier ( XMP_StringPtr schemaNS, 149 XMP_StringPtr propName, 150 XMP_StringPtr qualNS, 151 XMP_StringPtr qualName, 152 XMP_StringPtr qualValue, 153 XMP_OptionBits options ); 154 155 // --------------------------------------------------------------------------------------------- 156 157 virtual void 158 DeleteProperty ( XMP_StringPtr schemaNS, 159 XMP_StringPtr propName ); 160 161 virtual void 162 DeleteArrayItem ( XMP_StringPtr schemaNS, 163 XMP_StringPtr arrayName, 164 XMP_Index itemIndex ); 165 166 virtual void 167 DeleteStructField ( XMP_StringPtr schemaNS, 168 XMP_StringPtr structName, 169 XMP_StringPtr fieldNS, 170 XMP_StringPtr fieldName ); 171 172 virtual void 173 DeleteQualifier ( XMP_StringPtr schemaNS, 174 XMP_StringPtr propName, 175 XMP_StringPtr qualNS, 176 XMP_StringPtr qualName ); 177 178 // --------------------------------------------------------------------------------------------- 179 180 virtual bool 181 DoesPropertyExist ( XMP_StringPtr schemaNS, 182 XMP_StringPtr propName ) const; 183 184 bool 185 DoesArrayItemExist ( XMP_StringPtr schemaNS, 186 XMP_StringPtr arrayName, 187 XMP_Index itemIndex ) const; 188 189 bool 190 DoesStructFieldExist ( XMP_StringPtr schemaNS, 191 XMP_StringPtr structName, 192 XMP_StringPtr fieldNS, 193 XMP_StringPtr fieldName ) const; 194 195 bool 196 DoesQualifierExist ( XMP_StringPtr schemaNS, 197 XMP_StringPtr propName, 198 XMP_StringPtr qualNS, 199 XMP_StringPtr qualName ) const; 200 201 // --------------------------------------------------------------------------------------------- 202 203 virtual bool 204 GetLocalizedText ( XMP_StringPtr schemaNS, 205 XMP_StringPtr altTextName, 206 XMP_StringPtr genericLang, 207 XMP_StringPtr specificLang, 208 XMP_StringPtr * actualLang, 209 XMP_StringLen * langSize, 210 XMP_StringPtr * itemValue, 211 XMP_StringLen * valueSize, 212 XMP_OptionBits * options ) const; 213 214 virtual void 215 SetLocalizedText ( XMP_StringPtr schemaNS, 216 XMP_StringPtr altTextName, 217 XMP_StringPtr genericLang, 218 XMP_StringPtr specificLang, 219 XMP_StringPtr itemValue, 220 XMP_OptionBits options ); 221 222 virtual void 223 DeleteLocalizedText ( XMP_StringPtr schemaNS, 224 XMP_StringPtr altTextName, 225 XMP_StringPtr genericLang, 226 XMP_StringPtr specificLang); 227 228 // --------------------------------------------------------------------------------------------- 229 230 bool 231 GetProperty_Bool ( XMP_StringPtr schemaNS, 232 XMP_StringPtr propName, 233 bool * propValue, 234 XMP_OptionBits * options ) const; 235 236 bool 237 GetProperty_Int ( XMP_StringPtr schemaNS, 238 XMP_StringPtr propName, 239 XMP_Int32 * propValue, 240 XMP_OptionBits * options ) const; 241 242 bool 243 GetProperty_Int64 ( XMP_StringPtr schemaNS, 244 XMP_StringPtr propName, 245 XMP_Int64 * propValue, 246 XMP_OptionBits * options ) const; 247 248 bool 249 GetProperty_Float ( XMP_StringPtr schemaNS, 250 XMP_StringPtr propName, 251 double * propValue, 252 XMP_OptionBits * options ) const; 253 254 bool 255 GetProperty_Date ( XMP_StringPtr schemaNS, 256 XMP_StringPtr propName, 257 XMP_DateTime * propValue, 258 XMP_OptionBits * options ) const; 259 260 // --------------------------------------------------------------------------------------------- 261 262 void 263 SetProperty_Bool ( XMP_StringPtr schemaNS, 264 XMP_StringPtr propName, 265 bool propValue, 266 XMP_OptionBits options ); 267 268 void 269 SetProperty_Int ( XMP_StringPtr schemaNS, 270 XMP_StringPtr propName, 271 XMP_Int32 propValue, 272 XMP_OptionBits options ); 273 274 void 275 SetProperty_Int64 ( XMP_StringPtr schemaNS, 276 XMP_StringPtr propName, 277 XMP_Int64 propValue, 278 XMP_OptionBits options ); 279 280 void 281 SetProperty_Float ( XMP_StringPtr schemaNS, 282 XMP_StringPtr propName, 283 double propValue, 284 XMP_OptionBits options ); 285 286 void 287 SetProperty_Date ( XMP_StringPtr schemaNS, 288 XMP_StringPtr propName, 289 const XMP_DateTime & propValue, 290 XMP_OptionBits options ); 291 292 // --------------------------------------------------------------------------------------------- 293 294 virtual void 295 GetObjectName ( XMP_StringPtr * namePtr, 296 XMP_StringLen * nameLen ) const; 297 298 virtual void 299 SetObjectName ( XMP_StringPtr name ); 300 301 XMP_OptionBits 302 GetObjectOptions() const; 303 304 void 305 SetObjectOptions ( XMP_OptionBits options ); 306 307 virtual void 308 Sort(); 309 310 virtual void 311 Erase(); 312 313 virtual void 314 Clone ( XMPMeta * clone, XMP_OptionBits options ) const; 315 316 virtual XMP_Index 317 CountArrayItems ( XMP_StringPtr schemaNS, 318 XMP_StringPtr arrayName ) const; 319 320 virtual void 321 DumpObject ( XMP_TextOutputProc outProc, 322 void * refCon ) const; 323 324 // --------------------------------------------------------------------------------------------- 325 326 virtual void 327 ParseFromBuffer ( XMP_StringPtr buffer, 328 XMP_StringLen bufferSize, 329 XMP_OptionBits options ); 330 331 virtual void 332 SerializeToBuffer ( XMP_VarString * rdfString, 333 XMP_OptionBits options, 334 XMP_StringLen padding, 335 XMP_StringPtr newline, 336 XMP_StringPtr indent, 337 XMP_Index baseIndent ) const; 338 339 // --------------------------------------------------------------------------------------------- 340 341 static void 342 SetDefaultErrorCallback ( XMPMeta_ErrorCallbackWrapper wrapperProc, 343 XMPMeta_ErrorCallbackProc clientProc, 344 void * context, 345 XMP_Uns32 limit ); 346 347 virtual void 348 SetErrorCallback ( XMPMeta_ErrorCallbackWrapper wrapperProc, 349 XMPMeta_ErrorCallbackProc clientProc, 350 void * context, 351 XMP_Uns32 limit ); 352 353 virtual void 354 ResetErrorCallbackLimit ( XMP_Uns32 limit ); 355 356 class ErrorCallbackInfo : public GenericErrorCallback { 357 public: 358 359 XMPMeta_ErrorCallbackWrapper wrapperProc; 360 XMPMeta_ErrorCallbackProc clientProc; 361 void * context; 362 ErrorCallbackInfo()363 ErrorCallbackInfo() : wrapperProc(0), clientProc(0), context(0) {}; 364 Clear()365 void Clear() { this->wrapperProc = 0; this->clientProc = 0; this->context = 0; 366 GenericErrorCallback::Clear(); }; 367 368 bool CanNotify() const; 369 bool ClientCallbackWrapper ( XMP_StringPtr filePath, XMP_ErrorSeverity severity, XMP_Int32 cause, XMP_StringPtr messsage ) const; 370 }; 371 372 // ============================================================================================= 373 374 // --------------------------------------------------------------------------------------------- 375 // - Everything is built out of standard nodes. Each node has a name, value, option flags, a 376 // vector of child nodes, and a vector of qualifier nodes. 377 // 378 // - The option flags are those passed to SetProperty and returned from GetProperty. They tell 379 // if the node is simple, a struct or an array; whether it has qualifiers, etc. 380 // 381 // - The name of the node is an XML qualified name, of the form "prefix:simple-name". Since we 382 // force all namespaces to be known and to have unique prefixes, this is semantically equivalent 383 // to using a URI and simple name pair. 384 // 385 // - Although the value part is only for leaf properties and the children part is only for 386 // structs and arrays, it is easier to simply have them in every node. This keeps things visible 387 // so that debugging is easier 388 // 389 // - The top level node children are the namespaces that contain properties, the next level are 390 // the top level properties, lower levels are the fields of structs or items of arrays. The name 391 // of the top level nodes is just the namespace prefix, with the colon terminator. The name of 392 // top level properties includes the namespace prefix. 393 // 394 // - Any property node, at any level, can have qualifiers. These are themselves general property 395 // nodes. And could in fact themselves have qualifiers! 396 397 // ! Expose the implementation so that file static functions can see the data. 398 399 XMP_Int32 clientRefs; // ! Must be signed to allow decrement from 0. 400 XMP_ReadWriteLock lock; 401 402 // ! Any data member changes must be propagted to the Clone function! 403 404 XMP_Node tree; 405 XMLParserAdapter * xmlParser; 406 ErrorCallbackInfo errorCallback; 407 408 friend class XMPIterator; 409 friend class XMPUtils; 410 411 private: 412 413 // ! These are hidden on purpose: XMPMeta(const XMPMeta &)414 XMPMeta ( const XMPMeta & /* original */ ) : tree(XMP_Node(0,"",0)), clientRefs(0), xmlParser(0) 415 { XMP_Throw ( "Call to hidden constructor", kXMPErr_InternalFailure ); }; operator =(const XMPMeta &)416 void operator= ( const XMPMeta & /* rhs */ ) 417 { XMP_Throw ( "Call to hidden operator=", kXMPErr_InternalFailure ); }; 418 419 // Special support routines for parsing, here to be able to access the errorCallback. 420 void ProcessXMLTree ( XMP_OptionBits options ); 421 bool ProcessXMLBuffer ( XMP_StringPtr buffer, XMP_StringLen xmpSize, bool lastClientCall ); 422 void ProcessRDF ( const XML_Node & xmlTree, XMP_OptionBits options ); 423 424 }; // class XMPMeta 425 426 // ================================================================================================= 427 428 #endif // __XMPMeta_hpp__ 429