1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*63bba73cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*63bba73cSAndrew Rist  * distributed with this work for additional information
6*63bba73cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*63bba73cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist  * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*63bba73cSAndrew Rist  *
11*63bba73cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*63bba73cSAndrew Rist  *
13*63bba73cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist  * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*63bba73cSAndrew Rist  * specific language governing permissions and limitations
18*63bba73cSAndrew Rist  * under the License.
19*63bba73cSAndrew Rist  *
20*63bba73cSAndrew Rist  *************************************************************/
21*63bba73cSAndrew Rist 
22*63bba73cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir #include "XMLAutoTextEventImport.hxx"
27cdf0e10cSrcweir #include <com/sun/star/uno/Reference.hxx>
28cdf0e10cSrcweir #include <com/sun/star/xml/sax/XAttributeList.hpp>
29cdf0e10cSrcweir #include <com/sun/star/document/XEventsSupplier.hpp>
30cdf0e10cSrcweir #include <com/sun/star/uno/XInterface.hpp>
31cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
32cdf0e10cSrcweir #include "XMLAutoTextContainerEventImport.hxx"
33cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
34cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
35cdf0e10cSrcweir #include <tools/debug.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir using namespace ::com::sun::star;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir using ::rtl::OUString;
40cdf0e10cSrcweir using ::com::sun::star::uno::Any;
41cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
42cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
43cdf0e10cSrcweir using ::com::sun::star::uno::Type;
44cdf0e10cSrcweir using ::com::sun::star::uno::XInterface;
45cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException;
46cdf0e10cSrcweir using ::com::sun::star::uno::Exception;
47cdf0e10cSrcweir using ::com::sun::star::xml::sax::XAttributeList;
48cdf0e10cSrcweir using ::com::sun::star::document::XEventsSupplier;
49cdf0e10cSrcweir using ::com::sun::star::container::XNameReplace;
50cdf0e10cSrcweir using ::com::sun::star::lang::XMultiServiceFactory;
51cdf0e10cSrcweir using ::xmloff::token::IsXMLToken;
52cdf0e10cSrcweir using ::xmloff::token::XML_AUTO_TEXT_EVENTS;
53cdf0e10cSrcweir 
54cdf0e10cSrcweir const sal_Char sAPI_AutoText[] = "com.sun.star.text.AutoTextContainer";
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 
57cdf0e10cSrcweir // #110680#
XMLAutoTextEventImport(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & xServiceFactory)58cdf0e10cSrcweir XMLAutoTextEventImport::XMLAutoTextEventImport(
59cdf0e10cSrcweir 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory) throw()
60cdf0e10cSrcweir :	SvXMLImport(xServiceFactory)
61cdf0e10cSrcweir {
62cdf0e10cSrcweir }
63cdf0e10cSrcweir 
~XMLAutoTextEventImport()64cdf0e10cSrcweir XMLAutoTextEventImport::~XMLAutoTextEventImport() throw()
65cdf0e10cSrcweir {
66cdf0e10cSrcweir }
67cdf0e10cSrcweir 
initialize(const Sequence<Any> & rArguments)68cdf0e10cSrcweir void XMLAutoTextEventImport::initialize(
69cdf0e10cSrcweir 	const Sequence<Any> & rArguments )
70cdf0e10cSrcweir 		throw(Exception, RuntimeException)
71cdf0e10cSrcweir {
72cdf0e10cSrcweir 	// The events may come as either an XNameReplace or XEventsSupplier.
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 	const sal_Int32 nLength = rArguments.getLength();
75cdf0e10cSrcweir 	for( sal_Int32 i = 0; i < nLength; i++ )
76cdf0e10cSrcweir 	{
77cdf0e10cSrcweir 		const Type& rType = rArguments[i].getValueType();
78cdf0e10cSrcweir 		if ( rType == ::getCppuType( (Reference<XEventsSupplier>*)NULL ) )
79cdf0e10cSrcweir 		{
80cdf0e10cSrcweir 			Reference<XEventsSupplier> xSupplier;
81cdf0e10cSrcweir 			rArguments[i] >>= xSupplier;
82cdf0e10cSrcweir 			DBG_ASSERT(xSupplier.is(), "need XEventsSupplier or XNameReplace");
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 			xEvents = xSupplier->getEvents();
85cdf0e10cSrcweir 		}
86cdf0e10cSrcweir 		else if (rType == ::getCppuType( (Reference<XNameReplace>*)NULL ) )
87cdf0e10cSrcweir 		{
88cdf0e10cSrcweir 			rArguments[i] >>= xEvents;
89cdf0e10cSrcweir 			DBG_ASSERT(xEvents.is(), "need XEventsSupplier or XNameReplace");
90cdf0e10cSrcweir 		}
91cdf0e10cSrcweir 	}
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 	// call parent
94cdf0e10cSrcweir 	SvXMLImport::initialize(rArguments);
95cdf0e10cSrcweir }
96cdf0e10cSrcweir 
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 
CreateContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<XAttributeList> & xAttrList)99cdf0e10cSrcweir SvXMLImportContext* XMLAutoTextEventImport::CreateContext(
100cdf0e10cSrcweir 	sal_uInt16 nPrefix,
101cdf0e10cSrcweir 	const OUString& rLocalName,
102cdf0e10cSrcweir 	const Reference<XAttributeList > & xAttrList )
103cdf0e10cSrcweir {
104cdf0e10cSrcweir 	if ( xEvents.is() && (XML_NAMESPACE_OOO == nPrefix) &&
105cdf0e10cSrcweir 		 IsXMLToken( rLocalName, XML_AUTO_TEXT_EVENTS) )
106cdf0e10cSrcweir 	{
107cdf0e10cSrcweir 		return new XMLAutoTextContainerEventImport(
108cdf0e10cSrcweir 			*this, nPrefix, rLocalName, xEvents);
109cdf0e10cSrcweir 	}
110cdf0e10cSrcweir 	else
111cdf0e10cSrcweir 	{
112cdf0e10cSrcweir 		return SvXMLImport::CreateContext(nPrefix, rLocalName, xAttrList);
113cdf0e10cSrcweir 	}
114cdf0e10cSrcweir }
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 
117cdf0e10cSrcweir Sequence< OUString > SAL_CALL
XMLAutoTextEventImport_getSupportedServiceNames()118cdf0e10cSrcweir 	XMLAutoTextEventImport_getSupportedServiceNames()
119cdf0e10cSrcweir 		throw()
120cdf0e10cSrcweir {
121cdf0e10cSrcweir 	Sequence< OUString > aSeq( 1 );
122cdf0e10cSrcweir 	aSeq[0] = XMLAutoTextEventImport_getImplementationName();
123cdf0e10cSrcweir 	return aSeq;
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
XMLAutoTextEventImport_getImplementationName()126cdf0e10cSrcweir OUString SAL_CALL XMLAutoTextEventImport_getImplementationName() throw()
127cdf0e10cSrcweir {
128cdf0e10cSrcweir 	return OUString( RTL_CONSTASCII_USTRINGPARAM(
129cdf0e10cSrcweir 		"com.sun.star.comp.Writer.XMLOasisAutotextEventsImporter" ) );
130cdf0e10cSrcweir }
131cdf0e10cSrcweir 
XMLAutoTextEventImport_createInstance(const Reference<XMultiServiceFactory> & rSMgr)132cdf0e10cSrcweir Reference< XInterface > SAL_CALL XMLAutoTextEventImport_createInstance(
133cdf0e10cSrcweir 		const Reference< XMultiServiceFactory > & rSMgr)
134cdf0e10cSrcweir 	throw( Exception )
135cdf0e10cSrcweir {
136cdf0e10cSrcweir 	// #110680#
137cdf0e10cSrcweir 	// return (cppu::OWeakObject*)new XMLAutoTextEventImport;
138cdf0e10cSrcweir 	return (cppu::OWeakObject*)new XMLAutoTextEventImport(rSMgr);
139cdf0e10cSrcweir }
140cdf0e10cSrcweir 
141