Update ooo320-m1
[ooovba.git] / xmloff / source / xforms / xformsimport.cxx
blobdbe575e1d39214e487ac9c85751bd8d470bd36e6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xformsimport.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
34 #include "XFormsModelContext.hxx"
35 #include <vector>
36 #include <utility>
37 #include "xformsimport.hxx"
38 #include <com/sun/star/uno/Reference.hxx>
39 #include <com/sun/star/beans/XPropertySet.hpp>
40 #include <com/sun/star/form/binding/XValueBinding.hpp>
41 #include <com/sun/star/form/binding/XBindableValue.hpp>
42 #include <com/sun/star/form/binding/XListEntrySource.hpp>
43 #include <com/sun/star/form/binding/XListEntrySink.hpp>
44 #include <com/sun/star/form/submission/XSubmission.hpp>
45 #include <com/sun/star/form/submission/XSubmissionSupplier.hpp>
46 #include <com/sun/star/container/XNameAccess.hpp>
47 #include <rtl/ustring.hxx>
48 #include <xformsapi.hxx>
49 #include <comphelper/namedvaluecollection.hxx>
50 #include <tools/diagnose_ex.h>
52 using std::pair;
53 using com::sun::star::uno::Reference;
54 using com::sun::star::uno::Exception;
55 using com::sun::star::uno::UNO_QUERY;
56 using com::sun::star::uno::UNO_QUERY_THROW;
57 using com::sun::star::uno::UNO_SET_THROW;
58 using com::sun::star::uno::Sequence;
59 using com::sun::star::beans::XPropertySet;
60 using com::sun::star::beans::XPropertySetInfo;
61 using com::sun::star::beans::PropertyValue;
62 using com::sun::star::frame::XModel;
63 using com::sun::star::container::XNameAccess;
64 using com::sun::star::form::binding::XValueBinding;
65 using com::sun::star::form::binding::XBindableValue;
66 using com::sun::star::form::binding::XListEntrySource;
67 using com::sun::star::form::binding::XListEntrySink;
68 using com::sun::star::form::submission::XSubmission;
69 using com::sun::star::form::submission::XSubmissionSupplier;
70 using rtl::OUString;
72 SvXMLImportContext* createXFormsModelContext(
73 SvXMLImport& rImport,
74 USHORT nPrefix,
75 const rtl::OUString& rLocalName )
77 return new XFormsModelContext( rImport, nPrefix, rLocalName );
80 void bindXFormsValueBinding(
81 Reference<XModel> xModel,
82 pair<Reference<XPropertySet>,OUString> aPair )
84 Reference<XBindableValue> xBindable(
85 aPair.first,
86 UNO_QUERY );
87 Reference<XValueBinding> xBinding(
88 lcl_findXFormsBinding( xModel, aPair.second ),
89 UNO_QUERY );
91 if( xBindable.is() && xBinding.is() )
93 try
95 xBindable->setValueBinding( xBinding );
97 catch( const Exception& )
99 // ignore problems during binding
100 // TODO: call XML error handling
105 void bindXFormsListBinding(
106 Reference<XModel> xModel,
107 ::pair<Reference<XPropertySet>,OUString> aPair )
109 Reference<XListEntrySink> xListEntrySink(
110 aPair.first,
111 UNO_QUERY );
112 Reference<XListEntrySource> xListEntrySource(
113 lcl_findXFormsBinding( xModel, aPair.second ),
114 UNO_QUERY );
116 if( xListEntrySink.is() && xListEntrySource.is() )
120 xListEntrySink->setListEntrySource( xListEntrySource );
122 catch( const Exception& )
124 // ignore problems during binding
125 // TODO: call XML error handling
130 void bindXFormsSubmission(
131 Reference<XModel> xModel,
132 pair<Reference<XPropertySet>,OUString> aPair )
134 Reference<XSubmissionSupplier> xSubmissionSupp( aPair.first, UNO_QUERY );
135 Reference<XSubmission> xSubmission(
136 lcl_findXFormsSubmission( xModel, aPair.second ),
137 UNO_QUERY );
139 if( xSubmissionSupp.is() && xSubmission.is() )
143 xSubmissionSupp->setSubmission( xSubmission );
145 catch( const Exception& )
147 // ignore problems during binding
148 // TODO: call XML error handling
153 void applyXFormsSettings( const Reference< XNameAccess >& _rXForms, const Sequence< PropertyValue >& _rSettings )
155 OSL_PRECOND( _rXForms.is(), "applyXFormsSettings: invalid XForms container!" );
156 if ( !_rXForms.is() )
157 return;
159 ::comphelper::NamedValueCollection aSettings( _rSettings );
160 Reference< XNameAccess > xModelSettings( aSettings.get( "XFormModels" ), UNO_QUERY );
161 if ( !xModelSettings.is() )
163 OSL_ENSURE( false, "applyXFormsSettings: wrong type for the XFormModels settings!" );
164 return;
169 Sequence< ::rtl::OUString > aSettingsForModels( xModelSettings->getElementNames() );
170 for ( const ::rtl::OUString* pModelName = aSettingsForModels.getConstArray();
171 pModelName != aSettingsForModels.getConstArray() + aSettingsForModels.getLength();
172 ++pModelName
175 // the settings for this particular model
176 Sequence< PropertyValue > aModelSettings;
177 OSL_VERIFY( xModelSettings->getByName( *pModelName ) >>= aModelSettings );
179 // the model itself
180 if ( !_rXForms->hasByName( *pModelName ) )
182 OSL_ENSURE( false, "applyXFormsSettings: have settings for a non-existent XForms model!" );
183 continue;
186 // propagate the settings, being tolerant by omitting properties which are not supported
187 Reference< XPropertySet > xModelProps( _rXForms->getByName( *pModelName ), UNO_QUERY_THROW );
188 Reference< XPropertySetInfo > xModelPSI( xModelProps->getPropertySetInfo(), UNO_SET_THROW );
190 for ( const PropertyValue* pSetting = aModelSettings.getConstArray();
191 pSetting != aModelSettings.getConstArray() + aModelSettings.getLength();
192 ++pSetting
195 if ( !xModelPSI->hasPropertyByName( pSetting->Name ) )
197 OSL_ENSURE( false, "applyXFormsSettings: non-existent model property!" );
198 continue;
201 xModelProps->setPropertyValue( pSetting->Name, pSetting->Value );
205 catch( const Exception& )
207 DBG_UNHANDLED_EXCEPTION();