summaryrefslogtreecommitdiff
path: root/xmloff
diff options
context:
space:
mode:
authorSascha Ballach <sab@openoffice.org>2001-09-13 14:18:52 +0000
committerSascha Ballach <sab@openoffice.org>2001-09-13 14:18:52 +0000
commit93a0a535b059a8b106a5fb9eb55417a868e1520f (patch)
treee04a058fa3f6cd1ea10f60e21269a4f62ee1c61c /xmloff
parentcc275134c90216a856aca754df9ad85408c83039 (diff)
#91968#; use a EventListener for the model; first step of new Error handling
Diffstat (limited to 'xmloff')
-rw-r--r--xmloff/source/core/xmlexp.cxx157
-rw-r--r--xmloff/source/core/xmlimp.cxx84
2 files changed, 231 insertions, 10 deletions
diff --git a/xmloff/source/core/xmlexp.cxx b/xmloff/source/core/xmlexp.cxx
index cceccb7a3662..2f90d0d458ff 100644
--- a/xmloff/source/core/xmlexp.cxx
+++ b/xmloff/source/core/xmlexp.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: xmlexp.cxx,v $
*
- * $Revision: 1.78 $
+ * $Revision: 1.79 $
*
- * last change: $Author: dvo $ $Date: 2001-09-13 14:55:31 $
+ * last change: $Author: sab $ $Date: 2001-09-13 15:18:52 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -193,6 +193,9 @@
#ifndef _RTL_LOGFILE_HXX_
#include <rtl/logfile.hxx>
#endif
+#ifndef _CPPUHELPER_IMPLBASE1_HXX_
+#include <cppuhelper/implbase1.hxx>
+#endif
using namespace ::rtl;
using namespace ::osl;
@@ -241,6 +244,42 @@ const XMLServiceMapEntry_Impl aServiceMap[] =
{ 0, 0, 0, 0 }
};
+//==============================================================================
+
+class SvXMLExportEventListener : public cppu::WeakImplHelper1<
+ com::sun::star::lang::XEventListener >
+{
+private:
+ SvXMLExport* pExport;
+
+public:
+ SvXMLExportEventListener(SvXMLExport* pExport);
+ virtual ~SvXMLExportEventListener();
+
+ // XEventListener
+ virtual void SAL_CALL disposing(const lang::EventObject& rEventObject) throw(::com::sun::star::uno::RuntimeException);
+};
+
+SvXMLExportEventListener::SvXMLExportEventListener(SvXMLExport* pTempExport)
+ : pExport(pTempExport)
+{
+}
+
+SvXMLExportEventListener::~SvXMLExportEventListener()
+{
+}
+
+// XEventListener
+void SAL_CALL SvXMLExportEventListener::disposing( const lang::EventObject& rEventObject )
+ throw(uno::RuntimeException)
+{
+ if (pExport)
+ pExport->DisposingModel();
+}
+
+//==============================================================================
+
+
void SvXMLExport::_InitCtor()
{
pNamespaceMap->Add( GetXMLToken(XML_NP_OFFICE), GetXMLToken(XML_N_OFFICE), XML_NAMESPACE_OFFICE );
@@ -295,6 +334,12 @@ void SvXMLExport::_InitCtor()
sObjectsPath = OUString( RTL_CONSTASCII_USTRINGPARAM( "#./" ) );
sGraphicObjectProtocol = OUString( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.GraphicObject:" ) );
sEmbeddedObjectProtocol = OUString( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.EmbeddedObject:" ) );
+
+ if (xModel.is() && !pEventListener)
+ {
+ pEventListener = new SvXMLExportEventListener(this);
+ xModel->addEventListener(pEventListener);
+ }
}
SvXMLExport::SvXMLExport( MapUnit eDfltUnit, const enum XMLTokenEnum eClass, sal_uInt16 nExportFlags ) :
@@ -309,8 +354,11 @@ SvXMLExport::SvXMLExport( MapUnit eDfltUnit, const enum XMLTokenEnum eClass, sal
pProgressBarHelper( NULL ),
pEventExport( NULL ),
pImageMapExport( NULL ),
+ pEventListener( NULL ),
+ pXMLErrors( NULL ),
bSaveLinkedSections(sal_True),
- mnExportFlags( nExportFlags )
+ mnExportFlags( nExportFlags ),
+ mnErrorFlags( ERROR_NO )
{
_InitCtor();
}
@@ -333,8 +381,11 @@ SvXMLExport::SvXMLExport(
pProgressBarHelper( NULL ),
pEventExport( NULL ),
pImageMapExport( NULL ),
+ pEventListener( NULL ),
+ pXMLErrors( NULL ),
bSaveLinkedSections(sal_True),
- mnExportFlags( EXPORT_ALL )
+ mnExportFlags( EXPORT_ALL ),
+ mnErrorFlags( ERROR_NO )
{
_InitCtor();
@@ -363,8 +414,11 @@ SvXMLExport::SvXMLExport(
pProgressBarHelper( NULL ),
pEventExport( NULL ),
pImageMapExport( NULL ),
+ pEventListener( NULL ),
+ pXMLErrors( NULL ),
bSaveLinkedSections(sal_True),
- mnExportFlags( EXPORT_ALL )
+ mnExportFlags( EXPORT_ALL ),
+ mnErrorFlags( ERROR_NO )
{
_InitCtor();
@@ -395,8 +449,11 @@ SvXMLExport::SvXMLExport(
pProgressBarHelper( NULL ),
pEventExport( NULL ),
pImageMapExport( NULL ),
+ pEventListener( NULL ),
+ pXMLErrors( NULL ),
bSaveLinkedSections(sal_True),
- mnExportFlags( EXPORT_ALL )
+ mnExportFlags( EXPORT_ALL ),
+ mnErrorFlags( ERROR_NO )
{
_InitCtor();
@@ -452,6 +509,9 @@ SvXMLExport::~SvXMLExport()
}
xmloff::token::ResetTokens();
+
+ if (pEventListener && xModel.is())
+ xModel->removeEventListener(pEventListener);
}
///////////////////////////////////////////////////////////////////////
@@ -463,6 +523,11 @@ void SAL_CALL SvXMLExport::setSourceDocument( const uno::Reference< lang::XCompo
xModel = uno::Reference< frame::XModel >::query( xDoc );
if( !xModel.is() )
throw lang::IllegalArgumentException();
+ if (xModel.is() && !pEventListener)
+ {
+ pEventListener = new SvXMLExportEventListener(this);
+ xModel->addEventListener(pEventListener);
+ }
if(!xNumberFormatsSupplier.is() )
{
@@ -1476,6 +1541,86 @@ OUString SvXMLExport::GetRelativeReference(const OUString& rValue)
return INetURLObject::AbsToRel( rValue );
}
+void SvXMLExport::StartElement(sal_uInt16 nPrefix,
+ enum ::xmloff::token::XMLTokenEnum eName,
+ sal_Bool bIgnWSOutside )
+{
+ if ((mnErrorFlags & ERROR_DO_NOTHING) != ERROR_DO_NOTHING)
+ {
+ OUString sName(pNamespaceMap->GetQNameByKey( nPrefix, GetXMLToken(eName) ));
+ try
+ {
+ if( bIgnWSOutside )
+ xHandler->ignorableWhitespace( sWS );
+ xHandler->startElement( sName, GetXAttrList() );
+ ClearAttrList();
+ }
+ catch ( uno::Exception& )
+ {
+ // we have to add a error here,
+ // perhaps we should change the ErrorFlag to ERROR_DO_NOTHING
+ ClearAttrList();
+ DBG_ERROR("Not handled exception");
+ }
+ }
+}
+
+void SvXMLExport::Characters(const ::rtl::OUString& rChars)
+{
+ if ((mnErrorFlags & ERROR_DO_NOTHING) != ERROR_DO_NOTHING)
+ {
+ try
+ {
+ xHandler->characters(rChars);
+ }
+ catch ( uno::Exception& )
+ {
+ // we have to add a error here,
+ // perhaps we should change the ErrorFlag to ERROR_DO_NOTHING
+ DBG_ERROR("Not handled exception");
+ }
+ }
+}
+
+void SvXMLExport::EndElement(sal_uInt16 nPrefix,
+ enum ::xmloff::token::XMLTokenEnum eName,
+ sal_Bool bIgnWSInside )
+{
+ if ((mnErrorFlags & ERROR_DO_NOTHING) != ERROR_DO_NOTHING)
+ {
+ OUString sName(pNamespaceMap->GetQNameByKey( nPrefix, GetXMLToken(eName) ));
+ try
+ {
+ if( bIgnWSInside )
+ xHandler->ignorableWhitespace( sWS );
+ xHandler->endElement( sName );
+ }
+ catch ( uno::Exception& )
+ {
+ // we have to add a error here,
+ // perhaps we should change the ErrorFlag to ERROR_DO_NOTHING
+ DBG_ERROR("Not handled exception");
+ }
+ }
+}
+
+void SvXMLExport::SetError(sal_uInt16 nId, ::rtl::OUString& rErrorMessage, ::rtl::OUString& rExceptionMessage)
+{
+}
+
+XMLErrors* SvXMLExport::GetErrors()
+{
+ return pXMLErrors;
+}
+
+void SvXMLExport::DisposingModel()
+{
+ xModel = 0;
+ pEventListener = NULL;
+}
+
+//=============================================================================
+
void SvXMLElementExport::StartElement( SvXMLExport& rExp,
sal_uInt16 nPrefixKey,
const OUString& rLName,
diff --git a/xmloff/source/core/xmlimp.cxx b/xmloff/source/core/xmlimp.cxx
index 227323e88369..656c42141807 100644
--- a/xmloff/source/core/xmlimp.cxx
+++ b/xmloff/source/core/xmlimp.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: xmlimp.cxx,v $
*
- * $Revision: 1.54 $
+ * $Revision: 1.55 $
*
- * last change: $Author: dvo $ $Date: 2001-09-13 14:55:31 $
+ * last change: $Author: sab $ $Date: 2001-09-13 15:18:52 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -130,6 +130,9 @@
#ifndef _COM_SUN_STAR_DOCUMENT_XBINARYSTREAMRESOLVER_HPP_
#include <com/sun/star/document/XBinaryStreamResolver.hpp>
#endif
+#ifndef _COM_SUN_STAR_DOCUMENT_XEVENTLISTENER_HPP_
+#include <com/sun/star/lang/XEventListener.hpp>
+#endif
#ifndef _COMPHELPER_NAMECONTAINER_HXX_
#include <comphelper/namecontainer.hxx>
@@ -141,6 +144,9 @@
#ifndef _STRING_HXX
#include <tools/string.hxx> // used in StartElement for logging
#endif
+#ifndef _CPPUHELPER_IMPLBASE1_HXX_
+#include <cppuhelper/implbase1.hxx>
+#endif
#ifdef CONV_STAR_FONTS
#ifndef _VCL_FONTCVT_HXX
@@ -186,6 +192,40 @@ sal_Char __READONLY_DATA sXML_np__meta_old[] = "__meta";
#define LOGFILE_AUTHOR "mb93740"
#ifdef CONV_STAR_FONTS
+
+class SvXMLImportEventListener : public cppu::WeakImplHelper1<
+ com::sun::star::lang::XEventListener >
+{
+private:
+ SvXMLImport* pImport;
+
+public:
+ SvXMLImportEventListener(SvXMLImport* pImport);
+ virtual ~SvXMLImportEventListener();
+
+ // XEventListener
+ virtual void SAL_CALL disposing(const lang::EventObject& rEventObject) throw(::com::sun::star::uno::RuntimeException);
+};
+
+SvXMLImportEventListener::SvXMLImportEventListener(SvXMLImport* pTempImport)
+ : pImport(pTempImport)
+{
+}
+
+SvXMLImportEventListener::~SvXMLImportEventListener()
+{
+}
+
+// XEventListener
+void SAL_CALL SvXMLImportEventListener::disposing( const lang::EventObject& rEventObject )
+ throw(uno::RuntimeException)
+{
+ if (pImport)
+ pImport->DisposingModel();
+}
+
+//==============================================================================
+
class SvXMLImport_Impl
{
public:
@@ -294,6 +334,12 @@ void SvXMLImport::_InitCtor()
if (xNumberFormatsSupplier.is())
pNumImport = new SvXMLNumFmtHelper(xNumberFormatsSupplier);
+
+ if (xModel.is() && !pEventListener)
+ {
+ pEventListener = new SvXMLImportEventListener(this);
+ xModel->addEventListener(pEventListener);
+ }
}
SvXMLImport::SvXMLImport( sal_uInt16 nImportFlags ) throw () :
@@ -304,6 +350,8 @@ SvXMLImport::SvXMLImport( sal_uInt16 nImportFlags ) throw () :
pNumImport( NULL ),
pProgressBarHelper( NULL ),
pEventImportHelper( NULL ),
+ pEventListener( NULL ),
+ pXMLErrors( NULL ),
mnImportFlags( nImportFlags ),
mbIsFormsSupported( sal_True )
{
@@ -320,6 +368,8 @@ SvXMLImport::SvXMLImport( const Reference< XModel > & rModel ) throw () :
xNumberFormatsSupplier (rModel, uno::UNO_QUERY),
pProgressBarHelper( NULL ),
pEventImportHelper( NULL ),
+ pEventListener( NULL ),
+ pXMLErrors( NULL ),
mnImportFlags( IMPORT_ALL ),
mbIsFormsSupported( sal_True )
{
@@ -338,6 +388,8 @@ SvXMLImport::SvXMLImport( const Reference< XModel > & rModel,
xNumberFormatsSupplier (rModel, uno::UNO_QUERY),
pProgressBarHelper( NULL ),
pEventImportHelper( NULL ),
+ pEventListener( NULL ),
+ pXMLErrors( NULL ),
mnImportFlags( IMPORT_ALL ),
mbIsFormsSupported( sal_True )
{
@@ -400,6 +452,8 @@ SvXMLImport::~SvXMLImport() throw ()
if( pImpl )
delete pImpl;
#endif
+ if (pEventListener && xModel.is())
+ xModel->removeEventListener(pEventListener);
}
// XUnoTunnel & co
@@ -636,6 +690,11 @@ void SAL_CALL SvXMLImport::setTargetDocument( const uno::Reference< lang::XCompo
xModel = uno::Reference< frame::XModel >::query( xDoc );
if( !xModel.is() )
throw lang::IllegalArgumentException();
+ if (xModel.is() && !pEventListener)
+ {
+ pEventListener = new SvXMLImportEventListener(this);
+ xModel->addEventListener(pEventListener);
+ }
DBG_ASSERT( !pNumImport, "number format import already exists." );
if( pNumImport )
@@ -1171,8 +1230,9 @@ void SvXMLImport::_CreateNumberFormatsSupplier()
{
DBG_ASSERT( !xNumberFormatsSupplier.is(),
"number formats supplier already exists!" );
- xNumberFormatsSupplier =
- uno::Reference< util::XNumberFormatsSupplier> (xModel, uno::UNO_QUERY);
+ if(xModel.is())
+ xNumberFormatsSupplier =
+ uno::Reference< util::XNumberFormatsSupplier> (xModel, uno::UNO_QUERY);
}
@@ -1227,4 +1287,20 @@ sal_Unicode SvXMLImport::ConvStarMathCharToStarSymbol( sal_Unicode c )
return cNew;
}
+
+void SvXMLImport::SetError(sal_uInt16 nId, ::rtl::OUString& rErrorMessage, ::rtl::OUString& rExceptionMessage)
+{
+}
+
+XMLErrors* SvXMLImport::GetErrors()
+{
+ return pXMLErrors;
+}
+
+void SvXMLImport::DisposingModel()
+{
+ xModel = 0;
+ pEventListener = NULL;
+}
+
#endif