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: xmlComponent.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_dbaccess.hxx"
33 #ifndef DBA_XMLCOMPONENT_HXX
34 #include "xmlComponent.hxx"
36 #ifndef DBA_XMLFILTER_HXX
37 #include "xmlfilter.hxx"
39 #ifndef _XMLOFF_XMLTOKEN_HXX
40 #include <xmloff/xmltoken.hxx>
42 #ifndef _XMLOFF_XMLNMSPE_HXX
43 #include <xmloff/xmlnmspe.hxx>
45 #ifndef _XMLOFF_NMSPMAP_HXX
46 #include <xmloff/nmspmap.hxx>
48 #ifndef DBA_XMLENUMS_HXX
49 #include "xmlEnums.hxx"
51 #ifndef DBACCESS_SHARED_XMLSTRINGS_HRC
52 #include "xmlstrings.hrc"
54 #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
55 #include <com/sun/star/beans/PropertyValue.hpp>
57 #ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
58 #include <com/sun/star/container/XNameContainer.hpp>
60 #ifndef _TOOLS_DEBUG_HXX
61 #include <tools/debug.hxx>
63 #ifndef TOOLS_DIAGNOSE_EX_H
64 #include <tools/diagnose_ex.h>
69 using namespace ::com::sun::star::uno
;
70 using namespace ::com::sun::star::beans
;
71 using namespace ::com::sun::star::container
;
72 using namespace ::com::sun::star::xml::sax
;
73 DBG_NAME(OXMLComponent
)
75 OXMLComponent::OXMLComponent( ODBFilter
& rImport
77 ,const ::rtl::OUString
& _sLocalName
78 ,const Reference
< XAttributeList
> & _xAttrList
79 ,const Reference
< XNameAccess
>& _xParentContainer
80 ,const ::rtl::OUString
& _sComponentServiceName
82 SvXMLImportContext( rImport
, nPrfx
, _sLocalName
)
83 ,m_bAsTemplate(sal_False
)
85 DBG_CTOR(OXMLComponent
,NULL
);
87 OSL_ENSURE(_xAttrList
.is(),"Attribute list is NULL!");
88 const SvXMLNamespaceMap
& rMap
= rImport
.GetNamespaceMap();
89 const SvXMLTokenMap
& rTokenMap
= rImport
.GetComponentElemTokenMap();
91 sal_Int16 nLength
= (_xAttrList
.is()) ? _xAttrList
->getLength() : 0;
92 static const ::rtl::OUString s_sTRUE
= ::xmloff::token::GetXMLToken(XML_TRUE
);
93 for(sal_Int16 i
= 0; i
< nLength
; ++i
)
95 ::rtl::OUString sLocalName
;
96 rtl::OUString sAttrName
= _xAttrList
->getNameByIndex( i
);
97 sal_uInt16 nPrefix
= rMap
.GetKeyByAttrName( sAttrName
,&sLocalName
);
98 rtl::OUString sValue
= _xAttrList
->getValueByIndex( i
);
100 switch( rTokenMap
.Get( nPrefix
, sLocalName
) )
105 case XML_TOK_COMPONENT_NAME
:
107 // sanitize the name. Previously, we allowed to create forms/reports/queries which contain
108 // a / in their name, which nowadays is forbidden. To not lose such objects if they're contained
109 // in older files, we replace the slash with something less offending.
110 m_sName
= m_sName
.replace( '/', '_' );
112 case XML_TOK_AS_TEMPLATE
:
113 m_bAsTemplate
= (sValue
== s_sTRUE
? sal_True
: sal_False
);
117 if ( m_sHREF
.getLength() && m_sName
.getLength() && _xParentContainer
.is() )
119 Sequence
< Any
> aArguments(3);
120 PropertyValue aValue
;
122 aValue
.Name
= PROPERTY_NAME
;
123 aValue
.Value
<<= m_sName
;
124 aArguments
[0] <<= aValue
;
126 aValue
.Name
= PROPERTY_PERSISTENT_NAME
;
127 sal_Int32 nIndex
= m_sHREF
.lastIndexOf('/')+1;
128 aValue
.Value
<<= m_sHREF
.getToken(0,'/',nIndex
);
129 aArguments
[1] <<= aValue
;
131 aValue
.Name
= PROPERTY_AS_TEMPLATE
;
132 aValue
.Value
<<= m_bAsTemplate
;
133 aArguments
[2] <<= aValue
;
137 Reference
< XMultiServiceFactory
> xORB( _xParentContainer
, UNO_QUERY_THROW
);
138 Reference
< XInterface
> xComponent( xORB
->createInstanceWithArguments( _sComponentServiceName
, aArguments
) );
139 Reference
< XNameContainer
> xNameContainer( _xParentContainer
, UNO_QUERY_THROW
);
140 xNameContainer
->insertByName( m_sName
, makeAny( xComponent
) );
144 DBG_UNHANDLED_EXCEPTION();
148 // -----------------------------------------------------------------------------
150 OXMLComponent::~OXMLComponent()
153 DBG_DTOR(OXMLComponent
,NULL
);
155 // -----------------------------------------------------------------------------
156 //----------------------------------------------------------------------------
157 } // namespace dbaxml
158 // -----------------------------------------------------------------------------