LCOV - code coverage report
Current view: top level - libreoffice/forms/source/xforms - submission.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 286 0.0 %
Date: 2012-12-17 Functions: 0 61 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             : #include "submission.hxx"
      21             : 
      22             : #include "model.hxx"
      23             : #include "binding.hxx"
      24             : #include "mip.hxx"
      25             : #include "evaluationcontext.hxx"
      26             : #include "unohelper.hxx"
      27             : #include "submission/submission_put.hxx"
      28             : #include "submission/submission_post.hxx"
      29             : #include "submission/submission_get.hxx"
      30             : 
      31             : #include <rtl/ustring.hxx>
      32             : #include <rtl/ustrbuf.hxx>
      33             : 
      34             : #include <com/sun/star/uno/Sequence.hxx>
      35             : #include <com/sun/star/uno/Reference.hxx>
      36             : #include <com/sun/star/xforms/XModel.hpp>
      37             : #include <com/sun/star/uno/RuntimeException.hpp>
      38             : #include <com/sun/star/xml/xpath/XXPathObject.hpp>
      39             : #include <com/sun/star/container/XNameAccess.hpp>
      40             : #include <com/sun/star/xml/xpath/XPathObjectType.hpp>
      41             : #include <com/sun/star/xml/dom/XNodeList.hpp>
      42             : #include <com/sun/star/xml/dom/XDocument.hpp>
      43             : #include <com/sun/star/xml/dom/DocumentBuilder.hpp>
      44             : #include <com/sun/star/xml/dom/XDocumentFragment.hpp>
      45             : #include <com/sun/star/xml/dom/NodeType.hpp>
      46             : #include <com/sun/star/task/XInteractionHandler.hpp>
      47             : #include <com/sun/star/task/XInteractionRequest.hpp>
      48             : #include <com/sun/star/task/XInteractionContinuation.hpp>
      49             : #include <com/sun/star/xforms/InvalidDataOnSubmitException.hpp>
      50             : #include <com/sun/star/frame/XFrame.hpp>
      51             : #include <cppuhelper/typeprovider.hxx>
      52             : #include <comphelper/propertysetinfo.hxx>
      53             : #include <comphelper/interaction.hxx>
      54             : #include <comphelper/processfactory.hxx>
      55             : #include <memory>
      56             : 
      57             : 
      58             : 
      59             : 
      60             : using rtl::OUString;
      61             : using rtl::OUStringBuffer;
      62             : using com::sun::star::beans::UnknownPropertyException;
      63             : using com::sun::star::beans::PropertyVetoException;
      64             : using com::sun::star::lang::IllegalArgumentException;
      65             : using com::sun::star::util::VetoException;
      66             : using com::sun::star::form::submission::XSubmissionVetoListener;
      67             : using com::sun::star::lang::WrappedTargetException;
      68             : using com::sun::star::lang::NoSupportException;
      69             : using com::sun::star::task::XInteractionHandler;
      70             : using com::sun::star::task::XInteractionRequest;
      71             : using com::sun::star::task::XInteractionContinuation;
      72             : using com::sun::star::xforms::XModel;
      73             : using com::sun::star::xforms::InvalidDataOnSubmitException;
      74             : using com::sun::star::container::XNameAccess;
      75             : using com::sun::star::xml::xpath::XXPathObject;
      76             : using com::sun::star::xml::xpath::XPathObjectType;
      77             : using com::sun::star::frame::XFrame;
      78             : using xforms::Submission;
      79             : using xforms::Model;
      80             : using xforms::MIP;
      81             : using std::auto_ptr;
      82             : 
      83             : using namespace com::sun::star::uno;
      84             : using namespace com::sun::star::lang;
      85             : using namespace com::sun::star::xml::dom;
      86             : 
      87           0 : Submission::Submission() :
      88             :     msID(),
      89             :     msBind(),
      90             :     maRef(),
      91             :     msAction(),
      92             :     msMethod(),
      93             :     msVersion(),
      94             :     mbIndent(),
      95             :     msMediaType(),
      96             :     msEncoding(),
      97             :     mbOmitXmlDeclaration(),
      98             :     mbStandalone(),
      99             :     msCDataSectionElement(),
     100             :     msReplace( OUSTRING("none") ),
     101             :     msSeparator(),
     102             :     msIncludeNamespacePrefixes(),
     103           0 :     m_aFactory(comphelper::getProcessServiceFactory())
     104             : {
     105           0 :     initializePropertySet();
     106           0 : }
     107             : 
     108           0 : Submission::~Submission() throw()
     109             : {
     110           0 : }
     111             : 
     112           0 : Reference<XModel> Submission::getModel() const
     113             : {
     114           0 :     return mxModel;
     115             : }
     116             : 
     117           0 : void Submission::setModel( const Reference<XModel>& xModel )
     118             : {
     119           0 :     mxModel = xModel;
     120           0 : }
     121             : 
     122           0 : OUString Submission::getID() const
     123             : {
     124           0 :     return msID;
     125             : }
     126             : 
     127           0 : void Submission::setID( const OUString& sID )
     128             : {
     129           0 :     msID = sID;
     130           0 : }
     131             : 
     132           0 : OUString Submission::getBind() const
     133             : {
     134           0 :     return msBind;
     135             : }
     136             : 
     137           0 : void Submission::setBind( const OUString& sBind )
     138             : {
     139           0 :     msBind = sBind;
     140           0 : }
     141             : 
     142           0 : OUString Submission::getRef() const
     143             : {
     144           0 :     return maRef.getExpression();
     145             : }
     146             : 
     147           0 : void Submission::setRef( const OUString& sRef )
     148             : {
     149           0 :     maRef.setExpression( sRef );
     150           0 : }
     151             : 
     152           0 : OUString Submission::getAction() const
     153             : {
     154           0 :     return msAction;
     155             : }
     156             : 
     157           0 : void Submission::setAction( const OUString& sAction )
     158             : {
     159           0 :     msAction = sAction;
     160           0 : }
     161             : 
     162           0 : OUString Submission::getMethod() const
     163             : {
     164           0 :     return msMethod;
     165             : }
     166             : 
     167           0 : void Submission::setMethod( const OUString& sMethod )
     168             : {
     169           0 :     msMethod = sMethod;
     170           0 : }
     171             : 
     172           0 : OUString Submission::getVersion() const
     173             : {
     174           0 :     return msVersion;
     175             : }
     176             : 
     177           0 : void Submission::setVersion( const OUString& sVersion )
     178             : {
     179           0 :     msVersion = sVersion;
     180           0 : }
     181             : 
     182           0 : bool Submission::getIndent() const
     183             : {
     184           0 :     return mbIndent;
     185             : }
     186             : 
     187           0 : void Submission::setIndent( bool bIndent )
     188             : {
     189           0 :     mbIndent = bIndent;
     190           0 : }
     191             : 
     192           0 : OUString Submission::getMediaType() const
     193             : {
     194           0 :     return msMediaType;
     195             : }
     196             : 
     197           0 : void Submission::setMediaType( const OUString& sMediaType )
     198             : {
     199           0 :     msMediaType = sMediaType;
     200           0 : }
     201             : 
     202           0 : OUString Submission::getEncoding() const
     203             : {
     204           0 :     return msEncoding;
     205             : }
     206             : 
     207           0 : void Submission::setEncoding( const OUString& sEncoding )
     208             : {
     209           0 :     msEncoding = sEncoding;
     210           0 : }
     211             : 
     212           0 : bool Submission::getOmitXmlDeclaration() const
     213             : {
     214           0 :     return mbOmitXmlDeclaration;
     215             : }
     216             : 
     217           0 : void Submission::setOmitXmlDeclaration( bool bOmitXmlDeclaration )
     218             : {
     219           0 :     mbOmitXmlDeclaration = bOmitXmlDeclaration;
     220           0 : }
     221             : 
     222           0 : bool Submission::getStandalone() const
     223             : {
     224           0 :     return mbStandalone;
     225             : }
     226             : 
     227           0 : void Submission::setStandalone( bool bStandalone )
     228             : {
     229           0 :     mbStandalone = bStandalone;
     230           0 : }
     231             : 
     232           0 : OUString Submission::getCDataSectionElement() const
     233             : {
     234           0 :     return msCDataSectionElement;
     235             : }
     236             : 
     237           0 : void Submission::setCDataSectionElement( const OUString& sCDataSectionElement )
     238             : {
     239           0 :     msCDataSectionElement = sCDataSectionElement;
     240           0 : }
     241             : 
     242           0 : OUString Submission::getReplace() const
     243             : {
     244           0 :     return msReplace;
     245             : }
     246             : 
     247           0 : void Submission::setReplace( const OUString& sReplace )
     248             : {
     249           0 :     msReplace = sReplace;
     250           0 : }
     251             : 
     252           0 : OUString Submission::getSeparator() const
     253             : {
     254           0 :     return msSeparator;
     255             : }
     256             : 
     257           0 : void Submission::setSeparator( const OUString& sSeparator )
     258             : {
     259           0 :     msSeparator = sSeparator;
     260           0 : }
     261             : 
     262           0 : Sequence< OUString > Submission::getIncludeNamespacePrefixes() const
     263             : {
     264           0 :     return msIncludeNamespacePrefixes;
     265             : }
     266             : 
     267           0 : void Submission::setIncludeNamespacePrefixes( const Sequence< OUString >& rIncludeNamespacePrefixes )
     268             : {
     269           0 :     msIncludeNamespacePrefixes = rIncludeNamespacePrefixes;
     270           0 : }
     271             : 
     272           0 : bool Submission::doSubmit( const Reference< XInteractionHandler >& xHandler )
     273             : {
     274           0 :     liveCheck();
     275             : 
     276             :     // construct XXPathObject for submission doc; use bind in preference of ref
     277           0 :     EvaluationContext aEvalContext;
     278           0 :     ComputedExpression aExpression;
     279           0 :     if( !msBind.isEmpty() )
     280             :     {
     281           0 :         Binding* pBinding = Binding::getBinding( mxModel->getBinding(msBind) );
     282           0 :         if( pBinding != NULL )
     283             :         {
     284           0 :             aExpression.setExpression( pBinding->getBindingExpression() );
     285           0 :             aEvalContext = pBinding->getEvaluationContext();
     286             :         }
     287             :         // TODO: else: illegal binding name -> raise error
     288             :     }
     289           0 :     else if( !maRef.getExpression().isEmpty() )
     290             :     {
     291           0 :         aExpression.setExpression( maRef.getExpression() );
     292           0 :         aEvalContext = Model::getModel( mxModel )->getEvaluationContext();
     293             :     }
     294             :     else
     295             :     {
     296           0 :         aExpression.setExpression( OUSTRING( "/" ) );
     297           0 :         aEvalContext = Model::getModel( mxModel )->getEvaluationContext();
     298             :     }
     299           0 :     aExpression.evaluate( aEvalContext );
     300           0 :     Reference<XXPathObject> xResult = aExpression.getXPath();
     301             :     OSL_ENSURE( xResult.is(), "no result?" );
     302             : 
     303             :     // early out if we have not obtained any result
     304           0 :     if( ! xResult.is() )
     305           0 :         return false;
     306             : 
     307             : 
     308             :     // Reference< XNodeList > aList = xResult->getNodeList();
     309           0 :     OUString aMethod = getMethod();
     310             : 
     311             :     // strip whitespace-only text node for get submission
     312             :     Reference< XDocumentFragment > aFragment = createSubmissionDocument(
     313           0 :         xResult, aMethod.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("get")));
     314             : 
     315             :     // submit result; set encoding, etc.
     316           0 :     auto_ptr<CSubmission> xSubmission;
     317           0 :     if (aMethod.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("PUT")))
     318             :         xSubmission = auto_ptr<CSubmission>(
     319           0 :             new CSubmissionPut( getAction(), aFragment));
     320           0 :     else if (aMethod.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("post")))
     321             :         xSubmission = auto_ptr<CSubmission>(
     322           0 :             new CSubmissionPost( getAction(), aFragment));
     323           0 :     else if (aMethod.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("get")))
     324             :         xSubmission = auto_ptr<CSubmission>(
     325           0 :             new CSubmissionGet( getAction(), aFragment));
     326             :     else
     327             :     {
     328             :         OSL_FAIL("Unsupported xforms submission method");
     329           0 :         return false;
     330             :     }
     331             : 
     332           0 :     xSubmission->setEncoding(getEncoding());
     333           0 :     CSubmission::SubmissionResult aResult = xSubmission->submit( xHandler );
     334             : 
     335           0 :     if (aResult == CSubmission::SUCCESS)
     336             :     {
     337           0 :         Reference< XDocument > aInstanceDoc = getInstanceDocument(xResult);
     338           0 :         aResult = xSubmission->replace(getReplace(), aInstanceDoc, Reference< XFrame >());
     339             :     }
     340             : 
     341           0 :     return ( aResult == CSubmission::SUCCESS );
     342             : }
     343             : 
     344           0 : Sequence<sal_Int8> Submission::getUnoTunnelID()
     345             : {
     346           0 :     static cppu::OImplementationId aImplementationId;
     347           0 :     return aImplementationId.getImplementationId();
     348             : }
     349             : 
     350           0 : Submission* Submission::getSubmission(
     351             :     const Reference<XPropertySet>& xPropertySet )
     352             : {
     353           0 :     Reference<XUnoTunnel> xTunnel( xPropertySet, UNO_QUERY );
     354           0 :     return xTunnel.is()
     355             :         ? reinterpret_cast<Submission*>(
     356           0 :             xTunnel->getSomething( getUnoTunnelID() ) )
     357           0 :         : NULL;
     358             : }
     359             : 
     360             : 
     361             : 
     362             : 
     363             : 
     364             : 
     365           0 : void Submission::liveCheck()
     366             :     throw( RuntimeException )
     367             : {
     368           0 :     bool bValid = mxModel.is();
     369             : 
     370           0 :     if( ! bValid )
     371           0 :         throw RuntimeException();
     372           0 : }
     373             : 
     374           0 : Model* Submission::getModelImpl() const
     375             : {
     376           0 :     Model* pModel = NULL;
     377           0 :     if( mxModel.is() )
     378           0 :         pModel = Model::getModel( mxModel );
     379           0 :     return pModel;
     380             : }
     381             : 
     382             : 
     383             : //
     384             : // Property-Set implementation
     385             : //
     386             : 
     387             : #define HANDLE_ID 0
     388             : #define HANDLE_Bind 1
     389             : #define HANDLE_Ref 2
     390             : #define HANDLE_Action 3
     391             : #define HANDLE_Method 4
     392             : #define HANDLE_Version 5
     393             : #define HANDLE_Indent 6
     394             : #define HANDLE_MediaType 7
     395             : #define HANDLE_Encoding 8
     396             : #define HANDLE_OmitXmlDeclaration 9
     397             : #define HANDLE_Standalone 10
     398             : #define HANDLE_CDataSectionElement 11
     399             : #define HANDLE_Replace 12
     400             : #define HANDLE_Separator 13
     401             : #define HANDLE_IncludeNamespacePrefixes 14
     402             : #define HANDLE_Model 15
     403             : 
     404             : #define REGISTER_PROPERTY( property, type )   \
     405             :     registerProperty( PROPERTY( property, type ), \
     406             :     new DirectPropertyAccessor< Submission, type >( this, &Submission::set##property, &Submission::get##property ) );
     407             : 
     408             : #define REGISTER_PROPERTY_BOOL( property )   \
     409             :     registerProperty( PROPERTY( property, bool ), \
     410             :     new BooleanPropertyAccessor< Submission, bool >( this, &Submission::set##property, &Submission::get##property ) );
     411             : 
     412           0 : void Submission::initializePropertySet()
     413             : {
     414           0 :     REGISTER_PROPERTY     ( ID,                         OUString );
     415           0 :     REGISTER_PROPERTY     ( Bind,                       OUString );
     416           0 :     REGISTER_PROPERTY     ( Ref,                        OUString );
     417           0 :     REGISTER_PROPERTY     ( Action,                     OUString );
     418           0 :     REGISTER_PROPERTY     ( Method,                     OUString );
     419           0 :     REGISTER_PROPERTY     ( Version,                    OUString );
     420           0 :     REGISTER_PROPERTY_BOOL( Indent );
     421           0 :     REGISTER_PROPERTY     ( MediaType,                  OUString );
     422           0 :     REGISTER_PROPERTY     ( Encoding,                   OUString );
     423           0 :     REGISTER_PROPERTY_BOOL( OmitXmlDeclaration );
     424           0 :     REGISTER_PROPERTY_BOOL( Standalone );
     425           0 :     REGISTER_PROPERTY     ( CDataSectionElement,        OUString );
     426           0 :     REGISTER_PROPERTY     ( Replace,                    OUString );
     427           0 :     REGISTER_PROPERTY     ( Separator,                  OUString );
     428           0 :     REGISTER_PROPERTY     ( IncludeNamespacePrefixes,   Sequence< OUString > );
     429           0 :     REGISTER_PROPERTY     ( Model,                      Reference<XModel> );
     430             : 
     431           0 :     initializePropertyValueCache( HANDLE_Indent );
     432           0 :     initializePropertyValueCache( HANDLE_OmitXmlDeclaration );
     433           0 :     initializePropertyValueCache( HANDLE_Standalone );
     434           0 : }
     435             : 
     436           0 : sal_Bool SAL_CALL Submission::convertFastPropertyValue(
     437             :     Any& rConvertedValue, Any& rOldValue, sal_Int32 nHandle, const Any& rValue )
     438             :     throw ( IllegalArgumentException )
     439             : {
     440           0 :     if ( nHandle == HANDLE_IncludeNamespacePrefixes )
     441             :     {
     442             :         // for convinience reasons (????), we accept a string which contains
     443             :         // a comma-separated list of namespace prefixes
     444           0 :         ::rtl::OUString sTokenList;
     445           0 :         if ( rValue >>= sTokenList )
     446             :         {
     447           0 :             std::vector< OUString > aPrefixes;
     448           0 :             sal_Int32 p = 0;
     449           0 :             while ( p >= 0 )
     450           0 :                 aPrefixes.push_back( sTokenList.getToken( 0, ',', p ) );
     451             : 
     452           0 :             Sequence< ::rtl::OUString > aConvertedPrefixes( &aPrefixes[0], aPrefixes.size() );
     453           0 :             return PropertySetBase::convertFastPropertyValue( rConvertedValue, rOldValue, nHandle, makeAny( aConvertedPrefixes ) );
     454           0 :         }
     455             :     }
     456             : 
     457           0 :     return PropertySetBase::convertFastPropertyValue( rConvertedValue, rOldValue, nHandle, rValue );
     458             : }
     459             : 
     460           0 : OUString SAL_CALL Submission::getName()
     461             :     throw( RuntimeException )
     462             : {
     463           0 :     return getID();
     464             : }
     465             : 
     466           0 : void SAL_CALL Submission::setName( const OUString& sID )
     467             :     throw( RuntimeException )
     468             : {
     469           0 :     setID( sID );
     470           0 : }
     471             : 
     472             : 
     473             : 
     474           0 : sal_Int64 SAL_CALL Submission::getSomething(
     475             :     const Sequence<sal_Int8>& aId )
     476             :     throw( RuntimeException )
     477             : {
     478           0 :     return ( aId == getUnoTunnelID() ) ? reinterpret_cast<sal_Int64>(this) : 0;
     479             : }
     480             : 
     481             : 
     482           0 : static OUString lcl_message( const OUString& rID, const OUString& rText )
     483             : {
     484           0 :     OUStringBuffer aMessage;
     485           0 :     aMessage.append( OUSTRING("XForms submission '") );
     486           0 :     aMessage.append( rID );
     487           0 :     aMessage.append( OUSTRING("' failed") );
     488           0 :     aMessage.append( rText );
     489           0 :     aMessage.append( OUSTRING(".") );
     490           0 :     return aMessage.makeStringAndClear();
     491             : }
     492             : 
     493           0 : void SAL_CALL Submission::submitWithInteraction(
     494             :     const Reference<XInteractionHandler>& _rxHandler )
     495             :     throw ( VetoException,
     496             :             WrappedTargetException,
     497             :             RuntimeException )
     498             : {
     499             :     // as long as this class is not really threadsafe, we need to copy
     500             :     // the members we're interested in
     501           0 :     Reference< XModel > xModel( mxModel );
     502           0 :     ::rtl::OUString sID( msID );
     503             : 
     504           0 :     if ( !xModel.is() || msID.isEmpty() )
     505             :         throw RuntimeException(
     506             :                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "This is not a valid submission object." ) ),
     507             :                 *this
     508           0 :               );
     509             : 
     510           0 :     Model* pModel = Model::getModel( xModel );
     511             :     OSL_ENSURE( pModel != NULL, "illegal model?" );
     512             : 
     513             :     // #i36765# #i47248# warning on submission of illegal data
     514             :     // check for validity (and query user if invalid)
     515           0 :     bool bValid = pModel->isValid();
     516           0 :     if( ! bValid )
     517             :     {
     518             :         InvalidDataOnSubmitException aInvalidDataException(
     519           0 :             lcl_message(sID, OUSTRING(" due to invalid data") ), *this );
     520             : 
     521           0 :         if( _rxHandler.is() )
     522             :         {
     523             :             // labouriously create interaction request
     524             :             comphelper::OInteractionRequest* pRequest
     525             :                 = new comphelper::OInteractionRequest(
     526           0 :                     makeAny( aInvalidDataException ) );
     527           0 :             Reference<XInteractionRequest> xRequest = pRequest;
     528             : 
     529             :             comphelper::OInteractionApprove* pContinue
     530           0 :                 = new comphelper::OInteractionApprove();
     531           0 :             Reference<XInteractionContinuation> xContinue = pContinue;
     532           0 :             pRequest->addContinuation( xContinue );
     533             : 
     534             :             comphelper::OInteractionDisapprove* pCancel
     535           0 :                 = new comphelper::OInteractionDisapprove();
     536           0 :             Reference<XInteractionContinuation> xCancel = pCancel;
     537           0 :             pRequest->addContinuation( xCancel );
     538             : 
     539             :             // ask the handler...
     540           0 :             _rxHandler->handle( xRequest );
     541             :             OSL_ENSURE( pContinue->wasSelected() || pCancel->wasSelected(),
     542             :                         "handler didn't select" );
     543             : 
     544             :             // and continue, if user chose 'continue'
     545           0 :             if( pContinue->wasSelected() )
     546           0 :                 bValid = true;
     547             :         }
     548             : 
     549             :         // abort if invalid (and user didn't tell us to continue)
     550           0 :         if( ! bValid )
     551           0 :             throw aInvalidDataException;
     552             :     }
     553             : 
     554             :     // attempt submission
     555           0 :     bool bResult = false;
     556             :     try
     557             :     {
     558           0 :         bResult = doSubmit( _rxHandler );
     559             :     }
     560           0 :     catch( const VetoException& )
     561             :     {
     562             :         OSL_FAIL( "Model::submit: Hmm. How can a single submission have a veto right?" );
     563             :         // allowed to leave
     564           0 :         throw;
     565             :     }
     566           0 :     catch( const Exception& e )
     567             :     {
     568             :         // exception caught: re-throw as wrapped target exception
     569             :         throw WrappedTargetException(
     570             :             lcl_message( sID, OUSTRING(" due to exception being thrown") ),
     571           0 :             *this, makeAny( e ) );
     572             :     }
     573             : 
     574           0 :     if( bResult )
     575             :     {
     576           0 :         mxModel->rebuild();
     577             :     }
     578             :     else
     579             :     {
     580             :         // other failure: throw wrapped target exception, too.
     581             :         throw WrappedTargetException(
     582           0 :             lcl_message( sID, OUString() ), *this, Any() );
     583           0 :     }
     584           0 : }
     585             : 
     586           0 : void SAL_CALL Submission::submit( ) throw ( VetoException, WrappedTargetException, RuntimeException )
     587             : {
     588           0 :     submitWithInteraction( NULL );
     589           0 : }
     590             : 
     591           0 : void SAL_CALL Submission::addSubmissionVetoListener( const Reference< XSubmissionVetoListener >& /*listener*/ ) throw (NoSupportException, RuntimeException)
     592             : {
     593             :     // TODO
     594           0 :     throw NoSupportException();
     595             : }
     596             : 
     597           0 : void SAL_CALL Submission::removeSubmissionVetoListener( const Reference< XSubmissionVetoListener >& /*listener*/ ) throw (NoSupportException, RuntimeException)
     598             : {
     599             :     // TODO
     600           0 :     throw NoSupportException();
     601             : }
     602             : 
     603           0 : static sal_Bool _isIgnorable(const Reference< XNode >& aNode)
     604             : {
     605             :     // ignore whitespace-only textnodes
     606           0 :     if (aNode->getNodeType() == NodeType_TEXT_NODE)
     607             :     {
     608           0 :         OUString aTrimmedValue = aNode->getNodeValue().trim();
     609           0 :         if (aTrimmedValue.isEmpty()) return sal_True;
     610             :     }
     611             : 
     612           0 :     return sal_False;
     613             : }
     614             : 
     615             : // recursively copy relevant nodes from A to B
     616           0 : static void _cloneNodes(Model& aModel, const Reference< XNode >& dstParent, const Reference< XNode >& source, sal_Bool bRemoveWSNodes)
     617             : {
     618           0 :     if (!source.is()) return;
     619             : 
     620           0 :     Reference< XNode > cur = source;
     621           0 :     Reference< XDocument > dstDoc = dstParent->getOwnerDocument();
     622           0 :     Reference< XNode > imported;
     623             : 
     624           0 :     if (cur.is())
     625             :     {
     626             :         //  is this node relevant?
     627           0 :         MIP mip = aModel.queryMIP(cur);
     628           0 :         if(mip.isRelevant() && !(bRemoveWSNodes && _isIgnorable(cur)))
     629             :         {
     630           0 :             imported = dstDoc->importNode(cur, sal_False);
     631           0 :             imported = dstParent->appendChild(imported);
     632             :             // append source children to new imported parent
     633           0 :             for( cur = cur->getFirstChild(); cur.is(); cur = cur->getNextSibling() )
     634           0 :                 _cloneNodes(aModel, imported, cur, bRemoveWSNodes);
     635           0 :         }
     636           0 :     }
     637             : }
     638           0 : Reference< XDocument > Submission::getInstanceDocument(const Reference< XXPathObject >& aObj)
     639             : {
     640             :     using namespace com::sun::star::xml::xpath;
     641             :     // result
     642           0 :     Reference< XDocument > aDocument;
     643             : 
     644           0 :     if (aObj->getObjectType() == XPathObjectType_XPATH_NODESET)
     645             :     {
     646           0 :         Reference< XNodeList > aList = aObj->getNodeList();
     647           0 :         if (aList->getLength() > 0)
     648           0 :             aDocument = aList->item(0)->getOwnerDocument();
     649             :     }
     650           0 :     return aDocument;
     651             : }
     652             : 
     653           0 : Reference< XDocumentFragment > Submission::createSubmissionDocument(const Reference< XXPathObject >& aObj, sal_Bool bRemoveWSNodes)
     654             : {
     655             :     using namespace com::sun::star::xml::xpath;
     656           0 :     Reference< XDocumentBuilder > aDocBuilder(DocumentBuilder::create(comphelper::getComponentContext(m_aFactory)));
     657           0 :     Reference< XDocument > aDocument = aDocBuilder->newDocument();
     658           0 :     Reference< XDocumentFragment > aFragment = aDocument->createDocumentFragment();
     659             : 
     660             :     //
     661           0 :     if (aObj->getObjectType() == XPathObjectType_XPATH_NODESET)
     662             :     {
     663           0 :         Reference< XNodeList > aList = aObj->getNodeList();
     664           0 :         Reference< XNode > aListItem;
     665           0 :         for (sal_Int32 i=0; i < aList->getLength(); i++)
     666             :         {
     667           0 :             aListItem = aList->item(i);
     668           0 :             if (aListItem->getNodeType()==NodeType_DOCUMENT_NODE)
     669             :                 aListItem = Reference< XNode >(
     670           0 :                     (Reference< XDocument >(aListItem, UNO_QUERY))->getDocumentElement(), UNO_QUERY);
     671             :             // copy relevant nodes from instance into fragment
     672           0 :             _cloneNodes(*getModelImpl(), Reference< XNode >(aFragment, UNO_QUERY), aListItem, bRemoveWSNodes);
     673           0 :         }
     674             :     }
     675           0 :     return aFragment;
     676             : }
     677             : 
     678             : // some forwarding: XPropertySet is implemented in our base class,
     679             : // but also available as base of XSubmission
     680           0 : Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL Submission::getPropertySetInfo(  ) throw(RuntimeException)
     681             : {
     682           0 :     return PropertySetBase::getPropertySetInfo();
     683             : }
     684           0 : void SAL_CALL Submission::setPropertyValue( const ::rtl::OUString& aPropertyName, const Any& aValue ) throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
     685             : {
     686           0 :     PropertySetBase::setPropertyValue( aPropertyName, aValue );
     687           0 : }
     688           0 : Any SAL_CALL Submission::getPropertyValue( const ::rtl::OUString& PropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
     689             : {
     690           0 :     return PropertySetBase::getPropertyValue( PropertyName );
     691             : }
     692           0 : void SAL_CALL Submission::addPropertyChangeListener( const ::rtl::OUString& aPropertyName, const Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
     693             : {
     694           0 :     PropertySetBase::addPropertyChangeListener( aPropertyName, xListener );
     695           0 : }
     696           0 : void SAL_CALL Submission::removePropertyChangeListener( const ::rtl::OUString& aPropertyName, const Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
     697             : {
     698           0 :     PropertySetBase::removePropertyChangeListener( aPropertyName, aListener );
     699           0 : }
     700           0 : void SAL_CALL Submission::addVetoableChangeListener( const ::rtl::OUString& PropertyName, const Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
     701             : {
     702           0 :     PropertySetBase::addVetoableChangeListener( PropertyName, aListener );
     703           0 : }
     704           0 : void SAL_CALL Submission::removeVetoableChangeListener( const ::rtl::OUString& PropertyName, const Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
     705             : {
     706           0 :     PropertySetBase::removeVetoableChangeListener( PropertyName, aListener );
     707           0 : }
     708             : 
     709             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10