1*2d785d7eSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2d785d7eSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2d785d7eSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2d785d7eSAndrew Rist  * distributed with this work for additional information
6*2d785d7eSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2d785d7eSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2d785d7eSAndrew Rist  * "License"); you may not use this file except in compliance
9*2d785d7eSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2d785d7eSAndrew Rist  *
11*2d785d7eSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2d785d7eSAndrew Rist  *
13*2d785d7eSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2d785d7eSAndrew Rist  * software distributed under the License is distributed on an
15*2d785d7eSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2d785d7eSAndrew Rist  * KIND, either express or implied.  See the License for the
17*2d785d7eSAndrew Rist  * specific language governing permissions and limitations
18*2d785d7eSAndrew Rist  * under the License.
19*2d785d7eSAndrew Rist  *
20*2d785d7eSAndrew Rist  *************************************************************/
21*2d785d7eSAndrew Rist 
22*2d785d7eSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _COMPUTEDEXPRESSION_HXX
25cdf0e10cSrcweir #define _COMPUTEDEXPRESSION_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir // includes for member variables
29cdf0e10cSrcweir #include <rtl/ustring.hxx>
30cdf0e10cSrcweir #include <com/sun/star/uno/Reference.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir // forward declaractions
33cdf0e10cSrcweir namespace com { namespace sun { namespace star
34cdf0e10cSrcweir {
35cdf0e10cSrcweir     namespace xml
36cdf0e10cSrcweir     {
37cdf0e10cSrcweir         namespace dom { class XNode; }
38cdf0e10cSrcweir         namespace dom { class XNodeset; }
39cdf0e10cSrcweir         namespace xpath { class XXPathAPI; }
40cdf0e10cSrcweir         namespace xpath { class XXPathObject; }
41cdf0e10cSrcweir     }
42cdf0e10cSrcweir     namespace container { class XNameContainer; }
43cdf0e10cSrcweir } } }
44cdf0e10cSrcweir namespace xforms { class EvaluationContext; }
45cdf0e10cSrcweir 
46cdf0e10cSrcweir 
47cdf0e10cSrcweir 
48cdf0e10cSrcweir namespace xforms
49cdf0e10cSrcweir {
50cdf0e10cSrcweir 
51cdf0e10cSrcweir /** ComputedExpression represents an XPath Expression and caches results.
52cdf0e10cSrcweir  *
53cdf0e10cSrcweir  * As this class has no virtual methods, it should never be used
54cdf0e10cSrcweir  * polymorphically. */
55cdf0e10cSrcweir class ComputedExpression
56cdf0e10cSrcweir {
57cdf0e10cSrcweir     /// the expression string
58cdf0e10cSrcweir     rtl::OUString msExpression;
59cdf0e10cSrcweir 
60cdf0e10cSrcweir     /// is msExpression empty?
61cdf0e10cSrcweir     bool mbIsEmpty;
62cdf0e10cSrcweir 
63cdf0e10cSrcweir protected:
64cdf0e10cSrcweir     /// is msExpression a simple expression?
65cdf0e10cSrcweir     bool mbIsSimple;
66cdf0e10cSrcweir 
67cdf0e10cSrcweir     /// the result from the last bind
68cdf0e10cSrcweir     com::sun::star::uno::Reference<com::sun::star::xml::xpath::XXPathObject> mxResult;
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 
71cdf0e10cSrcweir     /// implementation of isSimpleExpression
72cdf0e10cSrcweir     bool _checkExpression( const sal_Char* pExpression ) const;
73cdf0e10cSrcweir 
74cdf0e10cSrcweir     /// allow manipulation of the expression before it is evaluated
75cdf0e10cSrcweir     const rtl::OUString _getExpressionForEvaluation() const;
76cdf0e10cSrcweir 
77cdf0e10cSrcweir     /// obtain a (suitable) XPathAPI implementation
78cdf0e10cSrcweir     com::sun::star::uno::Reference<com::sun::star::xml::xpath::XXPathAPI> _getXPathAPI(const xforms::EvaluationContext& aContext);
79cdf0e10cSrcweir 
80cdf0e10cSrcweir     /// evaluate the expression relative to the content node.
81cdf0e10cSrcweir     bool _evaluate( const xforms::EvaluationContext& rContext,
82cdf0e10cSrcweir                     const rtl::OUString& sExpression );
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 
85cdf0e10cSrcweir public:
86cdf0e10cSrcweir     ComputedExpression();
87cdf0e10cSrcweir     ~ComputedExpression();
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 
90cdf0e10cSrcweir     /// get the expression string
91cdf0e10cSrcweir     rtl::OUString getExpression() const;
92cdf0e10cSrcweir 
93cdf0e10cSrcweir     /// set a new expression string
94cdf0e10cSrcweir     void setExpression( const rtl::OUString& rExpression );
95cdf0e10cSrcweir 
96cdf0e10cSrcweir     /// get the namespaces that are used to interpret the expression string
97cdf0e10cSrcweir     com::sun::star::uno::Reference<com::sun::star::container::XNameContainer> getNamespaces() const;
98cdf0e10cSrcweir 
99cdf0e10cSrcweir     /// set the namespaces that are used to interpret the expression string
100cdf0e10cSrcweir     void setNamespaces( const com::sun::star::uno::Reference<com::sun::star::container::XNameContainer>& );
101cdf0e10cSrcweir 
102cdf0e10cSrcweir     /// do we have an actual expression?
103cdf0e10cSrcweir     bool isEmptyExpression() const;
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     /// heuristically determine whether this expression is 'simple',
106cdf0e10cSrcweir     /// i.e. whether its value will change depending on the values
107cdf0e10cSrcweir     /// of other nodes
108cdf0e10cSrcweir     bool isSimpleExpression() const;
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 
111cdf0e10cSrcweir     /// evaluate the expression relative to the content node.
112cdf0e10cSrcweir     bool evaluate( const xforms::EvaluationContext& rContext );
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 
115cdf0e10cSrcweir     /// does this expression have a value?
116cdf0e10cSrcweir     bool hasValue() const;
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 
119cdf0e10cSrcweir     /// remove value/evaluate results
120cdf0e10cSrcweir     void clear();
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 
123cdf0e10cSrcweir     // get the result of this expression as string/bool/...
124cdf0e10cSrcweir     // (Results will be based on the last call of evaluate(..). The caller
125cdf0e10cSrcweir     // must call evaluate to ensure current results.)
126cdf0e10cSrcweir 	com::sun::star::uno::Reference<com::sun::star::xml::xpath::XXPathObject> getXPath();
127cdf0e10cSrcweir     bool getBool( bool bDefault = false ) const;
128cdf0e10cSrcweir     rtl::OUString getString( const rtl::OUString& rDefault = rtl::OUString() ) const;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir };
131cdf0e10cSrcweir 
132cdf0e10cSrcweir } // namespace xforms
133cdf0e10cSrcweir 
134cdf0e10cSrcweir #endif
135