Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_FORMS_SOURCE_XFORMS_COMPUTEDEXPRESSION_HXX
21 : #define INCLUDED_FORMS_SOURCE_XFORMS_COMPUTEDEXPRESSION_HXX
22 :
23 : #include <rtl/ustring.hxx>
24 : #include <com/sun/star/uno/Reference.hxx>
25 :
26 : // forward declaractions
27 : namespace com { namespace sun { namespace star
28 : {
29 : namespace xml
30 : {
31 : namespace dom { class XNode; }
32 : namespace dom { class XNodeset; }
33 : namespace xpath { class XXPathAPI; }
34 : namespace xpath { class XXPathObject; }
35 : }
36 : namespace container { class XNameContainer; }
37 : } } }
38 : namespace xforms { class EvaluationContext; }
39 :
40 :
41 :
42 : namespace xforms
43 : {
44 :
45 : /** ComputedExpression represents an XPath Expression and caches results.
46 : *
47 : * As this class has no virtual methods, it should never be used
48 : * polymorphically. */
49 : class ComputedExpression
50 : {
51 : /// the expression string
52 : OUString msExpression;
53 :
54 : /// is msExpression empty?
55 : bool mbIsEmpty;
56 :
57 : protected:
58 : /// is msExpression a simple expression?
59 : bool mbIsSimple;
60 :
61 : /// the result from the last bind
62 : com::sun::star::uno::Reference<com::sun::star::xml::xpath::XXPathObject> mxResult;
63 :
64 :
65 : /// implementation of isSimpleExpression
66 : bool _checkExpression( const sal_Char* pExpression ) const;
67 :
68 : /// allow manipulation of the expression before it is evaluated
69 : // the default implementation is to do nothing...
70 0 : const OUString _getExpressionForEvaluation() const { return msExpression; }
71 :
72 : /// obtain a (suitable) XPathAPI implementation
73 : static com::sun::star::uno::Reference<com::sun::star::xml::xpath::XXPathAPI> _getXPathAPI(const xforms::EvaluationContext& aContext);
74 :
75 : /// evaluate the expression relative to the content node.
76 : bool _evaluate( const xforms::EvaluationContext& rContext,
77 : const OUString& sExpression );
78 :
79 :
80 : public:
81 : ComputedExpression();
82 : ~ComputedExpression();
83 :
84 :
85 : /// get the expression string
86 0 : OUString getExpression() const { return msExpression;}
87 :
88 : /// set a new expression string
89 : void setExpression( const OUString& rExpression );
90 :
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;
93 :
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>& );
96 :
97 : /// do we have an actual expression?
98 0 : bool isEmptyExpression() const { return mbIsEmpty;}
99 :
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;
104 :
105 :
106 : /// evaluate the expression relative to the content node.
107 : bool evaluate( const xforms::EvaluationContext& rContext );
108 :
109 :
110 : /// does this expression have a value?
111 : bool hasValue() const;
112 :
113 :
114 : /// remove value/evaluate results
115 : void clear();
116 :
117 :
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 0 : 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;
124 :
125 : };
126 :
127 : } // namespace xforms
128 :
129 : #endif
130 :
131 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|