1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: layerimport.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include "layerimport.hxx"
34 #include "formenums.hxx"
35 #include "elementimport.hxx"
36 #include "officeforms.hxx"
37 #include "strings.hxx"
38 #include "formstyles.hxx"
39 #include <xmloff/xmlictxt.hxx>
40 #include <xmloff/xmlstyle.hxx>
41 #include <xmloff/families.hxx>
42 #include <xmloff/xmlprmap.hxx>
43 #include <xmloff/prstylei.hxx>
44 #include <xmloff/xmlimp.hxx>
45 #include "XMLEventImportHelper.hxx"
46 #include <xmloff/xmlimppr.hxx>
47 #include <xmloff/xmlnumfi.hxx>
48 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
49 #include <com/sun/star/form/FormSubmitEncoding.hpp>
50 #include <com/sun/star/form/FormSubmitMethod.hpp>
51 #include <com/sun/star/sdb/CommandType.hpp>
52 #include <com/sun/star/form/NavigationBarMode.hpp>
53 #include <com/sun/star/form/TabulatorCycle.hpp>
54 #include <com/sun/star/form/FormButtonType.hpp>
55 #include <com/sun/star/awt/ScrollBarOrientation.hpp>
56 #include <com/sun/star/awt/VisualEffect.hpp>
57 #include <com/sun/star/form/ListSourceType.hpp>
58 #include <vcl/wintypes.hxx> // for check states
59 #include <com/sun/star/lang/Locale.hpp>
60 #include <xmloff/controlpropertyhdl.hxx>
61 #include "controlpropertymap.hxx"
62 #include "formevents.hxx"
63 #include "formcellbinding.hxx"
64 #include "xformsimport.hxx"
65 #include <xmloff/xmltoken.hxx>
66 #include "xmlnmspe.hxx"
67 #include <rtl/logfile.hxx>
70 SV_IMPL_REF( SvXMLStylesContext
);
72 //.........................................................................
75 //.........................................................................
77 using namespace ::com::sun::star::uno
;
78 using namespace ::com::sun::star::awt
;
79 using namespace ::com::sun::star::lang
;
80 using namespace ::com::sun::star::beans
;
81 using namespace ::com::sun::star::container
;
82 using namespace ::com::sun::star::drawing
;
83 using namespace ::com::sun::star::xml
;
84 using namespace ::com::sun::star::util
;
85 using namespace ::com::sun::star::form
;
86 using namespace ::com::sun::star::sdb
;
88 //=====================================================================
89 //= OFormLayerXMLImport_Impl
90 //=====================================================================
91 //---------------------------------------------------------------------
92 OFormLayerXMLImport_Impl::OFormLayerXMLImport_Impl(SvXMLImport
& _rImporter
)
93 :m_rImporter(_rImporter
)
96 // build the attribute2property map
97 // string properties which are exported as attributes
98 m_aAttributeMetaData
.addStringProperty(
99 OAttributeMetaData::getCommonControlAttributeName(CCA_NAME
), PROPERTY_NAME
);
100 m_aAttributeMetaData
.addStringProperty(
101 OAttributeMetaData::getSpecialAttributeName(SCA_GROUP_NAME
), PROPERTY_GROUP_NAME
);
102 m_aAttributeMetaData
.addStringProperty(
103 OAttributeMetaData::getCommonControlAttributeName(CCA_IMAGE_DATA
), PROPERTY_IMAGEURL
);
104 m_aAttributeMetaData
.addStringProperty(
105 OAttributeMetaData::getCommonControlAttributeName(CCA_LABEL
), PROPERTY_LABEL
);
106 m_aAttributeMetaData
.addStringProperty(
107 OAttributeMetaData::getCommonControlAttributeName(CCA_TARGET_LOCATION
), PROPERTY_TARGETURL
);
108 m_aAttributeMetaData
.addStringProperty(
109 OAttributeMetaData::getCommonControlAttributeName(CCA_TITLE
), PROPERTY_TITLE
);
110 m_aAttributeMetaData
.addStringProperty(
111 OAttributeMetaData::getCommonControlAttributeName(CCA_TARGET_FRAME
), PROPERTY_TARGETFRAME
, "_blank");
112 m_aAttributeMetaData
.addStringProperty(
113 OAttributeMetaData::getDatabaseAttributeName(DA_DATA_FIELD
), PROPERTY_DATAFIELD
);
114 m_aAttributeMetaData
.addStringProperty(
115 OAttributeMetaData::getFormAttributeName(faCommand
), PROPERTY_COMMAND
);
116 m_aAttributeMetaData
.addStringProperty(
117 OAttributeMetaData::getFormAttributeName(faDatasource
), PROPERTY_DATASOURCENAME
);
118 m_aAttributeMetaData
.addStringProperty(
119 OAttributeMetaData::getFormAttributeName(faFilter
), PROPERTY_FILTER
);
120 m_aAttributeMetaData
.addStringProperty(
121 OAttributeMetaData::getFormAttributeName(faOrder
), PROPERTY_ORDER
);
123 // properties not added because they're already present in another form
125 0 == ::rtl::OUString::createFromAscii(OAttributeMetaData::getCommonControlAttributeName(CCA_TARGET_LOCATION
)).compareToAscii(
126 OAttributeMetaData::getFormAttributeName(faAction
)),
127 "OFormLayerXMLImport_Impl::OFormLayerXMLImport_Impl: invalid attribute names (1)!");
128 // if this fails, we would have to add a translation from faAction->PROPERTY_TARGETURL
129 // We did not because we already have one CCA_TARGET_LOCATION->PROPERTY_TARGETURL,
130 // and CCA_TARGET_LOCATION and faAction should be represented by the same attribute
133 0 == ::rtl::OUString::createFromAscii(OAttributeMetaData::getCommonControlAttributeName(CCA_NAME
)).compareToAscii(
134 OAttributeMetaData::getFormAttributeName(faName
)),
135 "OFormLayerXMLImport_Impl::OFormLayerXMLImport_Impl: invalid attribute names (2)!");
136 // the same for faName, CCA_NAME and PROPERTY_NAME
138 // boolean properties which are exported as attributes
139 m_aAttributeMetaData
.addBooleanProperty(
140 OAttributeMetaData::getCommonControlAttributeName(CCA_CURRENT_SELECTED
), PROPERTY_STATE
, sal_False
);
141 m_aAttributeMetaData
.addBooleanProperty(
142 OAttributeMetaData::getCommonControlAttributeName(CCA_DISABLED
), PROPERTY_ENABLED
, sal_False
, sal_True
);
143 m_aAttributeMetaData
.addBooleanProperty(
144 OAttributeMetaData::getCommonControlAttributeName(CCA_DROPDOWN
), PROPERTY_DROPDOWN
, sal_False
);
145 m_aAttributeMetaData
.addBooleanProperty(
146 OAttributeMetaData::getCommonControlAttributeName(CCA_PRINTABLE
), PROPERTY_PRINTABLE
, sal_True
);
147 m_aAttributeMetaData
.addBooleanProperty(
148 OAttributeMetaData::getCommonControlAttributeName(CCA_READONLY
), PROPERTY_READONLY
, sal_False
);
149 m_aAttributeMetaData
.addBooleanProperty(
150 OAttributeMetaData::getCommonControlAttributeName(CCA_SELECTED
), PROPERTY_DEFAULT_STATE
, sal_False
);
151 m_aAttributeMetaData
.addBooleanProperty(
152 OAttributeMetaData::getCommonControlAttributeName(CCA_TAB_STOP
), PROPERTY_TABSTOP
, sal_True
);
153 m_aAttributeMetaData
.addBooleanProperty(
154 OAttributeMetaData::getDatabaseAttributeName(DA_CONVERT_EMPTY
), PROPERTY_EMPTY_IS_NULL
, sal_False
);
155 m_aAttributeMetaData
.addBooleanProperty(
156 OAttributeMetaData::getSpecialAttributeName(SCA_VALIDATION
), PROPERTY_STRICTFORMAT
, sal_False
);
157 m_aAttributeMetaData
.addBooleanProperty(
158 OAttributeMetaData::getSpecialAttributeName(SCA_MULTI_LINE
), PROPERTY_MULTILINE
, sal_False
);
159 m_aAttributeMetaData
.addBooleanProperty(
160 OAttributeMetaData::getSpecialAttributeName(SCA_AUTOMATIC_COMPLETION
), PROPERTY_AUTOCOMPLETE
, sal_False
);
161 m_aAttributeMetaData
.addBooleanProperty(
162 OAttributeMetaData::getSpecialAttributeName(SCA_MULTIPLE
), PROPERTY_MULTISELECTION
, sal_False
);
163 m_aAttributeMetaData
.addBooleanProperty(
164 OAttributeMetaData::getSpecialAttributeName(SCA_DEFAULT_BUTTON
), PROPERTY_DEFAULTBUTTON
, sal_False
);
165 m_aAttributeMetaData
.addBooleanProperty(
166 OAttributeMetaData::getSpecialAttributeName(SCA_IS_TRISTATE
), PROPERTY_TRISTATE
, sal_False
);
167 m_aAttributeMetaData
.addBooleanProperty(
168 OAttributeMetaData::getFormAttributeName(faAllowDeletes
), PROPERTY_ALLOWDELETES
, sal_True
);
169 m_aAttributeMetaData
.addBooleanProperty(
170 OAttributeMetaData::getFormAttributeName(faAllowInserts
), PROPERTY_ALLOWINSERTS
, sal_True
);
171 m_aAttributeMetaData
.addBooleanProperty(
172 OAttributeMetaData::getFormAttributeName(faAllowUpdates
), PROPERTY_ALLOWUPDATES
, sal_True
);
173 m_aAttributeMetaData
.addBooleanProperty(
174 OAttributeMetaData::getFormAttributeName(faApplyFilter
), PROPERTY_APPLYFILTER
, sal_False
);
175 m_aAttributeMetaData
.addBooleanProperty(
176 OAttributeMetaData::getFormAttributeName(faEscapeProcessing
), PROPERTY_ESCAPEPROCESSING
, sal_True
);
177 m_aAttributeMetaData
.addBooleanProperty(
178 OAttributeMetaData::getFormAttributeName(faIgnoreResult
), PROPERTY_IGNORERESULT
, sal_False
);
179 m_aAttributeMetaData
.addBooleanProperty(
180 OAttributeMetaData::getSpecialAttributeName( SCA_TOGGLE
), PROPERTY_TOGGLE
, sal_False
);
181 m_aAttributeMetaData
.addBooleanProperty(
182 OAttributeMetaData::getSpecialAttributeName( SCA_FOCUS_ON_CLICK
), PROPERTY_FOCUS_ON_CLICK
, sal_True
);
183 m_aAttributeMetaData
.addBooleanProperty(
184 OAttributeMetaData::getDatabaseAttributeName( DA_INPUT_REQUIRED
), PROPERTY_INPUT_REQUIRED
, sal_False
);
186 // the int16 attributes
187 m_aAttributeMetaData
.addInt16Property(
188 OAttributeMetaData::getCommonControlAttributeName(CCA_MAX_LENGTH
), PROPERTY_MAXTEXTLENGTH
, 0);
189 m_aAttributeMetaData
.addInt16Property(
190 OAttributeMetaData::getCommonControlAttributeName(CCA_SIZE
), PROPERTY_LINECOUNT
, 5);
191 m_aAttributeMetaData
.addInt16Property(
192 OAttributeMetaData::getCommonControlAttributeName(CCA_TAB_INDEX
), PROPERTY_TABINDEX
, 0);
193 m_aAttributeMetaData
.addInt16Property(
194 OAttributeMetaData::getDatabaseAttributeName(DA_BOUND_COLUMN
), PROPERTY_BOUNDCOLUMN
, 0);
196 // the int32 attributes
197 m_aAttributeMetaData
.addInt32Property(
198 OAttributeMetaData::getSpecialAttributeName( SCA_PAGE_STEP_SIZE
), PROPERTY_BLOCK_INCREMENT
, 10 );
200 // the enum attributes
201 m_aAttributeMetaData
.addEnumProperty(
202 OAttributeMetaData::getCommonControlAttributeName( CCA_VISUAL_EFFECT
), PROPERTY_VISUAL_EFFECT
,
203 VisualEffect::LOOK3D
, OEnumMapper::getEnumMap( OEnumMapper::epVisualEffect
),
204 &::getCppuType( static_cast< sal_Int16
* >( NULL
) ) );
205 m_aAttributeMetaData
.addEnumProperty(
206 OAttributeMetaData::getCommonControlAttributeName( CCA_ORIENTATION
), PROPERTY_ORIENTATION
,
207 ScrollBarOrientation::HORIZONTAL
, OEnumMapper::getEnumMap( OEnumMapper::epOrientation
),
208 &::getCppuType( static_cast< sal_Int32
* >( NULL
) ) );
209 m_aAttributeMetaData
.addEnumProperty(
210 OAttributeMetaData::getCommonControlAttributeName(CCA_BUTTON_TYPE
), PROPERTY_BUTTONTYPE
,
211 FormButtonType_PUSH
, OEnumMapper::getEnumMap(OEnumMapper::epButtonType
),
212 &::getCppuType( static_cast<FormButtonType
*>(NULL
) ));
213 m_aAttributeMetaData
.addEnumProperty(
214 OAttributeMetaData::getDatabaseAttributeName(DA_LIST_SOURCE_TYPE
), PROPERTY_LISTSOURCETYPE
,
215 ListSourceType_VALUELIST
, OEnumMapper::getEnumMap(OEnumMapper::epListSourceType
),
216 &::getCppuType( static_cast<ListSourceType
*>(NULL
) ));
217 m_aAttributeMetaData
.addEnumProperty(
218 OAttributeMetaData::getSpecialAttributeName(SCA_STATE
), PROPERTY_DEFAULT_STATE
, STATE_NOCHECK
,
219 OEnumMapper::getEnumMap(OEnumMapper::epCheckState
),
220 &::getCppuType( static_cast< sal_Int16
* >(NULL
)));
221 m_aAttributeMetaData
.addEnumProperty(
222 OAttributeMetaData::getSpecialAttributeName(SCA_CURRENT_STATE
), PROPERTY_STATE
, STATE_NOCHECK
,
223 OEnumMapper::getEnumMap(OEnumMapper::epCheckState
),
224 &::getCppuType( static_cast< sal_Int16
* >(NULL
)));
225 m_aAttributeMetaData
.addEnumProperty(
226 OAttributeMetaData::getFormAttributeName(faEnctype
), PROPERTY_SUBMIT_ENCODING
,
227 FormSubmitEncoding_URL
, OEnumMapper::getEnumMap(OEnumMapper::epSubmitEncoding
),
228 &::getCppuType( static_cast<FormSubmitEncoding
*>(NULL
) ));
229 m_aAttributeMetaData
.addEnumProperty(
230 OAttributeMetaData::getFormAttributeName(faMethod
), PROPERTY_SUBMIT_METHOD
,
231 FormSubmitMethod_GET
, OEnumMapper::getEnumMap(OEnumMapper::epSubmitMethod
),
232 &::getCppuType( static_cast<FormSubmitMethod
*>(NULL
) ));
233 m_aAttributeMetaData
.addEnumProperty(
234 OAttributeMetaData::getFormAttributeName(faCommandType
), PROPERTY_COMMAND_TYPE
,
235 CommandType::COMMAND
, OEnumMapper::getEnumMap(OEnumMapper::epCommandType
));
236 m_aAttributeMetaData
.addEnumProperty(
237 OAttributeMetaData::getFormAttributeName(faNavigationMode
), PROPERTY_NAVIGATION
,
238 NavigationBarMode_NONE
, OEnumMapper::getEnumMap(OEnumMapper::epNavigationType
),
239 &::getCppuType( static_cast<NavigationBarMode
*>(NULL
) ));
240 m_aAttributeMetaData
.addEnumProperty(
241 OAttributeMetaData::getFormAttributeName(faTabbingCycle
), PROPERTY_CYCLE
,
242 TabulatorCycle_RECORDS
, OEnumMapper::getEnumMap(OEnumMapper::epTabCyle
),
243 &::getCppuType( static_cast<TabulatorCycle
*>(NULL
) ));
245 // initialize our style map
246 m_xPropertyHandlerFactory
= new OControlPropertyHandlerFactory();
247 ::vos::ORef
< XMLPropertySetMapper
> xStylePropertiesMapper
= new XMLPropertySetMapper(getControlStylePropertyMap(), m_xPropertyHandlerFactory
.getBodyPtr());
248 m_xImportMapper
= new SvXMLImportPropertyMapper(xStylePropertiesMapper
.getBodyPtr(), _rImporter
);
251 m_aCurrentPageIds
= m_aControlIds
.end();
254 //---------------------------------------------------------------------
255 OFormLayerXMLImport_Impl::~OFormLayerXMLImport_Impl()
257 // outlined to allow forward declaration of OAttribute2Property in the header
260 m_pAutoStyles
->ReleaseRef();
263 //---------------------------------------------------------------------
264 void OFormLayerXMLImport_Impl::setAutoStyleContext(SvXMLStylesContext
* _pNewContext
)
266 OSL_ENSURE(!m_pAutoStyles
, "OFormLayerXMLImport_Impl::setAutoStyleContext: not to be called twice!");
267 m_pAutoStyles
= _pNewContext
;
269 m_pAutoStyles
->AddRef();
272 //---------------------------------------------------------------------
273 void OFormLayerXMLImport_Impl::applyControlNumberStyle(const Reference
< XPropertySet
>& _rxControlModel
, const ::rtl::OUString
& _rControlNumerStyleName
)
275 OSL_ENSURE(_rxControlModel
.is() && (0 != _rControlNumerStyleName
.getLength()),
276 "OFormLayerXMLImport_Impl::applyControlNumberStyle: invalid arguments (this will crash)!");
278 OSL_ENSURE(m_pAutoStyles
, "OFormLayerXMLImport_Impl::applyControlNumberStyle: have no auto style context!");
281 m_pAutoStyles
= m_rImporter
.GetShapeImport()->GetAutoStylesContext();
283 m_pAutoStyles
->AddRef();
288 const SvXMLStyleContext
* pStyle
= m_pAutoStyles
->FindStyleChildContext(XML_STYLE_FAMILY_DATA_STYLE
, _rControlNumerStyleName
);
291 const SvXMLNumFormatContext
* pDataStyle
= static_cast<const SvXMLNumFormatContext
*>(pStyle
);
293 // set this format at the control model
296 // the models number format supplier and formats
297 Reference
< XNumberFormatsSupplier
> xFormatsSupplier
;
298 _rxControlModel
->getPropertyValue(PROPERTY_FORMATSSUPPLIER
) >>= xFormatsSupplier
;
299 Reference
< XNumberFormats
> xFormats
;
300 if (xFormatsSupplier
.is())
301 xFormats
= xFormatsSupplier
->getNumberFormats();
302 OSL_ENSURE(xFormats
.is(), "OFormLayerXMLImport_Impl::applyControlNumberStyle: could not obtain the controls number formats!");
307 sal_Int32 nFormatKey
= const_cast<SvXMLNumFormatContext
*>(pDataStyle
)->CreateAndInsert( xFormatsSupplier
);
308 OSL_ENSURE(-1 != nFormatKey
, "OFormLayerXMLImport_Impl::applyControlNumberStyle: could not obtain a format key!");
310 // set the format on the control model
311 _rxControlModel
->setPropertyValue(PROPERTY_FORMATKEY
, makeAny(nFormatKey
));
314 catch(const Exception
&)
316 OSL_ENSURE(sal_False
, "OFormLayerXMLImport_Impl::applyControlNumberStyle: couldn't set the format!");
320 OSL_ENSURE(sal_False
, "OFormLayerXMLImport_Impl::applyControlNumberStyle: did not find the style with the given name!");
324 //---------------------------------------------------------------------
325 void OFormLayerXMLImport_Impl::registerCellValueBinding( const Reference
< XPropertySet
>& _rxControlModel
, const ::rtl::OUString
& _rCellAddress
)
327 OSL_ENSURE( _rxControlModel
.is() && _rCellAddress
.getLength(),
328 "OFormLayerXMLImport_Impl::registerCellValueBinding: invalid arguments!" );
329 m_aCellValueBindings
.push_back( ModelStringPair( _rxControlModel
, _rCellAddress
) );
332 //---------------------------------------------------------------------
333 void OFormLayerXMLImport_Impl::registerXFormsValueBinding(
334 const Reference
< XPropertySet
>& _rxControlModel
,
335 const ::rtl::OUString
& _rBindingID
)
337 // TODO: is an empty binding name allowed?
338 OSL_ENSURE( _rxControlModel
.is(), "need model" );
340 m_aXFormsValueBindings
.push_back(
341 ModelStringPair( _rxControlModel
, _rBindingID
) );
344 //---------------------------------------------------------------------
345 void OFormLayerXMLImport_Impl::registerXFormsListBinding(
346 const Reference
< XPropertySet
>& _rxControlModel
,
347 const ::rtl::OUString
& _rBindingID
)
349 // TODO: is an empty binding name allowed?
350 OSL_ENSURE( _rxControlModel
.is(), "need model" );
352 m_aXFormsListBindings
.push_back(
353 ModelStringPair( _rxControlModel
, _rBindingID
) );
356 //---------------------------------------------------------------------
357 void OFormLayerXMLImport_Impl::registerXFormsSubmission(
358 const Reference
< XPropertySet
>& _rxControlModel
,
359 const ::rtl::OUString
& _rSubmissionID
)
361 // TODO: is an empty binding name allowed?
362 OSL_ENSURE( _rxControlModel
.is(), "need model" );
364 m_aXFormsSubmissions
.push_back(
365 ModelStringPair( _rxControlModel
, _rSubmissionID
) );
368 //---------------------------------------------------------------------
369 void OFormLayerXMLImport_Impl::registerCellRangeListSource( const Reference
< XPropertySet
>& _rxControlModel
, const ::rtl::OUString
& _rCellRangeAddress
)
371 OSL_ENSURE( _rxControlModel
.is() && _rCellRangeAddress
.getLength(),
372 "OFormLayerXMLImport_Impl::registerCellRangeListSource: invalid arguments!" );
373 m_aCellRangeListSources
.push_back( ModelStringPair( _rxControlModel
, _rCellRangeAddress
) );
375 //---------------------------------------------------------------------
376 const SvXMLStyleContext
* OFormLayerXMLImport_Impl::getStyleElement(const ::rtl::OUString
& _rStyleName
) const
378 OSL_ENSURE( m_pAutoStyles
, "OFormLayerXMLImport_Impl::getStyleElement: have no auto style context!" );
379 // did you use setAutoStyleContext?
381 const SvXMLStyleContext
* pControlStyle
=
382 m_pAutoStyles
? m_pAutoStyles
->FindStyleChildContext( XML_STYLE_FAMILY_TEXT_PARAGRAPH
, _rStyleName
) : NULL
;
383 OSL_ENSURE( pControlStyle
|| !m_pAutoStyles
,
384 ::rtl::OString( "OFormLayerXMLImport_Impl::getStyleElement: did not find the style named \"" )
385 += ::rtl::OString( _rStyleName
.getStr(), _rStyleName
.getLength(), RTL_TEXTENCODING_ASCII_US
)
386 += ::rtl::OString( "\"!" ) );
387 return pControlStyle
;
390 //---------------------------------------------------------------------
391 void OFormLayerXMLImport_Impl::enterEventContext()
393 // install our own translation table. We need to disable the other tables because of name conflicts.
394 m_rImporter
.GetEventImport().PushTranslationTable();
395 m_rImporter
.GetEventImport().AddTranslationTable(g_pFormsEventTranslation
);
398 //---------------------------------------------------------------------
399 void OFormLayerXMLImport_Impl::leaveEventContext()
401 // install the original event tables.
402 m_rImporter
.GetEventImport().PopTranslationTable();
405 //---------------------------------------------------------------------
406 void OFormLayerXMLImport_Impl::registerControlId(const Reference
< XPropertySet
>& _rxControl
, const ::rtl::OUString
& _rId
)
408 OSL_ENSURE(m_aCurrentPageIds
!= m_aControlIds
.end(), "OFormLayerXMLImport_Impl::registerControlId: no current page!");
409 OSL_ENSURE(_rId
.getLength(), "OFormLayerXMLImport_Impl::registerControlId: invalid (empty) control id!");
411 OSL_ENSURE(m_aCurrentPageIds
->second
.end() == m_aCurrentPageIds
->second
.find(_rId
), "OFormLayerXMLImport_Impl::registerControlId: control id already used!");
412 m_aCurrentPageIds
->second
[_rId
] = _rxControl
;
415 //---------------------------------------------------------------------
416 void OFormLayerXMLImport_Impl::registerControlReferences(const Reference
< XPropertySet
>& _rxControl
, const ::rtl::OUString
& _rReferringControls
)
418 OSL_ENSURE(_rReferringControls
.getLength(), "OFormLayerXMLImport_Impl::registerControlReferences: invalid (empty) control id list!");
419 OSL_ENSURE(_rxControl
.is(), "OFormLayerXMLImport_Impl::registerControlReferences: invalid (NULL) control!");
420 m_aControlReferences
.push_back( ModelStringPair( _rxControl
, _rReferringControls
) );
423 //---------------------------------------------------------------------
424 ::vos::ORef
< SvXMLImportPropertyMapper
> OFormLayerXMLImport_Impl::getStylePropertyMapper() const
426 return m_xImportMapper
;
429 //---------------------------------------------------------------------
430 void OFormLayerXMLImport_Impl::startPage(const Reference
< XDrawPage
>& _rxDrawPage
)
432 m_xCurrentPageFormsSupp
.clear();
434 OSL_ENSURE(_rxDrawPage
.is(), "OFormLayerXMLImport_Impl::startPage: NULL page!");
435 m_xCurrentPageFormsSupp
= m_xCurrentPageFormsSupp
.query( _rxDrawPage
);
436 OSL_ENSURE( m_xCurrentPageFormsSupp
.is(), "OFormLayerXMLImport_Impl::startPage: invalid draw page (no XFormsSupplier)!" );
437 if ( !m_xCurrentPageFormsSupp
.is() )
440 // add a new entry to our page map
441 ::std::pair
< MapDrawPage2MapIterator
, bool > aPagePosition
;
443 m_aControlIds
.insert(MapDrawPage2Map::value_type(_rxDrawPage
, MapString2PropertySet()));
444 OSL_ENSURE(aPagePosition
.second
, "OFormLayerXMLImport_Impl::startPage: already imported this page!");
445 m_aCurrentPageIds
= aPagePosition
.first
;
448 //---------------------------------------------------------------------
449 void OFormLayerXMLImport_Impl::endPage()
451 OSL_ENSURE( m_xCurrentPageFormsSupp
.is(), "OFormLayerXMLImport_Impl::endPage: sure you called startPage before?" );
453 // do some knittings for the controls which are referring to each other
456 static const sal_Unicode s_nSeparator
= ',';
457 ::rtl::OUString sReferring
;
458 ::rtl::OUString sCurrentReferring
;
459 ::rtl::OUString
sSeparator(&s_nSeparator
, 1);
460 Reference
< XPropertySet
> xCurrentReferring
;
461 sal_Int32 nSeparator
, nPrevSep
;
462 ::std::vector
< ModelStringPair
>::const_iterator aEnd
= m_aControlReferences
.end();
463 for ( ::std::vector
< ModelStringPair
>::const_iterator aReferences
= m_aControlReferences
.begin();
468 // the list of control ids is comma separated
470 // in a list of n ids there are only n-1 separators ... have to catch this last id
471 // -> normalize the list
472 sReferring
= aReferences
->second
;
473 sReferring
+= sSeparator
;
476 while (-1 != (nSeparator
= sReferring
.indexOf(s_nSeparator
, nPrevSep
+ 1)))
478 sCurrentReferring
= sReferring
.copy(nPrevSep
+ 1, nSeparator
- nPrevSep
- 1);
479 xCurrentReferring
= lookupControlId(sCurrentReferring
);
480 if (xCurrentReferring
.is())
481 // if this condition fails, this is an error, but lookupControlId should have asserted this ...
482 xCurrentReferring
->setPropertyValue( PROPERTY_CONTROLLABEL
, makeAny( aReferences
->first
) );
484 nPrevSep
= nSeparator
;
490 OSL_ENSURE(sal_False
, "OFormLayerXMLImport_Impl::endPage: unable to knit the control references (caught an exception)!");
493 // now that we have all children of the forms collection, attach the events
494 Reference
< XIndexAccess
> xIndexContainer
;
495 if ( m_xCurrentPageFormsSupp
.is() && m_xCurrentPageFormsSupp
->hasForms() )
496 xIndexContainer
= xIndexContainer
.query( m_xCurrentPageFormsSupp
->getForms() );
497 if ( xIndexContainer
.is() )
498 ODefaultEventAttacherManager::setEvents( xIndexContainer
);
500 // clear the structures for the control references.
501 m_aControlReferences
.clear();
503 // and no we have no current page anymore
504 m_aCurrentPageIds
= m_aControlIds
.end();
507 //---------------------------------------------------------------------
508 Reference
< XPropertySet
> OFormLayerXMLImport_Impl::lookupControlId(const ::rtl::OUString
& _rControlId
)
510 OSL_ENSURE(m_aCurrentPageIds
!= m_aControlIds
.end(), "OFormLayerXMLImport_Impl::lookupControlId: no current page!");
511 Reference
< XPropertySet
> xReturn
;
512 if (m_aCurrentPageIds
!= m_aControlIds
.end())
514 ConstMapString2PropertySetIterator aPos
= m_aCurrentPageIds
->second
.find(_rControlId
);
515 if (m_aCurrentPageIds
->second
.end() != aPos
)
516 xReturn
= aPos
->second
;
518 OSL_ENSURE(sal_False
, "OFormLayerXMLImport_Impl::lookupControlId: invalid control id (did not find it)!");
523 //---------------------------------------------------------------------
524 SvXMLImportContext
* OFormLayerXMLImport_Impl::createOfficeFormsContext(
525 SvXMLImport
& _rImport
,
527 const rtl::OUString
& _rLocalName
)
529 return new OFormsRootImport( _rImport
, _nPrefix
, _rLocalName
);
532 //---------------------------------------------------------------------
533 SvXMLImportContext
* OFormLayerXMLImport_Impl::createContext(const sal_uInt16 _nPrefix
, const rtl::OUString
& _rLocalName
,
534 const Reference
< sax::XAttributeList
>&)
536 SvXMLImportContext
* pContext
= NULL
;
537 if ( 0 == _rLocalName
.compareToAscii( "form" ) )
539 if ( m_xCurrentPageFormsSupp
.is() )
540 pContext
= new OFormImport(*this, *this, _nPrefix
, _rLocalName
, m_xCurrentPageFormsSupp
->getForms() );
542 else if ( ( _nPrefix
== XML_NAMESPACE_XFORMS
543 && ( xmloff::token::IsXMLToken( _rLocalName
, xmloff::token::XML_MODEL
) ) )
546 pContext
= createXFormsModelContext( m_rImporter
, _nPrefix
, _rLocalName
);
551 OSL_ENSURE( false, "unknown element" );
553 new SvXMLImportContext(m_rImporter
, _nPrefix
, _rLocalName
);
559 //---------------------------------------------------------------------
560 void OFormLayerXMLImport_Impl::seekPage(const Reference
< XDrawPage
>& _rxDrawPage
)
562 OSL_ENSURE(m_aCurrentPageIds
== m_aControlIds
.end(), "OFormLayerXMLImport_Impl::seekPage: importing another page currently! This will smash your import!");
563 m_aCurrentPageIds
= m_aControlIds
.find(_rxDrawPage
);
564 OSL_ENSURE(m_aCurrentPageIds
!= m_aControlIds
.end(), "OFormLayerXMLImport_Impl::seekPage: did not find the given page (perhaps it has not been imported, yet?)!");
567 //---------------------------------------------------------------------
568 void OFormLayerXMLImport_Impl::documentDone( )
570 SvXMLImport
& rImport
= getGlobalContext();
571 if ( ( rImport
.getImportFlags() & IMPORT_CONTENT
) == 0 )
574 // create (and bind) the spreadsheet cell bindings
575 if ( !m_aCellValueBindings
.empty()
576 && FormCellBindingHelper::isCellBindingAllowed( rImport
.GetModel() )
579 static ::rtl::OUString
s_sIndex( RTL_CONSTASCII_USTRINGPARAM( ":index" ) );
580 ::std::vector
< ModelStringPair
>::const_iterator aEnd
= m_aCellValueBindings
.end();
581 for ( ::std::vector
< ModelStringPair
>::const_iterator aCellBindings
= m_aCellValueBindings
.begin();
582 aCellBindings
!= aEnd
;
588 FormCellBindingHelper
aHelper( aCellBindings
->first
, rImport
.GetModel() );
589 OSL_ENSURE( aHelper
.isCellBindingAllowed(), "OFormLayerXMLImport_Impl::documentDone: can't bind this control model!" );
590 if ( aHelper
.isCellBindingAllowed() )
592 // There are special bindings for listboxes. See
593 // OListAndComboImport::doRegisterCellValueBinding for a comment on this HACK.
594 ::rtl::OUString
sBoundCellAddress( aCellBindings
->second
);
595 sal_Int32 nIndicator
= sBoundCellAddress
.lastIndexOf( s_sIndex
);
597 bool bUseIndexBinding
= false;
598 if ( nIndicator
!= -1 )
600 sBoundCellAddress
= sBoundCellAddress
.copy( 0, nIndicator
);
601 bUseIndexBinding
= true;
604 aHelper
.setBinding( aHelper
.createCellBindingFromStringAddress( sBoundCellAddress
, bUseIndexBinding
) );
607 catch( const Exception
& )
609 OSL_ENSURE( sal_False
, "OFormLayerXMLImport_Impl::documentDone: caught an exception while binding to a cell!" );
612 m_aCellValueBindings
.clear();
615 // the same for the spreadsheet cell range list sources
616 if ( !m_aCellRangeListSources
.empty()
617 && FormCellBindingHelper::isListCellRangeAllowed( rImport
.GetModel() )
620 for ( ::std::vector
< ModelStringPair
>::const_iterator aRangeBindings
= m_aCellRangeListSources
.begin();
621 aRangeBindings
!= m_aCellRangeListSources
.end();
627 FormCellBindingHelper
aHelper( aRangeBindings
->first
, rImport
.GetModel() );
628 OSL_ENSURE( aHelper
.isListCellRangeAllowed(), "OFormLayerXMLImport_Impl::documentDone: can't bind this control model!" );
629 if ( aHelper
.isListCellRangeAllowed() )
631 aHelper
.setListSource( aHelper
.createCellListSourceFromStringAddress( aRangeBindings
->second
) );
634 catch( const Exception
& )
636 OSL_ENSURE( sal_False
, "OFormLayerXMLImport_Impl::documentDone: caught an exception while binding to a cell range!" );
639 m_aCellRangeListSources
.clear();
642 // process XForms-bindings; call registerXFormsValueBinding for each
643 std::for_each( m_aXFormsValueBindings
.begin(),
644 m_aXFormsValueBindings
.end(),
645 bind1st( ptr_fun( bindXFormsValueBinding
),
646 rImport
.GetModel() ) );
647 // same for list bindings
648 std::for_each( m_aXFormsListBindings
.begin(),
649 m_aXFormsListBindings
.end(),
650 bind1st( ptr_fun( bindXFormsListBinding
),
651 rImport
.GetModel() ) );
652 // same for submissions
653 std::for_each( m_aXFormsSubmissions
.begin(),
654 m_aXFormsSubmissions
.end(),
655 bind1st( ptr_fun( bindXFormsSubmission
),
656 rImport
.GetModel() ) );
659 //.........................................................................
660 } // namespace xmloff
661 //.........................................................................