1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
22 #include <com/sun/star/frame/XModel.hpp>
23 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
24 #include <com/sun/star/util/MeasureUnit.hpp>
25 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
26 #include <com/sun/star/document/XEventsSupplier.hpp>
27 #include <com/sun/star/container/XNameReplace.hpp>
28 #include <com/sun/star/container/XNameAccess.hpp>
29 #include <com/sun/star/uno/Reference.hxx>
30 #include <com/sun/star/uno/Sequence.hxx>
31 #include <com/sun/star/uno/Exception.hpp>
32 #include <rtl/ustrbuf.hxx>
33 #include <xmloff/xmlnmspe.hxx>
34 #include <xmloff/nmspmap.hxx>
35 #include <xmloff/xmltoken.hxx>
36 #include <xmloff/XMLEventExport.hxx>
37 #include <tools/debug.hxx>
38 #include <tools/fldunit.hxx>
39 #include <comphelper/processfactory.hxx>
42 using namespace ::com::sun::star
;
43 using namespace ::xmloff::token
;
46 using ::com::sun::star::beans::XPropertySet
;
47 using ::com::sun::star::beans::PropertyValue
;
48 using ::com::sun::star::container::XNameAccess
;
49 using ::com::sun::star::container::XNameReplace
;
50 using ::com::sun::star::document::XEventsSupplier
;
51 using ::com::sun::star::frame::XModel
;
52 using ::com::sun::star::lang::XMultiServiceFactory
;
53 using ::com::sun::star::uno::Any
;
54 using ::com::sun::star::uno::Exception
;
55 using ::com::sun::star::uno::Reference
;
56 using ::com::sun::star::uno::Sequence
;
57 using ::com::sun::star::uno::XInterface
;
58 using ::com::sun::star::uno::UNO_QUERY
;
59 using ::com::sun::star::xml::sax::XDocumentHandler
;
62 XMLAutoTextEventExport::XMLAutoTextEventExport(
63 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& xContext
,
64 OUString
const & implementationName
, SvXMLExportFlags nFlags
66 : SvXMLExport(util::MeasureUnit::INCH
, xContext
, implementationName
, XML_AUTO_TEXT
, nFlags
)
70 XMLAutoTextEventExport::~XMLAutoTextEventExport()
74 void XMLAutoTextEventExport::initialize(
75 const Sequence
<Any
> & rArguments
)
76 throw(uno::Exception
, uno::RuntimeException
, std::exception
)
78 if (rArguments
.getLength() > 1)
80 Reference
<XEventsSupplier
> xSupplier
;
81 rArguments
[1] >>= xSupplier
;
84 Reference
<XNameAccess
> xAccess(xSupplier
->getEvents(), UNO_QUERY
);
89 Reference
<XNameReplace
> xReplace
;
90 rArguments
[1] >>= xReplace
;
97 rArguments
[1] >>= xEvents
;
102 // call super class (for XHandler)
103 SvXMLExport::initialize(rArguments
);
107 sal_uInt32
XMLAutoTextEventExport::exportDoc( enum XMLTokenEnum
)
109 if( !(getExportFlags() & SvXMLExportFlags::OASIS
) )
111 Reference
< uno::XComponentContext
> xContext
= getComponentContext();
115 Sequence
<Any
> aArgs( 1 );
116 aArgs
[0] <<= GetDocHandler();
118 // get filter component
119 Reference
< xml::sax::XDocumentHandler
> xTmpDocHandler(
120 xContext
->getServiceManager()->createInstanceWithArgumentsAndContext(
121 "com.sun.star.comp.Oasis2OOoTransformer",
125 OSL_ENSURE( xTmpDocHandler
.is(),
126 "can't instantiate OASIS transformer component" );
127 if( xTmpDocHandler
.is() )
129 SetDocHandler( xTmpDocHandler
);
132 catch( com::sun::star::uno::Exception
& )
138 GetDocHandler()->startDocument();
140 addChaffWhenEncryptedStorage();
146 SvXMLElementExport
aContainerElement(
147 *this, XML_NAMESPACE_OOO
, XML_AUTO_TEXT_EVENTS
,
153 // and close document again
154 GetDocHandler()->endDocument();
160 bool XMLAutoTextEventExport::hasEvents()
162 // TODO: provide full implementation that check for presence of events
166 void XMLAutoTextEventExport::addNamespaces()
168 // namespaces for office:, text: and script:
169 GetAttrList().AddAttribute(
170 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_OFFICE
),
171 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_OFFICE
) );
172 GetAttrList().AddAttribute(
173 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_TEXT
),
174 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_TEXT
) );
175 GetAttrList().AddAttribute(
176 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_SCRIPT
),
177 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_SCRIPT
) );
178 GetAttrList().AddAttribute(
179 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_DOM
),
180 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_DOM
) );
181 GetAttrList().AddAttribute(
182 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_OOO
),
183 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_OOO
) );
184 GetAttrList().AddAttribute(
185 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_XLINK
),
186 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_XLINK
) );
189 void XMLAutoTextEventExport::exportEvents()
191 DBG_ASSERT(hasEvents(), "no events to export!");
193 GetEventExport().Export(xEvents
, true);
198 // methods without content:
200 void XMLAutoTextEventExport::_ExportMeta() {}
201 void XMLAutoTextEventExport::_ExportScripts() {}
202 void XMLAutoTextEventExport::_ExportFontDecls() {}
203 void XMLAutoTextEventExport::_ExportStyles( bool ) {}
204 void XMLAutoTextEventExport::_ExportAutoStyles() {}
205 void XMLAutoTextEventExport::_ExportMasterStyles() {}
206 void XMLAutoTextEventExport::_ExportContent() {}
210 // methods to support the component registration
212 Sequence
< OUString
> SAL_CALL
XMLAutoTextEventExport_getSupportedServiceNames()
215 Sequence
< OUString
> aSeq( 1 );
216 aSeq
[0] = XMLAutoTextEventExport_getImplementationName();
220 OUString SAL_CALL
XMLAutoTextEventExport_getImplementationName() throw()
222 return OUString( "com.sun.star.comp.Writer.XMLOasisAutotextEventsExporter" );
225 Reference
< XInterface
> SAL_CALL
XMLAutoTextEventExport_createInstance(
226 const Reference
< XMultiServiceFactory
> & rSMgr
)
229 return (cppu::OWeakObject
*)new XMLAutoTextEventExport( comphelper::getComponentContext(rSMgr
), XMLAutoTextEventExport_getImplementationName(), SvXMLExportFlags::ALL
|SvXMLExportFlags::OASIS
);
232 // methods to support the component registration
234 Sequence
< OUString
> SAL_CALL
XMLAutoTextEventExportOOO_getSupportedServiceNames()
237 Sequence
< OUString
> aSeq( 1 );
238 aSeq
[0] = XMLAutoTextEventExportOOO_getImplementationName();
242 OUString SAL_CALL
XMLAutoTextEventExportOOO_getImplementationName() throw()
244 return OUString( "com.sun.star.comp.Writer.XMLAutotextEventsExporter" );
247 Reference
< XInterface
> SAL_CALL
XMLAutoTextEventExportOOO_createInstance(
248 const Reference
< XMultiServiceFactory
> & rSMgr
)
251 return (cppu::OWeakObject
*)new XMLAutoTextEventExport( comphelper::getComponentContext(rSMgr
), XMLAutoTextEventExportOOO_getImplementationName(), SvXMLExportFlags::ALL
);
254 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */