1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "XMLAutoTextEventExport.hxx"
30 #include <com/sun/star/frame/XModel.hpp>
31 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
32 #include <com/sun/star/util/MeasureUnit.hpp>
33 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 #include <com/sun/star/document/XEventsSupplier.hpp>
35 #include <com/sun/star/container/XNameReplace.hpp>
36 #include <com/sun/star/container/XNameAccess.hpp>
37 #include <com/sun/star/uno/Reference.hxx>
38 #include <com/sun/star/uno/Sequence.hxx>
39 #include <com/sun/star/uno/Exception.hpp>
40 #include <rtl/ustrbuf.hxx>
41 #include "xmloff/xmlnmspe.hxx"
42 #include <xmloff/nmspmap.hxx>
43 #include <xmloff/xmltoken.hxx>
44 #include <xmloff/XMLEventExport.hxx>
45 #include <tools/debug.hxx>
46 #include <tools/fldunit.hxx>
49 using namespace ::com::sun::star
;
50 using namespace ::xmloff::token
;
52 using ::rtl::OUString
;
53 using ::rtl::OUStringBuffer
;
55 using ::com::sun::star::beans::XPropertySet
;
56 using ::com::sun::star::beans::PropertyValue
;
57 using ::com::sun::star::container::XNameAccess
;
58 using ::com::sun::star::container::XNameReplace
;
59 using ::com::sun::star::document::XEventsSupplier
;
60 using ::com::sun::star::frame::XModel
;
61 using ::com::sun::star::lang::XMultiServiceFactory
;
62 using ::com::sun::star::uno::Any
;
63 using ::com::sun::star::uno::Exception
;
64 using ::com::sun::star::uno::Reference
;
65 using ::com::sun::star::uno::Sequence
;
66 using ::com::sun::star::uno::XInterface
;
67 using ::com::sun::star::uno::UNO_QUERY
;
68 using ::com::sun::star::xml::sax::XDocumentHandler
;
71 const sal_Char sAPI_AutoText
[] = "com.sun.star.text.AutoTextContainer";
74 XMLAutoTextEventExport::XMLAutoTextEventExport(
75 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& xServiceFactory
,
78 : SvXMLExport(util::MeasureUnit::INCH
, xServiceFactory
, XML_AUTO_TEXT
, nFlags
)
80 sEventType("EventType"),
85 XMLAutoTextEventExport::~XMLAutoTextEventExport()
89 void XMLAutoTextEventExport::initialize(
90 const Sequence
<Any
> & rArguments
)
91 throw(uno::Exception
, uno::RuntimeException
)
93 if (rArguments
.getLength() > 1)
95 Reference
<XEventsSupplier
> xSupplier
;
96 rArguments
[1] >>= xSupplier
;
99 Reference
<XNameAccess
> xAccess(xSupplier
->getEvents(), UNO_QUERY
);
104 Reference
<XNameReplace
> xReplace
;
105 rArguments
[1] >>= xReplace
;
108 Reference
<XNameAccess
> xAccess(xReplace
, UNO_QUERY
);
113 rArguments
[1] >>= xEvents
;
118 // call super class (for XHandler)
119 SvXMLExport::initialize(rArguments
);
123 sal_uInt32
XMLAutoTextEventExport::exportDoc( enum XMLTokenEnum
)
125 if( (getExportFlags() & EXPORT_OASIS
) == 0 )
127 Reference
< lang::XMultiServiceFactory
> xFactory
= getServiceFactory();
133 Sequence
<Any
> aArgs( 1 );
134 aArgs
[0] <<= GetDocHandler();
136 // get filter component
137 Reference
< xml::sax::XDocumentHandler
> xTmpDocHandler(
138 xFactory
->createInstanceWithArguments(
139 OUString("com.sun.star.comp.Oasis2OOoTransformer"),
141 OSL_ENSURE( xTmpDocHandler
.is(),
142 "can't instantiate OASIS transformer component" );
143 if( xTmpDocHandler
.is() )
145 SetDocHandler( xTmpDocHandler
);
148 catch( com::sun::star::uno::Exception
& )
155 GetDocHandler()->startDocument();
157 addChaffWhenEncryptedStorage();
163 SvXMLElementExport
aContainerElement(
164 *this, XML_NAMESPACE_OOO
, XML_AUTO_TEXT_EVENTS
,
170 // and close document again
171 GetDocHandler()->endDocument();
177 sal_Bool
XMLAutoTextEventExport::hasEvents()
179 // TODO: provide full implementation that check for presence of events
183 void XMLAutoTextEventExport::addNamespaces()
185 // namespaces for office:, text: and script:
186 GetAttrList().AddAttribute(
187 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_OFFICE
),
188 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_OFFICE
) );
189 GetAttrList().AddAttribute(
190 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_TEXT
),
191 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_TEXT
) );
192 GetAttrList().AddAttribute(
193 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_SCRIPT
),
194 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_SCRIPT
) );
195 GetAttrList().AddAttribute(
196 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_DOM
),
197 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_DOM
) );
198 GetAttrList().AddAttribute(
199 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_OOO
),
200 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_OOO
) );
201 GetAttrList().AddAttribute(
202 GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_XLINK
),
203 GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_XLINK
) );
206 void XMLAutoTextEventExport::exportEvents()
208 DBG_ASSERT(hasEvents(), "no events to export!");
210 GetEventExport().Export(xEvents
, sal_True
);
215 // methods without content:
217 void XMLAutoTextEventExport::_ExportMeta() {}
218 void XMLAutoTextEventExport::_ExportScripts() {}
219 void XMLAutoTextEventExport::_ExportFontDecls() {}
220 void XMLAutoTextEventExport::_ExportStyles( sal_Bool
) {}
221 void XMLAutoTextEventExport::_ExportAutoStyles() {}
222 void XMLAutoTextEventExport::_ExportMasterStyles() {}
223 void XMLAutoTextEventExport::_ExportChangeTracking() {}
224 void XMLAutoTextEventExport::_ExportContent() {}
228 // methods to support the component registration
230 Sequence
< OUString
> SAL_CALL
XMLAutoTextEventExport_getSupportedServiceNames()
233 Sequence
< OUString
> aSeq( 1 );
234 aSeq
[0] = XMLAutoTextEventExport_getImplementationName();
238 OUString SAL_CALL
XMLAutoTextEventExport_getImplementationName() throw()
240 return OUString( "com.sun.star.comp.Writer.XMLOasisAutotextEventsExporter" );
243 Reference
< XInterface
> SAL_CALL
XMLAutoTextEventExport_createInstance(
244 const Reference
< XMultiServiceFactory
> & rSMgr
)
247 return (cppu::OWeakObject
*)new XMLAutoTextEventExport(rSMgr
, EXPORT_ALL
|EXPORT_OASIS
);
250 // methods to support the component registration
252 Sequence
< OUString
> SAL_CALL
XMLAutoTextEventExportOOO_getSupportedServiceNames()
255 Sequence
< OUString
> aSeq( 1 );
256 aSeq
[0] = XMLAutoTextEventExportOOO_getImplementationName();
260 OUString SAL_CALL
XMLAutoTextEventExportOOO_getImplementationName() throw()
262 return OUString( "com.sun.star.comp.Writer.XMLAutotextEventsExporter" );
265 Reference
< XInterface
> SAL_CALL
XMLAutoTextEventExportOOO_createInstance(
266 const Reference
< XMultiServiceFactory
> & rSMgr
)
269 return (cppu::OWeakObject
*)new XMLAutoTextEventExport(rSMgr
,EXPORT_ALL
);
272 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */