Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
31 :
32 : using namespace ::com::sun::star;
33 :
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;
47 :
48 0 : XMLAutoTextEventImport::XMLAutoTextEventImport(
49 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext) throw()
50 0 : : SvXMLImport(xContext, "")
51 : {
52 0 : }
53 :
54 0 : XMLAutoTextEventImport::~XMLAutoTextEventImport() throw()
55 : {
56 0 : }
57 :
58 0 : void XMLAutoTextEventImport::initialize(
59 : const Sequence<Any> & rArguments )
60 : throw(Exception, RuntimeException, std::exception)
61 : {
62 : // The events may come as either an XNameReplace or XEventsSupplier.
63 :
64 0 : const sal_Int32 nLength = rArguments.getLength();
65 0 : for( sal_Int32 i = 0; i < nLength; i++ )
66 : {
67 0 : const Type& rType = rArguments[i].getValueType();
68 0 : if ( rType == cppu::UnoType<XEventsSupplier>::get())
69 : {
70 0 : Reference<XEventsSupplier> xSupplier;
71 0 : rArguments[i] >>= xSupplier;
72 : DBG_ASSERT(xSupplier.is(), "need XEventsSupplier or XNameReplace");
73 :
74 0 : xEvents = xSupplier->getEvents();
75 : }
76 0 : else if (rType == cppu::UnoType<XNameReplace>::get())
77 : {
78 0 : rArguments[i] >>= xEvents;
79 : DBG_ASSERT(xEvents.is(), "need XEventsSupplier or XNameReplace");
80 : }
81 : }
82 :
83 : // call parent
84 0 : SvXMLImport::initialize(rArguments);
85 0 : }
86 :
87 :
88 :
89 0 : SvXMLImportContext* XMLAutoTextEventImport::CreateContext(
90 : sal_uInt16 nPrefix,
91 : const OUString& rLocalName,
92 : const Reference<XAttributeList > & xAttrList )
93 : {
94 0 : if ( xEvents.is() && (XML_NAMESPACE_OOO == nPrefix) &&
95 0 : IsXMLToken( rLocalName, XML_AUTO_TEXT_EVENTS) )
96 : {
97 : return new XMLAutoTextContainerEventImport(
98 0 : *this, nPrefix, rLocalName, xEvents);
99 : }
100 : else
101 : {
102 0 : return SvXMLImport::CreateContext(nPrefix, rLocalName, xAttrList);
103 : }
104 : }
105 :
106 :
107 : Sequence< OUString > SAL_CALL
108 0 : XMLAutoTextEventImport_getSupportedServiceNames()
109 : throw()
110 : {
111 0 : Sequence< OUString > aSeq( 1 );
112 0 : aSeq[0] = XMLAutoTextEventImport_getImplementationName();
113 0 : return aSeq;
114 : }
115 :
116 0 : OUString SAL_CALL XMLAutoTextEventImport_getImplementationName() throw()
117 : {
118 0 : return OUString( "com.sun.star.comp.Writer.XMLOasisAutotextEventsImporter" );
119 : }
120 :
121 0 : Reference< XInterface > SAL_CALL XMLAutoTextEventImport_createInstance(
122 : const Reference< XMultiServiceFactory > & rSMgr)
123 : throw( Exception )
124 : {
125 0 : return (cppu::OWeakObject*)new XMLAutoTextEventImport( comphelper::getComponentContext(rSMgr) );
126 : }
127 :
128 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|