bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / forms / layerimport.cxx
blob453c490098421c87abf0a3d6d456d9898b242b15
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include "layerimport.hxx"
21 #include "formenums.hxx"
22 #include "elementimport.hxx"
23 #include "officeforms.hxx"
24 #include "strings.hxx"
25 #include <xmloff/xmlictxt.hxx>
26 #include <xmloff/xmlstyle.hxx>
27 #include <xmloff/families.hxx>
28 #include <xmloff/xmlprmap.hxx>
29 #include <xmloff/prstylei.hxx>
30 #include <xmloff/xmlimp.hxx>
31 #include "XMLEventImportHelper.hxx"
32 #include <xmloff/xmlimppr.hxx>
33 #include <xmloff/xmlnumfi.hxx>
34 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
35 #include <com/sun/star/form/FormSubmitEncoding.hpp>
36 #include <com/sun/star/form/FormSubmitMethod.hpp>
37 #include <com/sun/star/sdb/CommandType.hpp>
38 #include <com/sun/star/form/NavigationBarMode.hpp>
39 #include <com/sun/star/form/TabulatorCycle.hpp>
40 #include <com/sun/star/form/FormButtonType.hpp>
41 #include <com/sun/star/awt/ScrollBarOrientation.hpp>
42 #include <com/sun/star/awt/VisualEffect.hpp>
43 #include <com/sun/star/form/ListSourceType.hpp>
44 #include <tools/gen.hxx>
45 #include <com/sun/star/lang/Locale.hpp>
46 #include <xmloff/controlpropertyhdl.hxx>
47 #include "controlpropertymap.hxx"
48 #include "formevents.hxx"
49 #include "formcellbinding.hxx"
50 #include <xmloff/xformsimport.hxx>
51 #include <xmloff/xmltoken.hxx>
52 #include <xmloff/xmlnmspe.hxx>
53 #include <rtl/strbuf.hxx>
54 #include <algorithm>
55 #include <functional>
57 namespace xmloff
60 using namespace ::com::sun::star::uno;
61 using namespace ::com::sun::star::awt;
62 using namespace ::com::sun::star::lang;
63 using namespace ::com::sun::star::beans;
64 using namespace ::com::sun::star::container;
65 using namespace ::com::sun::star::drawing;
66 using namespace ::com::sun::star;
67 using namespace ::com::sun::star::util;
68 using namespace ::com::sun::star::form;
69 using namespace ::com::sun::star::sdb;
71 //= OFormLayerXMLImport_Impl
72 OFormLayerXMLImport_Impl::OFormLayerXMLImport_Impl(SvXMLImport& _rImporter)
73 :m_rImporter(_rImporter)
74 ,m_pAutoStyles(NULL)
76 // build the attribute2property map
77 // string properties which are exported as attributes
78 m_aAttributeMetaData.addStringProperty(
79 OAttributeMetaData::getCommonControlAttributeName(CCA_NAME), PROPERTY_NAME);
80 m_aAttributeMetaData.addStringProperty(
81 OAttributeMetaData::getSpecialAttributeName(SCA_GROUP_NAME), PROPERTY_GROUP_NAME);
82 m_aAttributeMetaData.addStringProperty(
83 OAttributeMetaData::getCommonControlAttributeName(CCA_IMAGE_DATA), PROPERTY_IMAGEURL);
84 m_aAttributeMetaData.addStringProperty(
85 OAttributeMetaData::getCommonControlAttributeName(CCA_LABEL), PROPERTY_LABEL);
86 m_aAttributeMetaData.addStringProperty(
87 OAttributeMetaData::getCommonControlAttributeName(CCA_TARGET_LOCATION), PROPERTY_TARGETURL);
88 m_aAttributeMetaData.addStringProperty(
89 OAttributeMetaData::getCommonControlAttributeName(CCA_TITLE), PROPERTY_TITLE);
90 m_aAttributeMetaData.addStringProperty(
91 OAttributeMetaData::getCommonControlAttributeName(CCA_TARGET_FRAME), PROPERTY_TARGETFRAME, "_blank");
92 m_aAttributeMetaData.addStringProperty(
93 OAttributeMetaData::getDatabaseAttributeName(DA_DATA_FIELD), PROPERTY_DATAFIELD);
94 m_aAttributeMetaData.addStringProperty(
95 OAttributeMetaData::getFormAttributeName(faCommand), PROPERTY_COMMAND);
96 m_aAttributeMetaData.addStringProperty(
97 OAttributeMetaData::getFormAttributeName(faDatasource), PROPERTY_DATASOURCENAME);
98 m_aAttributeMetaData.addStringProperty(
99 OAttributeMetaData::getFormAttributeName(faFilter), PROPERTY_FILTER);
100 m_aAttributeMetaData.addStringProperty(
101 OAttributeMetaData::getFormAttributeName(faOrder), PROPERTY_ORDER);
103 // properties not added because they're already present in another form
104 OSL_ENSURE(
105 OUString::createFromAscii(OAttributeMetaData::getCommonControlAttributeName(CCA_TARGET_LOCATION)).equalsAscii(
106 OAttributeMetaData::getFormAttributeName(faAction)),
107 "OFormLayerXMLImport_Impl::OFormLayerXMLImport_Impl: invalid attribute names (1)!");
108 // if this fails, we would have to add a translation from faAction->PROPERTY_TARGETURL
109 // We did not because we already have one CCA_TARGET_LOCATION->PROPERTY_TARGETURL,
110 // and CCA_TARGET_LOCATION and faAction should be represented by the same attribute
112 OSL_ENSURE(
113 OUString::createFromAscii(OAttributeMetaData::getCommonControlAttributeName(CCA_NAME)).equalsAscii(
114 OAttributeMetaData::getFormAttributeName(faName)),
115 "OFormLayerXMLImport_Impl::OFormLayerXMLImport_Impl: invalid attribute names (2)!");
116 // the same for faName, CCA_NAME and PROPERTY_NAME
118 // boolean properties which are exported as attributes
119 m_aAttributeMetaData.addBooleanProperty(
120 OAttributeMetaData::getCommonControlAttributeName(CCA_CURRENT_SELECTED), PROPERTY_STATE, false);
121 m_aAttributeMetaData.addBooleanProperty(
122 OAttributeMetaData::getCommonControlAttributeName(CCA_DISABLED), PROPERTY_ENABLED, false, true);
123 m_aAttributeMetaData.addBooleanProperty(
124 OAttributeMetaData::getCommonControlAttributeName(CCA_DROPDOWN), PROPERTY_DROPDOWN, false);
125 m_aAttributeMetaData.addBooleanProperty(
126 OAttributeMetaData::getCommonControlAttributeName(CCA_PRINTABLE), PROPERTY_PRINTABLE, true);
127 m_aAttributeMetaData.addBooleanProperty(
128 OAttributeMetaData::getCommonControlAttributeName(CCA_READONLY), PROPERTY_READONLY, false);
129 m_aAttributeMetaData.addBooleanProperty(
130 OAttributeMetaData::getCommonControlAttributeName(CCA_SELECTED), PROPERTY_DEFAULT_STATE, false);
131 m_aAttributeMetaData.addBooleanProperty(
132 OAttributeMetaData::getCommonControlAttributeName(CCA_TAB_STOP), PROPERTY_TABSTOP, true);
133 m_aAttributeMetaData.addBooleanProperty(
134 OAttributeMetaData::getDatabaseAttributeName(DA_CONVERT_EMPTY), PROPERTY_EMPTY_IS_NULL, false);
135 m_aAttributeMetaData.addBooleanProperty(
136 OAttributeMetaData::getSpecialAttributeName(SCA_VALIDATION), PROPERTY_STRICTFORMAT, false);
137 m_aAttributeMetaData.addBooleanProperty(
138 OAttributeMetaData::getSpecialAttributeName(SCA_MULTI_LINE), PROPERTY_MULTILINE, false);
139 m_aAttributeMetaData.addBooleanProperty(
140 OAttributeMetaData::getSpecialAttributeName(SCA_AUTOMATIC_COMPLETION), PROPERTY_AUTOCOMPLETE, false);
141 m_aAttributeMetaData.addBooleanProperty(
142 OAttributeMetaData::getSpecialAttributeName(SCA_MULTIPLE), PROPERTY_MULTISELECTION, false);
143 m_aAttributeMetaData.addBooleanProperty(
144 OAttributeMetaData::getSpecialAttributeName(SCA_DEFAULT_BUTTON), PROPERTY_DEFAULTBUTTON, false);
145 m_aAttributeMetaData.addBooleanProperty(
146 OAttributeMetaData::getSpecialAttributeName(SCA_IS_TRISTATE), PROPERTY_TRISTATE, false);
147 m_aAttributeMetaData.addBooleanProperty(
148 OAttributeMetaData::getFormAttributeName(faAllowDeletes), PROPERTY_ALLOWDELETES, true);
149 m_aAttributeMetaData.addBooleanProperty(
150 OAttributeMetaData::getFormAttributeName(faAllowInserts), PROPERTY_ALLOWINSERTS, true);
151 m_aAttributeMetaData.addBooleanProperty(
152 OAttributeMetaData::getFormAttributeName(faAllowUpdates), PROPERTY_ALLOWUPDATES, true);
153 m_aAttributeMetaData.addBooleanProperty(
154 OAttributeMetaData::getFormAttributeName(faApplyFilter), PROPERTY_APPLYFILTER, false);
155 m_aAttributeMetaData.addBooleanProperty(
156 OAttributeMetaData::getFormAttributeName(faEscapeProcessing), PROPERTY_ESCAPEPROCESSING, true);
157 m_aAttributeMetaData.addBooleanProperty(
158 OAttributeMetaData::getFormAttributeName(faIgnoreResult), PROPERTY_IGNORERESULT, false);
159 m_aAttributeMetaData.addBooleanProperty(
160 OAttributeMetaData::getSpecialAttributeName( SCA_TOGGLE ), PROPERTY_TOGGLE, false );
161 m_aAttributeMetaData.addBooleanProperty(
162 OAttributeMetaData::getSpecialAttributeName( SCA_FOCUS_ON_CLICK ), PROPERTY_FOCUS_ON_CLICK, true );
163 m_aAttributeMetaData.addBooleanProperty(
164 OAttributeMetaData::getDatabaseAttributeName( DA_INPUT_REQUIRED ), PROPERTY_INPUT_REQUIRED, false );
166 // the int16 attributes
167 m_aAttributeMetaData.addInt16Property(
168 OAttributeMetaData::getCommonControlAttributeName(CCA_MAX_LENGTH), PROPERTY_MAXTEXTLENGTH, 0);
169 m_aAttributeMetaData.addInt16Property(
170 OAttributeMetaData::getCommonControlAttributeName(CCA_SIZE), PROPERTY_LINECOUNT, 5);
171 m_aAttributeMetaData.addInt16Property(
172 OAttributeMetaData::getCommonControlAttributeName(CCA_TAB_INDEX), PROPERTY_TABINDEX, 0);
173 m_aAttributeMetaData.addInt16Property(
174 OAttributeMetaData::getDatabaseAttributeName(DA_BOUND_COLUMN), PROPERTY_BOUNDCOLUMN, 0);
176 // the int32 attributes
177 m_aAttributeMetaData.addInt32Property(
178 OAttributeMetaData::getSpecialAttributeName( SCA_PAGE_STEP_SIZE ), PROPERTY_BLOCK_INCREMENT, 10 );
180 // the enum attributes
181 m_aAttributeMetaData.addEnumProperty(
182 OAttributeMetaData::getCommonControlAttributeName( CCA_VISUAL_EFFECT ), PROPERTY_VISUAL_EFFECT,
183 VisualEffect::LOOK3D, OEnumMapper::getEnumMap( OEnumMapper::epVisualEffect ),
184 &::cppu::UnoType<sal_Int16>::get() );
185 m_aAttributeMetaData.addEnumProperty(
186 OAttributeMetaData::getCommonControlAttributeName( CCA_ORIENTATION ), PROPERTY_ORIENTATION,
187 ScrollBarOrientation::HORIZONTAL, OEnumMapper::getEnumMap( OEnumMapper::epOrientation ),
188 &::cppu::UnoType<sal_Int32>::get() );
189 m_aAttributeMetaData.addEnumProperty(
190 OAttributeMetaData::getCommonControlAttributeName(CCA_BUTTON_TYPE), PROPERTY_BUTTONTYPE,
191 FormButtonType_PUSH, OEnumMapper::getEnumMap(OEnumMapper::epButtonType),
192 &::cppu::UnoType<FormButtonType>::get());
193 m_aAttributeMetaData.addEnumProperty(
194 OAttributeMetaData::getDatabaseAttributeName(DA_LIST_SOURCE_TYPE), PROPERTY_LISTSOURCETYPE,
195 ListSourceType_VALUELIST, OEnumMapper::getEnumMap(OEnumMapper::epListSourceType),
196 &::cppu::UnoType<ListSourceType>::get());
197 m_aAttributeMetaData.addEnumProperty(
198 OAttributeMetaData::getSpecialAttributeName(SCA_STATE), PROPERTY_DEFAULT_STATE, TRISTATE_FALSE,
199 OEnumMapper::getEnumMap(OEnumMapper::epCheckState),
200 &::cppu::UnoType<sal_Int16>::get());
201 m_aAttributeMetaData.addEnumProperty(
202 OAttributeMetaData::getSpecialAttributeName(SCA_CURRENT_STATE), PROPERTY_STATE, TRISTATE_FALSE,
203 OEnumMapper::getEnumMap(OEnumMapper::epCheckState),
204 &::cppu::UnoType<sal_Int16>::get());
205 m_aAttributeMetaData.addEnumProperty(
206 OAttributeMetaData::getFormAttributeName(faEnctype), PROPERTY_SUBMIT_ENCODING,
207 FormSubmitEncoding_URL, OEnumMapper::getEnumMap(OEnumMapper::epSubmitEncoding),
208 &::cppu::UnoType<FormSubmitEncoding>::get());
209 m_aAttributeMetaData.addEnumProperty(
210 OAttributeMetaData::getFormAttributeName(faMethod), PROPERTY_SUBMIT_METHOD,
211 FormSubmitMethod_GET, OEnumMapper::getEnumMap(OEnumMapper::epSubmitMethod),
212 &::cppu::UnoType<FormSubmitMethod>::get());
213 m_aAttributeMetaData.addEnumProperty(
214 OAttributeMetaData::getFormAttributeName(faCommandType), PROPERTY_COMMAND_TYPE,
215 CommandType::COMMAND, OEnumMapper::getEnumMap(OEnumMapper::epCommandType));
216 m_aAttributeMetaData.addEnumProperty(
217 OAttributeMetaData::getFormAttributeName(faNavigationMode), PROPERTY_NAVIGATION,
218 NavigationBarMode_NONE, OEnumMapper::getEnumMap(OEnumMapper::epNavigationType),
219 &::cppu::UnoType<NavigationBarMode>::get());
220 m_aAttributeMetaData.addEnumProperty(
221 OAttributeMetaData::getFormAttributeName(faTabbingCycle), PROPERTY_CYCLE,
222 TabulatorCycle_RECORDS, OEnumMapper::getEnumMap(OEnumMapper::epTabCyle),
223 &::cppu::UnoType<TabulatorCycle>::get());
225 // 'initialize'
226 m_aCurrentPageIds = m_aControlIds.end();
229 OFormLayerXMLImport_Impl::~OFormLayerXMLImport_Impl()
231 // outlined to allow forward declaration of OAttribute2Property in the header
233 if (m_pAutoStyles)
234 m_pAutoStyles->ReleaseRef();
237 void OFormLayerXMLImport_Impl::setAutoStyleContext(SvXMLStylesContext* _pNewContext)
239 OSL_ENSURE(!m_pAutoStyles, "OFormLayerXMLImport_Impl::setAutoStyleContext: not to be called twice!");
240 m_pAutoStyles = _pNewContext;
241 if (m_pAutoStyles)
242 m_pAutoStyles->AddFirstRef();
245 void OFormLayerXMLImport_Impl::applyControlNumberStyle(const Reference< XPropertySet >& _rxControlModel, const OUString& _rControlNumerStyleName)
247 OSL_ENSURE(_rxControlModel.is() && (!_rControlNumerStyleName.isEmpty()),
248 "OFormLayerXMLImport_Impl::applyControlNumberStyle: invalid arguments (this will crash)!");
250 OSL_ENSURE(m_pAutoStyles, "OFormLayerXMLImport_Impl::applyControlNumberStyle: have no auto style context!");
251 if (!m_pAutoStyles)
253 m_pAutoStyles = m_rImporter.GetShapeImport()->GetAutoStylesContext();
254 if (m_pAutoStyles)
255 m_pAutoStyles->AddFirstRef();
258 if (m_pAutoStyles)
260 const SvXMLStyleContext* pStyle = m_pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_DATA_STYLE, _rControlNumerStyleName);
261 if (pStyle)
263 const SvXMLNumFormatContext* pDataStyle = static_cast<const SvXMLNumFormatContext*>(pStyle);
265 // set this format at the control model
268 // the models number format supplier and formats
269 Reference< XNumberFormatsSupplier > xFormatsSupplier;
270 _rxControlModel->getPropertyValue(PROPERTY_FORMATSSUPPLIER) >>= xFormatsSupplier;
271 Reference< XNumberFormats > xFormats;
272 if (xFormatsSupplier.is())
273 xFormats = xFormatsSupplier->getNumberFormats();
274 OSL_ENSURE(xFormats.is(), "OFormLayerXMLImport_Impl::applyControlNumberStyle: could not obtain the controls number formats!");
276 // obtain a key
277 if (xFormats.is())
279 sal_Int32 nFormatKey = const_cast<SvXMLNumFormatContext*>(pDataStyle)->CreateAndInsert( xFormatsSupplier );
280 OSL_ENSURE(-1 != nFormatKey, "OFormLayerXMLImport_Impl::applyControlNumberStyle: could not obtain a format key!");
282 // set the format on the control model
283 _rxControlModel->setPropertyValue(PROPERTY_FORMATKEY, makeAny(nFormatKey));
286 catch(const Exception&)
288 OSL_FAIL("OFormLayerXMLImport_Impl::applyControlNumberStyle: couldn't set the format!");
291 else
292 OSL_FAIL("OFormLayerXMLImport_Impl::applyControlNumberStyle: did not find the style with the given name!");
296 void OFormLayerXMLImport_Impl::registerCellValueBinding( const Reference< XPropertySet >& _rxControlModel, const OUString& _rCellAddress )
298 OSL_ENSURE( _rxControlModel.is() && !_rCellAddress.isEmpty(),
299 "OFormLayerXMLImport_Impl::registerCellValueBinding: invalid arguments!" );
300 m_aCellValueBindings.push_back( ModelStringPair( _rxControlModel, _rCellAddress ) );
303 void OFormLayerXMLImport_Impl::registerXFormsValueBinding(
304 const Reference< XPropertySet >& _rxControlModel,
305 const OUString& _rBindingID )
307 // TODO: is an empty binding name allowed?
308 OSL_ENSURE( _rxControlModel.is(), "need model" );
310 m_aXFormsValueBindings.push_back(
311 ModelStringPair( _rxControlModel, _rBindingID ) );
314 void OFormLayerXMLImport_Impl::registerXFormsListBinding(
315 const Reference< XPropertySet >& _rxControlModel,
316 const OUString& _rBindingID )
318 // TODO: is an empty binding name allowed?
319 OSL_ENSURE( _rxControlModel.is(), "need model" );
321 m_aXFormsListBindings.push_back(
322 ModelStringPair( _rxControlModel, _rBindingID ) );
325 void OFormLayerXMLImport_Impl::registerXFormsSubmission(
326 const Reference< XPropertySet >& _rxControlModel,
327 const OUString& _rSubmissionID )
329 // TODO: is an empty binding name allowed?
330 OSL_ENSURE( _rxControlModel.is(), "need model" );
332 m_aXFormsSubmissions.push_back(
333 ModelStringPair( _rxControlModel, _rSubmissionID ) );
336 void OFormLayerXMLImport_Impl::registerCellRangeListSource( const Reference< XPropertySet >& _rxControlModel, const OUString& _rCellRangeAddress )
338 OSL_ENSURE( _rxControlModel.is() && !_rCellRangeAddress.isEmpty(),
339 "OFormLayerXMLImport_Impl::registerCellRangeListSource: invalid arguments!" );
340 m_aCellRangeListSources.push_back( ModelStringPair( _rxControlModel, _rCellRangeAddress ) );
342 const SvXMLStyleContext* OFormLayerXMLImport_Impl::getStyleElement(const OUString& _rStyleName) const
344 OSL_ENSURE( m_pAutoStyles, "OFormLayerXMLImport_Impl::getStyleElement: have no auto style context!" );
345 // did you use setAutoStyleContext?
347 const SvXMLStyleContext* pControlStyle =
348 m_pAutoStyles ? m_pAutoStyles->FindStyleChildContext( XML_STYLE_FAMILY_TEXT_PARAGRAPH, _rStyleName ) : NULL;
349 OSL_ENSURE( pControlStyle || !m_pAutoStyles,
350 OStringBuffer("OFormLayerXMLImport_Impl::getStyleElement: did not find the style named \"").append(OUStringToOString(_rStyleName, RTL_TEXTENCODING_ASCII_US)).append("\"!").getStr() );
351 return pControlStyle;
354 void OFormLayerXMLImport_Impl::enterEventContext()
356 // install our own translation table. We need to disable the other tables because of name conflicts.
357 m_rImporter.GetEventImport().PushTranslationTable();
358 m_rImporter.GetEventImport().AddTranslationTable(g_pFormsEventTranslation);
361 void OFormLayerXMLImport_Impl::leaveEventContext()
363 // install the original event tables.
364 m_rImporter.GetEventImport().PopTranslationTable();
367 void OFormLayerXMLImport_Impl::registerControlId(const Reference< XPropertySet >& _rxControl, const OUString& _rId)
369 OSL_ENSURE(m_aCurrentPageIds != m_aControlIds.end(), "OFormLayerXMLImport_Impl::registerControlId: no current page!");
370 OSL_ENSURE(!_rId.isEmpty(), "OFormLayerXMLImport_Impl::registerControlId: invalid (empty) control id!");
372 OSL_ENSURE(m_aCurrentPageIds->second.end() == m_aCurrentPageIds->second.find(_rId), "OFormLayerXMLImport_Impl::registerControlId: control id already used!");
373 m_aCurrentPageIds->second[_rId] = _rxControl;
376 void OFormLayerXMLImport_Impl::registerControlReferences(const Reference< XPropertySet >& _rxControl, const OUString& _rReferringControls)
378 OSL_ENSURE(!_rReferringControls.isEmpty(), "OFormLayerXMLImport_Impl::registerControlReferences: invalid (empty) control id list!");
379 OSL_ENSURE(_rxControl.is(), "OFormLayerXMLImport_Impl::registerControlReferences: invalid (NULL) control!");
380 m_aControlReferences.push_back( ModelStringPair( _rxControl, _rReferringControls ) );
383 void OFormLayerXMLImport_Impl::startPage(const Reference< XDrawPage >& _rxDrawPage)
385 m_xCurrentPageFormsSupp.clear();
387 OSL_ENSURE(_rxDrawPage.is(), "OFormLayerXMLImport_Impl::startPage: NULL page!");
388 m_xCurrentPageFormsSupp.set(_rxDrawPage, css::uno::UNO_QUERY);
389 OSL_ENSURE( m_xCurrentPageFormsSupp.is(), "OFormLayerXMLImport_Impl::startPage: invalid draw page (no XFormsSupplier)!" );
390 if ( !m_xCurrentPageFormsSupp.is() )
391 return;
393 // add a new entry to our page map
394 ::std::pair< MapDrawPage2Map::iterator, bool > aPagePosition;
395 aPagePosition =
396 m_aControlIds.insert(MapDrawPage2Map::value_type(_rxDrawPage, MapString2PropertySet()));
397 OSL_ENSURE(aPagePosition.second, "OFormLayerXMLImport_Impl::startPage: already imported this page!");
398 m_aCurrentPageIds = aPagePosition.first;
401 void OFormLayerXMLImport_Impl::endPage()
403 OSL_ENSURE( m_xCurrentPageFormsSupp.is(), "OFormLayerXMLImport_Impl::endPage: sure you called startPage before?" );
405 // do some knittings for the controls which are referring to each other
408 static const sal_Unicode s_nSeparator = ',';
409 OUString sReferring;
410 OUString sCurrentReferring;
411 OUString sSeparator(&s_nSeparator, 1);
412 Reference< XPropertySet > xCurrentReferring;
413 sal_Int32 nSeparator, nPrevSep;
414 ::std::vector< ModelStringPair >::const_iterator aEnd = m_aControlReferences.end();
415 for ( ::std::vector< ModelStringPair >::const_iterator aReferences = m_aControlReferences.begin();
416 aReferences != aEnd;
417 ++aReferences
420 // the list of control ids is comma separated
422 // in a list of n ids there are only n-1 separators ... have to catch this last id
423 // -> normalize the list
424 sReferring = aReferences->second;
425 sReferring += sSeparator;
427 nPrevSep = -1;
428 while (-1 != (nSeparator = sReferring.indexOf(s_nSeparator, nPrevSep + 1)))
430 sCurrentReferring = sReferring.copy(nPrevSep + 1, nSeparator - nPrevSep - 1);
431 xCurrentReferring = lookupControlId(sCurrentReferring);
432 if (xCurrentReferring.is())
433 // if this condition fails, this is an error, but lookupControlId should have asserted this ...
434 xCurrentReferring->setPropertyValue( PROPERTY_CONTROLLABEL, makeAny( aReferences->first ) );
436 nPrevSep = nSeparator;
440 catch(Exception&)
442 OSL_FAIL("OFormLayerXMLImport_Impl::endPage: unable to knit the control references (caught an exception)!");
445 // now that we have all children of the forms collection, attach the events
446 Reference< XIndexAccess > xIndexContainer;
447 if ( m_xCurrentPageFormsSupp.is() && m_xCurrentPageFormsSupp->hasForms() )
448 xIndexContainer.set(m_xCurrentPageFormsSupp->getForms(), css::uno::UNO_QUERY);
449 if ( xIndexContainer.is() )
450 ODefaultEventAttacherManager::setEvents( xIndexContainer );
452 // clear the structures for the control references.
453 m_aControlReferences.clear();
455 // and no we have no current page anymore
456 m_aCurrentPageIds = m_aControlIds.end();
459 Reference< XPropertySet > OFormLayerXMLImport_Impl::lookupControlId(const OUString& _rControlId)
461 OSL_ENSURE(m_aCurrentPageIds != m_aControlIds.end(), "OFormLayerXMLImport_Impl::lookupControlId: no current page!");
462 Reference< XPropertySet > xReturn;
463 if (m_aCurrentPageIds != m_aControlIds.end())
465 MapString2PropertySet::const_iterator aPos = m_aCurrentPageIds->second.find(_rControlId);
466 if (m_aCurrentPageIds->second.end() != aPos)
467 xReturn = aPos->second;
468 else
469 OSL_FAIL("OFormLayerXMLImport_Impl::lookupControlId: invalid control id (did not find it)!");
471 return xReturn;
474 SvXMLImportContext* OFormLayerXMLImport_Impl::createOfficeFormsContext(
475 SvXMLImport& _rImport,
476 sal_uInt16 _nPrefix,
477 const OUString& _rLocalName)
479 return new OFormsRootImport( _rImport, _nPrefix, _rLocalName );
482 SvXMLImportContext* OFormLayerXMLImport_Impl::createContext(const sal_uInt16 _nPrefix, const OUString& _rLocalName,
483 const Reference< xml::sax::XAttributeList >&)
485 SvXMLImportContext* pContext = NULL;
486 if ( _rLocalName == "form" )
488 if ( m_xCurrentPageFormsSupp.is() )
489 pContext = new OFormImport(*this, *this, _nPrefix, _rLocalName, m_xCurrentPageFormsSupp->getForms() );
491 else if ( ( _nPrefix == XML_NAMESPACE_XFORMS
492 && ( xmloff::token::IsXMLToken( _rLocalName, xmloff::token::XML_MODEL ) ) )
495 pContext = createXFormsModelContext( m_rImporter, _nPrefix, _rLocalName );
498 if ( !pContext )
500 OSL_FAIL( "unknown element" );
501 pContext =
502 new SvXMLImportContext(m_rImporter, _nPrefix, _rLocalName);
505 return pContext;
508 void OFormLayerXMLImport_Impl::documentDone( )
510 SvXMLImport& rImport = getGlobalContext();
511 if ( !( rImport.getImportFlags() & SvXMLImportFlags::CONTENT ) )
512 return;
514 // create (and bind) the spreadsheet cell bindings
515 if ( !m_aCellValueBindings.empty()
516 && FormCellBindingHelper::isCellBindingAllowed( rImport.GetModel() )
519 static const char s_sIndex[] = ":index";
520 ::std::vector< ModelStringPair >::const_iterator aEnd = m_aCellValueBindings.end();
521 for ( ::std::vector< ModelStringPair >::const_iterator aCellBindings = m_aCellValueBindings.begin();
522 aCellBindings != aEnd;
523 ++aCellBindings
528 FormCellBindingHelper aHelper( aCellBindings->first, rImport.GetModel() );
529 OSL_ENSURE( aHelper.isCellBindingAllowed(), "OFormLayerXMLImport_Impl::documentDone: can't bind this control model!" );
530 if ( aHelper.isCellBindingAllowed() )
532 // There are special bindings for listboxes. See
533 // OListAndComboImport::doRegisterCellValueBinding for a comment on this HACK.
534 OUString sBoundCellAddress( aCellBindings->second );
535 sal_Int32 nIndicator = sBoundCellAddress.lastIndexOf( s_sIndex );
537 bool bUseIndexBinding = false;
538 if ( nIndicator != -1 )
540 sBoundCellAddress = sBoundCellAddress.copy( 0, nIndicator );
541 bUseIndexBinding = true;
544 aHelper.setBinding( aHelper.createCellBindingFromStringAddress( sBoundCellAddress, bUseIndexBinding ) );
547 catch( const Exception& )
549 OSL_FAIL( "OFormLayerXMLImport_Impl::documentDone: caught an exception while binding to a cell!" );
552 m_aCellValueBindings.clear();
555 // the same for the spreadsheet cell range list sources
556 if ( !m_aCellRangeListSources.empty()
557 && FormCellBindingHelper::isListCellRangeAllowed( rImport.GetModel() )
560 for ( ::std::vector< ModelStringPair >::const_iterator aRangeBindings = m_aCellRangeListSources.begin();
561 aRangeBindings != m_aCellRangeListSources.end();
562 ++aRangeBindings
567 FormCellBindingHelper aHelper( aRangeBindings->first, rImport.GetModel() );
568 OSL_ENSURE( aHelper.isListCellRangeAllowed(), "OFormLayerXMLImport_Impl::documentDone: can't bind this control model!" );
569 if ( aHelper.isListCellRangeAllowed() )
571 aHelper.setListSource( aHelper.createCellListSourceFromStringAddress( aRangeBindings->second ) );
574 catch( const Exception& )
576 OSL_FAIL( "OFormLayerXMLImport_Impl::documentDone: caught an exception while binding to a cell range!" );
579 m_aCellRangeListSources.clear();
582 // process XForms-bindings; call registerXFormsValueBinding for each
583 std::for_each( m_aXFormsValueBindings.begin(),
584 m_aXFormsValueBindings.end(),
585 std::bind( bindXFormsValueBinding, rImport.GetModel(), std::placeholders::_1 ) );
586 // same for list bindings
587 std::for_each( m_aXFormsListBindings.begin(),
588 m_aXFormsListBindings.end(),
589 std::bind( bindXFormsListBinding, rImport.GetModel(), std::placeholders::_1 ) );
590 // same for submissions
591 std::for_each( m_aXFormsSubmissions.begin(),
592 m_aXFormsSubmissions.end(),
593 std::bind( bindXFormsSubmission, rImport.GetModel(), std::placeholders::_1 ) );
596 } // namespace xmloff
598 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */