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 .
21 #include "pathexpression.hxx"
22 #include "unohelper.hxx"
23 #include "evaluationcontext.hxx"
25 #include <com/sun/star/xml/dom/XNode.hpp>
26 #include <com/sun/star/xml/dom/XNodeList.hpp>
27 #include <com/sun/star/xml/xpath/XXPathObject.hpp>
28 #include <osl/diagnose.h>
33 using com::sun::star::uno::Reference
;
34 using com::sun::star::xml::dom::XNode
;
35 using com::sun::star::xml::dom::XNodeList
;
41 PathExpression::PathExpression()
45 PathExpression::~PathExpression()
50 void PathExpression::setExpression( const OUString
& rExpression
)
52 // set new expression, and clear pre-computed results
53 ComputedExpression::setExpression( rExpression
);
55 // check expression against regular expression to determine
56 // whether it contains only 'simple' (i.e. static) conditions. For
57 // now, we check whether it only contains number positions.
58 // (TODO: Only works for names containing only ASCII letters+digits.)
60 _checkExpression( "( */@?[a-zA-Z0-9:]+( *\\[ *[0-9 ]+ *\\] *)?)+" );
65 OUString
PathExpression::_getExpressionForEvaluation() const
67 OUString sExpr
= ComputedExpression::_getExpressionForEvaluation();
73 void PathExpression::evaluate( const EvaluationContext
& rContext
)
75 // for simple expression we don't need to re-bind (if we were bound before)
76 // (we will evaluate empty expressions, since they are interpreted as ".")
77 if( mxResult
.is() && isSimpleExpression() )
80 _evaluate( rContext
, _getExpressionForEvaluation() );
82 // clear old result, and copy new
87 Reference
<XNodeList
> xNodeList
= mxResult
->getNodeList();
88 OSL_ENSURE( xNodeList
.is(), "empty object (instead of empty list)" );
89 sal_Int32 nLength
= xNodeList
.is() ? xNodeList
->getLength() : 0;
90 for( sal_Int32 n
= 0; n
< nLength
; n
++ )
91 maNodes
.push_back( xNodeList
->item( n
) );
96 Reference
<XNode
> PathExpression::getNode() const
98 Reference
<XNode
> xResult
;
99 if( ! maNodes
.empty() )
100 xResult
= *maNodes
.begin();
105 Reference
<XNodeList
> PathExpression::getXNodeList() const
107 return mxResult
.is() ? mxResult
->getNodeList() : Reference
<XNodeList
>();
111 } // namespace xforms
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */