1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "XFormsModelContext.hxx"
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>
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
;
58 SvXMLImportContext
* createXFormsModelContext(
61 const OUString
& rLocalName
)
63 return new XFormsModelContext( rImport
, nPrefix
, rLocalName
);
66 void bindXFormsValueBinding(
67 Reference
<XModel
> xModel
,
68 pair
<Reference
<XPropertySet
>,OUString
> aPair
)
70 Reference
<XBindableValue
> xBindable(
73 Reference
<XValueBinding
> xBinding(
74 xforms_findXFormsBinding( xModel
, aPair
.second
),
77 if( xBindable
.is() && xBinding
.is() )
81 xBindable
->setValueBinding( xBinding
);
83 catch( const Exception
& )
85 // ignore problems during binding
86 // TODO: call XML error handling
91 void bindXFormsListBinding(
92 Reference
<XModel
> xModel
,
93 ::pair
<Reference
<XPropertySet
>,OUString
> aPair
)
95 Reference
<XListEntrySink
> xListEntrySink(
98 Reference
<XListEntrySource
> xListEntrySource(
99 xforms_findXFormsBinding( xModel
, aPair
.second
),
102 if( xListEntrySink
.is() && xListEntrySource
.is() )
106 xListEntrySink
->setListEntrySource( xListEntrySource
);
108 catch( const Exception
& )
110 // ignore problems during binding
111 // TODO: call XML error handling
116 void bindXFormsSubmission(
117 Reference
<XModel
> xModel
,
118 pair
<Reference
<XPropertySet
>,OUString
> aPair
)
120 Reference
<XSubmissionSupplier
> xSubmissionSupp( aPair
.first
, UNO_QUERY
);
121 Reference
<XSubmission
> xSubmission(
122 xforms_findXFormsSubmission( xModel
, aPair
.second
),
125 if( xSubmissionSupp
.is() && xSubmission
.is() )
129 xSubmissionSupp
->setSubmission( xSubmission
);
131 catch( const Exception
& )
133 // ignore problems during binding
134 // TODO: call XML error handling
139 void applyXFormsSettings( const Reference
< XNameAccess
>& _rXForms
, const Sequence
< PropertyValue
>& _rSettings
)
141 OSL_PRECOND( _rXForms
.is(), "applyXFormsSettings: invalid XForms container!" );
142 if ( !_rXForms
.is() )
145 ::comphelper::NamedValueCollection
aSettings( _rSettings
);
146 Reference
< XNameAccess
> xModelSettings( aSettings
.get( "XFormModels" ), UNO_QUERY
);
147 if ( !xModelSettings
.is() )
149 OSL_FAIL( "applyXFormsSettings: wrong type for the XFormModels settings!" );
155 Sequence
< OUString
> aSettingsForModels( xModelSettings
->getElementNames() );
156 for ( const OUString
* pModelName
= aSettingsForModels
.getConstArray();
157 pModelName
!= aSettingsForModels
.getConstArray() + aSettingsForModels
.getLength();
161 // the settings for this particular model
162 Sequence
< PropertyValue
> aModelSettings
;
163 OSL_VERIFY( xModelSettings
->getByName( *pModelName
) >>= aModelSettings
);
166 if ( !_rXForms
->hasByName( *pModelName
) )
168 OSL_FAIL( "applyXFormsSettings: have settings for a non-existent XForms model!" );
172 // propagate the settings, being tolerant by omitting properties which are not supported
173 Reference
< XPropertySet
> xModelProps( _rXForms
->getByName( *pModelName
), UNO_QUERY_THROW
);
174 Reference
< XPropertySetInfo
> xModelPSI( xModelProps
->getPropertySetInfo(), UNO_SET_THROW
);
176 for ( const PropertyValue
* pSetting
= aModelSettings
.getConstArray();
177 pSetting
!= aModelSettings
.getConstArray() + aModelSettings
.getLength();
181 if ( !xModelPSI
->hasPropertyByName( pSetting
->Name
) )
183 OSL_FAIL( "applyXFormsSettings: non-existent model property!" );
187 xModelProps
->setPropertyValue( pSetting
->Name
, pSetting
->Value
);
191 catch( const Exception
& )
193 DBG_UNHANDLED_EXCEPTION();
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */