1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "XMLAutoTextEventImport.hxx"
21 #include <com/sun/star/uno/Reference.hxx>
22 #include <com/sun/star/xml/sax/XAttributeList.hpp>
23 #include <com/sun/star/document/XEventsSupplier.hpp>
24 #include <com/sun/star/uno/XInterface.hpp>
25 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
26 #include "XMLAutoTextContainerEventImport.hxx"
27 #include <xmloff/xmlnmspe.hxx>
28 #include <xmloff/xmltoken.hxx>
29 #include <tools/debug.hxx>
30 #include <comphelper/processfactory.hxx>
32 using namespace ::com::sun::star
;
34 using ::com::sun::star::uno::Any
;
35 using ::com::sun::star::uno::Reference
;
36 using ::com::sun::star::uno::Sequence
;
37 using ::com::sun::star::uno::Type
;
38 using ::com::sun::star::uno::XInterface
;
39 using ::com::sun::star::uno::RuntimeException
;
40 using ::com::sun::star::uno::Exception
;
41 using ::com::sun::star::xml::sax::XAttributeList
;
42 using ::com::sun::star::document::XEventsSupplier
;
43 using ::com::sun::star::container::XNameReplace
;
44 using ::com::sun::star::lang::XMultiServiceFactory
;
45 using ::xmloff::token::IsXMLToken
;
46 using ::xmloff::token::XML_AUTO_TEXT_EVENTS
;
48 XMLAutoTextEventImport::XMLAutoTextEventImport(
49 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& xContext
) throw()
50 : SvXMLImport(xContext
, "")
54 XMLAutoTextEventImport::~XMLAutoTextEventImport() throw()
58 void XMLAutoTextEventImport::initialize(
59 const Sequence
<Any
> & rArguments
)
60 throw(Exception
, RuntimeException
, std::exception
)
62 // The events may come as either an XNameReplace or XEventsSupplier.
64 const sal_Int32 nLength
= rArguments
.getLength();
65 for( sal_Int32 i
= 0; i
< nLength
; i
++ )
67 const Type
& rType
= rArguments
[i
].getValueType();
68 if ( rType
== cppu::UnoType
<XEventsSupplier
>::get())
70 Reference
<XEventsSupplier
> xSupplier
;
71 rArguments
[i
] >>= xSupplier
;
72 DBG_ASSERT(xSupplier
.is(), "need XEventsSupplier or XNameReplace");
74 xEvents
= xSupplier
->getEvents();
76 else if (rType
== cppu::UnoType
<XNameReplace
>::get())
78 rArguments
[i
] >>= xEvents
;
79 DBG_ASSERT(xEvents
.is(), "need XEventsSupplier or XNameReplace");
84 SvXMLImport::initialize(rArguments
);
89 SvXMLImportContext
* XMLAutoTextEventImport::CreateContext(
91 const OUString
& rLocalName
,
92 const Reference
<XAttributeList
> & xAttrList
)
94 if ( xEvents
.is() && (XML_NAMESPACE_OOO
== nPrefix
) &&
95 IsXMLToken( rLocalName
, XML_AUTO_TEXT_EVENTS
) )
97 return new XMLAutoTextContainerEventImport(
98 *this, nPrefix
, rLocalName
, xEvents
);
102 return SvXMLImport::CreateContext(nPrefix
, rLocalName
, xAttrList
);
107 Sequence
< OUString
> SAL_CALL
108 XMLAutoTextEventImport_getSupportedServiceNames()
111 Sequence
< OUString
> aSeq( 1 );
112 aSeq
[0] = XMLAutoTextEventImport_getImplementationName();
116 OUString SAL_CALL
XMLAutoTextEventImport_getImplementationName() throw()
118 return OUString( "com.sun.star.comp.Writer.XMLOasisAutotextEventsImporter" );
121 Reference
< XInterface
> SAL_CALL
XMLAutoTextEventImport_createInstance(
122 const Reference
< XMultiServiceFactory
> & rSMgr
)
125 return (cppu::OWeakObject
*)new XMLAutoTextEventImport( comphelper::getComponentContext(rSMgr
) );
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */