nss: upgrade to release 3.73
[LibreOffice.git] / forms / source / xforms / pathexpression.cxx
blobea8fb8e63fd362a3d61e5c9d6eaca6e2deab98d4
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 .
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>
30 #include <algorithm>
33 using com::sun::star::uno::Reference;
34 using com::sun::star::xml::dom::XNode;
35 using com::sun::star::xml::dom::XNodeList;
36 using namespace std;
39 namespace xforms
42 PathExpression::PathExpression()
43 : ComputedExpression(),
44 maNodes()
48 PathExpression::~PathExpression()
53 void PathExpression::setExpression( const OUString& rExpression )
55 // set new expression, and clear pre-computed results
56 ComputedExpression::setExpression( rExpression );
58 // check expression against regular expression to determine
59 // whether it contains only 'simple' (i.e. static) conditions. For
60 // now, we check whether it only contains number positions.
61 // (TODO: Only works for names containing only ASCII letters+digits.)
62 mbIsSimple =
63 _checkExpression( "( */@?[a-zA-Z0-9:]+( *\\[ *[0-9 ]+ *\\] *)?)+" );
65 maNodes.clear();
68 OUString PathExpression::_getExpressionForEvaluation() const
70 OUString sExpr = ComputedExpression::_getExpressionForEvaluation();
71 if( sExpr.isEmpty())
72 sExpr = ".";
73 return sExpr;
76 void PathExpression::evaluate( const EvaluationContext& rContext )
78 // for simple expression we don't need to re-bind (if we were bound before)
79 // (we will evaluate empty expressions, since they are interpreted as ".")
80 if( mxResult.is() && isSimpleExpression() )
81 return;
83 _evaluate( rContext, _getExpressionForEvaluation() );
85 // clear old result, and copy new
86 maNodes.clear();
87 if( mxResult.is() )
89 // copy node list
90 Reference<XNodeList> xNodeList = mxResult->getNodeList();
91 OSL_ENSURE( xNodeList.is(), "empty object (instead of empty list)" );
92 sal_Int32 nLength = xNodeList.is() ? xNodeList->getLength() : 0;
93 for( sal_Int32 n = 0; n < nLength; n++ )
94 maNodes.push_back( xNodeList->item( n ) );
99 Reference<XNode> PathExpression::getNode() const
101 Reference<XNode> xResult;
102 if( ! maNodes.empty() )
103 xResult = *maNodes.begin();
104 return xResult;
108 Reference<XNodeList> PathExpression::getXNodeList() const
110 return mxResult.is() ? mxResult->getNodeList() : Reference<XNodeList>();
114 } // namespace xforms
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */