forked from morbac/xmltools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
XmlWrapperInterface.h
162 lines (138 loc) · 5.33 KB
/
XmlWrapperInterface.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#pragma once
#include "Report.h"
#include <sstream>
#include <vector>
#include <map>
struct XPathResultEntryType {
std::wstring type;
std::wstring name;
std::wstring value;
};
struct XSLTransformResultType {
std::string data;
UniMode encoding = UniMode::uniEnd;
};
struct ErrorEntryType {
bool positioned; // true if position is revelant
size_t line; // 0-based line number having the error
size_t linepos; // 0-based position in line
size_t filepos; // 0-based position in whole stream
std::wstring reason; // error description
};
struct ErrorEntryDesc {
HWND view;
bool positioned;
size_t line;
size_t linepos;
size_t filepos;
size_t numlines;
size_t maxannotwidth;
size_t width;
size_t start; // start position of the annotation, used to hightlight the annotations
// by default the value is 0, but might change if several annotations on a same line
size_t length; // length of the annotation
int style; // annotation style
};
enum XmlCapabilityType : int {
GET_ERROR_DETAILS = 1 << 0, // the wrapped api can return errors details
CHECK_SYNTAX = 1 << 1, // the wrapped api can perform syntax check
CHECK_VALIDITY = 1 << 2, // the wrapped api can perform validity check
EVALUATE_XPATH = 1 << 3, // the wrapped api can perform xpath evaluation
XSL_TRANSFORM = 1 << 4, // the wrapped api can perform xsl transformation
ALL_OPTIONS = GET_ERROR_DETAILS | CHECK_SYNTAX | CHECK_VALIDITY | EVALUATE_XPATH | XSL_TRANSFORM
};
// Option related types
enum class OptionDataType {
OPTION_TYPE_INTEGER,
OPTION_TYPE_DOUBLE,
OPTION_TYPE_BOOLEAN,
OPTION_TYPE_STRING
};
enum class OptionFormatType {
OPTION_FORMAT_TEXT,
OPTION_FORMAT_COMBO,
OPTION_FORMAT_CHECKBOX
};
struct XmlWrapperOptionType {
std::wstring label; // the option name or label
std::wstring description; // a text describing the option
std::wstring defaultValue; // the option default value
OptionDataType type = OptionDataType::OPTION_TYPE_STRING; // the option data type
OptionFormatType format = OptionFormatType::OPTION_FORMAT_TEXT; // the option format (when displayed in options dialog)
std::map<std::string, std::string> options; // a map with value and caption of combo entries
};
/*
* This abstract class is the interface for external XML-API wrappers.
* The purpose of this interface is to define the expected methods for
* an XML-API wrapper.
*/
class XmlWrapperInterface {
protected:
std::vector<ErrorEntryType> errors;
// A map with wrapper options
std::map<std::string, XmlWrapperOptionType> options;
void resetErrors() {
this->errors.clear();
}
public:
/*
* Contructor
* @param xml A pointer on the begin of xml buffer
* @param size The xml buffer length
*/
XmlWrapperInterface(const char* xml, size_t size) {}
/* Default contructor */
XmlWrapperInterface() {}
/* Default destructor */
virtual ~XmlWrapperInterface() {
this->resetErrors();
}
/*
* Inform about the interface capabilities
* @return An integer composed of XmlCapabilityType elements
*/
virtual int getCapabilities() = 0;
/*
* Perform syntax check
* @return Return true if xml is well formed, otherwise false
*/
virtual bool checkSyntax() = 0;
/*
* Perform validity check
* @param schemaFilename Optional. A schema file path; required if schema is not declared in root element
* @param validationNamespace Optional. A validation namespace
* @return Return true if xml is valid, otherwise false
*/
virtual bool checkValidity(std::wstring schemaFilename = L"", std::wstring validationNamespace = L"") = 0;
/*
* Perform xpath evaluation
* @param xpath The expression to be evaluated
* @param ns An optional string describing the required namespaces (ex: "xmlns:npp='http://notepad-plus-plus.org' xmlns:a='another-namespace'")
* @param A vector containing all evaluation occurrences
*/
virtual std::vector<XPathResultEntryType> xpathEvaluate(std::wstring xpath, std::wstring ns = L"") = 0;
/*
* Perform xsl transformation
* @param xslfile The path of XSL transformation stylesheet
* @param out A reference to the output object; the output object is updated with transformation result
* @param options Parameters passed to transformer
* @param srcEncoding The encoding of source document
* @param The transformation result as a XSLTransformResultType object
* @return The function retruns true if transformation could be done without error; if errors occurred, it returns false
*/
virtual bool xslTransform(std::wstring xslfile, XSLTransformResultType* out, std::wstring options = L"", UniMode srcEncoding = UniMode::uniEnd) = 0;
/*
* Get errors of last executed action
* @return A vector of errors descriptions
*/
std::vector<ErrorEntryType> getLastErrors() {
return this->errors;
}
/*
* Get wrapper options
* @return A vector of wrapper options
*/
std::map<std::string, XmlWrapperOptionType> getOptions() {
return this->options;
}
};