LibreOffice Module xmloff (master) 1
xformsimport.cxx
Go to the documentation of this file.
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
22#include <utility>
24#include <com/sun/star/uno/Reference.hxx>
25#include <com/sun/star/beans/XPropertySet.hpp>
26#include <com/sun/star/form/binding/XValueBinding.hpp>
27#include <com/sun/star/form/binding/XBindableValue.hpp>
28#include <com/sun/star/form/binding/XListEntrySource.hpp>
29#include <com/sun/star/form/binding/XListEntrySink.hpp>
30#include <com/sun/star/form/submission/XSubmission.hpp>
31#include <com/sun/star/form/submission/XSubmissionSupplier.hpp>
32#include <com/sun/star/container/XNameAccess.hpp>
33#include <rtl/ustring.hxx>
34#include "xformsapi.hxx"
36#include <tools/diagnose_ex.h>
37
38using std::pair;
40using com::sun::star::uno::Exception;
41using com::sun::star::uno::UNO_QUERY;
42using com::sun::star::uno::UNO_QUERY_THROW;
43using com::sun::star::uno::UNO_SET_THROW;
46using com::sun::star::beans::XPropertySetInfo;
47using com::sun::star::beans::PropertyValue;
48using com::sun::star::frame::XModel;
49using com::sun::star::container::XNameAccess;
50using com::sun::star::form::binding::XValueBinding;
51using com::sun::star::form::binding::XBindableValue;
52using com::sun::star::form::binding::XListEntrySource;
53using com::sun::star::form::binding::XListEntrySink;
54using com::sun::star::form::submission::XSubmission;
55using com::sun::star::form::submission::XSubmissionSupplier;
56
58 SvXMLImport& rImport )
59{
60 return new XFormsModelContext( rImport );
61}
62
64 const pair<Reference<XPropertySet>, OUString>& aPair)
65{
67 aPair.first,
68 UNO_QUERY );
70 xforms_findXFormsBinding( xModel, aPair.second ),
71 UNO_QUERY );
72
73 if( xBindable.is() && xBinding.is() )
74 {
75 try
76 {
77 xBindable->setValueBinding( xBinding );
78 }
79 catch( const Exception& )
80 {
81 // ignore problems during binding
82 // TODO: call XML error handling
83 }
84 }
85}
86
88 const ::pair<Reference<XPropertySet>, OUString>& aPair)
89{
90 Reference<XListEntrySink> xListEntrySink(
91 aPair.first,
92 UNO_QUERY );
93 Reference<XListEntrySource> xListEntrySource(
94 xforms_findXFormsBinding( xModel, aPair.second ),
95 UNO_QUERY );
96
97 if( xListEntrySink.is() && xListEntrySource.is() )
98 {
99 try
100 {
101 xListEntrySink->setListEntrySource( xListEntrySource );
102 }
103 catch( const Exception& )
104 {
105 // ignore problems during binding
106 // TODO: call XML error handling
107 }
108 }
109}
110
112 const pair<Reference<XPropertySet>, OUString>& aPair)
113{
114 Reference<XSubmissionSupplier> xSubmissionSupp( aPair.first, UNO_QUERY );
115 Reference<XSubmission> xSubmission(
116 xforms_findXFormsSubmission( xModel, aPair.second ),
117 UNO_QUERY );
118
119 if( xSubmissionSupp.is() && xSubmission.is() )
120 {
121 try
122 {
123 xSubmissionSupp->setSubmission( xSubmission );
124 }
125 catch( const Exception& )
126 {
127 // ignore problems during binding
128 // TODO: call XML error handling
129 }
130 }
131}
132
134{
135 OSL_PRECOND( _rXForms.is(), "applyXFormsSettings: invalid XForms container!" );
136 if ( !_rXForms.is() )
137 return;
138
139 Reference< XNameAccess > xModelSettings( ::comphelper::NamedValueCollection::get( _rSettings, u"XFormModels" ), UNO_QUERY );
140 if ( !xModelSettings.is() )
141 {
142 OSL_FAIL( "applyXFormsSettings: wrong type for the XFormModels settings!" );
143 return;
144 }
145
146 try
147 {
148 const Sequence< OUString > aSettingsForModels( xModelSettings->getElementNames() );
149 for ( auto const & modelName : aSettingsForModels )
150 {
151 // the settings for this particular model
152 Sequence< PropertyValue > aModelSettings;
153 OSL_VERIFY( xModelSettings->getByName( modelName ) >>= aModelSettings );
154
155 // the model itself
156 if ( !_rXForms->hasByName( modelName ) )
157 {
158 OSL_FAIL( "applyXFormsSettings: have settings for a non-existent XForms model!" );
159 continue;
160 }
161
162 // propagate the settings, being tolerant by omitting properties which are not supported
163 Reference< XPropertySet > xModelProps( _rXForms->getByName( modelName ), UNO_QUERY_THROW );
164 Reference< XPropertySetInfo > xModelPSI( xModelProps->getPropertySetInfo(), UNO_SET_THROW );
165
166 for ( auto const & setting : std::as_const(aModelSettings) )
167 {
168 if ( !xModelPSI->hasPropertyByName( setting.Name ) )
169 {
170 OSL_FAIL( "applyXFormsSettings: non-existent model property!" );
171 continue;
172 }
173
174 xModelProps->setPropertyValue( setting.Name, setting.Value );
175 }
176 }
177 }
178 catch( const Exception& )
179 {
180 DBG_UNHANDLED_EXCEPTION("xmloff");
181 }
182}
183
184/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This class deliberately does not support XWeak, to improve performance when loading large documents.
Definition: xmlictxt.hxx:48
import the xforms:model element
const css::uno::Any & get(const OUString &_rValueName) const
#define DBG_UNHANDLED_EXCEPTION(...)
float u
@ Exception
class SAL_NO_VTABLE XPropertySet
Reference< XModel > xModel
Reference< XPropertySet > xforms_findXFormsSubmission(Reference< frame::XModel > const &xDocument, const OUString &rBindingID)
Definition: xformsapi.cxx:159
Reference< XPropertySet > xforms_findXFormsBinding(Reference< frame::XModel > const &xDocument, const OUString &rBindingID)
Definition: xformsapi.cxx:152
void bindXFormsListBinding(Reference< XModel > const &xModel, const ::pair< Reference< XPropertySet >, OUString > &aPair)
void bindXFormsValueBinding(Reference< XModel > const &xModel, const pair< Reference< XPropertySet >, OUString > &aPair)
void applyXFormsSettings(const Reference< XNameAccess > &_rXForms, const Sequence< PropertyValue > &_rSettings)
SvXMLImportContext * createXFormsModelContext(SvXMLImport &rImport)
create import context for xforms:model element.
void bindXFormsSubmission(Reference< XModel > const &xModel, const pair< Reference< XPropertySet >, OUString > &aPair)