LCOV - code coverage report
Current view: top level - xmloff/source/xforms - xformsimport.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 50 0.0 %
Date: 2014-11-03 Functions: 0 5 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 "XFormsModelContext.hxx"
      22             : #include <vector>
      23             : #include <utility>
      24             : #include <xmloff/xformsimport.hxx>
      25             : #include <com/sun/star/uno/Reference.hxx>
      26             : #include <com/sun/star/beans/XPropertySet.hpp>
      27             : #include <com/sun/star/form/binding/XValueBinding.hpp>
      28             : #include <com/sun/star/form/binding/XBindableValue.hpp>
      29             : #include <com/sun/star/form/binding/XListEntrySource.hpp>
      30             : #include <com/sun/star/form/binding/XListEntrySink.hpp>
      31             : #include <com/sun/star/form/submission/XSubmission.hpp>
      32             : #include <com/sun/star/form/submission/XSubmissionSupplier.hpp>
      33             : #include <com/sun/star/container/XNameAccess.hpp>
      34             : #include <rtl/ustring.hxx>
      35             : #include <xformsapi.hxx>
      36             : #include <comphelper/namedvaluecollection.hxx>
      37             : #include <tools/diagnose_ex.h>
      38             : 
      39             : using std::pair;
      40             : using com::sun::star::uno::Reference;
      41             : using com::sun::star::uno::Exception;
      42             : using com::sun::star::uno::UNO_QUERY;
      43             : using com::sun::star::uno::UNO_QUERY_THROW;
      44             : using com::sun::star::uno::UNO_SET_THROW;
      45             : using com::sun::star::uno::Sequence;
      46             : using com::sun::star::beans::XPropertySet;
      47             : using com::sun::star::beans::XPropertySetInfo;
      48             : using com::sun::star::beans::PropertyValue;
      49             : using com::sun::star::frame::XModel;
      50             : using com::sun::star::container::XNameAccess;
      51             : using com::sun::star::form::binding::XValueBinding;
      52             : using com::sun::star::form::binding::XBindableValue;
      53             : using com::sun::star::form::binding::XListEntrySource;
      54             : using com::sun::star::form::binding::XListEntrySink;
      55             : using com::sun::star::form::submission::XSubmission;
      56             : using com::sun::star::form::submission::XSubmissionSupplier;
      57             : 
      58           0 : SvXMLImportContext* createXFormsModelContext(
      59             :     SvXMLImport& rImport,
      60             :     sal_uInt16 nPrefix,
      61             :     const OUString& rLocalName )
      62             : {
      63           0 :     return new XFormsModelContext( rImport, nPrefix, rLocalName );
      64             : }
      65             : 
      66           0 : void bindXFormsValueBinding(
      67             :     Reference<XModel> xModel,
      68             :     pair<Reference<XPropertySet>,OUString> aPair )
      69             : {
      70             :     Reference<XBindableValue> xBindable(
      71             :         aPair.first,
      72           0 :         UNO_QUERY );
      73             :     Reference<XValueBinding> xBinding(
      74             :         xforms_findXFormsBinding( xModel, aPair.second ),
      75           0 :         UNO_QUERY );
      76             : 
      77           0 :     if( xBindable.is() && xBinding.is() )
      78             :     {
      79             :         try
      80             :         {
      81           0 :             xBindable->setValueBinding( xBinding );
      82             :         }
      83           0 :         catch( const Exception& )
      84             :         {
      85             :             // ignore problems during binding
      86             :             // TODO: call XML error handling
      87             :         }
      88           0 :     }
      89           0 : }
      90             : 
      91           0 : void bindXFormsListBinding(
      92             :     Reference<XModel> xModel,
      93             :     ::pair<Reference<XPropertySet>,OUString> aPair )
      94             : {
      95             :     Reference<XListEntrySink> xListEntrySink(
      96             :         aPair.first,
      97           0 :         UNO_QUERY );
      98             :     Reference<XListEntrySource> xListEntrySource(
      99             :         xforms_findXFormsBinding( xModel, aPair.second ),
     100           0 :         UNO_QUERY );
     101             : 
     102           0 :     if( xListEntrySink.is() && xListEntrySource.is() )
     103             :     {
     104             :         try
     105             :         {
     106           0 :             xListEntrySink->setListEntrySource( xListEntrySource );
     107             :         }
     108           0 :         catch( const Exception& )
     109             :         {
     110             :             // ignore problems during binding
     111             :             // TODO: call XML error handling
     112             :         }
     113           0 :     }
     114           0 : }
     115             : 
     116           0 : void bindXFormsSubmission(
     117             :     Reference<XModel> xModel,
     118             :     pair<Reference<XPropertySet>,OUString> aPair )
     119             : {
     120           0 :     Reference<XSubmissionSupplier> xSubmissionSupp( aPair.first, UNO_QUERY );
     121             :     Reference<XSubmission> xSubmission(
     122             :         xforms_findXFormsSubmission( xModel, aPair.second ),
     123           0 :         UNO_QUERY );
     124             : 
     125           0 :     if( xSubmissionSupp.is() && xSubmission.is() )
     126             :     {
     127             :         try
     128             :         {
     129           0 :             xSubmissionSupp->setSubmission( xSubmission );
     130             :         }
     131           0 :         catch( const Exception& )
     132             :         {
     133             :             // ignore problems during binding
     134             :             // TODO: call XML error handling
     135             :         }
     136           0 :     }
     137           0 : }
     138             : 
     139           0 : void applyXFormsSettings( const Reference< XNameAccess >& _rXForms, const Sequence< PropertyValue >& _rSettings )
     140             : {
     141             :     OSL_PRECOND( _rXForms.is(), "applyXFormsSettings: invalid XForms container!" );
     142           0 :     if ( !_rXForms.is() )
     143           0 :         return;
     144             : 
     145           0 :     ::comphelper::NamedValueCollection aSettings( _rSettings );
     146           0 :     Reference< XNameAccess > xModelSettings( aSettings.get( "XFormModels" ), UNO_QUERY );
     147           0 :     if ( !xModelSettings.is() )
     148             :     {
     149             :         OSL_FAIL( "applyXFormsSettings: wrong type for the XFormModels settings!" );
     150           0 :         return;
     151             :     }
     152             : 
     153             :     try
     154             :     {
     155           0 :         Sequence< OUString > aSettingsForModels( xModelSettings->getElementNames() );
     156           0 :         for (   const OUString* pModelName = aSettingsForModels.getConstArray();
     157           0 :                 pModelName != aSettingsForModels.getConstArray() + aSettingsForModels.getLength();
     158             :                 ++pModelName
     159             :             )
     160             :         {
     161             :             // the settings for this particular model
     162           0 :             Sequence< PropertyValue > aModelSettings;
     163           0 :             OSL_VERIFY( xModelSettings->getByName( *pModelName ) >>= aModelSettings );
     164             : 
     165             :             // the model itself
     166           0 :             if ( !_rXForms->hasByName( *pModelName ) )
     167             :             {
     168             :                 OSL_FAIL( "applyXFormsSettings: have settings for a non-existent XForms model!" );
     169           0 :                 continue;
     170             :             }
     171             : 
     172             :             // propagate the settings, being tolerant by omitting properties which are not supported
     173           0 :             Reference< XPropertySet > xModelProps( _rXForms->getByName( *pModelName ), UNO_QUERY_THROW );
     174           0 :             Reference< XPropertySetInfo > xModelPSI( xModelProps->getPropertySetInfo(), UNO_SET_THROW );
     175             : 
     176           0 :             for (   const PropertyValue* pSetting = aModelSettings.getConstArray();
     177           0 :                     pSetting != aModelSettings.getConstArray() + aModelSettings.getLength();
     178             :                     ++pSetting
     179             :                 )
     180             :             {
     181           0 :                 if ( !xModelPSI->hasPropertyByName( pSetting->Name ) )
     182             :                 {
     183             :                     OSL_FAIL( "applyXFormsSettings: non-existent model property!" );
     184           0 :                     continue;
     185             :                 }
     186             : 
     187           0 :                 xModelProps->setPropertyValue( pSetting->Name, pSetting->Value );
     188             :             }
     189           0 :         }
     190             :     }
     191           0 :     catch( const Exception& )
     192             :     {
     193             :         DBG_UNHANDLED_EXCEPTION();
     194           0 :     }
     195             : }
     196             : 
     197             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10