1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _COMPUTEDEXPRESSION_HXX 29 #define _COMPUTEDEXPRESSION_HXX 30 31 32 // includes for member variables 33 #include <rtl/ustring.hxx> 34 #include <com/sun/star/uno/Reference.hxx> 35 36 // forward declaractions 37 namespace com { namespace sun { namespace star 38 { 39 namespace xml 40 { 41 namespace dom { class XNode; } 42 namespace dom { class XNodeset; } 43 namespace xpath { class XXPathAPI; } 44 namespace xpath { class XXPathObject; } 45 } 46 namespace container { class XNameContainer; } 47 } } } 48 namespace xforms { class EvaluationContext; } 49 50 51 52 namespace xforms 53 { 54 55 /** ComputedExpression represents an XPath Expression and caches results. 56 * 57 * As this class has no virtual methods, it should never be used 58 * polymorphically. */ 59 class ComputedExpression 60 { 61 /// the expression string 62 rtl::OUString msExpression; 63 64 /// is msExpression empty? 65 bool mbIsEmpty; 66 67 protected: 68 /// is msExpression a simple expression? 69 bool mbIsSimple; 70 71 /// the result from the last bind 72 com::sun::star::uno::Reference<com::sun::star::xml::xpath::XXPathObject> mxResult; 73 74 75 /// implementation of isSimpleExpression 76 bool _checkExpression( const sal_Char* pExpression ) const; 77 78 /// allow manipulation of the expression before it is evaluated 79 const rtl::OUString _getExpressionForEvaluation() const; 80 81 /// obtain a (suitable) XPathAPI implementation 82 com::sun::star::uno::Reference<com::sun::star::xml::xpath::XXPathAPI> _getXPathAPI(const xforms::EvaluationContext& aContext); 83 84 /// evaluate the expression relative to the content node. 85 bool _evaluate( const xforms::EvaluationContext& rContext, 86 const rtl::OUString& sExpression ); 87 88 89 public: 90 ComputedExpression(); 91 ~ComputedExpression(); 92 93 94 /// get the expression string 95 rtl::OUString getExpression() const; 96 97 /// set a new expression string 98 void setExpression( const rtl::OUString& rExpression ); 99 100 /// get the namespaces that are used to interpret the expression string 101 com::sun::star::uno::Reference<com::sun::star::container::XNameContainer> getNamespaces() const; 102 103 /// set the namespaces that are used to interpret the expression string 104 void setNamespaces( const com::sun::star::uno::Reference<com::sun::star::container::XNameContainer>& ); 105 106 /// do we have an actual expression? 107 bool isEmptyExpression() const; 108 109 /// heuristically determine whether this expression is 'simple', 110 /// i.e. whether its value will change depending on the values 111 /// of other nodes 112 bool isSimpleExpression() const; 113 114 115 /// evaluate the expression relative to the content node. 116 bool evaluate( const xforms::EvaluationContext& rContext ); 117 118 119 /// does this expression have a value? 120 bool hasValue() const; 121 122 123 /// remove value/evaluate results 124 void clear(); 125 126 127 // get the result of this expression as string/bool/... 128 // (Results will be based on the last call of evaluate(..). The caller 129 // must call evaluate to ensure current results.) 130 com::sun::star::uno::Reference<com::sun::star::xml::xpath::XXPathObject> getXPath(); 131 bool getBool( bool bDefault = false ) const; 132 rtl::OUString getString( const rtl::OUString& rDefault = rtl::OUString() ) const; 133 134 }; 135 136 } // namespace xforms 137 138 #endif 139