LibreOffice Module xmloff (master) 1
XMLAutoTextEventExport.cxx
Go to the documentation of this file.
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
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>
33#include <xmloff/xmltoken.hxx>
35#include <tools/debug.hxx>
37
38
39using namespace ::com::sun::star;
40using namespace ::xmloff::token;
41
42using ::com::sun::star::container::XNameReplace;
43using ::com::sun::star::document::XEventsSupplier;
44using ::com::sun::star::uno::Any;
45using ::com::sun::star::uno::Exception;
46using ::com::sun::star::uno::Reference;
47using ::com::sun::star::uno::Sequence;
48using ::com::sun::star::uno::XInterface;
49using ::com::sun::star::uno::UNO_QUERY;
50using ::com::sun::star::xml::sax::XDocumentHandler;
51
52
54 const css::uno::Reference< css::uno::XComponentContext >& xContext,
55 OUString const & implementationName, SvXMLExportFlags nFlags
56 )
57: SvXMLExport(xContext, implementationName, util::MeasureUnit::INCH, XML_AUTO_TEXT, nFlags)
58{
59}
60
62{
63}
64
66 const Sequence<Any> & rArguments )
67{
68 if (rArguments.getLength() > 1)
69 {
70 Reference<XEventsSupplier> xSupplier;
71 rArguments[1] >>= xSupplier;
72 if (xSupplier.is())
73 {
74 xEvents = xSupplier->getEvents();
75 }
76 else
77 {
78 Reference<XNameReplace> xReplace;
79 rArguments[1] >>= xReplace;
80 if (xReplace.is())
81 {
82 xEvents = xReplace;
83 }
84 else
85 {
86 rArguments[1] >>= xEvents;
87 }
88 }
89 }
90
91 // call super class (for XHandler)
92 SvXMLExport::initialize(rArguments);
93}
94
95
97{
99 {
100 Reference< uno::XComponentContext> xContext = getComponentContext();
101 try
102 {
103
104 Sequence<Any> aArgs{ Any(GetDocHandler()) };
105
106 // get filter component
107 Reference< xml::sax::XDocumentHandler > xTmpDocHandler(
108 xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
109 "com.sun.star.comp.Oasis2OOoTransformer",
110 aArgs,
111 xContext),
112 UNO_QUERY);
113 OSL_ENSURE( xTmpDocHandler.is(),
114 "can't instantiate OASIS transformer component" );
115 if( xTmpDocHandler.is() )
116 {
117 SetDocHandler( xTmpDocHandler );
118 }
119 }
120 catch( css::uno::Exception& )
121 {
122 }
123 }
124 if (hasEvents())
125 {
126 GetDocHandler()->startDocument();
127
129
131
132 {
133 // container element
134 SvXMLElementExport aContainerElement(
136 true, true);
137
138 exportEvents();
139 }
140
141 // and close document again
142 GetDocHandler()->endDocument();
143 }
144
145 return ERRCODE_NONE;
146}
147
149{
150 // TODO: provide full implementation that check for presence of events
151 return xEvents.is();
152}
153
155{
156 // namespaces for office:, text: and script:
158 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_OFFICE ),
159 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_OFFICE ) );
161 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_TEXT ),
162 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_TEXT ) );
164 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_SCRIPT ),
165 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_SCRIPT ) );
167 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_DOM ),
168 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_DOM ) );
170 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_OOO ),
171 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_OOO ) );
173 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_XLINK ),
174 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_XLINK ) );
175}
176
178{
179 DBG_ASSERT(hasEvents(), "no events to export!");
180
182}
183
184
185// methods without content:
186
194
195
196// methods to support the component registration
197
198extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
200 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
201{
202 return cppu::acquire(new XMLAutoTextEventExport(
203 context, "com.sun.star.comp.Writer.XMLOasisAutotextEventsExporter",
205}
206
207extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
209 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
210{
211 return cppu::acquire(new XMLAutoTextEventExport(
212 context, "com.sun.star.comp.Writer.XMLAutotextEventsExporter",
214}
215
216/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_Writer_XMLOasisAutotextEventsExporter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_Writer_XMLAutotextEventsExporter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
const SvXMLNamespaceMap & GetNamespaceMap() const
Definition: xmlexp.hxx:385
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
Definition: xmlexp.cxx:652
XMLEventExport & GetEventExport()
get Event export, with handlers for script types "None" and "StarBasic" already registered; other han...
Definition: xmlexp.cxx:1989
SvXMLExportFlags getExportFlags() const
Definition: xmlexp.hxx:473
void addChaffWhenEncryptedStorage()
Definition: xmlexp.cxx:1185
const css::uno::Reference< css::xml::sax::XDocumentHandler > & GetDocHandler() const
Definition: xmlexp.hxx:379
void SetDocHandler(const css::uno::Reference< css::xml::sax::XDocumentHandler > &rHandler)
Definition: xmlexp.cxx:285
const css::uno::Reference< css::uno::XComponentContext > & getComponentContext() const
Definition: xmlexp.hxx:517
comphelper::AttributeList & GetAttrList()
Definition: xmlexp.hxx:374
Component for the export of events attached to autotext blocks.
virtual void ExportContent_() override
Override this method to export the content of <office:body>.
virtual void ExportMasterStyles_() override
Override this method to export the contents of <style:master-styles>.
virtual void ExportAutoStyles_() override
Override this method to export the contents of <style:auto-styles>.
virtual void ExportFontDecls_() override
Override this method to export the font declarations The default implementation will export the conte...
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &rArguments) override
css::uno::Reference< css::container::XNameAccess > xEvents
bool hasEvents() const
does the document have any events ?
void exportEvents()
export the events element
virtual void ExportScripts_() override
Override this method to export the content of <office:scripts>.
void addNamespaces()
add the namespaces used by events (to be called for the document element)
virtual ~XMLAutoTextEventExport() override
virtual ErrCode exportDoc(enum ::xmloff::token::XMLTokenEnum eClass=xmloff::token::XML_TOKEN_INVALID) override
export the events off all autotexts
XMLAutoTextEventExport(const css::uno::Reference< css::uno::XComponentContext > &xContext, OUString const &implementationName, SvXMLExportFlags nFlags)
virtual void ExportStyles_(bool bUsed) override
Override this method to export the content of <style:styles>.
virtual void ExportMeta_() override
Override this method to export the content of <office:meta>.
void Export(css::uno::Reference< css::document::XEventsSupplier > const &xAccess, bool bUseWhitespace=true)
export the events (calls EventExport::Export(Reference<XNameAccess>) )
void AddAttribute(const OUString &sName, const OUString &sValue)
#define DBG_ASSERT(sCon, aError)
#define ERRCODE_NONE
constexpr OUStringLiteral implementationName
Handling of tokens in XML:
XMLTokenEnum
The enumeration of all XML tokens.
Definition: xmltoken.hxx:50
@ XML_AUTO_TEXT_EVENTS
Definition: xmltoken.hxx:295
SvXMLExportFlags
Definition: xmlexp.hxx:90
constexpr sal_uInt16 XML_NAMESPACE_XLINK
constexpr sal_uInt16 XML_NAMESPACE_TEXT
constexpr sal_uInt16 XML_NAMESPACE_DOM
constexpr sal_uInt16 XML_NAMESPACE_OFFICE
constexpr sal_uInt16 XML_NAMESPACE_OOO
constexpr sal_uInt16 XML_NAMESPACE_SCRIPT