-
Notifications
You must be signed in to change notification settings - Fork 56
WJElement Schema
WJElement provides selection and validation using json-schema.
Note:
Json-schema draft 3 is fully supported.
Draft 4 support is in-progress and partially working. (Patches are welcome!)
Callbacks:
typedef WJElement (* WJESchemaLoadCB)(const char *name, void *client, const char *file, const int line);
typedef void (* WJESchemaFreeCB)(WJElement schema, void *client);
typedef void (* WJESchemaMatchCB)(WJElement schema, const char *selector, void *client);
typedef void (* WJEErrCB)(void *client, const char *format, ...);
WJESchemaLoadCB callbacks are used to fetch schema as needed. WJESchemaFreeCB are called when schema is no longer needed.
WJESchemaValidate - Validate a document against a given schema.
XplBool WJESchemaValidate(WJElement schema, WJElement document,
WJEErrCB err, WJESchemaLoadCB load,
WJESchemaFreeCB freecb, void *client);
Additional schema will be loaded via the load callback if needed. Any validation errors will be reported, printf-style, to errcb.
If a the load callback is used to acquire schema but a NULL free callback is provided, WJECloseDocument will be used internally to release it.
WJESchemaIsType - Determine if a document implements a specific schema.
XplBool WJESchemaIsType(WJElement document, const char *type,
WJESchemaLoadCB loadcb, WJESchemaFreeCB freecb,
void *client);
Additional schema will be loaded via the load callback if needed.
If a load callback is not provided then the object type will still be checked but it will not be considered a match if it is a type that extends the specifed type.
WJESchemaNameIsType - variation of WJESchemaIsType which acts on schema name instead of a document
XplBool WJESchemaNameIsType(const char *describedby, const char *type,
WJESchemaLoadCB loadcb,
WJESchemaFreeCB freecb, void *client);
WJESchemaGetSelectors - find type/format-matching properties
void WJESchemaGetSelectors(WJElement document,
char *type, char *format,
WJESchemaLoadCB load,
WJESchemaFreeCB freecb,
WJESchemaMatchCB matchcb, void *client);
WJESchemaGetSelectors calls back matchcb for each WJElement selector which will fetch a property of a given type and format, from a given document. The load callback will be used to load all necessary schema, starting with the document's "describedby". stripat-type wildcards may be used; "Date*" will find "date" and "date-time".
WJESchemaGetAllSelectors - variation of WJESchemaGetSelectors which provides selectors that could exist in objects of the given "describedby" schema name
void WJESchemaGetAllSelectors(char *describedby,
char *type, char *format,
WJESchemaLoadCB load,
WJESchemaFreeCB freecb,
WJESchemaMatchCB matchcb, void *client);
WJESchemaFindBacklink - find "backlink" property by schema
char * WJESchemaFindBacklink(WJElement document, const char *format,
WJESchemaLoadCB loadcb, WJESchemaFreeCB freecb,
void *client);
WJESchemaNameFindBacklink - find "backlink" property by name
char * WJESchemaNameFindBacklink(char *describedby, const char *format,
WJESchemaLoadCB loadcb, WJESchemaFreeCB freecb,
void *client);
WJESchemaFreeBacklink - clean up a previously-found backlink
void WJESchemaFreeBacklink(char *backlink);