Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "XFormsModelContext.hxx"
31 : : #include <vector>
32 : : #include <utility>
33 : : #include "xmloff/xformsimport.hxx"
34 : : #include <com/sun/star/uno/Reference.hxx>
35 : : #include <com/sun/star/beans/XPropertySet.hpp>
36 : : #include <com/sun/star/form/binding/XValueBinding.hpp>
37 : : #include <com/sun/star/form/binding/XBindableValue.hpp>
38 : : #include <com/sun/star/form/binding/XListEntrySource.hpp>
39 : : #include <com/sun/star/form/binding/XListEntrySink.hpp>
40 : : #include <com/sun/star/form/submission/XSubmission.hpp>
41 : : #include <com/sun/star/form/submission/XSubmissionSupplier.hpp>
42 : : #include <com/sun/star/container/XNameAccess.hpp>
43 : : #include <rtl/ustring.hxx>
44 : : #include <xformsapi.hxx>
45 : : #include <comphelper/namedvaluecollection.hxx>
46 : : #include <tools/diagnose_ex.h>
47 : :
48 : : using std::pair;
49 : : using com::sun::star::uno::Reference;
50 : : using com::sun::star::uno::Exception;
51 : : using com::sun::star::uno::UNO_QUERY;
52 : : using com::sun::star::uno::UNO_QUERY_THROW;
53 : : using com::sun::star::uno::UNO_SET_THROW;
54 : : using com::sun::star::uno::Sequence;
55 : : using com::sun::star::beans::XPropertySet;
56 : : using com::sun::star::beans::XPropertySetInfo;
57 : : using com::sun::star::beans::PropertyValue;
58 : : using com::sun::star::frame::XModel;
59 : : using com::sun::star::container::XNameAccess;
60 : : using com::sun::star::form::binding::XValueBinding;
61 : : using com::sun::star::form::binding::XBindableValue;
62 : : using com::sun::star::form::binding::XListEntrySource;
63 : : using com::sun::star::form::binding::XListEntrySink;
64 : : using com::sun::star::form::submission::XSubmission;
65 : : using com::sun::star::form::submission::XSubmissionSupplier;
66 : : using rtl::OUString;
67 : :
68 : 0 : SvXMLImportContext* createXFormsModelContext(
69 : : SvXMLImport& rImport,
70 : : sal_uInt16 nPrefix,
71 : : const rtl::OUString& rLocalName )
72 : : {
73 [ # # ]: 0 : return new XFormsModelContext( rImport, nPrefix, rLocalName );
74 : : }
75 : :
76 : 0 : void bindXFormsValueBinding(
77 : : Reference<XModel> xModel,
78 : : pair<Reference<XPropertySet>,OUString> aPair )
79 : : {
80 : : Reference<XBindableValue> xBindable(
81 : : aPair.first,
82 [ # # ]: 0 : UNO_QUERY );
83 : : Reference<XValueBinding> xBinding(
84 : : lcl_findXFormsBinding( xModel, aPair.second ),
85 [ # # ][ # # ]: 0 : UNO_QUERY );
[ # # ]
86 : :
87 [ # # ][ # # ]: 0 : if( xBindable.is() && xBinding.is() )
[ # # ]
88 : : {
89 : : try
90 : : {
91 [ # # ][ # # ]: 0 : xBindable->setValueBinding( xBinding );
92 : : }
93 [ # # ]: 0 : catch( const Exception& )
94 : : {
95 : : // ignore problems during binding
96 : : // TODO: call XML error handling
97 : : }
98 : 0 : }
99 : 0 : }
100 : :
101 : 0 : void bindXFormsListBinding(
102 : : Reference<XModel> xModel,
103 : : ::pair<Reference<XPropertySet>,OUString> aPair )
104 : : {
105 : : Reference<XListEntrySink> xListEntrySink(
106 : : aPair.first,
107 [ # # ]: 0 : UNO_QUERY );
108 : : Reference<XListEntrySource> xListEntrySource(
109 : : lcl_findXFormsBinding( xModel, aPair.second ),
110 [ # # ][ # # ]: 0 : UNO_QUERY );
[ # # ]
111 : :
112 [ # # ][ # # ]: 0 : if( xListEntrySink.is() && xListEntrySource.is() )
[ # # ]
113 : : {
114 : : try
115 : : {
116 [ # # ][ # # ]: 0 : xListEntrySink->setListEntrySource( xListEntrySource );
117 : : }
118 [ # # ]: 0 : catch( const Exception& )
119 : : {
120 : : // ignore problems during binding
121 : : // TODO: call XML error handling
122 : : }
123 : 0 : }
124 : 0 : }
125 : :
126 : 0 : void bindXFormsSubmission(
127 : : Reference<XModel> xModel,
128 : : pair<Reference<XPropertySet>,OUString> aPair )
129 : : {
130 [ # # ]: 0 : Reference<XSubmissionSupplier> xSubmissionSupp( aPair.first, UNO_QUERY );
131 : : Reference<XSubmission> xSubmission(
132 : : lcl_findXFormsSubmission( xModel, aPair.second ),
133 [ # # ][ # # ]: 0 : UNO_QUERY );
[ # # ]
134 : :
135 [ # # ][ # # ]: 0 : if( xSubmissionSupp.is() && xSubmission.is() )
[ # # ]
136 : : {
137 : : try
138 : : {
139 [ # # ][ # # ]: 0 : xSubmissionSupp->setSubmission( xSubmission );
140 : : }
141 [ # # ]: 0 : catch( const Exception& )
142 : : {
143 : : // ignore problems during binding
144 : : // TODO: call XML error handling
145 : : }
146 : 0 : }
147 : 0 : }
148 : :
149 : 0 : void applyXFormsSettings( const Reference< XNameAccess >& _rXForms, const Sequence< PropertyValue >& _rSettings )
150 : : {
151 : : OSL_PRECOND( _rXForms.is(), "applyXFormsSettings: invalid XForms container!" );
152 [ # # ]: 0 : if ( !_rXForms.is() )
153 : : return;
154 : :
155 [ # # ]: 0 : ::comphelper::NamedValueCollection aSettings( _rSettings );
156 [ # # ][ # # ]: 0 : Reference< XNameAccess > xModelSettings( aSettings.get( "XFormModels" ), UNO_QUERY );
157 [ # # ]: 0 : if ( !xModelSettings.is() )
158 : : {
159 : : OSL_FAIL( "applyXFormsSettings: wrong type for the XFormModels settings!" );
160 : : return;
161 : : }
162 : :
163 : : try
164 : : {
165 [ # # ][ # # ]: 0 : Sequence< ::rtl::OUString > aSettingsForModels( xModelSettings->getElementNames() );
166 [ # # ]: 0 : for ( const ::rtl::OUString* pModelName = aSettingsForModels.getConstArray();
167 : 0 : pModelName != aSettingsForModels.getConstArray() + aSettingsForModels.getLength();
168 : : ++pModelName
169 : : )
170 : : {
171 : : // the settings for this particular model
172 [ # # ]: 0 : Sequence< PropertyValue > aModelSettings;
173 [ # # ][ # # ]: 0 : OSL_VERIFY( xModelSettings->getByName( *pModelName ) >>= aModelSettings );
[ # # ]
174 : :
175 : : // the model itself
176 [ # # ][ # # ]: 0 : if ( !_rXForms->hasByName( *pModelName ) )
[ # # ]
177 : : {
178 : : OSL_FAIL( "applyXFormsSettings: have settings for a non-existent XForms model!" );
179 : 0 : continue;
180 : : }
181 : :
182 : : // propagate the settings, being tolerant by omitting properties which are not supported
183 [ # # ][ # # ]: 0 : Reference< XPropertySet > xModelProps( _rXForms->getByName( *pModelName ), UNO_QUERY_THROW );
[ # # ]
184 [ # # ][ # # ]: 0 : Reference< XPropertySetInfo > xModelPSI( xModelProps->getPropertySetInfo(), UNO_SET_THROW );
[ # # ]
185 : :
186 [ # # ]: 0 : for ( const PropertyValue* pSetting = aModelSettings.getConstArray();
187 : 0 : pSetting != aModelSettings.getConstArray() + aModelSettings.getLength();
188 : : ++pSetting
189 : : )
190 : : {
191 [ # # ][ # # ]: 0 : if ( !xModelPSI->hasPropertyByName( pSetting->Name ) )
[ # # ]
192 : : {
193 : : OSL_FAIL( "applyXFormsSettings: non-existent model property!" );
194 : 0 : continue;
195 : : }
196 : :
197 [ # # ][ # # ]: 0 : xModelProps->setPropertyValue( pSetting->Name, pSetting->Value );
198 : : }
199 [ # # ][ # # ]: 0 : }
[ # # ][ # # ]
200 : : }
201 [ # # ]: 0 : catch( const Exception& )
202 : : {
203 : : DBG_UNHANDLED_EXCEPTION();
204 [ # # ][ # # ]: 0 : }
[ # # ]
205 : : }
206 : :
207 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|