1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <rtl/ustring.hxx>
23 #include <com/sun/star/uno/Reference.hxx>
25 // forward declarations
26 namespace com::sun::star
30 namespace dom
{ class XNode
; }
31 namespace dom
{ class XNodeset
; }
32 namespace xpath
{ class XXPathAPI
; }
33 namespace xpath
{ class XXPathObject
; }
35 namespace container
{ class XNameContainer
; }
37 namespace xforms
{ class EvaluationContext
; }
43 /** ComputedExpression represents an XPath Expression and caches results.
45 * As this class has no virtual methods, it should never be used
47 class ComputedExpression
49 /// the expression string
50 OUString msExpression
;
52 /// is msExpression empty?
56 /// is msExpression a simple expression?
59 /// the result from the last bind
60 css::uno::Reference
<css::xml::xpath::XXPathObject
> mxResult
;
63 /// implementation of isSimpleExpression
64 bool _checkExpression( const char* pExpression
) const;
66 /// allow manipulation of the expression before it is evaluated
67 // the default implementation is to do nothing...
68 const OUString
& _getExpressionForEvaluation() const { return msExpression
; }
70 /// obtain a (suitable) XPathAPI implementation
71 static css::uno::Reference
<css::xml::xpath::XXPathAPI
> _getXPathAPI(const xforms::EvaluationContext
& aContext
);
73 /// evaluate the expression relative to the content node.
74 bool _evaluate( const xforms::EvaluationContext
& rContext
,
75 const OUString
& sExpression
);
80 ~ComputedExpression();
83 /// get the expression string
84 const OUString
& getExpression() const { return msExpression
;}
86 /// set a new expression string
87 void setExpression( const OUString
& rExpression
);
89 /// do we have an actual expression?
90 bool isEmptyExpression() const { return mbIsEmpty
;}
92 /// heuristically determine whether this expression is 'simple',
93 /// i.e. whether its value will change depending on the values
95 bool isSimpleExpression() const;
98 /// evaluate the expression relative to the content node.
99 bool evaluate( const xforms::EvaluationContext
& rContext
);
102 /// does this expression have a value?
103 bool hasValue() const;
106 /// remove value/evaluate results
110 // get the result of this expression as string/bool/...
111 // (Results will be based on the last call of evaluate(..). The caller
112 // must call evaluate to ensure current results.)
113 css::uno::Reference
<css::xml::xpath::XXPathObject
> const & getXPath() const { return mxResult
;}
114 bool getBool( bool bDefault
= false ) const;
115 OUString
getString() const;
119 } // namespace xforms
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */