LCOV - code coverage report
Current view: top level - forms/source/xforms - pathexpression.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 35 0.0 %
Date: 2012-08-25 Functions: 0 8 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 40 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include "pathexpression.hxx"
      31                 :            : #include "unohelper.hxx"
      32                 :            : #include "evaluationcontext.hxx"
      33                 :            : #include "NameContainer.hxx"
      34                 :            : 
      35                 :            : #include <com/sun/star/xml/dom/XNode.hpp>
      36                 :            : #include <com/sun/star/xml/dom/XNodeList.hpp>
      37                 :            : #include <com/sun/star/xml/dom/NodeType.hpp>
      38                 :            : #include <com/sun/star/xml/dom/events/XEventListener.hpp>
      39                 :            : #include <com/sun/star/xml/dom/events/XEventTarget.hpp>
      40                 :            : #include <com/sun/star/xml/xpath/XXPathObject.hpp>
      41                 :            : #include <com/sun/star/container/XNameContainer.hpp>
      42                 :            : #include <com/sun/star/uno/Sequence.hxx>
      43                 :            : #include <rtl/ustrbuf.hxx>
      44                 :            : 
      45                 :            : #include <unotools/textsearch.hxx>
      46                 :            : 
      47                 :            : #include <algorithm>
      48                 :            : #include <functional>
      49                 :            : 
      50                 :            : 
      51                 :            : using rtl::OUString;
      52                 :            : using rtl::OUStringBuffer;
      53                 :            : using com::sun::star::uno::Reference;
      54                 :            : using com::sun::star::uno::Sequence;
      55                 :            : using com::sun::star::xml::dom::XNode;
      56                 :            : using com::sun::star::xml::dom::XNodeList;
      57                 :            : using com::sun::star::xml::dom::events::XEventListener;
      58                 :            : using com::sun::star::xml::dom::events::XEventTarget;
      59                 :            : using com::sun::star::container::XNameContainer;
      60                 :            : using com::sun::star::xml::xpath::XXPathObject;
      61                 :            : using com::sun::star::uno::RuntimeException;
      62                 :            : using com::sun::star::uno::UNO_QUERY;
      63                 :            : using com::sun::star::uno::UNO_QUERY_THROW;
      64                 :            : using com::sun::star::xml::dom::NodeType_TEXT_NODE;
      65                 :            : using com::sun::star::xml::xpath::XPathObjectType_XPATH_UNDEFINED;
      66                 :            : using namespace std;
      67                 :            : 
      68                 :            : 
      69                 :            : 
      70                 :            : 
      71                 :            : namespace xforms
      72                 :            : {
      73                 :            : 
      74                 :          0 : PathExpression::PathExpression()
      75                 :            :     : ComputedExpression(),
      76         [ #  # ]:          0 :       maNodes()
      77                 :            : {
      78                 :          0 : }
      79                 :            : 
      80                 :          0 : PathExpression::~PathExpression()
      81                 :            : {
      82                 :          0 : }
      83                 :            : 
      84                 :            : 
      85                 :            : 
      86                 :          0 : void PathExpression::setExpression( const OUString& rExpression )
      87                 :            : {
      88                 :            :     // set new expression, and clear pre-computed results
      89                 :          0 :     ComputedExpression::setExpression( rExpression );
      90                 :            : 
      91                 :            :     // check expression against regular expression to determine
      92                 :            :     // whether it contains only 'simple' (i.e. static) conditions. For
      93                 :            :     // now, we check whether it only contains number positions.
      94                 :            :     // (TODO: Only works for names containing only ASCII letters+digits.)
      95                 :            :     mbIsSimple =
      96                 :          0 :         _checkExpression( "( */@?[a-zA-Z0-9:]+( *\\[ *[0-9 ]+ *\\] *)?)+" );
      97                 :            : 
      98                 :          0 :     maNodes.clear();
      99                 :          0 : }
     100                 :            : 
     101                 :          0 : const rtl::OUString PathExpression::_getExpressionForEvaluation() const
     102                 :            : {
     103                 :          0 :     OUString sExpr = ComputedExpression::_getExpressionForEvaluation();
     104         [ #  # ]:          0 :     if( sExpr.isEmpty())
     105         [ #  # ]:          0 :         sExpr = OUSTRING(".");
     106                 :          0 :     return sExpr;
     107                 :            : }
     108                 :            : 
     109                 :          0 : bool PathExpression::evaluate( const EvaluationContext& rContext )
     110                 :            : {
     111                 :            :     // for simple expression we don't need to re-bind (if we were bound before)
     112                 :            :     // (we will evaluate empty expressions, since they are interpreted as ".")
     113 [ #  # ][ #  # ]:          0 :     if( mxResult.is() && isSimpleExpression() )
                 [ #  # ]
     114                 :          0 :         return true;
     115                 :            : 
     116         [ #  # ]:          0 :     bool bResult = _evaluate( rContext, _getExpressionForEvaluation() );
     117                 :            : 
     118                 :            :     // clear old result, and copy new
     119                 :          0 :     maNodes.clear();
     120         [ #  # ]:          0 :     if( mxResult.is() )
     121                 :            :     {
     122                 :            :         // copy node list
     123 [ #  # ][ #  # ]:          0 :         Reference<XNodeList> xNodeList = mxResult->getNodeList();
     124                 :            :         OSL_ENSURE( xNodeList.is(), "empty object (instead of empty list)" );
     125 [ #  # ][ #  # ]:          0 :         sal_Int32 nLength = xNodeList.is() ? xNodeList->getLength() : 0;
                 [ #  # ]
     126         [ #  # ]:          0 :         for( sal_Int32 n = 0; n < nLength; n++ )
     127 [ #  # ][ #  # ]:          0 :             maNodes.push_back( xNodeList->item( n ) );
                 [ #  # ]
     128                 :            :     }
     129                 :            : 
     130                 :          0 :     return bResult;
     131                 :            : }
     132                 :            : 
     133                 :            : 
     134                 :          0 : Reference<XNode> PathExpression::getNode() const
     135                 :            : {
     136                 :          0 :     Reference<XNode> xResult;
     137         [ #  # ]:          0 :     if( ! maNodes.empty() )
     138         [ #  # ]:          0 :         xResult = *maNodes.begin();
     139                 :          0 :     return xResult;
     140                 :            : }
     141                 :            : 
     142                 :          0 : const PathExpression::NodeVector_t PathExpression::getNodeList() const
     143                 :            : {
     144                 :          0 :     return maNodes;
     145                 :            : }
     146                 :            : 
     147                 :          0 : Reference<XNodeList> PathExpression::getXNodeList() const
     148                 :            : {
     149         [ #  # ]:          0 :     return mxResult.is() ? mxResult->getNodeList() : Reference<XNodeList>();
     150                 :            : }
     151                 :            : 
     152                 :            : 
     153                 :            : } // namespace xforms
     154                 :            : 
     155                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10