LCOV - code coverage report
Current view: top level - libreoffice/forms/source/xforms - pathexpression.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 35 0.0 %
Date: 2012-12-17 Functions: 0 8 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 rtl::OUString;
      43             : using rtl::OUStringBuffer;
      44             : using com::sun::star::uno::Reference;
      45             : using com::sun::star::uno::Sequence;
      46             : using com::sun::star::xml::dom::XNode;
      47             : using com::sun::star::xml::dom::XNodeList;
      48             : using com::sun::star::xml::dom::events::XEventListener;
      49             : using com::sun::star::xml::dom::events::XEventTarget;
      50             : using com::sun::star::container::XNameContainer;
      51             : using com::sun::star::xml::xpath::XXPathObject;
      52             : using com::sun::star::uno::RuntimeException;
      53             : using com::sun::star::uno::UNO_QUERY;
      54             : using com::sun::star::uno::UNO_QUERY_THROW;
      55             : using com::sun::star::xml::dom::NodeType_TEXT_NODE;
      56             : using com::sun::star::xml::xpath::XPathObjectType_XPATH_UNDEFINED;
      57             : using namespace std;
      58             : 
      59             : 
      60             : 
      61             : 
      62             : namespace xforms
      63             : {
      64             : 
      65           0 : PathExpression::PathExpression()
      66             :     : ComputedExpression(),
      67           0 :       maNodes()
      68             : {
      69           0 : }
      70             : 
      71           0 : PathExpression::~PathExpression()
      72             : {
      73           0 : }
      74             : 
      75             : 
      76             : 
      77           0 : void PathExpression::setExpression( const OUString& rExpression )
      78             : {
      79             :     // set new expression, and clear pre-computed results
      80           0 :     ComputedExpression::setExpression( rExpression );
      81             : 
      82             :     // check expression against regular expression to determine
      83             :     // whether it contains only 'simple' (i.e. static) conditions. For
      84             :     // now, we check whether it only contains number positions.
      85             :     // (TODO: Only works for names containing only ASCII letters+digits.)
      86             :     mbIsSimple =
      87           0 :         _checkExpression( "( */@?[a-zA-Z0-9:]+( *\\[ *[0-9 ]+ *\\] *)?)+" );
      88             : 
      89           0 :     maNodes.clear();
      90           0 : }
      91             : 
      92           0 : const rtl::OUString PathExpression::_getExpressionForEvaluation() const
      93             : {
      94           0 :     OUString sExpr = ComputedExpression::_getExpressionForEvaluation();
      95           0 :     if( sExpr.isEmpty())
      96           0 :         sExpr = OUSTRING(".");
      97           0 :     return sExpr;
      98             : }
      99             : 
     100           0 : bool PathExpression::evaluate( const EvaluationContext& rContext )
     101             : {
     102             :     // for simple expression we don't need to re-bind (if we were bound before)
     103             :     // (we will evaluate empty expressions, since they are interpreted as ".")
     104           0 :     if( mxResult.is() && isSimpleExpression() )
     105           0 :         return true;
     106             : 
     107           0 :     bool bResult = _evaluate( rContext, _getExpressionForEvaluation() );
     108             : 
     109             :     // clear old result, and copy new
     110           0 :     maNodes.clear();
     111           0 :     if( mxResult.is() )
     112             :     {
     113             :         // copy node list
     114           0 :         Reference<XNodeList> xNodeList = mxResult->getNodeList();
     115             :         OSL_ENSURE( xNodeList.is(), "empty object (instead of empty list)" );
     116           0 :         sal_Int32 nLength = xNodeList.is() ? xNodeList->getLength() : 0;
     117           0 :         for( sal_Int32 n = 0; n < nLength; n++ )
     118           0 :             maNodes.push_back( xNodeList->item( n ) );
     119             :     }
     120             : 
     121           0 :     return bResult;
     122             : }
     123             : 
     124             : 
     125           0 : Reference<XNode> PathExpression::getNode() const
     126             : {
     127           0 :     Reference<XNode> xResult;
     128           0 :     if( ! maNodes.empty() )
     129           0 :         xResult = *maNodes.begin();
     130           0 :     return xResult;
     131             : }
     132             : 
     133           0 : const PathExpression::NodeVector_t PathExpression::getNodeList() const
     134             : {
     135           0 :     return maNodes;
     136             : }
     137             : 
     138           0 : Reference<XNodeList> PathExpression::getXNodeList() const
     139             : {
     140           0 :     return mxResult.is() ? mxResult->getNodeList() : Reference<XNodeList>();
     141             : }
     142             : 
     143             : 
     144             : } // namespace xforms
     145             : 
     146             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10