1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLAutoTextEventExport.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include "XMLAutoTextEventExport.hxx"
34 #include <com/sun/star/frame/XModel.hpp>
35 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
36 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 #include <com/sun/star/document/XEventsSupplier.hpp>
38 #include <com/sun/star/container/XNameReplace.hpp>
39 #include <com/sun/star/container/XNameAccess.hpp>
40 #include <com/sun/star/uno/Reference.hxx>
41 #include <com/sun/star/uno/Sequence.hxx>
43 #ifndef _COM_SUN_STAR_UNO_EXCEPTION_HPP
44 #include <com/sun/star/uno/Exception.hpp>
48 //#ifndef _COMPHELPER_PROCESSFACTORY_HXX_
49 //#include <comphelper/processfactory.hxx>
51 #include <rtl/ustrbuf.hxx>
52 #include "xmlnmspe.hxx"
53 #include <xmloff/nmspmap.hxx>
54 #include <xmloff/xmltoken.hxx>
55 #include <xmloff/XMLEventExport.hxx>
56 #include <tools/debug.hxx>
59 using namespace ::com::sun::star
;
60 using namespace ::xmloff::token
;
63 // using ::comphelper::getProcessServiceFactory;
64 using ::rtl::OUString
;
65 using ::rtl::OUStringBuffer
;
67 using ::com::sun::star::beans::XPropertySet
;
68 using ::com::sun::star::beans::PropertyValue
;
69 using ::com::sun::star::container::XNameAccess
;
70 using ::com::sun::star::container::XNameReplace
;
71 using ::com::sun::star::document::XEventsSupplier
;
72 using ::com::sun::star::frame::XModel
;
73 using ::com::sun::star::lang::XMultiServiceFactory
;
74 using ::com::sun::star::uno::Any
;
75 using ::com::sun::star::uno::Exception
;
76 using ::com::sun::star::uno::Reference
;
77 using ::com::sun::star::uno::Sequence
;
78 using ::com::sun::star::uno::XInterface
;
79 using ::com::sun::star::uno::UNO_QUERY
;
80 using ::com::sun::star::xml::sax::XDocumentHandler
;
83 const sal_Char sAPI_AutoText
[] = "com.sun.star.text.AutoTextContainer";
87 XMLAutoTextEventExport::XMLAutoTextEventExport(
88 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& xServiceFactory
,
91 : SvXMLExport( xServiceFactory
, MAP_INCH
, XML_AUTO_TEXT
, nFlags
),
92 sEventType(RTL_CONSTASCII_USTRINGPARAM("EventType")),
93 sNone(RTL_CONSTASCII_USTRINGPARAM("None"))
98 XMLAutoTextEventExport::XMLAutoTextEventExport(
99 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& xServiceFactory
,
100 const OUString
& rFileName
,
101 const Reference
<XDocumentHandler
> & rHandler
,
102 const Reference
<XModel
> & rModel
,
103 const Reference
<XNameAccess
> & rEvents
,
104 sal_uInt16
/*nFlags*/ )
105 : SvXMLExport( xServiceFactory
, rFileName
, rHandler
, rModel
, MAP_INCH
),
107 sEventType(RTL_CONSTASCII_USTRINGPARAM("EventType")),
108 sNone(RTL_CONSTASCII_USTRINGPARAM("None"))
112 XMLAutoTextEventExport::~XMLAutoTextEventExport()
117 void XMLAutoTextEventExport::initialize(
118 const Sequence
<Any
> & rArguments
)
119 throw(uno::Exception
, uno::RuntimeException
)
121 if (rArguments
.getLength() > 1)
123 Reference
<XEventsSupplier
> xSupplier
;
124 rArguments
[1] >>= xSupplier
;
127 Reference
<XNameAccess
> xAccess(xSupplier
->getEvents(), UNO_QUERY
);
132 Reference
<XNameReplace
> xReplace
;
133 rArguments
[1] >>= xReplace
;
136 Reference
<XNameAccess
> xAccess(xReplace
, UNO_QUERY
);
141 rArguments
[1] >>= xEvents
;
146 // call super class (for XHandler)
147 SvXMLExport::initialize(rArguments
);
151 sal_uInt32
XMLAutoTextEventExport::exportDoc( enum XMLTokenEnum
)
153 if( (getExportFlags() & EXPORT_OASIS
) == 0 )
155 Reference
< lang::XMultiServiceFactory
> xFactory
= getServiceFactory();
161 Sequence
<Any
> aArgs( 1 );
162 aArgs
[0] <<= GetDocHandler();
164 // get filter component
165 Reference
< xml::sax::XDocumentHandler
> xTmpDocHandler(
166 xFactory
->createInstanceWithArguments(
167 OUString::createFromAscii("com.sun.star.comp.Oasis2OOoTransformer"),
169 OSL_ENSURE( xTmpDocHandler
.is(),
170 "can't instantiate OASIS transformer component" );
171 if( xTmpDocHandler
.is() )
173 SetDocHandler( xTmpDocHandler
);
176 catch( com::sun::star::uno::Exception
& )
183 GetDocHandler()->startDocument();
189 SvXMLElementExport
aContainerElement(
190 *this, XML_NAMESPACE_OOO
, XML_AUTO_TEXT_EVENTS
,
196 // and close document again
197 GetDocHandler()->endDocument();
203 sal_Bool
XMLAutoTextEventExport::hasEvents()
205 // TODO: provide full implementation that check for presence of events
209 void XMLAutoTextEventExport::addNamespaces()
211 // namespaces for office:, text: and script:
212 GetAttrList().AddAttribute(
213 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_OFFICE
),
214 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_OFFICE
) );
215 GetAttrList().AddAttribute(
216 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_TEXT
),
217 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_TEXT
) );
218 GetAttrList().AddAttribute(
219 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_SCRIPT
),
220 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_SCRIPT
) );
221 GetAttrList().AddAttribute(
222 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_DOM
),
223 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_DOM
) );
224 GetAttrList().AddAttribute(
225 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_OOO
),
226 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_OOO
) );
229 void XMLAutoTextEventExport::exportEvents()
231 DBG_ASSERT(hasEvents(), "no events to export!");
233 GetEventExport().Export(xEvents
, sal_True
);
238 // methods without content:
240 void XMLAutoTextEventExport::_ExportMeta() {}
241 void XMLAutoTextEventExport::_ExportScripts() {}
242 void XMLAutoTextEventExport::_ExportFontDecls() {}
243 void XMLAutoTextEventExport::_ExportStyles( sal_Bool
) {}
244 void XMLAutoTextEventExport::_ExportAutoStyles() {}
245 void XMLAutoTextEventExport::_ExportMasterStyles() {}
246 void XMLAutoTextEventExport::_ExportChangeTracking() {}
247 void XMLAutoTextEventExport::_ExportContent() {}
251 // methods to support the component registration
253 Sequence
< OUString
> SAL_CALL
XMLAutoTextEventExport_getSupportedServiceNames()
256 Sequence
< OUString
> aSeq( 1 );
257 aSeq
[0] = XMLAutoTextEventExport_getImplementationName();
261 OUString SAL_CALL
XMLAutoTextEventExport_getImplementationName() throw()
263 return OUString( RTL_CONSTASCII_USTRINGPARAM(
264 "com.sun.star.comp.Writer.XMLOasisAutotextEventsExporter" ) );
267 Reference
< XInterface
> SAL_CALL
XMLAutoTextEventExport_createInstance(
268 const Reference
< XMultiServiceFactory
> & rSMgr
)
272 // return (cppu::OWeakObject*)new XMLAutoTextEventExport;
273 return (cppu::OWeakObject
*)new XMLAutoTextEventExport(rSMgr
, EXPORT_ALL
|EXPORT_OASIS
);
276 // methods to support the component registration
278 Sequence
< OUString
> SAL_CALL
XMLAutoTextEventExportOOO_getSupportedServiceNames()
281 Sequence
< OUString
> aSeq( 1 );
282 aSeq
[0] = XMLAutoTextEventExportOOO_getImplementationName();
286 OUString SAL_CALL
XMLAutoTextEventExportOOO_getImplementationName() throw()
288 return OUString( RTL_CONSTASCII_USTRINGPARAM(
289 "com.sun.star.comp.Writer.XMLAutotextEventsExporter" ) );
292 Reference
< XInterface
> SAL_CALL
XMLAutoTextEventExportOOO_createInstance(
293 const Reference
< XMultiServiceFactory
> & rSMgr
)
297 // return (cppu::OWeakObject*)new XMLAutoTextEventExport;
298 return (cppu::OWeakObject
*)new XMLAutoTextEventExport(rSMgr
,EXPORT_ALL
);