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

Generated by: LCOV version 1.10