Project

Profile

Help

Bug #3952 » SchemaValidator.h

Contains workaround fix - O'Neil Delpratt, 2018-10-05 19:06

 
1
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright (c) 2015 Saxonica Limited.
3
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7

    
8
#ifndef SAXON_SCHEMA_H
9
#define SAXON_SCHEMA_H
10

    
11

    
12
#include "SaxonProcessor.h"
13
//#include "XdmValue.h"
14
//#include "XdmItem.h"
15

    
16
#include <string>
17

    
18
class SaxonProcessor;
19
class XdmValue;
20
class XdmNode;
21
class XdmItem;
22

    
23
/*! An <code>SchemaValidator</code> represents factory for validating instance documents against a schema.
24
 * <p/>
25
 */
26
class SchemaValidator {
27
public:
28
        
29
    //! Default constructor.
30
    /*!
31
      Creates Schema Validator
32
    */
33
    SchemaValidator();
34

    
35
    //! A constructor with a SaxonProcessor.
36
    /*!
37
     * The supplied processor should have license flag set to true for the Schema Validator to operate.
38
     * @param SaxonProcessor
39
     * @param cwd - set the current working directory
40
    */
41
    SchemaValidator(SaxonProcessor* proc, std::string cwd="");
42

    
43
     //! Set the Current working Directory
44
    /**
45
     * Set the current working directory for the Schema Validator
46
     * @param cwd Supplied working directory which replaces any set cwd. Ignore if cwd is NULL. 
47
    */
48
   void setcwd(const char* cwd);
49

    
50
       //! Register the schema from file name 
51
    /**
52
     * Set the current working directory for the Schema Validator
53
    * @param xsd    - File name of the schema relative to the cwd 
54
    */
55
  void registerSchemaFromFile(const char * xsd);
56

    
57
  void registerSchemaFromString(const char * schemaStr);
58

    
59
  /*!
60
   Set the name of the file where output from the validator will be sent.
61
  * @param outputFile the output file name for later use
62
 */
63
  void setOutputFile(const char * outputFile);
64

    
65

    
66
    /**
67
     * Validate an instance document by a registered schema.
68
     * @param sourceFile Name of the file to be validated. Allow null when source document is supplied
69
     * with other method
70
     */
71
  void validate(const char * sourceFile = NULL);
72
   
73
  //!Validate an instance document supplied as a Source object
74
   /**
75
  * @param sourceFile The name of the fiel to be validated. Default is NULL
76
  * @return XdmNode - the validated document returned to the calling program
77
  */
78
  XdmNode * validateToNode(const char * sourceFile = NULL);
79

    
80

    
81
     //!Set the source node for validation
82
    /**
83
     * @param source pointer to the XdmNode object
84
    */
85
    void setSourceNode(XdmNode * source);
86

    
87
     //! Get the Validation report
88
   /**
89
    * The valdiation-report option must have been set to true in the properties to use this feature.
90
    * @return XdmNode - Pointer to XdmNode. Return NULL if validation reporting feature has not been enabled
91
   */
92
    XdmNode* getValidationReport();
93

    
94

    
95
    /**
96
     * Set a parameter value used in the validator
97
     *s
98
     * @param name  of the parameter, as a string. For namespaced parameter use the JAXP solution i.e. "{uri}name"
99
     * @param value of the query parameter, or null to clear a previously set value
100
     */
101
    void setParameter(const char * name, XdmValue*value);
102

    
103

    
104
    /**
105
     * Remove a parameter (name, value) pair
106
     *
107
     * @param name  of the parameter
108
     * @return bool - outcome of the romoval
109
     */
110
    bool removeParameter(const char * name);
111
    /**
112
     * Set a property.
113
     *
114
     * @param name of the property
115
     * @param value of the property
116
     */
117
    void setProperty(const char * name, const char * value);
118

    
119
    /**
120
     * Clear parameter values set
121
     *  @param deleteValues.  Individual pointers to XdmValue objects have to be deleted in the calling program
122
     * Default behaviour (false) is to leave XdmValues in memory
123
     *  true then XdmValues are deleted
124
     */
125
    void clearParameters(bool deleteValues=false);
126

    
127
    /**
128
     * Clear property values set
129
     */
130
    void clearProperties();
131

    
132

    
133
     /**
134
      * Get all parameters as a std::map
135
     */
136
     std::map<std::string,XdmValue*>& getParameters();
137

    
138
     /**
139
      * Get all properties as a std::map 
140
     */
141
     std::map<std::string,std::string>& getProperties();
142

    
143
    /**
144
     * Checks for pending exceptions without creating a local reference to the exception object
145
     * @return bool - true when there is a pending exception; otherwise return false
146
    */
147
    bool exceptionOccurred();
148

    
149

    
150
     //! Check for exception thrown.
151
   /**
152
    * @return char*. Returns the main exception message if thrown otherwise return NULL
153
    */
154
    const char* checkException();
155

    
156
    //! Clear any exception thrown
157
    void exceptionClear();
158

    
159
     //!Get number of errors during validation of the source against the schema
160
    /**
161
     * @return int - Count of the exceptions reported during validation
162
    */
163
    int exceptionCount();
164

    
165
     //! Get the ith error message if there are any validation errors
166
    /**
167
     *  May have a number of validation errors reported against it the source.
168
     * @return char* - The message of the i'th exception 
169
    */
170
    const char * getErrorMessage(int i);
171

    
172
     //! Get the i'th error code if there are any error
173
    /**
174
     * Validation error are reported as exceptions. All errors can be retrieved.
175
     * @return char* - The error code of the i'th exception.
176
    */
177
    const char * getErrorCode(int i);
178

    
179
        void setLax(bool l){
180
                lax = l;
181
        }
182

    
183

    
184
private:
185
        bool lax;
186
        SaxonProcessor * proc;
187
        XdmItem * sourceNode;
188
        jclass  cppClass;
189
        jobject cppV;
190
        std::string cwdV; /*!< current working directory */
191
        std::string outputFile;
192
        std::map<std::string,XdmValue*> parameters; /*!< map of parameters used for the transformation as (string, value) pairs */
193
        std::map<std::string,std::string> properties; /*!< map of properties used for the transformation as (string, string) pairs */
194

    
195
};
196

    
197

    
198

    
199

    
200
#endif /* SAXON_XPATH_H */
(1-1/2)