1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // no include protection. This file is included from elementimport.hxx only.
29 
30 #ifndef _INCLUDING_FROM_ELEMENTIMPORT_HXX_
31 #error "do not include this file directly!"
32 #endif
33 
34 // no namespace. Same as above: this file is included from elementimport.hxx only,
35 // and this is done inside the namespace
36 
37 //=========================================================================
38 //= OContainerImport
39 //=========================================================================
40 //-------------------------------------------------------------------------
41 template <class BASE>
42 inline SvXMLImportContext* OContainerImport< BASE >::CreateChildContext(
43 	sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName,
44 	const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList)
45 {
46 	// maybe it's a sub control
47 	if (_rLocalName == m_sWrapperElementName)
48 	{
49 		if (m_xMeAsContainer.is())
50 			return implCreateControlWrapper(_nPrefix, _rLocalName);
51 		else
52 		{
53 			OSL_ENSURE(sal_False, "OContainerImport::CreateChildContext: don't have an element!");
54 			return NULL;
55 		}
56 	}
57 
58 	return BASE::CreateChildContext(_nPrefix, _rLocalName, _rxAttrList);
59 }
60 
61 //-------------------------------------------------------------------------
62 template <class BASE>
63 inline ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
64 	OContainerImport< BASE >::createElement()
65 {
66 	// let the base class create the object
67 	::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xReturn = BASE::createElement();
68 	if (!xReturn.is())
69 		return xReturn;
70 
71 	// ensure that the object is a XNameContainer (we strongly need this for inserting child elements)
72 	m_xMeAsContainer = ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >(xReturn, ::com::sun::star::uno::UNO_QUERY);
73 	if (!m_xMeAsContainer.is())
74 	{
75 		OSL_ENSURE(sal_False, "OContainerImport::createElement: invalid element (no XNameContainer) created!");
76 		xReturn.clear();
77 	}
78 
79 	return xReturn;
80 }
81 
82 //-------------------------------------------------------------------------
83 template <class BASE>
84 inline void OContainerImport< BASE >::EndElement()
85 {
86 	BASE::EndElement();
87 
88 	// now that we have all children, attach the events
89 	::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > xIndexContainer(m_xMeAsContainer, ::com::sun::star::uno::UNO_QUERY);
90 	if (xIndexContainer.is())
91 		ODefaultEventAttacherManager::setEvents(xIndexContainer);
92 }
93 
94 //=========================================================================
95 //= OColumnImport
96 //=========================================================================
97 //-------------------------------------------------------------------------
98 template <class BASE>
99 OColumnImport< BASE >::OColumnImport(OFormLayerXMLImport_Impl& _rImport, IEventAttacherManager& _rEventManager, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName,
100 		const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& _rxParentContainer,
101 		OControlElement::ElementType _eType)
102 	:BASE(_rImport, _rEventManager, _nPrefix, _rName, _rxParentContainer, _eType)
103 	,m_xColumnFactory(_rxParentContainer, ::com::sun::star::uno::UNO_QUERY)
104 {
105 	OSL_ENSURE(m_xColumnFactory.is(), "OColumnImport::OColumnImport: invalid parent container (no factory)!");
106 }
107 
108 //-------------------------------------------------------------------------
109 // OElementImport overridables
110 template <class BASE>
111 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > OColumnImport< BASE >::createElement()
112 {
113 	::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xReturn;
114 	// no call to the base class' method. We have to use the grid column factory
115 	if (m_xColumnFactory.is())
116 	{
117 		// create the column
118 		xReturn = m_xColumnFactory->createColumn(this->m_sServiceName);
119 		OSL_ENSURE(xReturn.is(), "OColumnImport::createElement: the factory returned an invalid object!");
120 	}
121 	return xReturn;
122 }
123 
124