diff options
author | Daniel Vogelheim <dvo@openoffice.org> | 2001-03-09 13:53:43 +0000 |
---|---|---|
committer | Daniel Vogelheim <dvo@openoffice.org> | 2001-03-09 13:53:43 +0000 |
commit | 50b328f577a47d5d2313d95db8c9f4249c59a8eb (patch) | |
tree | 554b68bcd6550584e50f1beb49da09e2a97a813a | |
parent | First checkin (diff) | |
download | core-50b328f577a47d5d2313d95db8c9f4249c59a8eb.tar.gz core-50b328f577a47d5d2313d95db8c9f4249c59a8eb.zip |
- changed: autotext event import/export is now based on an XNameReplace
-rw-r--r-- | xmloff/source/text/XMLAutoTextContainerEventImport.cxx | 32 | ||||
-rw-r--r-- | xmloff/source/text/XMLAutoTextContainerEventImport.hxx | 11 | ||||
-rw-r--r-- | xmloff/source/text/XMLAutoTextEventExport.cxx | 306 | ||||
-rw-r--r-- | xmloff/source/text/XMLAutoTextEventExport.hxx | 83 | ||||
-rw-r--r-- | xmloff/source/text/XMLAutoTextEventImport.cxx | 97 | ||||
-rw-r--r-- | xmloff/source/text/XMLAutoTextEventImport.hxx | 13 |
6 files changed, 198 insertions, 344 deletions
diff --git a/xmloff/source/text/XMLAutoTextContainerEventImport.cxx b/xmloff/source/text/XMLAutoTextContainerEventImport.cxx index b2c8342ee29b..6ce50da026ea 100644 --- a/xmloff/source/text/XMLAutoTextContainerEventImport.cxx +++ b/xmloff/source/text/XMLAutoTextContainerEventImport.cxx @@ -2,9 +2,9 @@ * * $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 * either of the following licenses @@ -63,10 +63,6 @@ #include "XMLAutoTextContainerEventImport.hxx" #endif -#ifndef _XMLOFF_XMLAUTOTEXTGROUPEVENTIMPORT_HXX -#include "XMLAutoTextGroupEventImport.hxx" -#endif - #ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_ #include <com/sun/star/uno/Reference.hxx> #endif @@ -75,8 +71,8 @@ #include <com/sun/star/xml/sax/XAttributeList.hpp> #endif -#ifndef _COM_SUN_STAR_TEXT_XAUTOTEXTCONTAINER_HPP_ -#include <com/sun/star/text/XAutoTextContainer.hpp> +#ifndef _COM_SUN_STAR_CONTAINER_XNAMEREPLACE_HPP_ +#include <com/sun/star/container/XNameReplace.hpp> #endif #ifndef _XMLOFF_XMLIMP_HXX @@ -95,6 +91,10 @@ #include "xmlkywd.hxx" #endif +#ifndef _XMLOFF_XMLEVENTSIMPORTCONTEXT_HXX +#include "XMLEventsImportContext.hxx" +#endif + using namespace ::com::sun::star; @@ -102,7 +102,7 @@ using ::rtl::OUString; using ::com::sun::star::uno::Any; using ::com::sun::star::uno::Reference; 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( SvXMLImport& rImport, USHORT nPrfx, const OUString& rLName, - const Reference<XAutoTextContainer > & rContnr ) : + const Reference<XNameReplace> & rEvnts ) : SvXMLImportContext(rImport, nPrfx, rLName), - rContainer(rContnr) + rEvents(rEvnts) { } @@ -128,12 +128,12 @@ SvXMLImportContext* XMLAutoTextContainerEventImport::CreateChildContext( const OUString& rLocalName, const Reference<XAttributeList> & xAttrList ) { - if ((XML_NAMESPACE_TEXT == nPrefix) && - rLocalName.equalsAsciiL(sXML_auto_text_group, - sizeof(sXML_auto_text_group)-1)) + if ((XML_NAMESPACE_OFFICE == nPrefix) && + rLocalName.equalsAsciiL(sXML_events, + sizeof(sXML_events)-1)) { - return new XMLAutoTextGroupEventImport(GetImport(), nPrefix, - rLocalName, rContainer); + return new XMLEventsImportContext(GetImport(), nPrefix, rLocalName, + rEvents); } else return new SvXMLImportContext(GetImport(), nPrefix, rLocalName); diff --git a/xmloff/source/text/XMLAutoTextContainerEventImport.hxx b/xmloff/source/text/XMLAutoTextContainerEventImport.hxx index 2fa7e8fd635f..7d20178cbd7c 100644 --- a/xmloff/source/text/XMLAutoTextContainerEventImport.hxx +++ b/xmloff/source/text/XMLAutoTextContainerEventImport.hxx @@ -2,9 +2,9 @@ * * $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 * either of the following licenses @@ -73,8 +73,7 @@ namespace rtl { class OUString; } namespace com { namespace sun { namespace star { - namespace text { class XAutoTextContainer; } - namespace text { class XAutoTextGroup; } + namespace container { class XNameReplace; } namespace xml { namespace sax { class XAttributeList; } } } } } @@ -87,7 +86,7 @@ class XMLAutoTextContainerEventImport : public SvXMLImportContext { /// the parent auto text container const ::com::sun::star::uno::Reference< - ::com::sun::star::text::XAutoTextContainer> & rContainer; + ::com::sun::star::container::XNameReplace> & rEvents; public: @@ -98,7 +97,7 @@ public: USHORT nPrfx, const ::rtl::OUString& rLName, const ::com::sun::star::uno::Reference< - ::com::sun::star::text::XAutoTextContainer > & rContainer ); + ::com::sun::star::container::XNameReplace > & rEvents ); ~XMLAutoTextContainerEventImport(); diff --git a/xmloff/source/text/XMLAutoTextEventExport.cxx b/xmloff/source/text/XMLAutoTextEventExport.cxx index ad1c64c4f633..4daad83ae2bb 100644 --- a/xmloff/source/text/XMLAutoTextEventExport.cxx +++ b/xmloff/source/text/XMLAutoTextEventExport.cxx @@ -2,9 +2,9 @@ * * $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 * either of the following licenses @@ -63,18 +63,6 @@ #include "XMLAutoTextEventExport.hxx" #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_ #include <com/sun/star/frame/XModel.hpp> #endif @@ -95,6 +83,10 @@ #include <com/sun/star/container/XNameReplace.hpp> #endif +#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_ +#include <com/sun/star/container/XNameAccess.hpp> +#endif + #ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_ #include <com/sun/star/uno/Reference.hxx> #endif @@ -142,284 +134,139 @@ using ::comphelper::getProcessServiceFactory; using ::rtl::OUString; using ::rtl::OUStringBuffer; using ::std::set; +using ::com::sun::star::beans::XPropertySet; using ::com::sun::star::beans::PropertyValue; +using ::com::sun::star::container::XNameAccess; 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::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::Exception; using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::Sequence; using ::com::sun::star::uno::XInterface; +using ::com::sun::star::uno::UNO_QUERY; using ::com::sun::star::xml::sax::XDocumentHandler; const sal_Char sAPI_AutoText[] = "com.sun.star.text.AutoTextContainer"; + XMLAutoTextEventExport::XMLAutoTextEventExport() : - SvXMLExport( MAP_INCH, sXML_auto_text ), - eventCount( NULL ), - rGroupNames( * new Sequence<OUString> ) + SvXMLExport( MAP_INCH, sXML_auto_text ), + sEventType(RTL_CONSTASCII_USTRINGPARAM("EventType")), + sNone(RTL_CONSTASCII_USTRINGPARAM("None")) { } XMLAutoTextEventExport::XMLAutoTextEventExport( const OUString& rFileName, const Reference<XDocumentHandler> & rHandler, - const Reference<XModel> & rModel) : + const Reference<XModel> & rModel, + const Reference<XNameAccess> & rEvents) : SvXMLExport(rFileName, rHandler, rModel, MAP_INCH), - eventCount( NULL ), - rGroupNames( * new Sequence<OUString> ) + xEvents(rEvents), + sEventType(RTL_CONSTASCII_USTRINGPARAM("EventType")), + sNone(RTL_CONSTASCII_USTRINGPARAM("None")) { } 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 - Reference<XMultiServiceFactory> xFactory = getProcessServiceFactory(); - if (xFactory.is()) + if (rArguments.getLength() > 1) { - OUString sService(RTL_CONSTASCII_USTRINGPARAM(sAPI_AutoText)); - Reference<XAutoTextContainer> xAutoTextContainer( - xFactory->createInstance(sService), uno::UNO_QUERY); - - if (xAutoTextContainer.is()) + Reference<XEventsSupplier> xSupplier; + rArguments[1] >>= xSupplier; + if (xSupplier.is()) { - // export all, or only the name groups? - Sequence<OUString> & rNames = - (rGroupNames.getLength() > 0) ? rGroupNames : - xAutoTextContainer->getElementNames(); - - countEvents(xAutoTextContainer, rNames); - exportAutoTextContainer(pClass, xAutoTextContainer, rNames); + 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; + } } } - return 0; + + // call super class (for XHandler) + SvXMLExport::initialize(rArguments); } -void XMLAutoTextEventExport::exportAutoTextContainer( - const sal_Char *pClass, - Reference<XAutoTextContainer> & rAutoTextContainer, - Sequence<OUString> & rNames) + +sal_uInt32 XMLAutoTextEventExport::exportDoc( + const sal_Char* pClass) { - if (hasDocumentEvents()) + if (hasEvents()) { GetDocHandler()->startDocument(); - // do we really want all namespaces ? -// 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 ) ); + addNamespaces(); { // container element SvXMLElementExport aContainerElement( - *this, XML_NAMESPACE_TEXT, sXML_auto_text_events, + *this, XML_NAMESPACE_OFFICE, sXML_auto_text_events, sal_True, sal_True); - // iterate over group list - 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); - } + exportEvents(); } // and close document again 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(); } - -sal_Bool XMLAutoTextEventExport::hasGroupEvents( - const OUString& rGroupName ) +void XMLAutoTextEventExport::addNamespaces() { - return (NULL == eventCount) ? sal_True : - (eventCount->find(rGroupName) != eventCount->end()); + // 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 ) ); } -sal_Bool XMLAutoTextEventExport::hasEntryEvents( - const OUString& rGroupName, - const OUString& rEntryName ) +void XMLAutoTextEventExport::exportEvents() { - return (NULL == eventCount) ? sal_True : - (eventCount->find(combinedName(rGroupName, rEntryName)) - != eventCount->end()); -} - - + DBG_ASSERT(hasEvents(), "no events to export!"); -OUString XMLAutoTextEventExport::combinedName( - const OUString& rGroupName, - const OUString& rEntryName) -{ - OUStringBuffer sBuf; - sBuf.append(rGroupName); - sBuf.append(sal_Unicode('#')); - sBuf.append(rEntryName); - return sBuf.makeStringAndClear(); + GetEventExport().Export(xEvents, sal_True); } // methods without content: + void XMLAutoTextEventExport::_ExportMeta() {} void XMLAutoTextEventExport::_ExportScripts() {} void XMLAutoTextEventExport::_ExportFontDecls() {} @@ -430,18 +277,21 @@ void XMLAutoTextEventExport::_ExportChangeTracking() {} void XMLAutoTextEventExport::_ExportContent() {} + +// methods to support the component registration + Sequence< OUString > SAL_CALL XMLAutoTextEventExport_getSupportedServiceNames() throw() { - const OUString aServiceName( - RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.office.sax.exporter.AutoTextEventWriter" ) ); - const Sequence< OUString > aSeq( &aServiceName, 1 ); + Sequence< OUString > aSeq( 1 ); + aSeq[0] = XMLAutoTextEventExport_getImplementationName(); return aSeq; } 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( diff --git a/xmloff/source/text/XMLAutoTextEventExport.hxx b/xmloff/source/text/XMLAutoTextEventExport.hxx index 5034d5025c2d..7ac8c241fec7 100644 --- a/xmloff/source/text/XMLAutoTextEventExport.hxx +++ b/xmloff/source/text/XMLAutoTextEventExport.hxx @@ -2,9 +2,9 @@ * * $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 * either of the following licenses @@ -71,11 +71,9 @@ namespace rtl { class OUString; } namespace com { namespace sun { namespace star { + namespace container { class XNameAccess; } namespace frame { class XModel; } 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 Sequence; } namespace uno { class XInterface; } @@ -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 { - ::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. - ::com::sun::star::uno::Sequence< ::rtl::OUString> & rGroupNames; + const ::rtl::OUString sEventType; + 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: + XMLAutoTextEventExport(); XMLAutoTextEventExport( @@ -105,51 +107,36 @@ public: const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > & rHandler, 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(); + // 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: - // export the events off all autotexts + + /// export the events off all autotexts virtual sal_uInt32 exportDoc( 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 ? - sal_Bool hasDocumentEvents(); + sal_Bool hasEvents(); - /// does the group have any events ? - sal_Bool hasGroupEvents( - const ::rtl::OUString& rGroupName ); + /// export the events element + void exportEvents(); - /// 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: @@ -163,6 +150,8 @@ protected: virtual void _ExportContent(); }; + + // global functions to support the component ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL diff --git a/xmloff/source/text/XMLAutoTextEventImport.cxx b/xmloff/source/text/XMLAutoTextEventImport.cxx index 442053a18359..1f24a4baa884 100644 --- a/xmloff/source/text/XMLAutoTextEventImport.cxx +++ b/xmloff/source/text/XMLAutoTextEventImport.cxx @@ -2,9 +2,9 @@ * * $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 * either of the following licenses @@ -71,32 +71,16 @@ #include <com/sun/star/xml/sax/XAttributeList.hpp> #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_XAUTOTEXTGROUP_HPP_ -#include <com/sun/star/text/XAutoTextGroup.hpp> -#endif - -#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ -#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#ifndef _COM_SUN_STAR_DOCUMENT_XEVENTSSUPPLIER_HPP_ +#include <com/sun/star/document/XEventsSupplier.hpp> #endif #ifndef _COM_SUN_STAR_UNO_XINTERFACE_HPP_ #include <com/sun/star/uno/XInterface.hpp> #endif -#ifndef _COMPHELPER_PROCESSFACTORY_HXX_ -#include <comphelper/processfactory.hxx> -#endif - -#ifndef _XMLOFF_XMLAUTOTEXTGROUPEVENTIMPORT_HXX -#include "XMLAutoTextGroupEventImport.hxx" +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> #endif #ifndef _XMLOFF_XMLAUTOTEXTCONTAINEREVENTIMPORT_HXX @@ -111,16 +95,23 @@ #include "xmlkywd.hxx" #endif +#ifndef _TOOLS_DEBUG_HXX +#include <tools/debug.hxx> +#endif + using namespace ::com::sun::star; using ::rtl::OUString; -using ::comphelper::getProcessServiceFactory; +using ::com::sun::star::uno::Any; using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::Type; using ::com::sun::star::uno::XInterface; +using ::com::sun::star::uno::RuntimeException; using ::com::sun::star::uno::Exception; 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; 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() : 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() { } +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( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference<XAttributeList > & xAttrList ) { - if ( xAutoTextContainer.is() && - (XML_NAMESPACE_TEXT == nPrefix) && + if ( xEvents.is() && + (XML_NAMESPACE_OFFICE == nPrefix) && rLocalName.equalsAsciiL(sXML_auto_text_events, sizeof(sXML_auto_text_events)-1) ) { - return new XMLAutoTextContainerEventImport(*this, nPrefix, rLocalName, - xAutoTextContainer); + return new XMLAutoTextContainerEventImport( + *this, nPrefix, rLocalName, xEvents); } else { @@ -167,20 +177,19 @@ SvXMLImportContext* XMLAutoTextEventImport::CreateContext( } - Sequence< OUString > SAL_CALL XMLAutoTextEventImport_getSupportedServiceNames() throw() { - const OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( - "com.sun.star.office.sax.importer.AutoTextEventReader" ) ); - const Sequence< OUString > aSeq( &aServiceName, 1 ); + Sequence< OUString > aSeq( 1 ); + aSeq[0] = XMLAutoTextEventImport_getImplementationName(); return aSeq; } 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( diff --git a/xmloff/source/text/XMLAutoTextEventImport.hxx b/xmloff/source/text/XMLAutoTextEventImport.hxx index f337004515c4..f60a4f9ccde2 100644 --- a/xmloff/source/text/XMLAutoTextEventImport.hxx +++ b/xmloff/source/text/XMLAutoTextEventImport.hxx @@ -2,9 +2,9 @@ * * $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 * either of the following licenses @@ -89,13 +89,20 @@ namespace com { namespace sun { namespace star { class XMLAutoTextEventImport : public SvXMLImport { ::com::sun::star::uno::Reference< - ::com::sun::star::text::XAutoTextContainer> xAutoTextContainer; + ::com::sun::star::container::XNameReplace> xEvents; public: XMLAutoTextEventImport() throw(); ~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: |