LCOV - code coverage report
Current view: top level - forms/source/xforms - pathexpression.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 33 0.0 %
Date: 2014-11-03 Functions: 0 7 0.0 %
Legend: Lines: hit not hit

          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             : 
      21             : #include "pathexpression.hxx"
      22             : #include "unohelper.hxx"
      23             : #include "evaluationcontext.hxx"
      24             : #include "NameContainer.hxx"
      25             : 
      26             : #include <com/sun/star/xml/dom/XNode.hpp>
      27             : #include <com/sun/star/xml/dom/XNodeList.hpp>
      28             : #include <com/sun/star/xml/dom/NodeType.hpp>
      29             : #include <com/sun/star/xml/dom/events/XEventListener.hpp>
      30             : #include <com/sun/star/xml/dom/events/XEventTarget.hpp>
      31             : #include <com/sun/star/xml/xpath/XXPathObject.hpp>
      32             : #include <com/sun/star/container/XNameContainer.hpp>
      33             : #include <com/sun/star/uno/Sequence.hxx>
      34             : #include <rtl/ustrbuf.hxx>
      35             : 
      36             : #include <unotools/textsearch.hxx>
      37             : 
      38             : #include <algorithm>
      39             : #include <functional>
      40             : 
      41             : 
      42             : using com::sun::star::uno::Reference;
      43             : using com::sun::star::uno::Sequence;
      44             : using com::sun::star::xml::dom::XNode;
      45             : using com::sun::star::xml::dom::XNodeList;
      46             : using com::sun::star::xml::dom::events::XEventListener;
      47             : using com::sun::star::xml::dom::events::XEventTarget;
      48             : using com::sun::star::container::XNameContainer;
      49             : using com::sun::star::xml::xpath::XXPathObject;
      50             : using com::sun::star::uno::RuntimeException;
      51             : using com::sun::star::uno::UNO_QUERY;
      52             : using com::sun::star::uno::UNO_QUERY_THROW;
      53             : using com::sun::star::xml::dom::NodeType_TEXT_NODE;
      54             : using com::sun::star::xml::xpath::XPathObjectType_XPATH_UNDEFINED;
      55             : using namespace std;
      56             : 
      57             : 
      58             : 
      59             : 
      60             : namespace xforms
      61             : {
      62             : 
      63           0 : PathExpression::PathExpression()
      64             :     : ComputedExpression(),
      65           0 :       maNodes()
      66             : {
      67           0 : }
      68             : 
      69           0 : PathExpression::~PathExpression()
      70             : {
      71           0 : }
      72             : 
      73             : 
      74             : 
      75           0 : void PathExpression::setExpression( const OUString& rExpression )
      76             : {
      77             :     // set new expression, and clear pre-computed results
      78           0 :     ComputedExpression::setExpression( rExpression );
      79             : 
      80             :     // check expression against regular expression to determine
      81             :     // whether it contains only 'simple' (i.e. static) conditions. For
      82             :     // now, we check whether it only contains number positions.
      83             :     // (TODO: Only works for names containing only ASCII letters+digits.)
      84             :     mbIsSimple =
      85           0 :         _checkExpression( "( */@?[a-zA-Z0-9:]+( *\\[ *[0-9 ]+ *\\] *)?)+" );
      86             : 
      87           0 :     maNodes.clear();
      88           0 : }
      89             : 
      90           0 : const OUString PathExpression::_getExpressionForEvaluation() const
      91             : {
      92           0 :     OUString sExpr = ComputedExpression::_getExpressionForEvaluation();
      93           0 :     if( sExpr.isEmpty())
      94           0 :         sExpr = ".";
      95           0 :     return sExpr;
      96             : }
      97             : 
      98           0 : bool PathExpression::evaluate( const EvaluationContext& rContext )
      99             : {
     100             :     // for simple expression we don't need to re-bind (if we were bound before)
     101             :     // (we will evaluate empty expressions, since they are interpreted as ".")
     102           0 :     if( mxResult.is() && isSimpleExpression() )
     103           0 :         return true;
     104             : 
     105           0 :     bool bResult = _evaluate( rContext, _getExpressionForEvaluation() );
     106             : 
     107             :     // clear old result, and copy new
     108           0 :     maNodes.clear();
     109           0 :     if( mxResult.is() )
     110             :     {
     111             :         // copy node list
     112           0 :         Reference<XNodeList> xNodeList = mxResult->getNodeList();
     113             :         OSL_ENSURE( xNodeList.is(), "empty object (instead of empty list)" );
     114           0 :         sal_Int32 nLength = xNodeList.is() ? xNodeList->getLength() : 0;
     115           0 :         for( sal_Int32 n = 0; n < nLength; n++ )
     116           0 :             maNodes.push_back( xNodeList->item( n ) );
     117             :     }
     118             : 
     119           0 :     return bResult;
     120             : }
     121             : 
     122             : 
     123           0 : Reference<XNode> PathExpression::getNode() const
     124             : {
     125           0 :     Reference<XNode> xResult;
     126           0 :     if( ! maNodes.empty() )
     127           0 :         xResult = *maNodes.begin();
     128           0 :     return xResult;
     129             : }
     130             : 
     131             : 
     132           0 : Reference<XNodeList> PathExpression::getXNodeList() const
     133             : {
     134           0 :     return mxResult.is() ? mxResult->getNodeList() : Reference<XNodeList>();
     135             : }
     136             : 
     137             : 
     138             : } // namespace xforms
     139             : 
     140             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10