nss: upgrade to release 3.73
[LibreOffice.git] / xmloff / source / text / XMLAutoTextEventExport.cxx
blobca7c0282d452cdc3fb15f51ae60907783fa08abe
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "XMLAutoTextEventExport.hxx"
21 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
22 #include <com/sun/star/util/MeasureUnit.hpp>
23 #include <com/sun/star/document/XEventsSupplier.hpp>
24 #include <com/sun/star/container/XNameReplace.hpp>
25 #include <com/sun/star/container/XNameAccess.hpp>
26 #include <com/sun/star/uno/Reference.hxx>
27 #include <com/sun/star/uno/Sequence.hxx>
28 #include <com/sun/star/uno/Exception.hpp>
29 #include <com/sun/star/uno/XComponentContext.hpp>
30 #include <osl/diagnose.h>
31 #include <xmloff/xmlnamespace.hxx>
32 #include <xmloff/namespacemap.hxx>
33 #include <xmloff/xmltoken.hxx>
34 #include <xmloff/XMLEventExport.hxx>
35 #include <tools/debug.hxx>
36 #include <comphelper/processfactory.hxx>
39 using namespace ::com::sun::star;
40 using namespace ::xmloff::token;
42 using ::com::sun::star::container::XNameReplace;
43 using ::com::sun::star::document::XEventsSupplier;
44 using ::com::sun::star::lang::XMultiServiceFactory;
45 using ::com::sun::star::uno::Any;
46 using ::com::sun::star::uno::Exception;
47 using ::com::sun::star::uno::Reference;
48 using ::com::sun::star::uno::Sequence;
49 using ::com::sun::star::uno::XInterface;
50 using ::com::sun::star::uno::UNO_QUERY;
51 using ::com::sun::star::xml::sax::XDocumentHandler;
54 XMLAutoTextEventExport::XMLAutoTextEventExport(
55 const css::uno::Reference< css::uno::XComponentContext >& xContext,
56 OUString const & implementationName, SvXMLExportFlags nFlags
58 : SvXMLExport(xContext, implementationName, util::MeasureUnit::INCH, XML_AUTO_TEXT, nFlags)
62 XMLAutoTextEventExport::~XMLAutoTextEventExport()
66 void XMLAutoTextEventExport::initialize(
67 const Sequence<Any> & rArguments )
69 if (rArguments.getLength() > 1)
71 Reference<XEventsSupplier> xSupplier;
72 rArguments[1] >>= xSupplier;
73 if (xSupplier.is())
75 xEvents = xSupplier->getEvents();
77 else
79 Reference<XNameReplace> xReplace;
80 rArguments[1] >>= xReplace;
81 if (xReplace.is())
83 xEvents = xReplace;
85 else
87 rArguments[1] >>= xEvents;
92 // call super class (for XHandler)
93 SvXMLExport::initialize(rArguments);
97 ErrCode XMLAutoTextEventExport::exportDoc( enum XMLTokenEnum )
99 if( !(getExportFlags() & SvXMLExportFlags::OASIS) )
101 Reference< uno::XComponentContext> xContext = getComponentContext();
105 Sequence<Any> aArgs( 1 );
106 aArgs[0] <<= GetDocHandler();
108 // get filter component
109 Reference< xml::sax::XDocumentHandler > xTmpDocHandler(
110 xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
111 "com.sun.star.comp.Oasis2OOoTransformer",
112 aArgs,
113 xContext),
114 UNO_QUERY);
115 OSL_ENSURE( xTmpDocHandler.is(),
116 "can't instantiate OASIS transformer component" );
117 if( xTmpDocHandler.is() )
119 SetDocHandler( xTmpDocHandler );
122 catch( css::uno::Exception& )
126 if (hasEvents())
128 GetDocHandler()->startDocument();
130 addChaffWhenEncryptedStorage();
132 addNamespaces();
135 // container element
136 SvXMLElementExport aContainerElement(
137 *this, XML_NAMESPACE_OOO, XML_AUTO_TEXT_EVENTS,
138 true, true);
140 exportEvents();
143 // and close document again
144 GetDocHandler()->endDocument();
147 return ERRCODE_NONE;
150 bool XMLAutoTextEventExport::hasEvents() const
152 // TODO: provide full implementation that check for presence of events
153 return xEvents.is();
156 void XMLAutoTextEventExport::addNamespaces()
158 // namespaces for office:, text: and script:
159 GetAttrList().AddAttribute(
160 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_OFFICE ),
161 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_OFFICE ) );
162 GetAttrList().AddAttribute(
163 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_TEXT ),
164 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_TEXT ) );
165 GetAttrList().AddAttribute(
166 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_SCRIPT ),
167 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_SCRIPT ) );
168 GetAttrList().AddAttribute(
169 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_DOM ),
170 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_DOM ) );
171 GetAttrList().AddAttribute(
172 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_OOO ),
173 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_OOO ) );
174 GetAttrList().AddAttribute(
175 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_XLINK ),
176 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_XLINK ) );
179 void XMLAutoTextEventExport::exportEvents()
181 DBG_ASSERT(hasEvents(), "no events to export!");
183 GetEventExport().Export(xEvents);
187 // methods without content:
189 void XMLAutoTextEventExport::ExportMeta_() {}
190 void XMLAutoTextEventExport::ExportScripts_() {}
191 void XMLAutoTextEventExport::ExportFontDecls_() {}
192 void XMLAutoTextEventExport::ExportStyles_( bool ) {}
193 void XMLAutoTextEventExport::ExportAutoStyles_() {}
194 void XMLAutoTextEventExport::ExportMasterStyles_() {}
195 void XMLAutoTextEventExport::ExportContent_() {}
198 // methods to support the component registration
200 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
201 com_sun_star_comp_Writer_XMLOasisAutotextEventsExporter_get_implementation(
202 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
204 return cppu::acquire(new XMLAutoTextEventExport(
205 context, "com.sun.star.comp.Writer.XMLOasisAutotextEventsExporter",
206 SvXMLExportFlags::ALL | SvXMLExportFlags::OASIS));
209 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
210 com_sun_star_comp_Writer_XMLAutotextEventsExporter_get_implementation(
211 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
213 return cppu::acquire(new XMLAutoTextEventExport(
214 context, "com.sun.star.comp.Writer.XMLAutotextEventsExporter",
215 SvXMLExportFlags::ALL));
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */