Kaydet (Commit) 50b328f5 authored tarafından Daniel Vogelheim's avatar Daniel Vogelheim

- changed: autotext event import/export is now based on an XNameReplace

üst 35667520
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: XMLAutoTextContainerEventImport.cxx,v $ * $RCSfile: XMLAutoTextContainerEventImport.cxx,v $
* *
* $Revision: 1.1 $ * $Revision: 1.2 $
* *
* last change: $Author: dvo $ $Date: 2001-02-06 16:34:29 $ * last change: $Author: dvo $ $Date: 2001-03-09 14:53:43 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -63,10 +63,6 @@ ...@@ -63,10 +63,6 @@
#include "XMLAutoTextContainerEventImport.hxx" #include "XMLAutoTextContainerEventImport.hxx"
#endif #endif
#ifndef _XMLOFF_XMLAUTOTEXTGROUPEVENTIMPORT_HXX
#include "XMLAutoTextGroupEventImport.hxx"
#endif
#ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_ #ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_
#include <com/sun/star/uno/Reference.hxx> #include <com/sun/star/uno/Reference.hxx>
#endif #endif
...@@ -75,8 +71,8 @@ ...@@ -75,8 +71,8 @@
#include <com/sun/star/xml/sax/XAttributeList.hpp> #include <com/sun/star/xml/sax/XAttributeList.hpp>
#endif #endif
#ifndef _COM_SUN_STAR_TEXT_XAUTOTEXTCONTAINER_HPP_ #ifndef _COM_SUN_STAR_CONTAINER_XNAMEREPLACE_HPP_
#include <com/sun/star/text/XAutoTextContainer.hpp> #include <com/sun/star/container/XNameReplace.hpp>
#endif #endif
#ifndef _XMLOFF_XMLIMP_HXX #ifndef _XMLOFF_XMLIMP_HXX
...@@ -95,6 +91,10 @@ ...@@ -95,6 +91,10 @@
#include "xmlkywd.hxx" #include "xmlkywd.hxx"
#endif #endif
#ifndef _XMLOFF_XMLEVENTSIMPORTCONTEXT_HXX
#include "XMLEventsImportContext.hxx"
#endif
using namespace ::com::sun::star; using namespace ::com::sun::star;
...@@ -102,7 +102,7 @@ using ::rtl::OUString; ...@@ -102,7 +102,7 @@ using ::rtl::OUString;
using ::com::sun::star::uno::Any; using ::com::sun::star::uno::Any;
using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::Reference;
using ::com::sun::star::xml::sax::XAttributeList; using ::com::sun::star::xml::sax::XAttributeList;
using ::com::sun::star::text::XAutoTextContainer; using ::com::sun::star::container::XNameReplace;
...@@ -113,9 +113,9 @@ XMLAutoTextContainerEventImport::XMLAutoTextContainerEventImport( ...@@ -113,9 +113,9 @@ XMLAutoTextContainerEventImport::XMLAutoTextContainerEventImport(
SvXMLImport& rImport, SvXMLImport& rImport,
USHORT nPrfx, USHORT nPrfx,
const OUString& rLName, const OUString& rLName,
const Reference<XAutoTextContainer > & rContnr ) : const Reference<XNameReplace> & rEvnts ) :
SvXMLImportContext(rImport, nPrfx, rLName), SvXMLImportContext(rImport, nPrfx, rLName),
rContainer(rContnr) rEvents(rEvnts)
{ {
} }
...@@ -128,12 +128,12 @@ SvXMLImportContext* XMLAutoTextContainerEventImport::CreateChildContext( ...@@ -128,12 +128,12 @@ SvXMLImportContext* XMLAutoTextContainerEventImport::CreateChildContext(
const OUString& rLocalName, const OUString& rLocalName,
const Reference<XAttributeList> & xAttrList ) const Reference<XAttributeList> & xAttrList )
{ {
if ((XML_NAMESPACE_TEXT == nPrefix) && if ((XML_NAMESPACE_OFFICE == nPrefix) &&
rLocalName.equalsAsciiL(sXML_auto_text_group, rLocalName.equalsAsciiL(sXML_events,
sizeof(sXML_auto_text_group)-1)) sizeof(sXML_events)-1))
{ {
return new XMLAutoTextGroupEventImport(GetImport(), nPrefix, return new XMLEventsImportContext(GetImport(), nPrefix, rLocalName,
rLocalName, rContainer); rEvents);
} }
else else
return new SvXMLImportContext(GetImport(), nPrefix, rLocalName); return new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: XMLAutoTextContainerEventImport.hxx,v $ * $RCSfile: XMLAutoTextContainerEventImport.hxx,v $
* *
* $Revision: 1.1 $ * $Revision: 1.2 $
* *
* last change: $Author: dvo $ $Date: 2001-02-06 16:34:29 $ * last change: $Author: dvo $ $Date: 2001-03-09 14:53:43 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -73,8 +73,7 @@ ...@@ -73,8 +73,7 @@
namespace rtl { class OUString; } namespace rtl { class OUString; }
namespace com { namespace sun { namespace star { namespace com { namespace sun { namespace star {
namespace text { class XAutoTextContainer; } namespace container { class XNameReplace; }
namespace text { class XAutoTextGroup; }
namespace xml { namespace sax { class XAttributeList; } } namespace xml { namespace sax { class XAttributeList; } }
} } } } } }
...@@ -87,7 +86,7 @@ class XMLAutoTextContainerEventImport : public SvXMLImportContext ...@@ -87,7 +86,7 @@ class XMLAutoTextContainerEventImport : public SvXMLImportContext
{ {
/// the parent auto text container /// the parent auto text container
const ::com::sun::star::uno::Reference< const ::com::sun::star::uno::Reference<
::com::sun::star::text::XAutoTextContainer> & rContainer; ::com::sun::star::container::XNameReplace> & rEvents;
public: public:
...@@ -98,7 +97,7 @@ public: ...@@ -98,7 +97,7 @@ public:
USHORT nPrfx, USHORT nPrfx,
const ::rtl::OUString& rLName, const ::rtl::OUString& rLName,
const ::com::sun::star::uno::Reference< const ::com::sun::star::uno::Reference<
::com::sun::star::text::XAutoTextContainer > & rContainer ); ::com::sun::star::container::XNameReplace > & rEvents );
~XMLAutoTextContainerEventImport(); ~XMLAutoTextContainerEventImport();
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: XMLAutoTextEventExport.cxx,v $ * $RCSfile: XMLAutoTextEventExport.cxx,v $
* *
* $Revision: 1.3 $ * $Revision: 1.4 $
* *
* last change: $Author: dvo $ $Date: 2001-02-13 16:55:00 $ * last change: $Author: dvo $ $Date: 2001-03-09 14:53:43 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -63,18 +63,6 @@ ...@@ -63,18 +63,6 @@
#include "XMLAutoTextEventExport.hxx" #include "XMLAutoTextEventExport.hxx"
#endif #endif
#ifndef _COM_SUN_STAR_TEXT_XAUTOTEXTCONTAINER_HPP_
#include <com/sun/star/text/XAutoTextContainer.hpp>
#endif
#ifndef _COM_SUN_STAR_TEXT_XAUTOTEXTGROUP_HPP_
#include <com/sun/star/text/XAutoTextGroup.hpp>
#endif
#ifndef _COM_SUN_STAR_TEXT_XAUTOTEXTENTRY_HPP_
#include <com/sun/star/text/XAutoTextEntry.hpp>
#endif
#ifndef _COM_SUN_STAR_FRAME_XMODEL_HPP_ #ifndef _COM_SUN_STAR_FRAME_XMODEL_HPP_
#include <com/sun/star/frame/XModel.hpp> #include <com/sun/star/frame/XModel.hpp>
#endif #endif
...@@ -95,6 +83,10 @@ ...@@ -95,6 +83,10 @@
#include <com/sun/star/container/XNameReplace.hpp> #include <com/sun/star/container/XNameReplace.hpp>
#endif #endif
#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
#include <com/sun/star/container/XNameAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_ #ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_
#include <com/sun/star/uno/Reference.hxx> #include <com/sun/star/uno/Reference.hxx>
#endif #endif
...@@ -142,284 +134,139 @@ using ::comphelper::getProcessServiceFactory; ...@@ -142,284 +134,139 @@ using ::comphelper::getProcessServiceFactory;
using ::rtl::OUString; using ::rtl::OUString;
using ::rtl::OUStringBuffer; using ::rtl::OUStringBuffer;
using ::std::set; using ::std::set;
using ::com::sun::star::beans::XPropertySet;
using ::com::sun::star::beans::PropertyValue; using ::com::sun::star::beans::PropertyValue;
using ::com::sun::star::container::XNameAccess;
using ::com::sun::star::container::XNameReplace; using ::com::sun::star::container::XNameReplace;
using ::com::sun::star::document::XEventsSupplier; using ::com::sun::star::document::XEventsSupplier;
using ::com::sun::star::frame::XModel; using ::com::sun::star::frame::XModel;
using ::com::sun::star::lang::XMultiServiceFactory; using ::com::sun::star::lang::XMultiServiceFactory;
using ::com::sun::star::text::XAutoTextContainer;
using ::com::sun::star::text::XAutoTextEntry;
using ::com::sun::star::text::XAutoTextGroup;
using ::com::sun::star::uno::Any; using ::com::sun::star::uno::Any;
using ::com::sun::star::uno::Exception; using ::com::sun::star::uno::Exception;
using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::Reference;
using ::com::sun::star::uno::Sequence; using ::com::sun::star::uno::Sequence;
using ::com::sun::star::uno::XInterface; using ::com::sun::star::uno::XInterface;
using ::com::sun::star::uno::UNO_QUERY;
using ::com::sun::star::xml::sax::XDocumentHandler; using ::com::sun::star::xml::sax::XDocumentHandler;
const sal_Char sAPI_AutoText[] = "com.sun.star.text.AutoTextContainer"; const sal_Char sAPI_AutoText[] = "com.sun.star.text.AutoTextContainer";
XMLAutoTextEventExport::XMLAutoTextEventExport() : XMLAutoTextEventExport::XMLAutoTextEventExport() :
SvXMLExport( MAP_INCH, sXML_auto_text ), SvXMLExport( MAP_INCH, sXML_auto_text ),
eventCount( NULL ), sEventType(RTL_CONSTASCII_USTRINGPARAM("EventType")),
rGroupNames( * new Sequence<OUString> ) sNone(RTL_CONSTASCII_USTRINGPARAM("None"))
{ {
} }
XMLAutoTextEventExport::XMLAutoTextEventExport( XMLAutoTextEventExport::XMLAutoTextEventExport(
const OUString& rFileName, const OUString& rFileName,
const Reference<XDocumentHandler> & rHandler, const Reference<XDocumentHandler> & rHandler,
const Reference<XModel> & rModel) : const Reference<XModel> & rModel,
const Reference<XNameAccess> & rEvents) :
SvXMLExport(rFileName, rHandler, rModel, MAP_INCH), SvXMLExport(rFileName, rHandler, rModel, MAP_INCH),
eventCount( NULL ), xEvents(rEvents),
rGroupNames( * new Sequence<OUString> ) sEventType(RTL_CONSTASCII_USTRINGPARAM("EventType")),
sNone(RTL_CONSTASCII_USTRINGPARAM("None"))
{ {
} }
XMLAutoTextEventExport::~XMLAutoTextEventExport() XMLAutoTextEventExport::~XMLAutoTextEventExport()
{ {
delete eventCount;
} }
// export the events off all autotexts
sal_uInt32 XMLAutoTextEventExport::exportDoc( const sal_Char *pClass ) void XMLAutoTextEventExport::initialize(
const Sequence<Any> & rArguments )
throw(uno::Exception, uno::RuntimeException)
{ {
// instantiate AutoTextContainer via factory if (rArguments.getLength() > 1)
Reference<XMultiServiceFactory> xFactory = getProcessServiceFactory();
if (xFactory.is())
{ {
OUString sService(RTL_CONSTASCII_USTRINGPARAM(sAPI_AutoText)); Reference<XEventsSupplier> xSupplier;
Reference<XAutoTextContainer> xAutoTextContainer( rArguments[1] >>= xSupplier;
xFactory->createInstance(sService), uno::UNO_QUERY); if (xSupplier.is())
if (xAutoTextContainer.is())
{ {
// export all, or only the name groups? Reference<XNameAccess> xAccess(xSupplier->getEvents(), UNO_QUERY);
Sequence<OUString> & rNames = xEvents = xAccess;
(rGroupNames.getLength() > 0) ? rGroupNames : }
xAutoTextContainer->getElementNames(); else
{
countEvents(xAutoTextContainer, rNames); Reference<XNameReplace> xReplace;
exportAutoTextContainer(pClass, xAutoTextContainer, rNames); rArguments[1] >>= xReplace;
if (xReplace.is())
{
Reference<XNameAccess> xAccess(xReplace, UNO_QUERY);
xEvents = xAccess;
}
else
{
rArguments[1] >>= xEvents;
}
} }
} }
return 0;
// call super class (for XHandler)
SvXMLExport::initialize(rArguments);
} }
void XMLAutoTextEventExport::exportAutoTextContainer(
const sal_Char *pClass, sal_uInt32 XMLAutoTextEventExport::exportDoc(
Reference<XAutoTextContainer> & rAutoTextContainer, const sal_Char* pClass)
Sequence<OUString> & rNames)
{ {
if (hasDocumentEvents()) if (hasEvents())
{ {
GetDocHandler()->startDocument(); GetDocHandler()->startDocument();
// do we really want all namespaces ? addNamespaces();
// sal_uInt16 nPos = pNamespaceMap->GetFirstIndex();
// while( USHRT_MAX != nPos )
// {
// pAttrList->AddAttribute( pNamespaceMap->GetAttrNameByIndex( nPos ),
// sCDATA,
// pNamespaceMap->GetNameByIndex( nPos ) );
// nPos = pNamespaceMap->GetNextIndex( nPos );
// }
// namespaces for office:, text: and script:
GetAttrList().AddAttribute(
GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_TEXT ),
sCDATA, GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_TEXT ) );
GetAttrList().AddAttribute(
GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_SCRIPT ),
sCDATA, GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_SCRIPT ) );
GetAttrList().AddAttribute(
GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_OFFICE ),
sCDATA, GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_OFFICE ) );
{ {
// container element // container element
SvXMLElementExport aContainerElement( SvXMLElementExport aContainerElement(
*this, XML_NAMESPACE_TEXT, sXML_auto_text_events, *this, XML_NAMESPACE_OFFICE, sXML_auto_text_events,
sal_True, sal_True); sal_True, sal_True);
// iterate over group list exportEvents();
sal_Int32 nCount = rNames.getLength();
for(sal_Int32 i = 0; i < nCount; i++)
{
OUString& rName = rNames[i];
Any aAny = rAutoTextContainer->getByName(rName);
Reference<XAutoTextGroup> xGroup;
aAny >>= xGroup;
exportAutoTextGroup(rName, xGroup);
}
} }
// and close document again // and close document again
GetDocHandler()->endDocument(); GetDocHandler()->endDocument();
} }
}
void XMLAutoTextEventExport::exportAutoTextGroup(
OUString& rGroupName,
Reference<XAutoTextGroup> & rGroup)
{
DBG_ASSERT(rGroup.is(), "Where is the group?");
if (hasGroupEvents(rGroupName))
{
AddAttribute(XML_NAMESPACE_TEXT, sXML_group_name, rGroupName);
SvXMLElementExport aGroupElement(
*this, XML_NAMESPACE_TEXT, sXML_auto_text_group,
sal_True, sal_True);
// iterate over all autotexts in this group
Sequence<OUString> aNames = rGroup->getElementNames();
sal_Int32 nCount = aNames.getLength();
for(sal_Int32 i = 0; i < nCount; i++)
{
OUString& rTextName = aNames[i];
Any aAny = rGroup->getByName(rTextName);
Reference<XAutoTextEntry> xEntry;
aAny >>= xEntry;
exportAutoTextEntry(rGroupName, rTextName, xEntry);
}
}
}
void XMLAutoTextEventExport::exportAutoTextEntry(
OUString& rGroupName,
OUString& rName,
Reference<XAutoTextEntry> & rEntry)
{
if (hasEntryEvents(rGroupName, rName))
{
Reference<XEventsSupplier> xEventsSupp(rEntry, uno::UNO_QUERY);
DBG_ASSERT(xEventsSupp.is(),
"XEventsSupplier is required by service descr.");
AddAttribute(XML_NAMESPACE_TEXT, sXML_name, rName);
SvXMLElementExport aElem(*this, XML_NAMESPACE_TEXT, sXML_auto_text,
sal_True, sal_True);
GetEventExport().Export(xEventsSupp, sal_True);
}
}
void XMLAutoTextEventExport::countEvents(
Reference<XAutoTextContainer> & rAutoTextContainer,
Sequence<OUString> & rNames)
{
OUString sEventType(RTL_CONSTASCII_USTRINGPARAM("EventType"));
OUString sNone(RTL_CONSTASCII_USTRINGPARAM("None"));
set<OUString> * pEventCount = new set<OUString> ;
// iterate over all groups
sal_Int32 nGroupsCount = rNames.getLength();
for(sal_Int32 i = 0; i < nGroupsCount; i++)
{
OUString& rGroupName = rNames[i];
Any aAny = rAutoTextContainer->getByName(rGroupName);
Reference<XAutoTextGroup> xGroup;
aAny >>= xGroup;
// iterate over all autotexts in this group
Sequence<OUString> aEntryNames = xGroup->getElementNames();
sal_Int32 nEntryCount = aEntryNames.getLength();
for(sal_Int32 i = 0; i < nEntryCount; i++)
{
OUString& rEntryName = aEntryNames[i];
Any aAny = xGroup->getByName(rEntryName);
Reference<XAutoTextEntry> xEntry;
aAny >>= xEntry;
// iterate over all events of the autotext
Reference<XEventsSupplier> xSupplier(xEntry, uno::UNO_QUERY);
Reference<XNameReplace> xEvents = xSupplier->getEvents();
Sequence<OUString> aEventNames = xEvents->getElementNames();
sal_Int32 nEventsCount = aEventNames.getLength();
for(sal_Int32 i = 0; i < nEventsCount; i++)
{
OUString& rEventName = aEventNames[i];
Any aAny = xEvents->getByName(rEventName);
Sequence<PropertyValue> aValues;
aAny >>= aValues;
// now, finally, iterate over values and find a non-empty macro
sal_Int32 nValuesCount = aValues.getLength();
for(sal_Int32 i = 0; i < nValuesCount; i++)
{
if (aValues[i].Name == sEventType)
{
OUString sType;
aValues[i].Value >>= sType;
// non-empty macro?
if (sType != sNone)
{
// Wow! We found a event. Let's celebrate!
// insert the group + the event
pEventCount->insert(rGroupName);
pEventCount->insert(
combinedName(rGroupName, rEntryName));
}
}
}
}
}
}
eventCount = pEventCount; return 0;
} }
sal_Bool XMLAutoTextEventExport::hasDocumentEvents() sal_Bool XMLAutoTextEventExport::hasEvents()
{ {
return (NULL == eventCount) ? sal_True : (eventCount->size() != 0); // TODO: provide full implementation that check for presence of events
return xEvents.is();
} }
void XMLAutoTextEventExport::addNamespaces()
sal_Bool XMLAutoTextEventExport::hasGroupEvents(
const OUString& rGroupName )
{ {
return (NULL == eventCount) ? sal_True : // namespaces for office:, text: and script:
(eventCount->find(rGroupName) != eventCount->end()); GetAttrList().AddAttribute(
GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_TEXT ),
sCDATA, GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_TEXT ) );
GetAttrList().AddAttribute(
GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_SCRIPT ),
sCDATA, GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_SCRIPT ) );
GetAttrList().AddAttribute(
GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_OFFICE ),
sCDATA, GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_OFFICE ) );
} }
sal_Bool XMLAutoTextEventExport::hasEntryEvents( void XMLAutoTextEventExport::exportEvents()
const OUString& rGroupName,
const OUString& rEntryName )
{ {
return (NULL == eventCount) ? sal_True : DBG_ASSERT(hasEvents(), "no events to export!");
(eventCount->find(combinedName(rGroupName, rEntryName))
!= eventCount->end());
}
OUString XMLAutoTextEventExport::combinedName( GetEventExport().Export(xEvents, sal_True);
const OUString& rGroupName,
const OUString& rEntryName)
{
OUStringBuffer sBuf;
sBuf.append(rGroupName);
sBuf.append(sal_Unicode('#'));
sBuf.append(rEntryName);
return sBuf.makeStringAndClear();
} }
// methods without content: // methods without content:
void XMLAutoTextEventExport::_ExportMeta() {} void XMLAutoTextEventExport::_ExportMeta() {}
void XMLAutoTextEventExport::_ExportScripts() {} void XMLAutoTextEventExport::_ExportScripts() {}
void XMLAutoTextEventExport::_ExportFontDecls() {} void XMLAutoTextEventExport::_ExportFontDecls() {}
...@@ -430,18 +277,21 @@ void XMLAutoTextEventExport::_ExportChangeTracking() {} ...@@ -430,18 +277,21 @@ void XMLAutoTextEventExport::_ExportChangeTracking() {}
void XMLAutoTextEventExport::_ExportContent() {} void XMLAutoTextEventExport::_ExportContent() {}
// methods to support the component registration
Sequence< OUString > SAL_CALL XMLAutoTextEventExport_getSupportedServiceNames() Sequence< OUString > SAL_CALL XMLAutoTextEventExport_getSupportedServiceNames()
throw() throw()
{ {
const OUString aServiceName( Sequence< OUString > aSeq( 1 );
RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.office.sax.exporter.AutoTextEventWriter" ) ); aSeq[0] = XMLAutoTextEventExport_getImplementationName();
const Sequence< OUString > aSeq( &aServiceName, 1 );
return aSeq; return aSeq;
} }
OUString SAL_CALL XMLAutoTextEventExport_getImplementationName() throw() OUString SAL_CALL XMLAutoTextEventExport_getImplementationName() throw()
{ {
return OUString( RTL_CONSTASCII_USTRINGPARAM( "XMLAutoTextEventExport" ) ); return OUString( RTL_CONSTASCII_USTRINGPARAM(
"com.sun.star.comp.Writer.XMLAutotextEventsExporter" ) );
} }
Reference< XInterface > SAL_CALL XMLAutoTextEventExport_createInstance( Reference< XInterface > SAL_CALL XMLAutoTextEventExport_createInstance(
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: XMLAutoTextEventExport.hxx,v $ * $RCSfile: XMLAutoTextEventExport.hxx,v $
* *
* $Revision: 1.2 $ * $Revision: 1.3 $
* *
* last change: $Author: dvo $ $Date: 2001-02-13 16:55:00 $ * last change: $Author: dvo $ $Date: 2001-03-09 14:53:43 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -71,11 +71,9 @@ ...@@ -71,11 +71,9 @@
namespace rtl { class OUString; } namespace rtl { class OUString; }
namespace com { namespace sun { namespace star { namespace com { namespace sun { namespace star {
namespace container { class XNameAccess; }
namespace frame { class XModel; } namespace frame { class XModel; }
namespace lang { class XMultiServiceFactory; } namespace lang { class XMultiServiceFactory; }
namespace text { class XAutoTextContainer; }
namespace text { class XAutoTextGroup; }
namespace text { class XAutoTextEntry; }
namespace uno { template<class X> class Reference; } namespace uno { template<class X> class Reference; }
namespace uno { template<class X> class Sequence; } namespace uno { template<class X> class Sequence; }
namespace uno { class XInterface; } namespace uno { class XInterface; }
...@@ -84,20 +82,24 @@ namespace com { namespace sun { namespace star { ...@@ -84,20 +82,24 @@ namespace com { namespace sun { namespace star {
} } } } } }
/**
* Component for the export of events attached to autotext blocks.
* Via the XInitialization interface it expects up to two strings, the
* first giving the file name (URL) of the autotext group, and the second
* identifying the autotext. If one of the strings is not given, it
* will export the whole group / all groups.
*/
class XMLAutoTextEventExport : public SvXMLExport class XMLAutoTextEventExport : public SvXMLExport
{ {
::std::set< ::rtl::OUString > * eventCount; ::com::sun::star::uno::Reference<
::com::sun::star::container::XNameAccess> xEvents;
/// names of groups to be exported; export all group if empty. const ::rtl::OUString sEventType;
::com::sun::star::uno::Sequence< ::rtl::OUString> & rGroupNames; const ::rtl::OUString sNone;
// generate a combined name for sake of counting names
::rtl::OUString combinedName(
const ::rtl::OUString& rGroupName,
const ::rtl::OUString& rEntryName);
public: public:
XMLAutoTextEventExport(); XMLAutoTextEventExport();
XMLAutoTextEventExport( XMLAutoTextEventExport(
...@@ -105,51 +107,36 @@ public: ...@@ -105,51 +107,36 @@ public:
const ::com::sun::star::uno::Reference< const ::com::sun::star::uno::Reference<
::com::sun::star::xml::sax::XDocumentHandler > & rHandler, ::com::sun::star::xml::sax::XDocumentHandler > & rHandler,
const ::com::sun::star::uno::Reference< const ::com::sun::star::uno::Reference<
::com::sun::star::frame::XModel > & rModel); ::com::sun::star::frame::XModel > & rModel,
const ::com::sun::star::uno::Reference<
::com::sun::star::container::XNameAccess > & rEvents);
~XMLAutoTextEventExport(); ~XMLAutoTextEventExport();
// XInitialization
virtual void SAL_CALL initialize(
const ::com::sun::star::uno::Sequence<
::com::sun::star::uno::Any> & rArguments )
throw(
::com::sun::star::uno::Exception,
::com::sun::star::uno::RuntimeException);
protected: protected:
// export the events off all autotexts
/// export the events off all autotexts
virtual sal_uInt32 exportDoc( virtual sal_uInt32 exportDoc(
const sal_Char *pClass = NULL ); const sal_Char *pClass = NULL );
void exportAutoTextContainer(
const sal_Char* pClass,
::com::sun::star::uno::Reference<
::com::sun::star::text::XAutoTextContainer> & rAutoTextContainer,
::com::sun::star::uno::Sequence< ::rtl::OUString> & rGroupNames);
void exportAutoTextGroup(
::rtl::OUString& rName,
::com::sun::star::uno::Reference<
::com::sun::star::text::XAutoTextGroup> & rGroup);
void exportAutoTextEntry(
::rtl::OUString& rGroupName,
::rtl::OUString& rName,
::com::sun::star::uno::Reference<
::com::sun::star::text::XAutoTextEntry> & rEntry);
/// count the number of events (to be used before hasXXX() methods)
void countEvents(
::com::sun::star::uno::Reference<
::com::sun::star::text::XAutoTextContainer> & rAutoTextContainer,
::com::sun::star::uno::Sequence< ::rtl::OUString> & rGroupNames);
/// does the document have any events ? /// does the document have any events ?
sal_Bool hasDocumentEvents(); sal_Bool hasEvents();
/// does the group have any events ? /// export the events element
sal_Bool hasGroupEvents( void exportEvents();
const ::rtl::OUString& rGroupName );
/// does this entry have any events ?
sal_Bool hasEntryEvents(
const ::rtl::OUString& rGroupName,
const ::rtl::OUString& rEntryName );
/// add the namespaces used by events
/// (to be called for the document element)
void addNamespaces();
// methods without content: // methods without content:
...@@ -163,6 +150,8 @@ protected: ...@@ -163,6 +150,8 @@ protected:
virtual void _ExportContent(); virtual void _ExportContent();
}; };
// global functions to support the component // global functions to support the component
::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: XMLAutoTextEventImport.cxx,v $ * $RCSfile: XMLAutoTextEventImport.cxx,v $
* *
* $Revision: 1.2 $ * $Revision: 1.3 $
* *
* last change: $Author: dvo $ $Date: 2001-02-06 16:34:29 $ * last change: $Author: dvo $ $Date: 2001-03-09 14:53:43 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -71,32 +71,16 @@ ...@@ -71,32 +71,16 @@
#include <com/sun/star/xml/sax/XAttributeList.hpp> #include <com/sun/star/xml/sax/XAttributeList.hpp>
#endif #endif
#ifndef _COM_SUN_STAR_TEXT_XAUTOTEXTCONTAINER_HPP_ #ifndef _COM_SUN_STAR_DOCUMENT_XEVENTSSUPPLIER_HPP_
#include <com/sun/star/text/XAutoTextContainer.hpp> #include <com/sun/star/document/XEventsSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_TEXT_XAUTOTEXTGROUP_HPP_
#include <com/sun/star/text/XAutoTextGroup.hpp>
#endif
#ifndef _COM_SUN_STAR_TEXT_XAUTOTEXTGROUP_HPP_
#include <com/sun/star/text/XAutoTextGroup.hpp>
#endif
#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#endif #endif
#ifndef _COM_SUN_STAR_UNO_XINTERFACE_HPP_ #ifndef _COM_SUN_STAR_UNO_XINTERFACE_HPP_
#include <com/sun/star/uno/XInterface.hpp> #include <com/sun/star/uno/XInterface.hpp>
#endif #endif
#ifndef _COMPHELPER_PROCESSFACTORY_HXX_ #ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
#include <comphelper/processfactory.hxx> #include <com/sun/star/lang/XMultiServiceFactory.hpp>
#endif
#ifndef _XMLOFF_XMLAUTOTEXTGROUPEVENTIMPORT_HXX
#include "XMLAutoTextGroupEventImport.hxx"
#endif #endif
#ifndef _XMLOFF_XMLAUTOTEXTCONTAINEREVENTIMPORT_HXX #ifndef _XMLOFF_XMLAUTOTEXTCONTAINEREVENTIMPORT_HXX
...@@ -111,16 +95,23 @@ ...@@ -111,16 +95,23 @@
#include "xmlkywd.hxx" #include "xmlkywd.hxx"
#endif #endif
#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif
using namespace ::com::sun::star; using namespace ::com::sun::star;
using ::rtl::OUString; using ::rtl::OUString;
using ::comphelper::getProcessServiceFactory; using ::com::sun::star::uno::Any;
using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::Reference;
using ::com::sun::star::uno::Sequence; using ::com::sun::star::uno::Sequence;
using ::com::sun::star::uno::Type;
using ::com::sun::star::uno::XInterface; using ::com::sun::star::uno::XInterface;
using ::com::sun::star::uno::RuntimeException;
using ::com::sun::star::uno::Exception; using ::com::sun::star::uno::Exception;
using ::com::sun::star::xml::sax::XAttributeList; using ::com::sun::star::xml::sax::XAttributeList;
using ::com::sun::star::text::XAutoTextContainer; using ::com::sun::star::document::XEventsSupplier;
using ::com::sun::star::container::XNameReplace;
using ::com::sun::star::lang::XMultiServiceFactory; using ::com::sun::star::lang::XMultiServiceFactory;
const sal_Char sAPI_AutoText[] = "com.sun.star.text.AutoTextContainer"; const sal_Char sAPI_AutoText[] = "com.sun.star.text.AutoTextContainer";
...@@ -129,36 +120,55 @@ const sal_Char sAPI_AutoText[] = "com.sun.star.text.AutoTextContainer"; ...@@ -129,36 +120,55 @@ const sal_Char sAPI_AutoText[] = "com.sun.star.text.AutoTextContainer";
XMLAutoTextEventImport::XMLAutoTextEventImport() throw() : XMLAutoTextEventImport::XMLAutoTextEventImport() throw() :
SvXMLImport() SvXMLImport()
{ {
// instantiate AutoTextContainer via factory
Reference<XMultiServiceFactory> xFactory = getProcessServiceFactory();
if (xFactory.is())
{
OUString sService(RTL_CONSTASCII_USTRINGPARAM(sAPI_AutoText));
Reference<XAutoTextContainer> xContainer(
xFactory->createInstance(sService), uno::UNO_QUERY);
xAutoTextContainer = xContainer;
}
} }
XMLAutoTextEventImport::~XMLAutoTextEventImport() XMLAutoTextEventImport::~XMLAutoTextEventImport()
{ {
} }
void XMLAutoTextEventImport::initialize(
const Sequence<Any> & rArguments )
throw(Exception, RuntimeException)
{
// The events may come as either an XNameReplace or XEventsSupplier.
const sal_Int32 nLength = rArguments.getLength();
for( sal_Int32 i = 0; i < nLength; i++ )
{
const Type& rType = rArguments[i].getValueType();
if ( rType == ::getCppuType( (Reference<XEventsSupplier>*)NULL ) )
{
Reference<XEventsSupplier> xSupplier;
rArguments[i] >>= xSupplier;
DBG_ASSERT(xSupplier.is(), "need XEventsSupplier or XNameReplace");
xEvents = xSupplier->getEvents();
}
else if (rType == ::getCppuType( (Reference<XNameReplace>*)NULL ) )
{
rArguments[i] >>= xEvents;
DBG_ASSERT(xEvents.is(), "need XEventsSupplier or XNameReplace");
}
}
// call parent
SvXMLImport::initialize(rArguments);
}
SvXMLImportContext* XMLAutoTextEventImport::CreateContext( SvXMLImportContext* XMLAutoTextEventImport::CreateContext(
sal_uInt16 nPrefix, sal_uInt16 nPrefix,
const OUString& rLocalName, const OUString& rLocalName,
const Reference<XAttributeList > & xAttrList ) const Reference<XAttributeList > & xAttrList )
{ {
if ( xAutoTextContainer.is() && if ( xEvents.is() &&
(XML_NAMESPACE_TEXT == nPrefix) && (XML_NAMESPACE_OFFICE == nPrefix) &&
rLocalName.equalsAsciiL(sXML_auto_text_events, rLocalName.equalsAsciiL(sXML_auto_text_events,
sizeof(sXML_auto_text_events)-1) ) sizeof(sXML_auto_text_events)-1) )
{ {
return new XMLAutoTextContainerEventImport(*this, nPrefix, rLocalName, return new XMLAutoTextContainerEventImport(
xAutoTextContainer); *this, nPrefix, rLocalName, xEvents);
} }
else else
{ {
...@@ -167,20 +177,19 @@ SvXMLImportContext* XMLAutoTextEventImport::CreateContext( ...@@ -167,20 +177,19 @@ SvXMLImportContext* XMLAutoTextEventImport::CreateContext(
} }
Sequence< OUString > SAL_CALL Sequence< OUString > SAL_CALL
XMLAutoTextEventImport_getSupportedServiceNames() XMLAutoTextEventImport_getSupportedServiceNames()
throw() throw()
{ {
const OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( Sequence< OUString > aSeq( 1 );
"com.sun.star.office.sax.importer.AutoTextEventReader" ) ); aSeq[0] = XMLAutoTextEventImport_getImplementationName();
const Sequence< OUString > aSeq( &aServiceName, 1 );
return aSeq; return aSeq;
} }
OUString SAL_CALL XMLAutoTextEventImport_getImplementationName() throw() OUString SAL_CALL XMLAutoTextEventImport_getImplementationName() throw()
{ {
return OUString( RTL_CONSTASCII_USTRINGPARAM( "XMLAutoTextEventImport" ) ); return OUString( RTL_CONSTASCII_USTRINGPARAM(
"com.sun.star.comp.Writer.XMLAutotextEventsImporter" ) );
} }
Reference< XInterface > SAL_CALL XMLAutoTextEventImport_createInstance( Reference< XInterface > SAL_CALL XMLAutoTextEventImport_createInstance(
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: XMLAutoTextEventImport.hxx,v $ * $RCSfile: XMLAutoTextEventImport.hxx,v $
* *
* $Revision: 1.1 $ * $Revision: 1.2 $
* *
* last change: $Author: dvo $ $Date: 2001-02-06 11:51:27 $ * last change: $Author: dvo $ $Date: 2001-03-09 14:53:43 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -89,13 +89,20 @@ namespace com { namespace sun { namespace star { ...@@ -89,13 +89,20 @@ namespace com { namespace sun { namespace star {
class XMLAutoTextEventImport : public SvXMLImport class XMLAutoTextEventImport : public SvXMLImport
{ {
::com::sun::star::uno::Reference< ::com::sun::star::uno::Reference<
::com::sun::star::text::XAutoTextContainer> xAutoTextContainer; ::com::sun::star::container::XNameReplace> xEvents;
public: public:
XMLAutoTextEventImport() throw(); XMLAutoTextEventImport() throw();
~XMLAutoTextEventImport(); ~XMLAutoTextEventImport();
// XInitialization
virtual void SAL_CALL initialize(
const ::com::sun::star::uno::Sequence<
::com::sun::star::uno::Any> & rArguments )
throw(
::com::sun::star::uno::Exception,
::com::sun::star::uno::RuntimeException);
protected: protected:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment