SaxonC 12.7.0
Saxon Processor library for C/C++, PHP and Python
Loading...
Searching...
No Matches
SaxonProcessor.h
1
2// Copyright (c) 2022 - 2023 Saxonica Limited.
3// This Source Code Form is subject to the terms of the Mozilla Public License,
4// v. 2.0. If a copy of the MPL was not distributed with this file, You can
5// obtain one at http://mozilla.org/MPL/2.0/. This Source Code Form is
6// "Incompatible With Secondary Licenses", as defined by the Mozilla Public
7// License, v. 2.0.
9
10#ifndef SAXON_PROCESSOR_H
11#define SAXON_PROCESSOR_H
12
13#if defined __linux__ || defined __APPLE__
14
15#include <dlfcn.h>
16#include <stdlib.h>
17#include <string>
18
19#define HANDLE void *
20#define LoadLibrary(x) dlopen(x, RTLD_LAZY)
21#define GetProcAddress(x, y) dlsym(x, y)
22#else
23#include <windows.h>
24#endif
25
26//#define DEBUG //remove
27//#define MEM_DEBUG //remove
28#define CVERSION_API_NO 1210
29
30#include <iostream>
31#include <map>
32#include <sstream>
33#include <stdexcept> // std::logic_error
34#include <string>
35#include <vector>
36
37#include "saxonc_export.h"
38#include "saxonc/DocumentBuilder.h"
39#include "saxonc/SaxonApiException.h"
40#include "saxonc/SaxonCGlue.h"
41#include "saxonc/SaxonCXPath.h"
42#include "saxonc/SchemaValidator.h"
43#include "saxonc/XPathProcessor.h"
44#include "saxonc/XQueryProcessor.h"
45#include "saxonc/Xslt30Processor.h"
46#include "saxonc/XsltExecutable.h"
47
48
49//#define MEM_DEBUG
50#if defined MEM_DEBUG
51
52#include <algorithm>
53#include <cstdlib>
54#include <new>
55
56static std::vector<void *> myAlloc;
57
58void *newImpl(std::size_t sz, char const *file, int line);
59
60void *operator new(std::size_t sz, char const *file, int line);
61
62void *operator new[](std::size_t sz, char const *file, int line);
63
64void operator delete(void *ptr) noexcept;
65
66void operator delete(void *, std::size_t) noexcept;
67
68#endif
69
70class Xslt30Processor;
71
72class XQueryProcessor;
73
74class XPathProcessor;
75
76class SchemaValidator;
77
78class XdmValue;
79
80class XdmNode;
81
82class XdmItem;
83
84class XdmAtomicValue;
85
86class XdmFunctionItem;
87
88class XdmArray;
89
90class XdmMap;
91
92class XsltExecutable;
93
94class DocumentBuilder;
95
97
98typedef enum eXdmType {
99 XDM_VALUE = 0,
100 XDM_ATOMIC_VALUE = 1,
101 XDM_NODE = 2,
102 XDM_ARRAY = 3,
103 XDM_MAP = 4,
104 XDM_FUNCTION_ITEM = 5,
105 XDM_EMPTY = 6,
106 XDM_ITEM = 7,
107} XDM_TYPE;
108
109//==========================================
110
117class SAXONC_EXPORT SaxonProcessor {
118
119 friend class DocumentBuilder;
120
121 friend class Xslt30Processor;
122
123 friend class XsltExecutable;
124
125 friend class XQueryProcessor;
126
127 friend class SchemaValidator;
128
129 friend class XPathProcessor;
130
131 friend class XdmValue;
132
133 friend class XdmItem;
134
135 friend class XdmAtomicValue;
136
137 friend class XdmFunctionItem;
138
139 friend class XdmNode;
140
141 friend class XdmMap;
142
143 friend class XdmArray;
144
145public:
153
160 SaxonProcessor(const char *configFile);
161
168 SaxonProcessor(bool l);
169
175 SaxonProcessor &operator=(const SaxonProcessor &other);
176
181 SaxonProcessor(const SaxonProcessor &other);
182
187
194 const char *getErrorMessage();
195
202 DocumentBuilder *newDocumentBuilder();
203
210 Xslt30Processor *newXslt30Processor();
211
218 XQueryProcessor *newXQueryProcessor();
219
226 XPathProcessor *newXPathProcessor();
227
234 SchemaValidator *newSchemaValidator();
235
236
237 void setExtensionLibrary(const char * libraryName);
238
246 XdmAtomicValue *makeStringValue(std::string str,
247 const char *encoding = nullptr);
248
256 XdmAtomicValue *makeStringValue(const char *str,
257 const char *encoding = nullptr);
258
267 XdmAtomicValue *makeIntegerValue(int i);
268
274 XdmAtomicValue *makeDoubleValue(double d);
275
281 XdmAtomicValue *makeFloatValue(float f);
282
291 XdmAtomicValue *makeLongValue(long l);
292
298 XdmAtomicValue *makeBooleanValue(bool b);
299
305 XdmAtomicValue *makeQNameValue(const char *str);
306
314 XdmAtomicValue *makeAtomicValue(const char *type, const char *value);
315
323 XdmArray *makeArray(char **input, int length);
324
332 XdmArray *makeArray(short *input, int length);
333
341 XdmArray *makeArray(int *input, int length);
342
350 XdmArray *makeArray(long long *input, int length);
351
359 XdmArray *makeArray(bool *input, int length);
360
368 XdmArray *makeArray(XdmValue **values, int length);
369
370
371 static void * makeInternalArray(void **inputs, int length);
372
380 XdmMap *makeMap(std::map<XdmAtomicValue *, XdmValue *> dataMap);
381
389 static XdmMap *makeMap2(std::map<std::string, XdmValue *> dataMap);
390
399 XdmMap *makeMap3(XdmAtomicValue **keys, XdmValue **values, int len);
400
412 const char *clarkNameToEQName(const char *name);
413
421 const char *EQNameToClarkName(const char *name);
422
428 const char *getStringValue(XdmItem *item);
429
441 XdmNode *parseXmlFromString(const char *source,
442 const char *encoding = nullptr,
443 SchemaValidator *validator = nullptr);
444
454 XdmNode *parseXmlFromFile(const char *source,
455 SchemaValidator *validator = nullptr);
456
466 XdmNode *parseXmlFromUri(const char *source,
467 SchemaValidator *validator = nullptr);
468
477 XdmValue *parseJsonFromString(const char *source,
478 const char *encoding = NULL);
479
488 XdmValue *parseJsonFromFile(const char *source);
489
495 int getNodeKind(int64_t obj);
496
502 bool isSchemaAwareProcessor();
503
509 bool exceptionOccurred();
510
517 void exceptionClear();
518
522 XdmValue **createXdmValueArray(int len) { return (new XdmValue *[len]); }
523
530 void deleteXdmValueArray(XdmValue **arr, int len);
531
536 return (new XdmAtomicValue *[len]);
537 }
538
545 void deleteXdmAtomicValueArray(XdmAtomicValue **arr, int len);
546
551 static SaxonApiException *checkForExceptionCPP(
552 /*JNIEnv *env, jclass callingClass, jobject callingObject*/);
553
554
558 static const char * encodeString(const char * stringValue, const char * toCharSetName);
559
563 static void release();
564
568 static void attachCurrentThread();
569
573 static void detachCurrentThread();
574
579 void setcwd(const char *cwd);
580
585 const char *getcwd();
586
591 const char *getResourcesDirectory();
592
597 void setResourcesDirectory(const char *dir);
598
605 void setCatalog(const char *catalogFile);
606
613 void setCatalogFiles(const char **catalogFiles, int length);
614
623 void setConfigurationProperty(const char *name, const char *value);
624
628 void clearConfigurationProperties();
629
634 bool isLicensed();
635
643 const char * getSaxonEdition();
644
649 const char *version();
650
651
652 static int jvmCreatedCPP;
654 static sxnc_environment
657 std::string cwd;
663 static void deleteString(const char *data) {
664 if (data != nullptr) {
665 operator delete((char *)data);
666 data = nullptr;
667 }
668 }
669
673 void createHeapDump(bool live);
674
675
676 /*static JavaVM *jvm;*/
677
678protected:
679 // jclass xdmAtomicClass; /*!< The XdmAtomicValue instance */
680 // jclass versionClass; /*!< The Version instance */
681 // jclass procClass; /*!< The Saxon Processor instance */
682 // jclass saxonCAPIClass; /*!< The SaxonCAPI instance */
683 std::string cwdV;
684 // std::string resources_dir; /*!< Saxon resources directory */
685 std::string versionStr;
686 std::map<std::string, XdmValue *>
689 //std::map<std::string, std::string>
690 // configProperties; /*!< Map of properties used for the transformation as
691 // (string, string) pairs */
692 bool licensei;
695 int64_t procRef;
697 // JNINativeMethod *nativeMethods; /*!< native methods variable used in
698 // extension methods */ std::vector<JNINativeMethod> nativeMethodVect; /*!<
699 // Vector of native methods defined by user */
704private:
705 // void createException(const char *message = nullptr);
706
707 void initialize(bool l);
708
709 void applyConfigurationProperties();
710
711 // SaxonC method for internal use
712 static int64_t
713 createParameterJArray(std::map<std::string, XdmValue *> parameters,
714 std::map<std::string, std::string> properties,
715 int additions = 0);
716
717 static int64_t
718 createParameterJArray2(std::map<std::string, XdmValue *> parameters);
719
720 static int64_t createJArray(XdmValue **values, int length);
721
722 static XdmValue *makeXdmValueFromRef(int64_t valueRef);
723
724 static XdmItem *makeXdmItemFromRef(int64_t valueRef);
725
726 static const char *checkException();
727
731 static void destroyHandle(int64_t handleRef);
732
736 static void getInfo();
737};
738
739//===============================================================================================
740
741#endif /* SAXON_PROCESSOR_H */
This C header file contains a number of factory functions for running SaxonC C/C++ APIs,...
EXTERN_SAXONC SAXONC_EXPORT const char * version(sxnc_environment *environi, sxnc_processor *proc)
Get the Saxon version.
Definition SaxonCProcessor.c:6
SAXONC_EXPORT void setCatalog(sxnc_environment *environi, sxnc_processor *proc, char *cwd, char *catalogFileName)
Set a catalog file to be used in Saxon.
Definition SaxonCProcessor.c:49
SAXONC_EXPORT void setCatalogFiles(sxnc_environment *environi, sxnc_processor *proc, char *cwd, char **catalogFileName, int length)
Set multiple catalog files to be used in Saxon.
Definition SaxonCProcessor.c:67
SAXONC_EXPORT void setConfigurationProperty(sxnc_environment *environi, sxnc_processor *proc, char *name, char *value)
Set a configuration property specific to the processor in use.
Definition SaxonCProcessor.c:38
SaxonCXPath.h provides the C API for XPath processing. This file contains a set of functions to compi...
SAXONC_EXPORT const char * getStringValue(sxnc_environment *environi, sxnc_value value)
Get the string value of the item.
Definition SaxonCXPath.c:223
A document builder holds properties controlling how a Saxon document tree should be built,...
Definition DocumentBuilder.h:35
SaxonApiException.
Definition SaxonApiException.h:24
The SaxonProcessor class acts as a factory for generating XQuery, XPath, Schema and XSLT compilers.
Definition SaxonProcessor.h:117
std::string cwdV
Definition SaxonProcessor.h:683
static sxnc_environment * sxn_environ
Definition SaxonProcessor.h:655
std::map< std::string, XdmValue * > parameters
Definition SaxonProcessor.h:687
XdmValue ** createXdmValueArray(int len)
Utility method for working with SaxonC on Python - internal use only.
Definition SaxonProcessor.h:522
XdmAtomicValue ** createXdmAtomicValueArray(int len)
Utility method for working with SaxonC on Python - internal use only.
Definition SaxonProcessor.h:535
std::string cwd
Definition SaxonProcessor.h:657
std::string versionStr
Definition SaxonProcessor.h:685
bool licensei
Definition SaxonProcessor.h:692
static void deleteString(const char *data)
Utility method required for the python and PHP extensions to delete a string created in the C++ code-...
Definition SaxonProcessor.h:663
SaxonApiException * exception
Definition SaxonProcessor.h:701
static int jvmCreatedCPP
Definition SaxonProcessor.h:652
int64_t procRef
Definition SaxonProcessor.h:695
Definition SchemaValidator.h:26
An XPathProcessor represents a factory to compile, load and execute XPath expressions.
Definition XPathProcessor.h:64
An XQueryProcessor represents a factory to compile, load and execute queries.
Definition XQueryProcessor.h:25
An array in the XDM data model.
Definition XdmArray.h:27
The class XdmAtomicValue represents an item in an XPath sequence that is an atomic value.
Definition XdmAtomicValue.h:27
The class XdmFunctionItem represents a function item.
Definition XdmFunctionItem.h:26
The class XdmItem represents an item in a sequence, as defined by the XDM data model.
Definition XdmItem.h:31
A map in the XDM data model.
Definition XdmMap.h:30
This class represents a node in the XDM data model.
Definition XdmNode.h:57
An XdmValue represents a value in the XDM data model.
Definition XdmValue.h:43
An Xslt30Processor represents a factory to compile, load and execute stylesheets.
Definition Xslt30Processor.h:29
An XsltExecutable represents the compiled form of a stylesheet.
Definition XsltExecutable.h:30
sxnc_environment.
Definition SaxonCGlue.h:80