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>
31 #include <xmloff/xmlnamespace.hxx>
32 #include <xmloff/namespacemap.hxx>
33 #include <xmloff/xmltoken.hxx>
35 #include <tools/debug.hxx>
37 
38 
39 using namespace ::com::sun::star;
40 using namespace ::xmloff::token;
41 
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;
52 
53 
55  const css::uno::Reference< css::uno::XComponentContext >& xContext,
56  OUString const & implementationName, SvXMLExportFlags nFlags
57  )
58 : SvXMLExport(xContext, implementationName, util::MeasureUnit::INCH, XML_AUTO_TEXT, nFlags)
59 {
60 }
61 
63 {
64 }
65 
67  const Sequence<Any> & rArguments )
68 {
69  if (rArguments.getLength() > 1)
70  {
71  Reference<XEventsSupplier> xSupplier;
72  rArguments[1] >>= xSupplier;
73  if (xSupplier.is())
74  {
75  xEvents = xSupplier->getEvents();
76  }
77  else
78  {
79  Reference<XNameReplace> xReplace;
80  rArguments[1] >>= xReplace;
81  if (xReplace.is())
82  {
83  xEvents = xReplace;
84  }
85  else
86  {
87  rArguments[1] >>= xEvents;
88  }
89  }
90  }
91 
92  // call super class (for XHandler)
93  SvXMLExport::initialize(rArguments);
94 }
95 
96 
98 {
100  {
102  try
103  {
104 
105  Sequence<Any> aArgs( 1 );
106  aArgs[0] <<= GetDocHandler();
107 
108  // get filter component
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() )
118  {
119  SetDocHandler( xTmpDocHandler );
120  }
121  }
122  catch( css::uno::Exception& )
123  {
124  }
125  }
126  if (hasEvents())
127  {
128  GetDocHandler()->startDocument();
129 
131 
132  addNamespaces();
133 
134  {
135  // container element
136  SvXMLElementExport aContainerElement(
138  true, true);
139 
140  exportEvents();
141  }
142 
143  // and close document again
144  GetDocHandler()->endDocument();
145  }
146 
147  return ERRCODE_NONE;
148 }
149 
151 {
152  // TODO: provide full implementation that check for presence of events
153  return xEvents.is();
154 }
155 
157 {
158  // namespaces for office:, text: and script:
160  GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_OFFICE ),
161  GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_OFFICE ) );
163  GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_TEXT ),
164  GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_TEXT ) );
166  GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_SCRIPT ),
167  GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_SCRIPT ) );
169  GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_DOM ),
170  GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_DOM ) );
172  GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_OOO ),
173  GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_OOO ) );
175  GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_XLINK ),
176  GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_XLINK ) );
177 }
178 
180 {
181  DBG_ASSERT(hasEvents(), "no events to export!");
182 
184 }
185 
186 
187 // methods without content:
188 
196 
197 
198 // methods to support the component registration
199 
200 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
202  css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
203 {
204  return cppu::acquire(new XMLAutoTextEventExport(
205  context, "com.sun.star.comp.Writer.XMLOasisAutotextEventsExporter",
207 }
208 
209 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
211  css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
212 {
213  return cppu::acquire(new XMLAutoTextEventExport(
214  context, "com.sun.star.comp.Writer.XMLAutotextEventsExporter",
216 }
217 
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
exports com.sun.star.lib. util
constexpr sal_uInt16 XML_NAMESPACE_OFFICE
virtual void ExportContent_() override
Override this method to export the content of .
constexpr sal_uInt16 XML_NAMESPACE_SCRIPT
virtual void ExportMeta_() override
Override this method to export the content of .
void addChaffWhenEncryptedStorage()
Definition: xmlexp.cxx:1205
SvXMLExportFlags
Definition: xmlexp.hxx:89
constexpr sal_uInt16 XML_NAMESPACE_XLINK
constexpr sal_uInt16 XML_NAMESPACE_OOO
XMLAutoTextEventExport(const css::uno::Reference< css::uno::XComponentContext > &xContext, OUString const &implementationName, SvXMLExportFlags nFlags)
Component for the export of events attached to autotext blocks.
const css::uno::Reference< css::xml::sax::XDocumentHandler > & GetDocHandler() const
Definition: xmlexp.hxx:385
virtual ErrCode exportDoc(enum::xmloff::token::XMLTokenEnum eClass=xmloff::token::XML_TOKEN_INVALID) override
export the events off all autotexts
constexpr sal_uInt16 XML_NAMESPACE_DOM
SvXMLAttributeList & GetAttrList()
Definition: xmlexp.hxx:380
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 &)
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
Definition: xmlexp.cxx:636
XMLTokenEnum
The enumeration of all XML tokens.
Definition: xmltoken.hxx:49
virtual void ExportMasterStyles_() override
Override this method to export the contents of .
#define DBG_ASSERT(sCon, aError)
XMLEventExport & GetEventExport()
get Event export, with handlers for script types "None" and "StarBasic" already registered; other han...
Definition: xmlexp.cxx:2009
constexpr sal_uInt16 XML_NAMESPACE_TEXT
const css::uno::Reference< css::uno::XComponentContext > & getComponentContext() const
Definition: xmlexp.hxx:520
void exportEvents()
export the events element
virtual ~XMLAutoTextEventExport() override
void SetDocHandler(const css::uno::Reference< css::xml::sax::XDocumentHandler > &rHandler)
Definition: xmlexp.cxx:299
const SvXMLNamespaceMap & GetNamespaceMap() const
Definition: xmlexp.hxx:391
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 &)
virtual void ExportFontDecls_() override
Override this method to export the font declarations The default implementation will export the conte...
#define ERRCODE_NONE
Handling of tokens in XML:
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &rArguments) override
bool hasEvents() const
does the document have any events ?
css::uno::Reference< css::container::XNameAccess > xEvents
virtual void ExportAutoStyles_() override
Override this method to export the contents of .
void AddAttribute(const OUString &sName, const OUString &sValue)
Definition: attrlist.cxx:143
virtual void ExportStyles_(bool bUsed) override
Override this method to export the content of .
virtual void ExportScripts_() override
Override this method to export the content of .
SvXMLExportFlags getExportFlags() const
Definition: xmlexp.hxx:476
void addNamespaces()
add the namespaces used by events (to be called for the document element)
void Export(css::uno::Reference< css::document::XEventsSupplier > const &xAccess, bool bUseWhitespace=true)
export the events (calls EventExport::Export(Reference) )