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 <facreg.hxx>
22 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
23 #include <com/sun/star/util/MeasureUnit.hpp>
24 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
25 #include <com/sun/star/document/XEventsSupplier.hpp>
26 #include <com/sun/star/container/XNameReplace.hpp>
27 #include <com/sun/star/container/XNameAccess.hpp>
28 #include <com/sun/star/uno/Reference.hxx>
29 #include <com/sun/star/uno/Sequence.hxx>
30 #include <com/sun/star/uno/Exception.hpp>
31 #include <com/sun/star/uno/XComponentContext.hpp>
32 #include <osl/diagnose.h>
33 #include <xmloff/xmlnmspe.hxx>
34 #include <xmloff/nmspmap.hxx>
35 #include <xmloff/xmltoken.hxx>
37 #include <tools/debug.hxx>
39 
40 
41 using namespace ::com::sun::star;
42 using namespace ::xmloff::token;
43 
44 using ::com::sun::star::container::XNameReplace;
45 using ::com::sun::star::document::XEventsSupplier;
46 using ::com::sun::star::lang::XMultiServiceFactory;
47 using ::com::sun::star::uno::Any;
48 using ::com::sun::star::uno::Exception;
49 using ::com::sun::star::uno::Reference;
50 using ::com::sun::star::uno::Sequence;
51 using ::com::sun::star::uno::XInterface;
52 using ::com::sun::star::uno::UNO_QUERY;
53 using ::com::sun::star::xml::sax::XDocumentHandler;
54 
55 
57  const css::uno::Reference< css::uno::XComponentContext >& xContext,
58  OUString const & implementationName, SvXMLExportFlags nFlags
59  )
60 : SvXMLExport(util::MeasureUnit::INCH, xContext, implementationName, XML_AUTO_TEXT, nFlags)
61 {
62 }
63 
65 {
66 }
67 
69  const Sequence<Any> & rArguments )
70 {
71  if (rArguments.getLength() > 1)
72  {
73  Reference<XEventsSupplier> xSupplier;
74  rArguments[1] >>= xSupplier;
75  if (xSupplier.is())
76  {
77  xEvents = xSupplier->getEvents();
78  }
79  else
80  {
81  Reference<XNameReplace> xReplace;
82  rArguments[1] >>= xReplace;
83  if (xReplace.is())
84  {
85  xEvents = xReplace;
86  }
87  else
88  {
89  rArguments[1] >>= xEvents;
90  }
91  }
92  }
93 
94  // call super class (for XHandler)
95  SvXMLExport::initialize(rArguments);
96 }
97 
98 
100 {
102  {
104  try
105  {
106 
107  Sequence<Any> aArgs( 1 );
108  aArgs[0] <<= GetDocHandler();
109 
110  // get filter component
112  xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
113  "com.sun.star.comp.Oasis2OOoTransformer",
114  aArgs,
115  xContext),
116  UNO_QUERY);
117  OSL_ENSURE( xTmpDocHandler.is(),
118  "can't instantiate OASIS transformer component" );
119  if( xTmpDocHandler.is() )
120  {
121  SetDocHandler( xTmpDocHandler );
122  }
123  }
124  catch( css::uno::Exception& )
125  {
126  }
127  }
128  if (hasEvents())
129  {
130  GetDocHandler()->startDocument();
131 
133 
134  addNamespaces();
135 
136  {
137  // container element
138  SvXMLElementExport aContainerElement(
140  true, true);
141 
142  exportEvents();
143  }
144 
145  // and close document again
146  GetDocHandler()->endDocument();
147  }
148 
149  return ERRCODE_NONE;
150 }
151 
153 {
154  // TODO: provide full implementation that check for presence of events
155  return xEvents.is();
156 }
157 
159 {
160  // namespaces for office:, text: and script:
162  GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_OFFICE ),
163  GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_OFFICE ) );
165  GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_TEXT ),
166  GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_TEXT ) );
168  GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_SCRIPT ),
169  GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_SCRIPT ) );
171  GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_DOM ),
172  GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_DOM ) );
174  GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_OOO ),
175  GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_OOO ) );
177  GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_XLINK ),
178  GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_XLINK ) );
179 }
180 
182 {
183  DBG_ASSERT(hasEvents(), "no events to export!");
184 
186 }
187 
188 
189 // methods without content:
190 
198 
199 
200 // methods to support the component registration
201 
203  throw()
204 {
206  return aSeq;
207 }
208 
210 {
211  return "com.sun.star.comp.Writer.XMLOasisAutotextEventsExporter";
212 }
213 
215  const Reference< XMultiServiceFactory > & rSMgr)
216 {
218 }
219 
220 // methods to support the component registration
221 
223  throw()
224 {
226  return aSeq;
227 }
228 
230 {
231  return "com.sun.star.comp.Writer.XMLAutotextEventsExporter";
232 }
233 
235  const Reference< XMultiServiceFactory > & rSMgr)
236 {
238 }
239 
240 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString XMLAutoTextEventExportOOO_getImplementationName()
virtual void ExportContent_() override
Override this method to export the content of .
virtual void ExportMeta_() override
Override this method to export the content of .
void addChaffWhenEncryptedStorage()
Definition: xmlexp.cxx:1222
SvXMLExportFlags
Definition: xmlexp.hxx:89
Reference< XInterface > XMLAutoTextEventExportOOO_createInstance(const Reference< XMultiServiceFactory > &rSMgr)
XMLAutoTextEventExport(const css::uno::Reference< css::uno::XComponentContext > &xContext, OUString const &implementationName, SvXMLExportFlags nFlags)
Component for the export of events attached to autotext blocks.
constexpr sal_uInt16 XML_NAMESPACE_TEXT
Definition: xmlnmspe.hxx:31
OUString XMLAutoTextEventExport_getImplementationName()
const css::uno::Reference< css::xml::sax::XDocumentHandler > & GetDocHandler() const
Definition: xmlexp.hxx:386
virtual ErrCode exportDoc(enum::xmloff::token::XMLTokenEnum eClass=xmloff::token::XML_TOKEN_INVALID) override
export the events off all autotexts
SvXMLAttributeList & GetAttrList()
Definition: xmlexp.hxx:381
Sequence< OUString > XMLAutoTextEventExportOOO_getSupportedServiceNames()
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
Definition: xmlexp.cxx:653
XMLTokenEnum
The enumeration of all XML tokens.
Definition: xmltoken.hxx:47
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:2014
const css::uno::Reference< css::uno::XComponentContext > & getComponentContext() const
Definition: xmlexp.hxx:521
constexpr sal_uInt16 XML_NAMESPACE_OOO
Definition: xmlnmspe.hxx:62
void exportEvents()
export the events element
virtual ~XMLAutoTextEventExport() override
Reference< XComponentContext > getComponentContext(Reference< XMultiServiceFactory > const &factory)
void SetDocHandler(const css::uno::Reference< css::xml::sax::XDocumentHandler > &rHandler)
Definition: xmlexp.cxx:303
const SvXMLNamespaceMap & GetNamespaceMap() const
Definition: xmlexp.hxx:392
constexpr sal_uInt16 XML_NAMESPACE_XLINK
Definition: xmlnmspe.hxx:35
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:
Reference< XInterface > XMLAutoTextEventExport_createInstance(const Reference< XMultiServiceFactory > &rSMgr)
Sequence< sal_Int8 > aSeq
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
Sequence< OUString > XMLAutoTextEventExport_getSupportedServiceNames()
constexpr sal_uInt16 XML_NAMESPACE_SCRIPT
Definition: xmlnmspe.hxx:45
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:477
constexpr sal_uInt16 XML_NAMESPACE_DOM
Definition: xmlnmspe.hxx:57
void addNamespaces()
add the namespaces used by events (to be called for the document element)
constexpr sal_uInt16 XML_NAMESPACE_OFFICE
Definition: xmlnmspe.hxx:29
void Export(css::uno::Reference< css::document::XEventsSupplier > const &xAccess, bool bUseWhitespace=true)
export the events (calls EventExport::Export(Reference) )