xref: /trunk/main/xmloff/source/text/XMLAutoTextEventImport.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 #include "XMLAutoTextEventImport.hxx"
31 #include <com/sun/star/uno/Reference.hxx>
32 #include <com/sun/star/xml/sax/XAttributeList.hpp>
33 #include <com/sun/star/document/XEventsSupplier.hpp>
34 #include <com/sun/star/uno/XInterface.hpp>
35 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
36 #include "XMLAutoTextContainerEventImport.hxx"
37 #include "xmloff/xmlnmspe.hxx"
38 #include <xmloff/xmltoken.hxx>
39 #include <tools/debug.hxx>
40 
41 using namespace ::com::sun::star;
42 
43 using ::rtl::OUString;
44 using ::com::sun::star::uno::Any;
45 using ::com::sun::star::uno::Reference;
46 using ::com::sun::star::uno::Sequence;
47 using ::com::sun::star::uno::Type;
48 using ::com::sun::star::uno::XInterface;
49 using ::com::sun::star::uno::RuntimeException;
50 using ::com::sun::star::uno::Exception;
51 using ::com::sun::star::xml::sax::XAttributeList;
52 using ::com::sun::star::document::XEventsSupplier;
53 using ::com::sun::star::container::XNameReplace;
54 using ::com::sun::star::lang::XMultiServiceFactory;
55 using ::xmloff::token::IsXMLToken;
56 using ::xmloff::token::XML_AUTO_TEXT_EVENTS;
57 
58 const sal_Char sAPI_AutoText[] = "com.sun.star.text.AutoTextContainer";
59 
60 
61 // #110680#
62 XMLAutoTextEventImport::XMLAutoTextEventImport(
63     const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory) throw()
64 :   SvXMLImport(xServiceFactory)
65 {
66 }
67 
68 XMLAutoTextEventImport::~XMLAutoTextEventImport() throw()
69 {
70 }
71 
72 void XMLAutoTextEventImport::initialize(
73     const Sequence<Any> & rArguments )
74         throw(Exception, RuntimeException)
75 {
76     // The events may come as either an XNameReplace or XEventsSupplier.
77 
78     const sal_Int32 nLength = rArguments.getLength();
79     for( sal_Int32 i = 0; i < nLength; i++ )
80     {
81         const Type& rType = rArguments[i].getValueType();
82         if ( rType == ::getCppuType( (Reference<XEventsSupplier>*)NULL ) )
83         {
84             Reference<XEventsSupplier> xSupplier;
85             rArguments[i] >>= xSupplier;
86             DBG_ASSERT(xSupplier.is(), "need XEventsSupplier or XNameReplace");
87 
88             xEvents = xSupplier->getEvents();
89         }
90         else if (rType == ::getCppuType( (Reference<XNameReplace>*)NULL ) )
91         {
92             rArguments[i] >>= xEvents;
93             DBG_ASSERT(xEvents.is(), "need XEventsSupplier or XNameReplace");
94         }
95     }
96 
97     // call parent
98     SvXMLImport::initialize(rArguments);
99 }
100 
101 
102 
103 SvXMLImportContext* XMLAutoTextEventImport::CreateContext(
104     sal_uInt16 nPrefix,
105     const OUString& rLocalName,
106     const Reference<XAttributeList > & xAttrList )
107 {
108     if ( xEvents.is() && (XML_NAMESPACE_OOO == nPrefix) &&
109          IsXMLToken( rLocalName, XML_AUTO_TEXT_EVENTS) )
110     {
111         return new XMLAutoTextContainerEventImport(
112             *this, nPrefix, rLocalName, xEvents);
113     }
114     else
115     {
116         return SvXMLImport::CreateContext(nPrefix, rLocalName, xAttrList);
117     }
118 }
119 
120 
121 Sequence< OUString > SAL_CALL
122     XMLAutoTextEventImport_getSupportedServiceNames()
123         throw()
124 {
125     Sequence< OUString > aSeq( 1 );
126     aSeq[0] = XMLAutoTextEventImport_getImplementationName();
127     return aSeq;
128 }
129 
130 OUString SAL_CALL XMLAutoTextEventImport_getImplementationName() throw()
131 {
132     return OUString( RTL_CONSTASCII_USTRINGPARAM(
133         "com.sun.star.comp.Writer.XMLOasisAutotextEventsImporter" ) );
134 }
135 
136 Reference< XInterface > SAL_CALL XMLAutoTextEventImport_createInstance(
137         const Reference< XMultiServiceFactory > & rSMgr)
138     throw( Exception )
139 {
140     // #110680#
141     // return (cppu::OWeakObject*)new XMLAutoTextEventImport;
142     return (cppu::OWeakObject*)new XMLAutoTextEventImport(rSMgr);
143 }
144 
145