merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / text / XMLAutoTextEventImport.cxx
blob97c3ad719b6e50edb9509d8efab7663215d98a9f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLAutoTextEventImport.cxx,v $
10 * $Revision: 1.11 $
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 "XMLAutoTextEventImport.hxx"
34 #include <com/sun/star/uno/Reference.hxx>
35 #include <com/sun/star/xml/sax/XAttributeList.hpp>
36 #include <com/sun/star/document/XEventsSupplier.hpp>
37 #include <com/sun/star/uno/XInterface.hpp>
38 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
39 #include "XMLAutoTextContainerEventImport.hxx"
40 #include "xmlnmspe.hxx"
41 #include <xmloff/xmltoken.hxx>
42 #include <tools/debug.hxx>
44 using namespace ::com::sun::star;
46 using ::rtl::OUString;
47 using ::com::sun::star::uno::Any;
48 using ::com::sun::star::uno::Reference;
49 using ::com::sun::star::uno::Sequence;
50 using ::com::sun::star::uno::Type;
51 using ::com::sun::star::uno::XInterface;
52 using ::com::sun::star::uno::RuntimeException;
53 using ::com::sun::star::uno::Exception;
54 using ::com::sun::star::xml::sax::XAttributeList;
55 using ::com::sun::star::document::XEventsSupplier;
56 using ::com::sun::star::container::XNameReplace;
57 using ::com::sun::star::lang::XMultiServiceFactory;
58 using ::xmloff::token::IsXMLToken;
59 using ::xmloff::token::XML_AUTO_TEXT_EVENTS;
61 const sal_Char sAPI_AutoText[] = "com.sun.star.text.AutoTextContainer";
64 // #110680#
65 XMLAutoTextEventImport::XMLAutoTextEventImport(
66 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory) throw()
67 : SvXMLImport(xServiceFactory)
71 XMLAutoTextEventImport::~XMLAutoTextEventImport() throw()
75 void XMLAutoTextEventImport::initialize(
76 const Sequence<Any> & rArguments )
77 throw(Exception, RuntimeException)
79 // The events may come as either an XNameReplace or XEventsSupplier.
81 const sal_Int32 nLength = rArguments.getLength();
82 for( sal_Int32 i = 0; i < nLength; i++ )
84 const Type& rType = rArguments[i].getValueType();
85 if ( rType == ::getCppuType( (Reference<XEventsSupplier>*)NULL ) )
87 Reference<XEventsSupplier> xSupplier;
88 rArguments[i] >>= xSupplier;
89 DBG_ASSERT(xSupplier.is(), "need XEventsSupplier or XNameReplace");
91 xEvents = xSupplier->getEvents();
93 else if (rType == ::getCppuType( (Reference<XNameReplace>*)NULL ) )
95 rArguments[i] >>= xEvents;
96 DBG_ASSERT(xEvents.is(), "need XEventsSupplier or XNameReplace");
100 // call parent
101 SvXMLImport::initialize(rArguments);
106 SvXMLImportContext* XMLAutoTextEventImport::CreateContext(
107 sal_uInt16 nPrefix,
108 const OUString& rLocalName,
109 const Reference<XAttributeList > & xAttrList )
111 if ( xEvents.is() && (XML_NAMESPACE_OOO == nPrefix) &&
112 IsXMLToken( rLocalName, XML_AUTO_TEXT_EVENTS) )
114 return new XMLAutoTextContainerEventImport(
115 *this, nPrefix, rLocalName, xEvents);
117 else
119 return SvXMLImport::CreateContext(nPrefix, rLocalName, xAttrList);
124 Sequence< OUString > SAL_CALL
125 XMLAutoTextEventImport_getSupportedServiceNames()
126 throw()
128 Sequence< OUString > aSeq( 1 );
129 aSeq[0] = XMLAutoTextEventImport_getImplementationName();
130 return aSeq;
133 OUString SAL_CALL XMLAutoTextEventImport_getImplementationName() throw()
135 return OUString( RTL_CONSTASCII_USTRINGPARAM(
136 "com.sun.star.comp.Writer.XMLOasisAutotextEventsImporter" ) );
139 Reference< XInterface > SAL_CALL XMLAutoTextEventImport_createInstance(
140 const Reference< XMultiServiceFactory > & rSMgr)
141 throw( Exception )
143 // #110680#
144 // return (cppu::OWeakObject*)new XMLAutoTextEventImport;
145 return (cppu::OWeakObject*)new XMLAutoTextEventImport(rSMgr);