bump product version to 5.0.4.1
[LibreOffice.git] / forms / source / xforms / computedexpression.hxx
blob1e11fea781057de333b5617b86ca84d02e44239a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #ifndef INCLUDED_FORMS_SOURCE_XFORMS_COMPUTEDEXPRESSION_HXX
21 #define INCLUDED_FORMS_SOURCE_XFORMS_COMPUTEDEXPRESSION_HXX
23 #include <rtl/ustring.hxx>
24 #include <com/sun/star/uno/Reference.hxx>
26 // forward declaractions
27 namespace com { namespace sun { namespace star
29 namespace xml
31 namespace dom { class XNode; }
32 namespace dom { class XNodeset; }
33 namespace xpath { class XXPathAPI; }
34 namespace xpath { class XXPathObject; }
36 namespace container { class XNameContainer; }
37 } } }
38 namespace xforms { class EvaluationContext; }
42 namespace xforms
45 /** ComputedExpression represents an XPath Expression and caches results.
47 * As this class has no virtual methods, it should never be used
48 * polymorphically. */
49 class ComputedExpression
51 /// the expression string
52 OUString msExpression;
54 /// is msExpression empty?
55 bool mbIsEmpty;
57 protected:
58 /// is msExpression a simple expression?
59 bool mbIsSimple;
61 /// the result from the last bind
62 com::sun::star::uno::Reference<com::sun::star::xml::xpath::XXPathObject> mxResult;
65 /// implementation of isSimpleExpression
66 bool _checkExpression( const sal_Char* pExpression ) const;
68 /// allow manipulation of the expression before it is evaluated
69 // the default implementation is to do nothing...
70 const OUString _getExpressionForEvaluation() const { return msExpression; }
72 /// obtain a (suitable) XPathAPI implementation
73 static com::sun::star::uno::Reference<com::sun::star::xml::xpath::XXPathAPI> _getXPathAPI(const xforms::EvaluationContext& aContext);
75 /// evaluate the expression relative to the content node.
76 bool _evaluate( const xforms::EvaluationContext& rContext,
77 const OUString& sExpression );
80 public:
81 ComputedExpression();
82 ~ComputedExpression();
85 /// get the expression string
86 OUString getExpression() const { return msExpression;}
88 /// set a new expression string
89 void setExpression( const OUString& rExpression );
91 /// get the namespaces that are used to interpret the expression string
92 com::sun::star::uno::Reference<com::sun::star::container::XNameContainer> getNamespaces() const;
94 /// set the namespaces that are used to interpret the expression string
95 void setNamespaces( const com::sun::star::uno::Reference<com::sun::star::container::XNameContainer>& );
97 /// do we have an actual expression?
98 bool isEmptyExpression() const { return mbIsEmpty;}
100 /// heuristically determine whether this expression is 'simple',
101 /// i.e. whether its value will change depending on the values
102 /// of other nodes
103 bool isSimpleExpression() const;
106 /// evaluate the expression relative to the content node.
107 bool evaluate( const xforms::EvaluationContext& rContext );
110 /// does this expression have a value?
111 bool hasValue() const;
114 /// remove value/evaluate results
115 void clear();
118 // get the result of this expression as string/bool/...
119 // (Results will be based on the last call of evaluate(..). The caller
120 // must call evaluate to ensure current results.)
121 com::sun::star::uno::Reference<com::sun::star::xml::xpath::XXPathObject> getXPath() const { return mxResult;}
122 bool getBool( bool bDefault = false ) const;
123 OUString getString( const OUString& rDefault = OUString() ) const;
127 } // namespace xforms
129 #endif
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */