Project

Profile

Help

How to connect?
Download (6.83 KB) Statistics
| Branch: | Revision:

he / src / main / c / Saxon.C.API / SchemaValidator.h @ 6af44631

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 nullptr.
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
  //! Export a precompiled Schema Component Model containing all the components (except built-in components) that have been loaded by using the register methods.
60
  /**
61
  *
62
  */
63
  void exportSchema(const char * fileName);
64

    
65
  /*!
66
   Set the name of the output file that will be used by the validator.
67
  * @param outputFile the output file name for later use
68
 */
69
  void setOutputFile(const char * outputFile);
70

    
71

    
72
    /**
73
     * Validate an instance document by a registered schema.
74
     * @param sourceFile Name of the file to be validated. Allow nullptr when source document is supplied
75
     * with other method
76
     */
77
  void validate(const char * sourceFile = nullptr);
78
   
79
  //!Validate an instance document supplied as a Source object
80
   /**
81
  * @param sourceFile The name of the file to be validated. Default is nullptr
82
  * @return XdmNode - the validated document returned to the calling program
83
  */
84
  XdmNode * validateToNode(const char * sourceFile = nullptr);
85

    
86

    
87
     //!Set the source node for validation
88
    /**
89
     * @param The source document supplied as an XdmNode, which will be used to validate against the schema using the validate methods.
90
    */
91
    void setSourceNode(XdmNode * source);
92

    
93
     //! Get the Validation report
94
   /**
95
    * The valdiation-report option must have been set to true in the properties to use this feature.
96
    * @return XdmNode - Pointer to XdmNode. Return nullptr if validation reporting feature has not been enabled
97
   */
98
    XdmNode* getValidationReport();
99

    
100

    
101
    /**
102
     * Set a parameter value used in the validator
103
     *s
104
     * @param name  of the parameter, as a string. For namespaced parameter use the JAXP solution i.e. "{uri}name"
105
     * @param value of the query parameter, or nullptr to clear a previously set value
106
     */
107
    void setParameter(const char * name, XdmValue*value);
108

    
109

    
110
    /**
111
     * Remove a parameter (name, value) pair
112
     *
113
     * @param name  of the parameter
114
     * @return bool - outcome of the romoval
115
     */
116
    bool removeParameter(const char * name);
117
    /**
118
     * Set a property.
119
     *
120
     * @param name of the property
121
     * @param value of the property
122
     */
123
    void setProperty(const char * name, const char * value);
124

    
125
    /**
126
     * Clear parameter values set
127
     *  @param deleteValues.  Individual pointers to XdmValue objects have to be deleted in the calling program
128
     * Default behaviour (false) is to leave XdmValues in memory
129
     *  true then XdmValues are deleted
130
     */
131
    void clearParameters(bool deleteValues=false);
132

    
133
    /**
134
     * Clear property values set
135
     */
136
    void clearProperties();
137

    
138

    
139
     /**
140
      * Get all parameters as a std::map
141
     */
142
     std::map<std::string,XdmValue*>& getParameters();
143

    
144
     /**
145
      * Get all properties as a std::map 
146
     */
147
     std::map<std::string,std::string>& getProperties();
148

    
149
    /**
150
     * Checks for pending exceptions without creating a local reference to the exception object
151
     * @return bool - true when there is a pending exception; otherwise return false
152
    */
153
    bool exceptionOccurred();
154

    
155

    
156
     //! Check for exception thrown.
157
   /**
158
    * @return char*. Returns the main exception message if thrown otherwise return nullptr
159
    */
160
    const char* checkException();
161

    
162
    //! Clear any exception thrown
163
    void exceptionClear();
164

    
165
     //!Get number of errors during validation of the source against the schema
166
    /**
167
     * @return int - Count of the exceptions reported during validation
168
    */
169
    //int exceptionCount();
170

    
171
     //! Get the ith error message if there are any validation errors
172
    /**
173
     *  May have a number of validation errors reported against it the source.
174
     * @return char* - The message of the i'th exception 
175
    */
176
    const char * getErrorMessage(int i);
177

    
178
     //! Get the i'th error code if there are any error
179
    /**
180
     * Validation error are reported as exceptions. All errors can be retrieved.
181
     * @return char* - The error code of the i'th exception.
182
    */
183
    const char * getErrorCode(int i);
184

    
185
     //! The validation mode may be either strict or lax.
186
    /**
187
     * The default is strict; this method may be called
188
     * to indicate that lax validation is required. With strict validation, validation fails if no element
189
     * declaration can be located for the outermost element. With lax validation, the absence of an
190
     * element declaration results in the content being considered valid.
191
     * @param lax true if validation is to be lax, false if it is to be strict
192
    */
193
    void setLax(bool l){
194
      lax = l;
195
    }
196

    
197

    
198
private:
199
    bool lax;
200
        SaxonProcessor * proc;
201
        XdmItem * sourceNode;
202
        jclass  cppClass;
203
        jobject cppV;
204
        std::string cwdV; /*!< current working directory */
205
        std::string outputFile;
206
        std::map<std::string,XdmValue*> parameters; /*!< map of parameters used for the transformation as (string, value) pairs */
207
        std::map<std::string,std::string> properties; /*!< map of properties used for the transformation as (string, string) pairs */
208
    SaxonApiException * exception;
209
};
210

    
211

    
212

    
213

    
214
#endif /* SAXON_XPATH_H */
(17-17/51)