Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #ifndef __TX_I_XPATH_CONTEXT
7 : #define __TX_I_XPATH_CONTEXT
8 :
9 : #include "txCore.h"
10 :
11 : class FunctionCall;
12 : class nsIAtom;
13 : class txAExprResult;
14 : class txResultRecycler;
15 : class txXPathNode;
16 :
17 : /*
18 : * txIParseContext
19 : *
20 : * This interface describes the context needed to create
21 : * XPath Expressions and XSLT Patters.
22 : * (not completely though. key() requires the ProcessorState, which is
23 : * not part of this interface.)
24 : */
25 :
26 0 : class txIParseContext
27 : {
28 : public:
29 0 : virtual ~txIParseContext()
30 0 : {
31 0 : }
32 :
33 : /*
34 : * Return a namespaceID for a given prefix.
35 : */
36 : virtual nsresult resolveNamespacePrefix(nsIAtom* aPrefix, int32_t& aID) = 0;
37 :
38 : /*
39 : * Create a FunctionCall, needed for extension function calls and
40 : * XSLT. XPath function calls are resolved by the Parser.
41 : */
42 : virtual nsresult resolveFunctionCall(nsIAtom* aName, int32_t aID,
43 : FunctionCall** aFunction) = 0;
44 :
45 : /**
46 : * Should nametests parsed in this context be case-sensitive
47 : */
48 : virtual bool caseInsensitiveNameTests() = 0;
49 :
50 : /*
51 : * Callback to be used by the Parser if errors are detected.
52 : */
53 : virtual void SetErrorOffset(uint32_t aOffset) = 0;
54 :
55 : enum Allowed {
56 : KEY_FUNCTION = 1 << 0
57 : };
58 0 : virtual bool allowed(Allowed aAllowed)
59 : {
60 0 : return true;
61 : }
62 : };
63 :
64 : /*
65 : * txIMatchContext
66 : *
67 : * Interface used for matching XSLT Patters.
68 : * This is the part of txIEvalContext (see below), that is independent
69 : * of the context node when evaluating a XPath expression, too.
70 : * When evaluating a XPath expression, |txIMatchContext|s are used
71 : * to transport the information from Step to Step.
72 : */
73 0 : class txIMatchContext
74 : {
75 : public:
76 0 : virtual ~txIMatchContext()
77 0 : {
78 0 : }
79 :
80 : /*
81 : * Return the ExprResult associated with the variable with the
82 : * given namespace and local name.
83 : */
84 : virtual nsresult getVariable(int32_t aNamespace, nsIAtom* aLName,
85 : txAExprResult*& aResult) = 0;
86 :
87 : /*
88 : * Is whitespace stripping allowed for the given node?
89 : * See http://www.w3.org/TR/xslt#strip
90 : */
91 : virtual nsresult isStripSpaceAllowed(const txXPathNode& aNode,
92 : bool& aAllowed) = 0;
93 :
94 : /**
95 : * Returns a pointer to the private context
96 : */
97 : virtual void* getPrivateContext() = 0;
98 :
99 : virtual txResultRecycler* recycler() = 0;
100 :
101 : /*
102 : * Callback to be used by the expression/pattern if errors are detected.
103 : */
104 : virtual void receiveError(const nsAString& aMsg, nsresult aRes) = 0;
105 : };
106 :
107 : #define TX_DECL_MATCH_CONTEXT \
108 : nsresult getVariable(int32_t aNamespace, nsIAtom* aLName, \
109 : txAExprResult*& aResult); \
110 : nsresult isStripSpaceAllowed(const txXPathNode& aNode, bool& aAllowed); \
111 : void* getPrivateContext(); \
112 : txResultRecycler* recycler(); \
113 : void receiveError(const nsAString& aMsg, nsresult aRes)
114 :
115 0 : class txIEvalContext : public txIMatchContext
116 : {
117 : public:
118 : /*
119 : * Get the context node.
120 : */
121 : virtual const txXPathNode& getContextNode() = 0;
122 :
123 : /*
124 : * Get the size of the context node set.
125 : */
126 : virtual uint32_t size() = 0;
127 :
128 : /*
129 : * Get the position of the context node in the context node set,
130 : * starting with 1.
131 : */
132 : virtual uint32_t position() = 0;
133 : };
134 :
135 : #define TX_DECL_EVAL_CONTEXT \
136 : TX_DECL_MATCH_CONTEXT; \
137 : const txXPathNode& getContextNode(); \
138 : uint32_t size(); \
139 : uint32_t position()
140 :
141 : #endif // __TX_I_XPATH_CONTEXT
|