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