xref: /trunk/main/xmloff/source/text/XMLAutoTextEventImport.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 {
71     // The events may come as either an XNameReplace or XEventsSupplier.
72 
73     const sal_Int32 nLength = rArguments.getLength();
74     for( sal_Int32 i = 0; i < nLength; i++ )
75     {
76         const Type& rType = rArguments[i].getValueType();
77         if ( rType == ::getCppuType( (Reference<XEventsSupplier>*)NULL ) )
78         {
79             Reference<XEventsSupplier> xSupplier;
80             rArguments[i] >>= xSupplier;
81             DBG_ASSERT(xSupplier.is(), "need XEventsSupplier or XNameReplace");
82 
83             xEvents = xSupplier->getEvents();
84         }
85         else if (rType == ::getCppuType( (Reference<XNameReplace>*)NULL ) )
86         {
87             rArguments[i] >>= xEvents;
88             DBG_ASSERT(xEvents.is(), "need XEventsSupplier or XNameReplace");
89         }
90     }
91 
92     // call parent
93     SvXMLImport::initialize(rArguments);
94 }
95 
96 
97 
CreateContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<XAttributeList> & xAttrList)98 SvXMLImportContext* XMLAutoTextEventImport::CreateContext(
99     sal_uInt16 nPrefix,
100     const OUString& rLocalName,
101     const Reference<XAttributeList > & xAttrList )
102 {
103     if ( xEvents.is() && (XML_NAMESPACE_OOO == nPrefix) &&
104          IsXMLToken( rLocalName, XML_AUTO_TEXT_EVENTS) )
105     {
106         return new XMLAutoTextContainerEventImport(
107             *this, nPrefix, rLocalName, xEvents);
108     }
109     else
110     {
111         return SvXMLImport::CreateContext(nPrefix, rLocalName, xAttrList);
112     }
113 }
114 
115 
116 Sequence< OUString > SAL_CALL
XMLAutoTextEventImport_getSupportedServiceNames()117     XMLAutoTextEventImport_getSupportedServiceNames()
118         throw()
119 {
120     Sequence< OUString > aSeq( 1 );
121     aSeq[0] = XMLAutoTextEventImport_getImplementationName();
122     return aSeq;
123 }
124 
XMLAutoTextEventImport_getImplementationName()125 OUString SAL_CALL XMLAutoTextEventImport_getImplementationName() throw()
126 {
127     return OUString( RTL_CONSTASCII_USTRINGPARAM(
128         "com.sun.star.comp.Writer.XMLOasisAutotextEventsImporter" ) );
129 }
130 
XMLAutoTextEventImport_createInstance(const Reference<XMultiServiceFactory> & rSMgr)131 Reference< XInterface > SAL_CALL XMLAutoTextEventImport_createInstance(
132         const Reference< XMultiServiceFactory > & rSMgr)
133 {
134     // #110680#
135     // return (cppu::OWeakObject*)new XMLAutoTextEventImport;
136     return (cppu::OWeakObject*)new XMLAutoTextEventImport(rSMgr);
137 }
138