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