1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is TransforMiiX XSLT processor code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * The MITRE Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1999
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Keith Visco <kvisco@ziplink.net> (Original Author)
24 : * Bob Miller <kbob@oblix.com>
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either the GNU General Public License Version 2 or later (the "GPL"), or
28 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : #include "txExpr.h"
41 : #include "txNodeSet.h"
42 : #include "txIXPathContext.h"
43 :
44 : //-- Implementation of FilterExpr --/
45 :
46 : //-----------------------------/
47 : //- Virtual methods from Expr -/
48 : //-----------------------------/
49 :
50 : /**
51 : * Evaluates this Expr based on the given context node and processor state
52 : * @param context the context node for evaluation of this Expr
53 : * @param ps the ProcessorState containing the stack information needed
54 : * for evaluation
55 : * @return the result of the evaluation
56 : * @see Expr
57 : **/
58 : nsresult
59 0 : FilterExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
60 : {
61 0 : *aResult = nsnull;
62 :
63 0 : nsRefPtr<txAExprResult> exprRes;
64 0 : nsresult rv = expr->evaluate(aContext, getter_AddRefs(exprRes));
65 0 : NS_ENSURE_SUCCESS(rv, rv);
66 :
67 0 : NS_ENSURE_TRUE(exprRes->getResultType() == txAExprResult::NODESET,
68 : NS_ERROR_XSLT_NODESET_EXPECTED);
69 :
70 : nsRefPtr<txNodeSet> nodes =
71 0 : static_cast<txNodeSet*>(static_cast<txAExprResult*>(exprRes));
72 : // null out exprRes so that we can test for shared-ness
73 0 : exprRes = nsnull;
74 :
75 0 : nsRefPtr<txNodeSet> nonShared;
76 0 : rv = aContext->recycler()->getNonSharedNodeSet(nodes,
77 0 : getter_AddRefs(nonShared));
78 0 : NS_ENSURE_SUCCESS(rv, rv);
79 :
80 0 : rv = evaluatePredicates(nonShared, aContext);
81 0 : NS_ENSURE_SUCCESS(rv, rv);
82 :
83 0 : *aResult = nonShared;
84 0 : NS_ADDREF(*aResult);
85 :
86 0 : return NS_OK;
87 : } //-- evaluate
88 :
89 0 : TX_IMPL_EXPR_STUBS_BASE(FilterExpr, NODESET_RESULT)
90 :
91 : Expr*
92 0 : FilterExpr::getSubExprAt(PRUint32 aPos)
93 : {
94 0 : if (aPos == 0) {
95 0 : return expr;
96 : }
97 0 : return PredicateList::getSubExprAt(aPos - 1);
98 : }
99 :
100 : void
101 0 : FilterExpr::setSubExprAt(PRUint32 aPos, Expr* aExpr)
102 : {
103 0 : if (aPos == 0) {
104 0 : expr.forget();
105 0 : expr = aExpr;
106 : }
107 : else {
108 0 : PredicateList::setSubExprAt(aPos - 1, aExpr);
109 : }
110 0 : }
111 :
112 : bool
113 0 : FilterExpr::isSensitiveTo(ContextSensitivity aContext)
114 : {
115 0 : return expr->isSensitiveTo(aContext) ||
116 0 : PredicateList::isSensitiveTo(aContext);
117 : }
118 :
119 : #ifdef TX_TO_STRING
120 : void
121 0 : FilterExpr::toString(nsAString& str)
122 : {
123 0 : if ( expr ) expr->toString(str);
124 0 : else str.AppendLiteral("null");
125 0 : PredicateList::toString(str);
126 0 : }
127 : #endif
128 :
|