1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*63bba73cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*63bba73cSAndrew Rist * distributed with this work for additional information
6*63bba73cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*63bba73cSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist * with the License. You may obtain a copy of the License at
10*63bba73cSAndrew Rist *
11*63bba73cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*63bba73cSAndrew Rist *
13*63bba73cSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist * KIND, either express or implied. See the License for the
17*63bba73cSAndrew Rist * specific language governing permissions and limitations
18*63bba73cSAndrew Rist * under the License.
19*63bba73cSAndrew Rist *
20*63bba73cSAndrew Rist *************************************************************/
21*63bba73cSAndrew Rist
22*63bba73cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir #include "XMLAutoTextEventExport.hxx"
27cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
28cdf0e10cSrcweir #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
29cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30cdf0e10cSrcweir #include <com/sun/star/document/XEventsSupplier.hpp>
31cdf0e10cSrcweir #include <com/sun/star/container/XNameReplace.hpp>
32cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
33cdf0e10cSrcweir #include <com/sun/star/uno/Reference.hxx>
34cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
35cdf0e10cSrcweir
36cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UNO_EXCEPTION_HPP
37cdf0e10cSrcweir #include <com/sun/star/uno/Exception.hpp>
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir
40cdf0e10cSrcweir // #110680#
41cdf0e10cSrcweir //#ifndef _COMPHELPER_PROCESSFACTORY_HXX_
42cdf0e10cSrcweir //#include <comphelper/processfactory.hxx>
43cdf0e10cSrcweir //#endif
44cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
45cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
46cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
47cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
48cdf0e10cSrcweir #include <xmloff/XMLEventExport.hxx>
49cdf0e10cSrcweir #include <tools/debug.hxx>
50cdf0e10cSrcweir
51cdf0e10cSrcweir
52cdf0e10cSrcweir using namespace ::com::sun::star;
53cdf0e10cSrcweir using namespace ::xmloff::token;
54cdf0e10cSrcweir
55cdf0e10cSrcweir // #110680#
56cdf0e10cSrcweir // using ::comphelper::getProcessServiceFactory;
57cdf0e10cSrcweir using ::rtl::OUString;
58cdf0e10cSrcweir using ::rtl::OUStringBuffer;
59cdf0e10cSrcweir using ::std::set;
60cdf0e10cSrcweir using ::com::sun::star::beans::XPropertySet;
61cdf0e10cSrcweir using ::com::sun::star::beans::PropertyValue;
62cdf0e10cSrcweir using ::com::sun::star::container::XNameAccess;
63cdf0e10cSrcweir using ::com::sun::star::container::XNameReplace;
64cdf0e10cSrcweir using ::com::sun::star::document::XEventsSupplier;
65cdf0e10cSrcweir using ::com::sun::star::frame::XModel;
66cdf0e10cSrcweir using ::com::sun::star::lang::XMultiServiceFactory;
67cdf0e10cSrcweir using ::com::sun::star::uno::Any;
68cdf0e10cSrcweir using ::com::sun::star::uno::Exception;
69cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
70cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
71cdf0e10cSrcweir using ::com::sun::star::uno::XInterface;
72cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY;
73cdf0e10cSrcweir using ::com::sun::star::xml::sax::XDocumentHandler;
74cdf0e10cSrcweir
75cdf0e10cSrcweir
76cdf0e10cSrcweir const sal_Char sAPI_AutoText[] = "com.sun.star.text.AutoTextContainer";
77cdf0e10cSrcweir
78cdf0e10cSrcweir
79cdf0e10cSrcweir // #110680#
XMLAutoTextEventExport(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & xServiceFactory,sal_uInt16 nFlags)80cdf0e10cSrcweir XMLAutoTextEventExport::XMLAutoTextEventExport(
81cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
82cdf0e10cSrcweir sal_uInt16 nFlags
83cdf0e10cSrcweir )
84cdf0e10cSrcweir : SvXMLExport( xServiceFactory, MAP_INCH, XML_AUTO_TEXT, nFlags ),
85cdf0e10cSrcweir sEventType(RTL_CONSTASCII_USTRINGPARAM("EventType")),
86cdf0e10cSrcweir sNone(RTL_CONSTASCII_USTRINGPARAM("None"))
87cdf0e10cSrcweir {
88cdf0e10cSrcweir }
89cdf0e10cSrcweir
90cdf0e10cSrcweir // #110680#
XMLAutoTextEventExport(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & xServiceFactory,const OUString & rFileName,const Reference<XDocumentHandler> & rHandler,const Reference<XModel> & rModel,const Reference<XNameAccess> & rEvents,sal_uInt16)91cdf0e10cSrcweir XMLAutoTextEventExport::XMLAutoTextEventExport(
92cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
93cdf0e10cSrcweir const OUString& rFileName,
94cdf0e10cSrcweir const Reference<XDocumentHandler> & rHandler,
95cdf0e10cSrcweir const Reference<XModel> & rModel,
96cdf0e10cSrcweir const Reference<XNameAccess> & rEvents,
97cdf0e10cSrcweir sal_uInt16 /*nFlags*/ )
98cdf0e10cSrcweir : SvXMLExport( xServiceFactory, rFileName, rHandler, rModel, MAP_INCH ),
99cdf0e10cSrcweir xEvents(rEvents),
100cdf0e10cSrcweir sEventType(RTL_CONSTASCII_USTRINGPARAM("EventType")),
101cdf0e10cSrcweir sNone(RTL_CONSTASCII_USTRINGPARAM("None"))
102cdf0e10cSrcweir {
103cdf0e10cSrcweir }
104cdf0e10cSrcweir
~XMLAutoTextEventExport()105cdf0e10cSrcweir XMLAutoTextEventExport::~XMLAutoTextEventExport()
106cdf0e10cSrcweir {
107cdf0e10cSrcweir }
108cdf0e10cSrcweir
109cdf0e10cSrcweir
initialize(const Sequence<Any> & rArguments)110cdf0e10cSrcweir void XMLAutoTextEventExport::initialize(
111cdf0e10cSrcweir const Sequence<Any> & rArguments )
112cdf0e10cSrcweir throw(uno::Exception, uno::RuntimeException)
113cdf0e10cSrcweir {
114cdf0e10cSrcweir if (rArguments.getLength() > 1)
115cdf0e10cSrcweir {
116cdf0e10cSrcweir Reference<XEventsSupplier> xSupplier;
117cdf0e10cSrcweir rArguments[1] >>= xSupplier;
118cdf0e10cSrcweir if (xSupplier.is())
119cdf0e10cSrcweir {
120cdf0e10cSrcweir Reference<XNameAccess> xAccess(xSupplier->getEvents(), UNO_QUERY);
121cdf0e10cSrcweir xEvents = xAccess;
122cdf0e10cSrcweir }
123cdf0e10cSrcweir else
124cdf0e10cSrcweir {
125cdf0e10cSrcweir Reference<XNameReplace> xReplace;
126cdf0e10cSrcweir rArguments[1] >>= xReplace;
127cdf0e10cSrcweir if (xReplace.is())
128cdf0e10cSrcweir {
129cdf0e10cSrcweir Reference<XNameAccess> xAccess(xReplace, UNO_QUERY);
130cdf0e10cSrcweir xEvents = xAccess;
131cdf0e10cSrcweir }
132cdf0e10cSrcweir else
133cdf0e10cSrcweir {
134cdf0e10cSrcweir rArguments[1] >>= xEvents;
135cdf0e10cSrcweir }
136cdf0e10cSrcweir }
137cdf0e10cSrcweir }
138cdf0e10cSrcweir
139cdf0e10cSrcweir // call super class (for XHandler)
140cdf0e10cSrcweir SvXMLExport::initialize(rArguments);
141cdf0e10cSrcweir }
142cdf0e10cSrcweir
143cdf0e10cSrcweir
exportDoc(enum XMLTokenEnum)144cdf0e10cSrcweir sal_uInt32 XMLAutoTextEventExport::exportDoc( enum XMLTokenEnum )
145cdf0e10cSrcweir {
146cdf0e10cSrcweir if( (getExportFlags() & EXPORT_OASIS) == 0 )
147cdf0e10cSrcweir {
148cdf0e10cSrcweir Reference< lang::XMultiServiceFactory > xFactory = getServiceFactory();
149cdf0e10cSrcweir if( xFactory.is() )
150cdf0e10cSrcweir {
151cdf0e10cSrcweir try
152cdf0e10cSrcweir {
153cdf0e10cSrcweir
154cdf0e10cSrcweir Sequence<Any> aArgs( 1 );
155cdf0e10cSrcweir aArgs[0] <<= GetDocHandler();
156cdf0e10cSrcweir
157cdf0e10cSrcweir // get filter component
158cdf0e10cSrcweir Reference< xml::sax::XDocumentHandler > xTmpDocHandler(
159cdf0e10cSrcweir xFactory->createInstanceWithArguments(
160cdf0e10cSrcweir OUString::createFromAscii("com.sun.star.comp.Oasis2OOoTransformer"),
161cdf0e10cSrcweir aArgs), UNO_QUERY);
162cdf0e10cSrcweir OSL_ENSURE( xTmpDocHandler.is(),
163cdf0e10cSrcweir "can't instantiate OASIS transformer component" );
164cdf0e10cSrcweir if( xTmpDocHandler.is() )
165cdf0e10cSrcweir {
166cdf0e10cSrcweir SetDocHandler( xTmpDocHandler );
167cdf0e10cSrcweir }
168cdf0e10cSrcweir }
169cdf0e10cSrcweir catch( com::sun::star::uno::Exception& )
170cdf0e10cSrcweir {
171cdf0e10cSrcweir }
172cdf0e10cSrcweir }
173cdf0e10cSrcweir }
174cdf0e10cSrcweir if (hasEvents())
175cdf0e10cSrcweir {
176cdf0e10cSrcweir GetDocHandler()->startDocument();
177cdf0e10cSrcweir
178cdf0e10cSrcweir addNamespaces();
179cdf0e10cSrcweir
180cdf0e10cSrcweir {
181cdf0e10cSrcweir // container element
182cdf0e10cSrcweir SvXMLElementExport aContainerElement(
183cdf0e10cSrcweir *this, XML_NAMESPACE_OOO, XML_AUTO_TEXT_EVENTS,
184cdf0e10cSrcweir sal_True, sal_True);
185cdf0e10cSrcweir
186cdf0e10cSrcweir exportEvents();
187cdf0e10cSrcweir }
188cdf0e10cSrcweir
189cdf0e10cSrcweir // and close document again
190cdf0e10cSrcweir GetDocHandler()->endDocument();
191cdf0e10cSrcweir }
192cdf0e10cSrcweir
193cdf0e10cSrcweir return 0;
194cdf0e10cSrcweir }
195cdf0e10cSrcweir
hasEvents()196cdf0e10cSrcweir sal_Bool XMLAutoTextEventExport::hasEvents()
197cdf0e10cSrcweir {
198cdf0e10cSrcweir // TODO: provide full implementation that check for presence of events
199cdf0e10cSrcweir return xEvents.is();
200cdf0e10cSrcweir }
201cdf0e10cSrcweir
addNamespaces()202cdf0e10cSrcweir void XMLAutoTextEventExport::addNamespaces()
203cdf0e10cSrcweir {
204cdf0e10cSrcweir // namespaces for office:, text: and script:
205cdf0e10cSrcweir GetAttrList().AddAttribute(
206cdf0e10cSrcweir GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_OFFICE ),
207cdf0e10cSrcweir GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_OFFICE ) );
208cdf0e10cSrcweir GetAttrList().AddAttribute(
209cdf0e10cSrcweir GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_TEXT ),
210cdf0e10cSrcweir GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_TEXT ) );
211cdf0e10cSrcweir GetAttrList().AddAttribute(
212cdf0e10cSrcweir GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_SCRIPT ),
213cdf0e10cSrcweir GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_SCRIPT ) );
214cdf0e10cSrcweir GetAttrList().AddAttribute(
215cdf0e10cSrcweir GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_DOM ),
216cdf0e10cSrcweir GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_DOM ) );
217cdf0e10cSrcweir GetAttrList().AddAttribute(
218cdf0e10cSrcweir GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_OOO ),
219cdf0e10cSrcweir GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_OOO ) );
220cdf0e10cSrcweir GetAttrList().AddAttribute(
221cdf0e10cSrcweir GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_XLINK ),
222cdf0e10cSrcweir GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_XLINK ) );
223cdf0e10cSrcweir }
224cdf0e10cSrcweir
exportEvents()225cdf0e10cSrcweir void XMLAutoTextEventExport::exportEvents()
226cdf0e10cSrcweir {
227cdf0e10cSrcweir DBG_ASSERT(hasEvents(), "no events to export!");
228cdf0e10cSrcweir
229cdf0e10cSrcweir GetEventExport().Export(xEvents, sal_True);
230cdf0e10cSrcweir }
231cdf0e10cSrcweir
232cdf0e10cSrcweir
233cdf0e10cSrcweir
234cdf0e10cSrcweir // methods without content:
235cdf0e10cSrcweir
_ExportMeta()236cdf0e10cSrcweir void XMLAutoTextEventExport::_ExportMeta() {}
_ExportScripts()237cdf0e10cSrcweir void XMLAutoTextEventExport::_ExportScripts() {}
_ExportFontDecls()238cdf0e10cSrcweir void XMLAutoTextEventExport::_ExportFontDecls() {}
_ExportStyles(sal_Bool)239cdf0e10cSrcweir void XMLAutoTextEventExport::_ExportStyles( sal_Bool ) {}
_ExportAutoStyles()240cdf0e10cSrcweir void XMLAutoTextEventExport::_ExportAutoStyles() {}
_ExportMasterStyles()241cdf0e10cSrcweir void XMLAutoTextEventExport::_ExportMasterStyles() {}
_ExportChangeTracking()242cdf0e10cSrcweir void XMLAutoTextEventExport::_ExportChangeTracking() {}
_ExportContent()243cdf0e10cSrcweir void XMLAutoTextEventExport::_ExportContent() {}
244cdf0e10cSrcweir
245cdf0e10cSrcweir
246cdf0e10cSrcweir
247cdf0e10cSrcweir // methods to support the component registration
248cdf0e10cSrcweir
XMLAutoTextEventExport_getSupportedServiceNames()249cdf0e10cSrcweir Sequence< OUString > SAL_CALL XMLAutoTextEventExport_getSupportedServiceNames()
250cdf0e10cSrcweir throw()
251cdf0e10cSrcweir {
252cdf0e10cSrcweir Sequence< OUString > aSeq( 1 );
253cdf0e10cSrcweir aSeq[0] = XMLAutoTextEventExport_getImplementationName();
254cdf0e10cSrcweir return aSeq;
255cdf0e10cSrcweir }
256cdf0e10cSrcweir
XMLAutoTextEventExport_getImplementationName()257cdf0e10cSrcweir OUString SAL_CALL XMLAutoTextEventExport_getImplementationName() throw()
258cdf0e10cSrcweir {
259cdf0e10cSrcweir return OUString( RTL_CONSTASCII_USTRINGPARAM(
260cdf0e10cSrcweir "com.sun.star.comp.Writer.XMLOasisAutotextEventsExporter" ) );
261cdf0e10cSrcweir }
262cdf0e10cSrcweir
XMLAutoTextEventExport_createInstance(const Reference<XMultiServiceFactory> & rSMgr)263cdf0e10cSrcweir Reference< XInterface > SAL_CALL XMLAutoTextEventExport_createInstance(
264cdf0e10cSrcweir const Reference< XMultiServiceFactory > & rSMgr)
265cdf0e10cSrcweir throw( Exception )
266cdf0e10cSrcweir {
267cdf0e10cSrcweir // #110680#
268cdf0e10cSrcweir // return (cppu::OWeakObject*)new XMLAutoTextEventExport;
269cdf0e10cSrcweir return (cppu::OWeakObject*)new XMLAutoTextEventExport(rSMgr, EXPORT_ALL|EXPORT_OASIS);
270cdf0e10cSrcweir }
271cdf0e10cSrcweir
272cdf0e10cSrcweir // methods to support the component registration
273cdf0e10cSrcweir
XMLAutoTextEventExportOOO_getSupportedServiceNames()274cdf0e10cSrcweir Sequence< OUString > SAL_CALL XMLAutoTextEventExportOOO_getSupportedServiceNames()
275cdf0e10cSrcweir throw()
276cdf0e10cSrcweir {
277cdf0e10cSrcweir Sequence< OUString > aSeq( 1 );
278cdf0e10cSrcweir aSeq[0] = XMLAutoTextEventExportOOO_getImplementationName();
279cdf0e10cSrcweir return aSeq;
280cdf0e10cSrcweir }
281cdf0e10cSrcweir
XMLAutoTextEventExportOOO_getImplementationName()282cdf0e10cSrcweir OUString SAL_CALL XMLAutoTextEventExportOOO_getImplementationName() throw()
283cdf0e10cSrcweir {
284cdf0e10cSrcweir return OUString( RTL_CONSTASCII_USTRINGPARAM(
285cdf0e10cSrcweir "com.sun.star.comp.Writer.XMLAutotextEventsExporter" ) );
286cdf0e10cSrcweir }
287cdf0e10cSrcweir
XMLAutoTextEventExportOOO_createInstance(const Reference<XMultiServiceFactory> & rSMgr)288cdf0e10cSrcweir Reference< XInterface > SAL_CALL XMLAutoTextEventExportOOO_createInstance(
289cdf0e10cSrcweir const Reference< XMultiServiceFactory > & rSMgr)
290cdf0e10cSrcweir throw( Exception )
291cdf0e10cSrcweir {
292cdf0e10cSrcweir // #110680#
293cdf0e10cSrcweir // return (cppu::OWeakObject*)new XMLAutoTextEventExport;
294cdf0e10cSrcweir return (cppu::OWeakObject*)new XMLAutoTextEventExport(rSMgr,EXPORT_ALL);
295cdf0e10cSrcweir }
296cdf0e10cSrcweir
297