2 * The contents of this file are subject to the Mozilla Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/MPL/
7 * Software distributed under the License is distributed on an "AS
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 * implied. See the License for the specific language governing
10 * rights and limitations under the License.
12 * The Original Code is the Sablotron XSLT Processor.
14 * The Initial Developer of the Original Code is Ginger Alliance Ltd.
15 * Portions created by Ginger Alliance are Copyright (C) 2000-2002
16 * Ginger Alliance Ltd. All Rights Reserved.
20 * Alternatively, the contents of this file may be used under the
21 * terms of the GNU General Public License Version 2 or later (the
22 * "GPL"), in which case the provisions of the GPL are applicable
23 * instead of those above. If you wish to allow use of your
24 * version of this file only under the terms of the GPL and not to
25 * allow others to use your version of this file under the MPL,
26 * indicate your decision by deleting the provisions above and
27 * replace them with the notice and other provisions required by
28 * the GPL. If you do not delete the provisions above, a recipient
29 * may use your version of this file under either the MPL or the
33 #define SablotAsExport
36 #include "domprovider.h"
41 #define SIT(S) (*(Situation*)S)
42 #define QC(Q) (*(QueryContextClass*)Q)
45 // SablotRegDOMHandler
48 void SXP_registerDOMHandler(SablotSituation S, DOMHandler *domh, void* udata)
50 SIT(S).setDOMProvider(domh, udata);
53 void SXP_unregisterDOMHandler(SablotSituation S)
55 SIT(S).setDOMProvider(NULL, NULL);
60 * QueryContext functions
64 void SXP_setOptions(SablotSituation S, unsigned long options)
66 SIT(S).setSXPOptions(options);
69 unsigned long SXP_getOptions(SablotSituation S)
71 return SIT(S).getSXPOptions();
74 void SXP_setMaskBit(SablotSituation S, int mask)
76 SIT(S).setSXPMaskBit(mask);
79 int SXP_createQueryContext(SablotSituation S, QueryContext *Q)
81 *Q = new QueryContextClass(SIT(S));
85 int SXP_addVariableNumber(QueryContext Q,
86 const SXP_char* name, double value)
88 GP( Expression ) e = QC(Q).getNewExpr();
89 (*e).setAtom(Number(value));
90 if (! QC(Q).addVariableExpr(name, e))
92 return QC(Q).getError();
95 int SXP_addVariableString(QueryContext Q,
96 const SXP_char* name, const SXP_char* value)
98 GP( Expression ) e = QC(Q).getNewExpr();
99 (*e).setAtom(Str((char*)value));
100 if (! QC(Q).addVariableExpr(name, e))
102 return QC(Q).getError();
105 int SXP_addVariableBoolean(QueryContext Q,
106 const SXP_char* name, int value)
108 GP( Expression ) e = QC(Q).getNewExpr();
109 (*e).setAtom(value ? TRUE : FALSE);
110 if (! QC(Q).addVariableExpr(name, e))
112 return QC(Q).getError();
115 int SXP_addVariableBinding(QueryContext Q,
116 const SXP_char* name, QueryContext source)
118 QC(Q).addVariableBinding(name, QC(source));
119 return QC(Q).getError();
122 int SXP_addNamespaceDeclaration(QueryContext Q,
123 const SXP_char* prefix, const SXP_char* uri)
125 QC(Q).addNamespaceDeclaration(prefix, uri);
126 return QC(Q).getError();
129 int SXP_query(QueryContext Q, const SXP_char* queryText,
130 SXP_Node n, int contextPosition, int contextSize)
132 QC(Q).query(queryText, n, contextPosition, contextSize);
133 return QC(Q).getError();
136 int SXP_destroyQueryContext(QueryContext Q)
138 delete (QueryContextClass*)Q;
144 * Functions to retrieve the query result and its type
148 int SXP_getResultType(QueryContext Q, SXP_ExpressionType *type)
150 *type = QC(Q).getType();
154 int SXP_getResultNumber(QueryContext Q, double *result)
156 *result = (double)(*(QC(Q).getNumber()));
160 int SXP_getResultBool(QueryContext Q, int *result)
162 *result = QC(Q).getBoolean();
166 int SXP_getResultString(QueryContext Q, const char **result)
168 *result = (char*)(*(QC(Q).getString()));
172 int SXP_getResultNodeset(QueryContext Q, SXP_NodeList *result)
174 *result = (SXP_NodeList)(QC(Q).getNodeset());
180 * NodeList manipulation
184 int SXP_getNodeListLength(SXP_NodeList l)
186 return ((Context*)l) -> getSize();
189 SXP_Node SXP_getNodeListItem(QueryContext Q, SXP_NodeList l, int index)
191 int count = SXP_getNodeListLength(l);
192 if (index < 0 || index >= count)
196 NodeHandle n = (*((Context*)l))[index];
197 int bit = QC(Q).getSituation().getSXPMaskBit();
198 return SXP_UNMASK_LEVEL(n, bit);