LibreOffice Module forms (master) 1
pathexpression.cxx
Go to the documentation of this file.
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
21#include "pathexpression.hxx"
22#include "unohelper.hxx"
23#include "evaluationcontext.hxx"
24
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>
29
30#include <algorithm>
31
32
34using com::sun::star::xml::dom::XNode;
35using com::sun::star::xml::dom::XNodeList;
36
37
38namespace xforms
39{
40
42{
43}
44
46{
47}
48
49
50void PathExpression::setExpression( const OUString& rExpression )
51{
52 // set new expression, and clear pre-computed results
54
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 ]+ *\\] *)?)+" );
61
62 maNodes.clear();
63}
64
66{
68 if( sExpr.isEmpty())
69 sExpr = ".";
70 return sExpr;
71}
72
74{
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() )
78 return;
79
81
82 // clear old result, and copy new
83 maNodes.clear();
84 if( mxResult.is() )
85 {
86 // copy node list
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 ) );
92 }
93}
94
95
97{
98 Reference<XNode> xResult;
99 if( ! maNodes.empty() )
100 xResult = *maNodes.begin();
101 return xResult;
102}
103
104
106{
107 return mxResult.is() ? mxResult->getNodeList() : Reference<XNodeList>();
108}
109
110
111} // namespace xforms
112
113/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool isSimpleExpression() const
heuristically determine whether this expression is 'simple', i.e.
css::uno::Reference< css::xml::xpath::XXPathObject > mxResult
the result from the last bind
const OUString & _getExpressionForEvaluation() const
allow manipulation of the expression before it is evaluated
bool _checkExpression(const char *pExpression) const
implementation of isSimpleExpression
bool mbIsSimple
is msExpression a simple expression?
bool _evaluate(const xforms::EvaluationContext &rContext, const OUString &sExpression)
evaluate the expression relative to the content node.
void setExpression(const OUString &rExpression)
set a new expression string
define the context for the evaluation of an XPath expression
NodeVector_t maNodes
the node-list result from the last bind (cached from mxResult)
OUString _getExpressionForEvaluation() const
get expression for evaluation
css::uno::Reference< css::xml::dom::XNodeList > getXNodeList() const
void setExpression(const OUString &rExpression)
set the expression string (overridden to do remove old listeners) (also defines simple expressions)
void evaluate(const xforms::EvaluationContext &rContext)
evaluate the expression relative to the content node.
css::uno::Reference< css::xml::dom::XNode > getNode() const
sal_Int64 n
sal_Int32 nLength