2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-11-12 17:21:24 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2001-02-06 10:51:27 +00:00
|
|
|
|
|
|
|
#include "XMLAutoTextEventExport.hxx"
|
|
|
|
#include <com/sun/star/frame/XModel.hpp>
|
|
|
|
#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
|
2011-10-11 14:19:09 +02:00
|
|
|
#include <com/sun/star/util/MeasureUnit.hpp>
|
2001-02-06 10:51:27 +00:00
|
|
|
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
|
|
|
|
#include <com/sun/star/document/XEventsSupplier.hpp>
|
|
|
|
#include <com/sun/star/container/XNameReplace.hpp>
|
2001-03-09 13:53:43 +00:00
|
|
|
#include <com/sun/star/container/XNameAccess.hpp>
|
2001-02-06 10:51:27 +00:00
|
|
|
#include <com/sun/star/uno/Reference.hxx>
|
|
|
|
#include <com/sun/star/uno/Sequence.hxx>
|
|
|
|
#include <com/sun/star/uno/Exception.hpp>
|
|
|
|
#include <rtl/ustrbuf.hxx>
|
2010-04-16 23:04:00 +02:00
|
|
|
#include "xmloff/xmlnmspe.hxx"
|
2007-06-27 14:51:13 +00:00
|
|
|
#include <xmloff/nmspmap.hxx>
|
|
|
|
#include <xmloff/xmltoken.hxx>
|
|
|
|
#include <xmloff/XMLEventExport.hxx>
|
2001-02-06 10:51:27 +00:00
|
|
|
#include <tools/debug.hxx>
|
2011-10-11 14:19:09 +02:00
|
|
|
#include <tools/fldunit.hxx>
|
2013-01-16 17:12:47 +02:00
|
|
|
#include <comphelper/processfactory.hxx>
|
2001-02-06 10:51:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
using namespace ::com::sun::star;
|
2001-06-18 14:08:14 +00:00
|
|
|
using namespace ::xmloff::token;
|
2001-02-06 10:51:27 +00:00
|
|
|
|
|
|
|
using ::rtl::OUString;
|
|
|
|
using ::rtl::OUStringBuffer;
|
|
|
|
using ::std::set;
|
2001-03-09 13:53:43 +00:00
|
|
|
using ::com::sun::star::beans::XPropertySet;
|
2001-02-06 10:51:27 +00:00
|
|
|
using ::com::sun::star::beans::PropertyValue;
|
2001-03-09 13:53:43 +00:00
|
|
|
using ::com::sun::star::container::XNameAccess;
|
2001-02-06 10:51:27 +00:00
|
|
|
using ::com::sun::star::container::XNameReplace;
|
|
|
|
using ::com::sun::star::document::XEventsSupplier;
|
|
|
|
using ::com::sun::star::frame::XModel;
|
|
|
|
using ::com::sun::star::lang::XMultiServiceFactory;
|
|
|
|
using ::com::sun::star::uno::Any;
|
|
|
|
using ::com::sun::star::uno::Exception;
|
|
|
|
using ::com::sun::star::uno::Reference;
|
|
|
|
using ::com::sun::star::uno::Sequence;
|
|
|
|
using ::com::sun::star::uno::XInterface;
|
2001-03-09 13:53:43 +00:00
|
|
|
using ::com::sun::star::uno::UNO_QUERY;
|
2001-02-06 10:51:27 +00:00
|
|
|
using ::com::sun::star::xml::sax::XDocumentHandler;
|
|
|
|
|
|
|
|
|
2004-05-03 12:36:41 +00:00
|
|
|
XMLAutoTextEventExport::XMLAutoTextEventExport(
|
2013-01-16 17:12:47 +02:00
|
|
|
const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext,
|
2004-07-13 07:29:48 +00:00
|
|
|
sal_uInt16 nFlags
|
2004-05-03 12:36:41 +00:00
|
|
|
)
|
2013-01-16 17:12:47 +02:00
|
|
|
: SvXMLExport(util::MeasureUnit::INCH, xContext, XML_AUTO_TEXT, nFlags)
|
2011-10-11 14:19:09 +02:00
|
|
|
,
|
2012-06-02 15:26:21 -05:00
|
|
|
sEventType("EventType"),
|
|
|
|
sNone("None")
|
2001-02-06 10:51:27 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
XMLAutoTextEventExport::~XMLAutoTextEventExport()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-03-09 13:53:43 +00:00
|
|
|
void XMLAutoTextEventExport::initialize(
|
|
|
|
const Sequence<Any> & rArguments )
|
|
|
|
throw(uno::Exception, uno::RuntimeException)
|
2001-02-06 10:51:27 +00:00
|
|
|
{
|
2001-03-09 13:53:43 +00:00
|
|
|
if (rArguments.getLength() > 1)
|
2001-02-06 10:51:27 +00:00
|
|
|
{
|
2001-03-09 13:53:43 +00:00
|
|
|
Reference<XEventsSupplier> xSupplier;
|
|
|
|
rArguments[1] >>= xSupplier;
|
|
|
|
if (xSupplier.is())
|
2001-02-06 10:51:27 +00:00
|
|
|
{
|
2001-03-09 13:53:43 +00:00
|
|
|
Reference<XNameAccess> xAccess(xSupplier->getEvents(), UNO_QUERY);
|
|
|
|
xEvents = xAccess;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Reference<XNameReplace> xReplace;
|
|
|
|
rArguments[1] >>= xReplace;
|
|
|
|
if (xReplace.is())
|
|
|
|
{
|
|
|
|
Reference<XNameAccess> xAccess(xReplace, UNO_QUERY);
|
|
|
|
xEvents = xAccess;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rArguments[1] >>= xEvents;
|
|
|
|
}
|
2001-02-06 10:51:27 +00:00
|
|
|
}
|
|
|
|
}
|
2001-03-09 13:53:43 +00:00
|
|
|
|
|
|
|
// call super class (for XHandler)
|
|
|
|
SvXMLExport::initialize(rArguments);
|
2001-02-06 10:51:27 +00:00
|
|
|
}
|
|
|
|
|
2001-03-09 13:53:43 +00:00
|
|
|
|
2006-06-19 17:38:12 +00:00
|
|
|
sal_uInt32 XMLAutoTextEventExport::exportDoc( enum XMLTokenEnum )
|
2001-02-06 10:51:27 +00:00
|
|
|
{
|
2004-07-13 07:29:48 +00:00
|
|
|
if( (getExportFlags() & EXPORT_OASIS) == 0 )
|
|
|
|
{
|
2013-01-16 17:12:47 +02:00
|
|
|
Reference< uno::XComponentContext> xContext = getComponentContext();
|
|
|
|
try
|
2004-07-13 07:29:48 +00:00
|
|
|
{
|
|
|
|
|
2013-01-16 17:12:47 +02:00
|
|
|
Sequence<Any> aArgs( 1 );
|
|
|
|
aArgs[0] <<= GetDocHandler();
|
|
|
|
|
|
|
|
// get filter component
|
|
|
|
Reference< xml::sax::XDocumentHandler > xTmpDocHandler(
|
|
|
|
xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
|
|
|
|
"com.sun.star.comp.Oasis2OOoTransformer",
|
|
|
|
aArgs,
|
|
|
|
xContext),
|
|
|
|
UNO_QUERY);
|
|
|
|
OSL_ENSURE( xTmpDocHandler.is(),
|
|
|
|
"can't instantiate OASIS transformer component" );
|
|
|
|
if( xTmpDocHandler.is() )
|
2004-07-13 07:29:48 +00:00
|
|
|
{
|
2013-01-16 17:12:47 +02:00
|
|
|
SetDocHandler( xTmpDocHandler );
|
2004-07-13 07:29:48 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-16 17:12:47 +02:00
|
|
|
catch( com::sun::star::uno::Exception& )
|
|
|
|
{
|
|
|
|
}
|
2004-07-13 07:29:48 +00:00
|
|
|
}
|
2001-03-09 13:53:43 +00:00
|
|
|
if (hasEvents())
|
2001-02-06 10:51:27 +00:00
|
|
|
{
|
|
|
|
GetDocHandler()->startDocument();
|
|
|
|
|
2011-09-08 13:50:30 +01:00
|
|
|
addChaffWhenEncryptedStorage();
|
|
|
|
|
2001-03-09 13:53:43 +00:00
|
|
|
addNamespaces();
|
2001-02-06 10:51:27 +00:00
|
|
|
|
|
|
|
{
|
2001-02-06 15:34:29 +00:00
|
|
|
// container element
|
|
|
|
SvXMLElementExport aContainerElement(
|
2004-07-13 07:29:48 +00:00
|
|
|
*this, XML_NAMESPACE_OOO, XML_AUTO_TEXT_EVENTS,
|
2001-02-06 10:51:27 +00:00
|
|
|
sal_True, sal_True);
|
|
|
|
|
2001-03-09 13:53:43 +00:00
|
|
|
exportEvents();
|
2001-02-06 10:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// and close document again
|
|
|
|
GetDocHandler()->endDocument();
|
|
|
|
}
|
|
|
|
|
2001-03-09 13:53:43 +00:00
|
|
|
return 0;
|
2001-02-06 10:51:27 +00:00
|
|
|
}
|
|
|
|
|
2001-03-09 13:53:43 +00:00
|
|
|
sal_Bool XMLAutoTextEventExport::hasEvents()
|
2001-02-06 10:51:27 +00:00
|
|
|
{
|
2001-03-09 13:53:43 +00:00
|
|
|
// TODO: provide full implementation that check for presence of events
|
|
|
|
return xEvents.is();
|
2001-02-06 10:51:27 +00:00
|
|
|
}
|
|
|
|
|
2001-03-09 13:53:43 +00:00
|
|
|
void XMLAutoTextEventExport::addNamespaces()
|
2001-02-06 10:51:27 +00:00
|
|
|
{
|
2001-03-09 13:53:43 +00:00
|
|
|
// namespaces for office:, text: and script:
|
2004-07-13 07:29:48 +00:00
|
|
|
GetAttrList().AddAttribute(
|
|
|
|
GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_OFFICE ),
|
|
|
|
GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_OFFICE ) );
|
2001-03-09 13:53:43 +00:00
|
|
|
GetAttrList().AddAttribute(
|
2003-03-27 17:21:03 +00:00
|
|
|
GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_TEXT ),
|
|
|
|
GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_TEXT ) );
|
2001-03-09 13:53:43 +00:00
|
|
|
GetAttrList().AddAttribute(
|
2003-03-27 17:21:03 +00:00
|
|
|
GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_SCRIPT ),
|
|
|
|
GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_SCRIPT ) );
|
2001-03-09 13:53:43 +00:00
|
|
|
GetAttrList().AddAttribute(
|
2004-07-13 07:29:48 +00:00
|
|
|
GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_DOM ),
|
|
|
|
GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_DOM ) );
|
|
|
|
GetAttrList().AddAttribute(
|
|
|
|
GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_OOO ),
|
|
|
|
GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_OOO ) );
|
2011-02-21 16:22:29 +01:00
|
|
|
GetAttrList().AddAttribute(
|
|
|
|
GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_XLINK ),
|
|
|
|
GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_XLINK ) );
|
2001-02-06 10:51:27 +00:00
|
|
|
}
|
|
|
|
|
2001-03-09 13:53:43 +00:00
|
|
|
void XMLAutoTextEventExport::exportEvents()
|
2001-02-06 10:51:27 +00:00
|
|
|
{
|
2001-03-09 13:53:43 +00:00
|
|
|
DBG_ASSERT(hasEvents(), "no events to export!");
|
2001-02-06 10:51:27 +00:00
|
|
|
|
2001-03-09 13:53:43 +00:00
|
|
|
GetEventExport().Export(xEvents, sal_True);
|
2001-02-06 10:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// methods without content:
|
2001-03-09 13:53:43 +00:00
|
|
|
|
2001-02-06 10:51:27 +00:00
|
|
|
void XMLAutoTextEventExport::_ExportMeta() {}
|
|
|
|
void XMLAutoTextEventExport::_ExportScripts() {}
|
|
|
|
void XMLAutoTextEventExport::_ExportFontDecls() {}
|
2006-06-19 17:38:12 +00:00
|
|
|
void XMLAutoTextEventExport::_ExportStyles( sal_Bool ) {}
|
2001-02-06 10:51:27 +00:00
|
|
|
void XMLAutoTextEventExport::_ExportAutoStyles() {}
|
|
|
|
void XMLAutoTextEventExport::_ExportMasterStyles() {}
|
|
|
|
void XMLAutoTextEventExport::_ExportContent() {}
|
|
|
|
|
|
|
|
|
2001-03-09 13:53:43 +00:00
|
|
|
|
|
|
|
// methods to support the component registration
|
|
|
|
|
2001-02-06 10:51:27 +00:00
|
|
|
Sequence< OUString > SAL_CALL XMLAutoTextEventExport_getSupportedServiceNames()
|
|
|
|
throw()
|
|
|
|
{
|
2001-03-09 13:53:43 +00:00
|
|
|
Sequence< OUString > aSeq( 1 );
|
|
|
|
aSeq[0] = XMLAutoTextEventExport_getImplementationName();
|
2001-02-06 10:51:27 +00:00
|
|
|
return aSeq;
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString SAL_CALL XMLAutoTextEventExport_getImplementationName() throw()
|
|
|
|
{
|
2012-06-02 15:26:21 -05:00
|
|
|
return OUString( "com.sun.star.comp.Writer.XMLOasisAutotextEventsExporter" );
|
2001-02-06 10:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Reference< XInterface > SAL_CALL XMLAutoTextEventExport_createInstance(
|
|
|
|
const Reference< XMultiServiceFactory > & rSMgr)
|
|
|
|
throw( Exception )
|
|
|
|
{
|
2013-01-16 17:12:47 +02:00
|
|
|
return (cppu::OWeakObject*)new XMLAutoTextEventExport( comphelper::getComponentContext(rSMgr), EXPORT_ALL|EXPORT_OASIS);
|
2004-07-13 07:29:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// methods to support the component registration
|
|
|
|
|
|
|
|
Sequence< OUString > SAL_CALL XMLAutoTextEventExportOOO_getSupportedServiceNames()
|
|
|
|
throw()
|
|
|
|
{
|
|
|
|
Sequence< OUString > aSeq( 1 );
|
|
|
|
aSeq[0] = XMLAutoTextEventExportOOO_getImplementationName();
|
|
|
|
return aSeq;
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString SAL_CALL XMLAutoTextEventExportOOO_getImplementationName() throw()
|
|
|
|
{
|
2012-06-02 15:26:21 -05:00
|
|
|
return OUString( "com.sun.star.comp.Writer.XMLAutotextEventsExporter" );
|
2004-07-13 07:29:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Reference< XInterface > SAL_CALL XMLAutoTextEventExportOOO_createInstance(
|
|
|
|
const Reference< XMultiServiceFactory > & rSMgr)
|
|
|
|
throw( Exception )
|
|
|
|
{
|
2013-01-16 17:12:47 +02:00
|
|
|
return (cppu::OWeakObject*)new XMLAutoTextEventExport( comphelper::getComponentContext(rSMgr),EXPORT_ALL);
|
2001-02-06 10:51:27 +00:00
|
|
|
}
|
|
|
|
|
2010-10-12 15:53:47 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|