summaryrefslogtreecommitdiffstats
path: root/dom/xslt/xpath/txIXPathContext.h
blob: 8d5b5df4becefcbe4de01426553cb67aa379bd62 (plain)
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
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef __TX_I_XPATH_CONTEXT
#define __TX_I_XPATH_CONTEXT

#include "nscore.h"
#include "nsISupportsImpl.h"
#include "nsStringFwd.h"

class FunctionCall;
class nsAtom;
class txAExprResult;
class txResultRecycler;
class txXPathNode;

/*
 * txIParseContext
 *
 * This interface describes the context needed to create
 * XPath Expressions and XSLT Patters.
 * (not completely though. key() requires the ProcessorState, which is
 * not part of this interface.)
 */

class txIParseContext {
 public:
  virtual ~txIParseContext() = default;

  /*
   * Return a namespaceID for a given prefix.
   */
  virtual nsresult resolveNamespacePrefix(nsAtom* aPrefix, int32_t& aID) = 0;

  /*
   * Create a FunctionCall, needed for extension function calls and
   * XSLT. XPath function calls are resolved by the Parser.
   */
  virtual nsresult resolveFunctionCall(nsAtom* aName, int32_t aID,
                                       FunctionCall** aFunction) = 0;

  /**
   * Should nametests parsed in this context be case-sensitive
   */
  virtual bool caseInsensitiveNameTests() = 0;

  /*
   * Callback to be used by the Parser if errors are detected.
   */
  virtual void SetErrorOffset(uint32_t aOffset) = 0;

  enum Allowed { KEY_FUNCTION = 1 << 0 };
  virtual bool allowed(Allowed aAllowed) { return true; }
};

/*
 * txIMatchContext
 *
 * Interface used for matching XSLT Patters.
 * This is the part of txIEvalContext (see below), that is independent
 * of the context node when evaluating a XPath expression, too.
 * When evaluating a XPath expression, |txIMatchContext|s are used
 * to transport the information from Step to Step.
 */
class txIMatchContext {
 public:
  virtual ~txIMatchContext() = default;

  /*
   * Return the ExprResult associated with the variable with the
   * given namespace and local name.
   */
  virtual nsresult getVariable(int32_t aNamespace, nsAtom* aLName,
                               txAExprResult*& aResult) = 0;

  /*
   * Is whitespace stripping allowed for the given node?
   * See http://www.w3.org/TR/xslt#strip
   */
  virtual nsresult isStripSpaceAllowed(const txXPathNode& aNode,
                                       bool& aAllowed) = 0;

  /**
   * Returns a pointer to the private context
   */
  virtual void* getPrivateContext() = 0;

  virtual txResultRecycler* recycler() = 0;

  /*
   * Callback to be used by the expression/pattern if errors are detected.
   */
  virtual void receiveError(const nsAString& aMsg, nsresult aRes) = 0;
};

#define TX_DECL_MATCH_CONTEXT                                            \
  nsresult getVariable(int32_t aNamespace, nsAtom* aLName,               \
                       txAExprResult*& aResult) override;                \
  nsresult isStripSpaceAllowed(const txXPathNode& aNode, bool& aAllowed) \
      override;                                                          \
  void* getPrivateContext() override;                                    \
  txResultRecycler* recycler() override;                                 \
  void receiveError(const nsAString& aMsg, nsresult aRes) override

class txIEvalContext : public txIMatchContext {
 public:
  /*
   * Get the context node.
   */
  virtual const txXPathNode& getContextNode() = 0;

  /*
   * Get the size of the context node set.
   */
  virtual uint32_t size() = 0;

  /*
   * Get the position of the context node in the context node set,
   * starting with 1.
   */
  virtual uint32_t position() = 0;
};

#define TX_DECL_EVAL_CONTEXT                    \
  TX_DECL_MATCH_CONTEXT;                        \
  const txXPathNode& getContextNode() override; \
  uint32_t size() override;                     \
  uint32_t position() override

#endif  // __TX_I_XPATH_CONTEXT