Line data Source code
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 : #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 :
56 : namespace xmloff
57 : {
58 :
59 : using namespace ::com::sun::star::uno;
60 : using namespace ::com::sun::star::awt;
61 : using namespace ::com::sun::star::lang;
62 : using namespace ::com::sun::star::beans;
63 : using namespace ::com::sun::star::container;
64 : using namespace ::com::sun::star::drawing;
65 : using namespace ::com::sun::star;
66 : using namespace ::com::sun::star::util;
67 : using namespace ::com::sun::star::form;
68 : using namespace ::com::sun::star::sdb;
69 :
70 : //= OFormLayerXMLImport_Impl
71 0 : OFormLayerXMLImport_Impl::OFormLayerXMLImport_Impl(SvXMLImport& _rImporter)
72 : :m_rImporter(_rImporter)
73 0 : ,m_pAutoStyles(NULL)
74 : {
75 : // build the attribute2property map
76 : // string properties which are exported as attributes
77 : m_aAttributeMetaData.addStringProperty(
78 0 : OAttributeMetaData::getCommonControlAttributeName(CCA_NAME), PROPERTY_NAME);
79 : m_aAttributeMetaData.addStringProperty(
80 0 : OAttributeMetaData::getSpecialAttributeName(SCA_GROUP_NAME), PROPERTY_GROUP_NAME);
81 : m_aAttributeMetaData.addStringProperty(
82 0 : OAttributeMetaData::getCommonControlAttributeName(CCA_IMAGE_DATA), PROPERTY_IMAGEURL);
83 : m_aAttributeMetaData.addStringProperty(
84 0 : OAttributeMetaData::getCommonControlAttributeName(CCA_LABEL), PROPERTY_LABEL);
85 : m_aAttributeMetaData.addStringProperty(
86 0 : OAttributeMetaData::getCommonControlAttributeName(CCA_TARGET_LOCATION), PROPERTY_TARGETURL);
87 : m_aAttributeMetaData.addStringProperty(
88 0 : OAttributeMetaData::getCommonControlAttributeName(CCA_TITLE), PROPERTY_TITLE);
89 : m_aAttributeMetaData.addStringProperty(
90 0 : OAttributeMetaData::getCommonControlAttributeName(CCA_TARGET_FRAME), PROPERTY_TARGETFRAME, "_blank");
91 : m_aAttributeMetaData.addStringProperty(
92 0 : OAttributeMetaData::getDatabaseAttributeName(DA_DATA_FIELD), PROPERTY_DATAFIELD);
93 : m_aAttributeMetaData.addStringProperty(
94 0 : OAttributeMetaData::getFormAttributeName(faCommand), PROPERTY_COMMAND);
95 : m_aAttributeMetaData.addStringProperty(
96 0 : OAttributeMetaData::getFormAttributeName(faDatasource), PROPERTY_DATASOURCENAME);
97 : m_aAttributeMetaData.addStringProperty(
98 0 : OAttributeMetaData::getFormAttributeName(faFilter), PROPERTY_FILTER);
99 : m_aAttributeMetaData.addStringProperty(
100 0 : OAttributeMetaData::getFormAttributeName(faOrder), PROPERTY_ORDER);
101 :
102 : // properties not added because they're already present in another form
103 : OSL_ENSURE(
104 : OUString::createFromAscii(OAttributeMetaData::getCommonControlAttributeName(CCA_TARGET_LOCATION)).equalsAscii(
105 : OAttributeMetaData::getFormAttributeName(faAction)),
106 : "OFormLayerXMLImport_Impl::OFormLayerXMLImport_Impl: invalid attribute names (1)!");
107 : // if this fails, we would have to add a translation from faAction->PROPERTY_TARGETURL
108 : // We did not because we already have one CCA_TARGET_LOCATION->PROPERTY_TARGETURL,
109 : // and CCA_TARGET_LOCATION and faAction should be represented by the same attribute
110 :
111 : OSL_ENSURE(
112 : OUString::createFromAscii(OAttributeMetaData::getCommonControlAttributeName(CCA_NAME)).equalsAscii(
113 : OAttributeMetaData::getFormAttributeName(faName)),
114 : "OFormLayerXMLImport_Impl::OFormLayerXMLImport_Impl: invalid attribute names (2)!");
115 : // the same for faName, CCA_NAME and PROPERTY_NAME
116 :
117 : // boolean properties which are exported as attributes
118 : m_aAttributeMetaData.addBooleanProperty(
119 0 : OAttributeMetaData::getCommonControlAttributeName(CCA_CURRENT_SELECTED), PROPERTY_STATE, sal_False);
120 : m_aAttributeMetaData.addBooleanProperty(
121 0 : OAttributeMetaData::getCommonControlAttributeName(CCA_DISABLED), PROPERTY_ENABLED, sal_False, sal_True);
122 : m_aAttributeMetaData.addBooleanProperty(
123 0 : OAttributeMetaData::getCommonControlAttributeName(CCA_DROPDOWN), PROPERTY_DROPDOWN, sal_False);
124 : m_aAttributeMetaData.addBooleanProperty(
125 0 : OAttributeMetaData::getCommonControlAttributeName(CCA_PRINTABLE), PROPERTY_PRINTABLE, sal_True);
126 : m_aAttributeMetaData.addBooleanProperty(
127 0 : OAttributeMetaData::getCommonControlAttributeName(CCA_READONLY), PROPERTY_READONLY, sal_False);
128 : m_aAttributeMetaData.addBooleanProperty(
129 0 : OAttributeMetaData::getCommonControlAttributeName(CCA_SELECTED), PROPERTY_DEFAULT_STATE, sal_False);
130 : m_aAttributeMetaData.addBooleanProperty(
131 0 : OAttributeMetaData::getCommonControlAttributeName(CCA_TAB_STOP), PROPERTY_TABSTOP, sal_True);
132 : m_aAttributeMetaData.addBooleanProperty(
133 0 : OAttributeMetaData::getDatabaseAttributeName(DA_CONVERT_EMPTY), PROPERTY_EMPTY_IS_NULL, sal_False);
134 : m_aAttributeMetaData.addBooleanProperty(
135 0 : OAttributeMetaData::getSpecialAttributeName(SCA_VALIDATION), PROPERTY_STRICTFORMAT, sal_False);
136 : m_aAttributeMetaData.addBooleanProperty(
137 0 : OAttributeMetaData::getSpecialAttributeName(SCA_MULTI_LINE), PROPERTY_MULTILINE, sal_False);
138 : m_aAttributeMetaData.addBooleanProperty(
139 0 : OAttributeMetaData::getSpecialAttributeName(SCA_AUTOMATIC_COMPLETION), PROPERTY_AUTOCOMPLETE, sal_False);
140 : m_aAttributeMetaData.addBooleanProperty(
141 0 : OAttributeMetaData::getSpecialAttributeName(SCA_MULTIPLE), PROPERTY_MULTISELECTION, sal_False);
142 : m_aAttributeMetaData.addBooleanProperty(
143 0 : OAttributeMetaData::getSpecialAttributeName(SCA_DEFAULT_BUTTON), PROPERTY_DEFAULTBUTTON, sal_False);
144 : m_aAttributeMetaData.addBooleanProperty(
145 0 : OAttributeMetaData::getSpecialAttributeName(SCA_IS_TRISTATE), PROPERTY_TRISTATE, sal_False);
146 : m_aAttributeMetaData.addBooleanProperty(
147 0 : OAttributeMetaData::getFormAttributeName(faAllowDeletes), PROPERTY_ALLOWDELETES, sal_True);
148 : m_aAttributeMetaData.addBooleanProperty(
149 0 : OAttributeMetaData::getFormAttributeName(faAllowInserts), PROPERTY_ALLOWINSERTS, sal_True);
150 : m_aAttributeMetaData.addBooleanProperty(
151 0 : OAttributeMetaData::getFormAttributeName(faAllowUpdates), PROPERTY_ALLOWUPDATES, sal_True);
152 : m_aAttributeMetaData.addBooleanProperty(
153 0 : OAttributeMetaData::getFormAttributeName(faApplyFilter), PROPERTY_APPLYFILTER, sal_False);
154 : m_aAttributeMetaData.addBooleanProperty(
155 0 : OAttributeMetaData::getFormAttributeName(faEscapeProcessing), PROPERTY_ESCAPEPROCESSING, sal_True);
156 : m_aAttributeMetaData.addBooleanProperty(
157 0 : OAttributeMetaData::getFormAttributeName(faIgnoreResult), PROPERTY_IGNORERESULT, sal_False);
158 : m_aAttributeMetaData.addBooleanProperty(
159 0 : OAttributeMetaData::getSpecialAttributeName( SCA_TOGGLE ), PROPERTY_TOGGLE, sal_False );
160 : m_aAttributeMetaData.addBooleanProperty(
161 0 : OAttributeMetaData::getSpecialAttributeName( SCA_FOCUS_ON_CLICK ), PROPERTY_FOCUS_ON_CLICK, sal_True );
162 : m_aAttributeMetaData.addBooleanProperty(
163 0 : OAttributeMetaData::getDatabaseAttributeName( DA_INPUT_REQUIRED ), PROPERTY_INPUT_REQUIRED, sal_False );
164 :
165 : // the int16 attributes
166 : m_aAttributeMetaData.addInt16Property(
167 0 : OAttributeMetaData::getCommonControlAttributeName(CCA_MAX_LENGTH), PROPERTY_MAXTEXTLENGTH, 0);
168 : m_aAttributeMetaData.addInt16Property(
169 0 : OAttributeMetaData::getCommonControlAttributeName(CCA_SIZE), PROPERTY_LINECOUNT, 5);
170 : m_aAttributeMetaData.addInt16Property(
171 0 : OAttributeMetaData::getCommonControlAttributeName(CCA_TAB_INDEX), PROPERTY_TABINDEX, 0);
172 : m_aAttributeMetaData.addInt16Property(
173 0 : OAttributeMetaData::getDatabaseAttributeName(DA_BOUND_COLUMN), PROPERTY_BOUNDCOLUMN, 0);
174 :
175 : // the int32 attributes
176 : m_aAttributeMetaData.addInt32Property(
177 0 : OAttributeMetaData::getSpecialAttributeName( SCA_PAGE_STEP_SIZE ), PROPERTY_BLOCK_INCREMENT, 10 );
178 :
179 : // the enum attributes
180 : m_aAttributeMetaData.addEnumProperty(
181 : OAttributeMetaData::getCommonControlAttributeName( CCA_VISUAL_EFFECT ), PROPERTY_VISUAL_EFFECT,
182 : VisualEffect::LOOK3D, OEnumMapper::getEnumMap( OEnumMapper::epVisualEffect ),
183 0 : &::getCppuType( static_cast< sal_Int16* >( NULL ) ) );
184 : m_aAttributeMetaData.addEnumProperty(
185 : OAttributeMetaData::getCommonControlAttributeName( CCA_ORIENTATION ), PROPERTY_ORIENTATION,
186 : ScrollBarOrientation::HORIZONTAL, OEnumMapper::getEnumMap( OEnumMapper::epOrientation ),
187 0 : &::getCppuType( static_cast< sal_Int32* >( NULL ) ) );
188 : m_aAttributeMetaData.addEnumProperty(
189 : OAttributeMetaData::getCommonControlAttributeName(CCA_BUTTON_TYPE), PROPERTY_BUTTONTYPE,
190 : FormButtonType_PUSH, OEnumMapper::getEnumMap(OEnumMapper::epButtonType),
191 0 : &::getCppuType( static_cast<FormButtonType*>(NULL) ));
192 : m_aAttributeMetaData.addEnumProperty(
193 : OAttributeMetaData::getDatabaseAttributeName(DA_LIST_SOURCE_TYPE), PROPERTY_LISTSOURCETYPE,
194 : ListSourceType_VALUELIST, OEnumMapper::getEnumMap(OEnumMapper::epListSourceType),
195 0 : &::getCppuType( static_cast<ListSourceType*>(NULL) ));
196 : m_aAttributeMetaData.addEnumProperty(
197 : OAttributeMetaData::getSpecialAttributeName(SCA_STATE), PROPERTY_DEFAULT_STATE, TRISTATE_FALSE,
198 : OEnumMapper::getEnumMap(OEnumMapper::epCheckState),
199 0 : &::getCppuType( static_cast< sal_Int16* >(NULL)));
200 : m_aAttributeMetaData.addEnumProperty(
201 : OAttributeMetaData::getSpecialAttributeName(SCA_CURRENT_STATE), PROPERTY_STATE, TRISTATE_FALSE,
202 : OEnumMapper::getEnumMap(OEnumMapper::epCheckState),
203 0 : &::getCppuType( static_cast< sal_Int16* >(NULL)));
204 : m_aAttributeMetaData.addEnumProperty(
205 : OAttributeMetaData::getFormAttributeName(faEnctype), PROPERTY_SUBMIT_ENCODING,
206 : FormSubmitEncoding_URL, OEnumMapper::getEnumMap(OEnumMapper::epSubmitEncoding),
207 0 : &::getCppuType( static_cast<FormSubmitEncoding*>(NULL) ));
208 : m_aAttributeMetaData.addEnumProperty(
209 : OAttributeMetaData::getFormAttributeName(faMethod), PROPERTY_SUBMIT_METHOD,
210 : FormSubmitMethod_GET, OEnumMapper::getEnumMap(OEnumMapper::epSubmitMethod),
211 0 : &::getCppuType( static_cast<FormSubmitMethod*>(NULL) ));
212 : m_aAttributeMetaData.addEnumProperty(
213 : OAttributeMetaData::getFormAttributeName(faCommandType), PROPERTY_COMMAND_TYPE,
214 0 : CommandType::COMMAND, OEnumMapper::getEnumMap(OEnumMapper::epCommandType));
215 : m_aAttributeMetaData.addEnumProperty(
216 : OAttributeMetaData::getFormAttributeName(faNavigationMode), PROPERTY_NAVIGATION,
217 : NavigationBarMode_NONE, OEnumMapper::getEnumMap(OEnumMapper::epNavigationType),
218 0 : &::getCppuType( static_cast<NavigationBarMode*>(NULL) ));
219 : m_aAttributeMetaData.addEnumProperty(
220 : OAttributeMetaData::getFormAttributeName(faTabbingCycle), PROPERTY_CYCLE,
221 : TabulatorCycle_RECORDS, OEnumMapper::getEnumMap(OEnumMapper::epTabCyle),
222 0 : &::getCppuType( static_cast<TabulatorCycle*>(NULL) ));
223 :
224 : // 'initialize'
225 0 : m_aCurrentPageIds = m_aControlIds.end();
226 0 : }
227 :
228 0 : OFormLayerXMLImport_Impl::~OFormLayerXMLImport_Impl()
229 : {
230 : // outlined to allow forward declaration of OAttribute2Property in the header
231 :
232 0 : if (m_pAutoStyles)
233 0 : m_pAutoStyles->ReleaseRef();
234 0 : }
235 :
236 0 : void OFormLayerXMLImport_Impl::setAutoStyleContext(SvXMLStylesContext* _pNewContext)
237 : {
238 : OSL_ENSURE(!m_pAutoStyles, "OFormLayerXMLImport_Impl::setAutoStyleContext: not to be called twice!");
239 0 : m_pAutoStyles = _pNewContext;
240 0 : if (m_pAutoStyles)
241 0 : m_pAutoStyles->AddRef();
242 0 : }
243 :
244 0 : void OFormLayerXMLImport_Impl::applyControlNumberStyle(const Reference< XPropertySet >& _rxControlModel, const OUString& _rControlNumerStyleName)
245 : {
246 : OSL_ENSURE(_rxControlModel.is() && (!_rControlNumerStyleName.isEmpty()),
247 : "OFormLayerXMLImport_Impl::applyControlNumberStyle: invalid arguments (this will crash)!");
248 :
249 : OSL_ENSURE(m_pAutoStyles, "OFormLayerXMLImport_Impl::applyControlNumberStyle: have no auto style context!");
250 0 : if (!m_pAutoStyles)
251 : {
252 0 : m_pAutoStyles = m_rImporter.GetShapeImport()->GetAutoStylesContext();
253 0 : if (m_pAutoStyles)
254 0 : m_pAutoStyles->AddRef();
255 : }
256 :
257 0 : if (m_pAutoStyles)
258 : {
259 0 : const SvXMLStyleContext* pStyle = m_pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_DATA_STYLE, _rControlNumerStyleName);
260 0 : if (pStyle)
261 : {
262 0 : const SvXMLNumFormatContext* pDataStyle = static_cast<const SvXMLNumFormatContext*>(pStyle);
263 :
264 : // set this format at the control model
265 : try
266 : {
267 : // the models number format supplier and formats
268 0 : Reference< XNumberFormatsSupplier > xFormatsSupplier;
269 0 : _rxControlModel->getPropertyValue(PROPERTY_FORMATSSUPPLIER) >>= xFormatsSupplier;
270 0 : Reference< XNumberFormats > xFormats;
271 0 : if (xFormatsSupplier.is())
272 0 : xFormats = xFormatsSupplier->getNumberFormats();
273 : OSL_ENSURE(xFormats.is(), "OFormLayerXMLImport_Impl::applyControlNumberStyle: could not obtain the controls number formats!");
274 :
275 : // obtain a key
276 0 : if (xFormats.is())
277 : {
278 0 : sal_Int32 nFormatKey = const_cast<SvXMLNumFormatContext*>(pDataStyle)->CreateAndInsert( xFormatsSupplier );
279 : OSL_ENSURE(-1 != nFormatKey, "OFormLayerXMLImport_Impl::applyControlNumberStyle: could not obtain a format key!");
280 :
281 : // set the format on the control model
282 0 : _rxControlModel->setPropertyValue(PROPERTY_FORMATKEY, makeAny(nFormatKey));
283 0 : }
284 : }
285 0 : catch(const Exception&)
286 : {
287 : OSL_FAIL("OFormLayerXMLImport_Impl::applyControlNumberStyle: couldn't set the format!");
288 : }
289 : }
290 : else
291 : OSL_FAIL("OFormLayerXMLImport_Impl::applyControlNumberStyle: did not find the style with the given name!");
292 : }
293 0 : }
294 :
295 0 : void OFormLayerXMLImport_Impl::registerCellValueBinding( const Reference< XPropertySet >& _rxControlModel, const OUString& _rCellAddress )
296 : {
297 : OSL_ENSURE( _rxControlModel.is() && !_rCellAddress.isEmpty(),
298 : "OFormLayerXMLImport_Impl::registerCellValueBinding: invalid arguments!" );
299 0 : m_aCellValueBindings.push_back( ModelStringPair( _rxControlModel, _rCellAddress ) );
300 0 : }
301 :
302 0 : void OFormLayerXMLImport_Impl::registerXFormsValueBinding(
303 : const Reference< XPropertySet >& _rxControlModel,
304 : const OUString& _rBindingID )
305 : {
306 : // TODO: is an empty binding name allowed?
307 : OSL_ENSURE( _rxControlModel.is(), "need model" );
308 :
309 : m_aXFormsValueBindings.push_back(
310 0 : ModelStringPair( _rxControlModel, _rBindingID ) );
311 0 : }
312 :
313 0 : void OFormLayerXMLImport_Impl::registerXFormsListBinding(
314 : const Reference< XPropertySet >& _rxControlModel,
315 : const OUString& _rBindingID )
316 : {
317 : // TODO: is an empty binding name allowed?
318 : OSL_ENSURE( _rxControlModel.is(), "need model" );
319 :
320 : m_aXFormsListBindings.push_back(
321 0 : ModelStringPair( _rxControlModel, _rBindingID ) );
322 0 : }
323 :
324 0 : void OFormLayerXMLImport_Impl::registerXFormsSubmission(
325 : const Reference< XPropertySet >& _rxControlModel,
326 : const OUString& _rSubmissionID )
327 : {
328 : // TODO: is an empty binding name allowed?
329 : OSL_ENSURE( _rxControlModel.is(), "need model" );
330 :
331 : m_aXFormsSubmissions.push_back(
332 0 : ModelStringPair( _rxControlModel, _rSubmissionID ) );
333 0 : }
334 :
335 0 : void OFormLayerXMLImport_Impl::registerCellRangeListSource( const Reference< XPropertySet >& _rxControlModel, const OUString& _rCellRangeAddress )
336 : {
337 : OSL_ENSURE( _rxControlModel.is() && !_rCellRangeAddress.isEmpty(),
338 : "OFormLayerXMLImport_Impl::registerCellRangeListSource: invalid arguments!" );
339 0 : m_aCellRangeListSources.push_back( ModelStringPair( _rxControlModel, _rCellRangeAddress ) );
340 0 : }
341 0 : const SvXMLStyleContext* OFormLayerXMLImport_Impl::getStyleElement(const OUString& _rStyleName) const
342 : {
343 : OSL_ENSURE( m_pAutoStyles, "OFormLayerXMLImport_Impl::getStyleElement: have no auto style context!" );
344 : // did you use setAutoStyleContext?
345 :
346 : const SvXMLStyleContext* pControlStyle =
347 0 : m_pAutoStyles ? m_pAutoStyles->FindStyleChildContext( XML_STYLE_FAMILY_TEXT_PARAGRAPH, _rStyleName ) : NULL;
348 : OSL_ENSURE( pControlStyle || !m_pAutoStyles,
349 : OStringBuffer("OFormLayerXMLImport_Impl::getStyleElement: did not find the style named \"").append(OUStringToOString(_rStyleName, RTL_TEXTENCODING_ASCII_US)).append("\"!").getStr() );
350 0 : return pControlStyle;
351 : }
352 :
353 0 : void OFormLayerXMLImport_Impl::enterEventContext()
354 : {
355 : // install our own translation table. We need to disable the other tables because of name conflicts.
356 0 : m_rImporter.GetEventImport().PushTranslationTable();
357 0 : m_rImporter.GetEventImport().AddTranslationTable(g_pFormsEventTranslation);
358 0 : }
359 :
360 0 : void OFormLayerXMLImport_Impl::leaveEventContext()
361 : {
362 : // install the original event tables.
363 0 : m_rImporter.GetEventImport().PopTranslationTable();
364 0 : }
365 :
366 0 : void OFormLayerXMLImport_Impl::registerControlId(const Reference< XPropertySet >& _rxControl, const OUString& _rId)
367 : {
368 : OSL_ENSURE(m_aCurrentPageIds != m_aControlIds.end(), "OFormLayerXMLImport_Impl::registerControlId: no current page!");
369 : OSL_ENSURE(!_rId.isEmpty(), "OFormLayerXMLImport_Impl::registerControlId: invalid (empty) control id!");
370 :
371 : OSL_ENSURE(m_aCurrentPageIds->second.end() == m_aCurrentPageIds->second.find(_rId), "OFormLayerXMLImport_Impl::registerControlId: control id already used!");
372 0 : m_aCurrentPageIds->second[_rId] = _rxControl;
373 0 : }
374 :
375 0 : void OFormLayerXMLImport_Impl::registerControlReferences(const Reference< XPropertySet >& _rxControl, const OUString& _rReferringControls)
376 : {
377 : OSL_ENSURE(!_rReferringControls.isEmpty(), "OFormLayerXMLImport_Impl::registerControlReferences: invalid (empty) control id list!");
378 : OSL_ENSURE(_rxControl.is(), "OFormLayerXMLImport_Impl::registerControlReferences: invalid (NULL) control!");
379 0 : m_aControlReferences.push_back( ModelStringPair( _rxControl, _rReferringControls ) );
380 0 : }
381 :
382 0 : void OFormLayerXMLImport_Impl::startPage(const Reference< XDrawPage >& _rxDrawPage)
383 : {
384 0 : m_xCurrentPageFormsSupp.clear();
385 :
386 : OSL_ENSURE(_rxDrawPage.is(), "OFormLayerXMLImport_Impl::startPage: NULL page!");
387 0 : m_xCurrentPageFormsSupp = m_xCurrentPageFormsSupp.query( _rxDrawPage );
388 : OSL_ENSURE( m_xCurrentPageFormsSupp.is(), "OFormLayerXMLImport_Impl::startPage: invalid draw page (no XFormsSupplier)!" );
389 0 : if ( !m_xCurrentPageFormsSupp.is() )
390 0 : return;
391 :
392 : // add a new entry to our page map
393 0 : ::std::pair< MapDrawPage2Map::iterator, bool > aPagePosition;
394 0 : aPagePosition =
395 0 : m_aControlIds.insert(MapDrawPage2Map::value_type(_rxDrawPage, MapString2PropertySet()));
396 : OSL_ENSURE(aPagePosition.second, "OFormLayerXMLImport_Impl::startPage: already imported this page!");
397 0 : m_aCurrentPageIds = aPagePosition.first;
398 : }
399 :
400 0 : void OFormLayerXMLImport_Impl::endPage()
401 : {
402 : OSL_ENSURE( m_xCurrentPageFormsSupp.is(), "OFormLayerXMLImport_Impl::endPage: sure you called startPage before?" );
403 :
404 : // do some knittings for the controls which are referring to each other
405 : try
406 : {
407 : static const sal_Unicode s_nSeparator = ',';
408 0 : OUString sReferring;
409 0 : OUString sCurrentReferring;
410 0 : OUString sSeparator(&s_nSeparator, 1);
411 0 : Reference< XPropertySet > xCurrentReferring;
412 : sal_Int32 nSeparator, nPrevSep;
413 0 : ::std::vector< ModelStringPair >::const_iterator aEnd = m_aControlReferences.end();
414 0 : for ( ::std::vector< ModelStringPair >::const_iterator aReferences = m_aControlReferences.begin();
415 : aReferences != aEnd;
416 : ++aReferences
417 : )
418 : {
419 : // the list of control ids is comma separated
420 :
421 : // in a list of n ids there are only n-1 separators ... have to catch this last id
422 : // -> normalize the list
423 0 : sReferring = aReferences->second;
424 0 : sReferring += sSeparator;
425 :
426 0 : nPrevSep = -1;
427 0 : while (-1 != (nSeparator = sReferring.indexOf(s_nSeparator, nPrevSep + 1)))
428 : {
429 0 : sCurrentReferring = sReferring.copy(nPrevSep + 1, nSeparator - nPrevSep - 1);
430 0 : xCurrentReferring = lookupControlId(sCurrentReferring);
431 0 : if (xCurrentReferring.is())
432 : // if this condition fails, this is an error, but lookupControlId should have asserted this ...
433 0 : xCurrentReferring->setPropertyValue( PROPERTY_CONTROLLABEL, makeAny( aReferences->first ) );
434 :
435 0 : nPrevSep = nSeparator;
436 : }
437 0 : }
438 : }
439 0 : catch(Exception&)
440 : {
441 : OSL_FAIL("OFormLayerXMLImport_Impl::endPage: unable to knit the control references (caught an exception)!");
442 : }
443 :
444 : // now that we have all children of the forms collection, attach the events
445 0 : Reference< XIndexAccess > xIndexContainer;
446 0 : if ( m_xCurrentPageFormsSupp.is() && m_xCurrentPageFormsSupp->hasForms() )
447 0 : xIndexContainer = xIndexContainer.query( m_xCurrentPageFormsSupp->getForms() );
448 0 : if ( xIndexContainer.is() )
449 0 : ODefaultEventAttacherManager::setEvents( xIndexContainer );
450 :
451 : // clear the structures for the control references.
452 0 : m_aControlReferences.clear();
453 :
454 : // and no we have no current page anymore
455 0 : m_aCurrentPageIds = m_aControlIds.end();
456 0 : }
457 :
458 0 : Reference< XPropertySet > OFormLayerXMLImport_Impl::lookupControlId(const OUString& _rControlId)
459 : {
460 : OSL_ENSURE(m_aCurrentPageIds != m_aControlIds.end(), "OFormLayerXMLImport_Impl::lookupControlId: no current page!");
461 0 : Reference< XPropertySet > xReturn;
462 0 : if (m_aCurrentPageIds != m_aControlIds.end())
463 : {
464 0 : MapString2PropertySet::const_iterator aPos = m_aCurrentPageIds->second.find(_rControlId);
465 0 : if (m_aCurrentPageIds->second.end() != aPos)
466 0 : xReturn = aPos->second;
467 : else
468 : OSL_FAIL("OFormLayerXMLImport_Impl::lookupControlId: invalid control id (did not find it)!");
469 : }
470 0 : return xReturn;
471 : }
472 :
473 0 : SvXMLImportContext* OFormLayerXMLImport_Impl::createOfficeFormsContext(
474 : SvXMLImport& _rImport,
475 : sal_uInt16 _nPrefix,
476 : const OUString& _rLocalName)
477 : {
478 0 : return new OFormsRootImport( _rImport, _nPrefix, _rLocalName );
479 : }
480 :
481 0 : SvXMLImportContext* OFormLayerXMLImport_Impl::createContext(const sal_uInt16 _nPrefix, const OUString& _rLocalName,
482 : const Reference< xml::sax::XAttributeList >&)
483 : {
484 0 : SvXMLImportContext* pContext = NULL;
485 0 : if ( _rLocalName.equalsAscii( "form" ) )
486 : {
487 0 : if ( m_xCurrentPageFormsSupp.is() )
488 0 : pContext = new OFormImport(*this, *this, _nPrefix, _rLocalName, m_xCurrentPageFormsSupp->getForms() );
489 : }
490 0 : else if ( ( _nPrefix == XML_NAMESPACE_XFORMS
491 0 : && ( xmloff::token::IsXMLToken( _rLocalName, xmloff::token::XML_MODEL ) ) )
492 : )
493 : {
494 0 : pContext = createXFormsModelContext( m_rImporter, _nPrefix, _rLocalName );
495 : }
496 :
497 0 : if ( !pContext )
498 : {
499 : OSL_FAIL( "unknown element" );
500 : pContext =
501 0 : new SvXMLImportContext(m_rImporter, _nPrefix, _rLocalName);
502 : }
503 :
504 0 : return pContext;
505 : }
506 :
507 0 : void OFormLayerXMLImport_Impl::documentDone( )
508 : {
509 0 : SvXMLImport& rImport = getGlobalContext();
510 0 : if ( ( rImport.getImportFlags() & IMPORT_CONTENT ) == 0 )
511 0 : return;
512 :
513 : // create (and bind) the spreadsheet cell bindings
514 0 : if ( !m_aCellValueBindings.empty()
515 0 : && FormCellBindingHelper::isCellBindingAllowed( rImport.GetModel() )
516 : )
517 : {
518 0 : static OUString s_sIndex( ":index" );
519 0 : ::std::vector< ModelStringPair >::const_iterator aEnd = m_aCellValueBindings.end();
520 0 : for ( ::std::vector< ModelStringPair >::const_iterator aCellBindings = m_aCellValueBindings.begin();
521 : aCellBindings != aEnd;
522 : ++aCellBindings
523 : )
524 : {
525 : try
526 : {
527 0 : FormCellBindingHelper aHelper( aCellBindings->first, rImport.GetModel() );
528 : OSL_ENSURE( aHelper.isCellBindingAllowed(), "OFormLayerXMLImport_Impl::documentDone: can't bind this control model!" );
529 0 : if ( aHelper.isCellBindingAllowed() )
530 : {
531 : // There are special bindings for listboxes. See
532 : // OListAndComboImport::doRegisterCellValueBinding for a comment on this HACK.
533 0 : OUString sBoundCellAddress( aCellBindings->second );
534 0 : sal_Int32 nIndicator = sBoundCellAddress.lastIndexOf( s_sIndex );
535 :
536 0 : bool bUseIndexBinding = false;
537 0 : if ( nIndicator != -1 )
538 : {
539 0 : sBoundCellAddress = sBoundCellAddress.copy( 0, nIndicator );
540 0 : bUseIndexBinding = true;
541 : }
542 :
543 0 : aHelper.setBinding( aHelper.createCellBindingFromStringAddress( sBoundCellAddress, bUseIndexBinding ) );
544 0 : }
545 : }
546 0 : catch( const Exception& )
547 : {
548 : OSL_FAIL( "OFormLayerXMLImport_Impl::documentDone: caught an exception while binding to a cell!" );
549 : }
550 : }
551 0 : m_aCellValueBindings.clear();
552 : }
553 :
554 : // the same for the spreadsheet cell range list sources
555 0 : if ( !m_aCellRangeListSources.empty()
556 0 : && FormCellBindingHelper::isListCellRangeAllowed( rImport.GetModel() )
557 : )
558 : {
559 0 : for ( ::std::vector< ModelStringPair >::const_iterator aRangeBindings = m_aCellRangeListSources.begin();
560 0 : aRangeBindings != m_aCellRangeListSources.end();
561 : ++aRangeBindings
562 : )
563 : {
564 : try
565 : {
566 0 : FormCellBindingHelper aHelper( aRangeBindings->first, rImport.GetModel() );
567 : OSL_ENSURE( aHelper.isListCellRangeAllowed(), "OFormLayerXMLImport_Impl::documentDone: can't bind this control model!" );
568 0 : if ( aHelper.isListCellRangeAllowed() )
569 : {
570 0 : aHelper.setListSource( aHelper.createCellListSourceFromStringAddress( aRangeBindings->second ) );
571 0 : }
572 : }
573 0 : catch( const Exception& )
574 : {
575 : OSL_FAIL( "OFormLayerXMLImport_Impl::documentDone: caught an exception while binding to a cell range!" );
576 : }
577 : }
578 0 : m_aCellRangeListSources.clear();
579 : }
580 :
581 : // process XForms-bindings; call registerXFormsValueBinding for each
582 : std::for_each( m_aXFormsValueBindings.begin(),
583 : m_aXFormsValueBindings.end(),
584 : bind1st( ptr_fun( bindXFormsValueBinding ),
585 0 : rImport.GetModel() ) );
586 : // same for list bindings
587 : std::for_each( m_aXFormsListBindings.begin(),
588 : m_aXFormsListBindings.end(),
589 : bind1st( ptr_fun( bindXFormsListBinding ),
590 0 : rImport.GetModel() ) );
591 : // same for submissions
592 : std::for_each( m_aXFormsSubmissions.begin(),
593 : m_aXFormsSubmissions.end(),
594 : bind1st( ptr_fun( bindXFormsSubmission ),
595 0 : rImport.GetModel() ) );
596 : }
597 :
598 : } // namespace xmloff
599 :
600 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|