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