From d5cde56df40591f47423aa3491cdf5ae2df966eb Mon Sep 17 00:00:00 2001 From: Daniel Vogelheim Date: Fri, 28 Sep 2001 15:39:54 +0000 Subject: [PATCH] #91636# improved error handlings - throw SAXParseException for any severe errors found during import - generate warnings for illegal style attribute values --- xmloff/inc/xmlerror.hxx | 15 ++++++++++--- xmloff/source/core/xmlerror.cxx | 36 ++++++++++++++++++++++++++++---- xmloff/source/core/xmlimp.cxx | 15 +++++++++---- xmloff/source/style/xmlimppr.cxx | 18 ++++++++++++++-- 4 files changed, 71 insertions(+), 13 deletions(-) diff --git a/xmloff/inc/xmlerror.hxx b/xmloff/inc/xmlerror.hxx index 129fd434603a..50899ab99c2a 100644 --- a/xmloff/inc/xmlerror.hxx +++ b/xmloff/inc/xmlerror.hxx @@ -2,9 +2,9 @@ * * $RCSfile: xmlerror.hxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: dvo $ $Date: 2001-09-28 08:39:06 $ + * last change: $Author: dvo $ $Date: 2001-09-28 16:39:54 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -97,7 +97,8 @@ // I/O errors: // format errors: -#define XMLERROR_SAX ( XMLERROR_CLASS_FORMAT | 0x00000001 ) +#define XMLERROR_SAX ( XMLERROR_CLASS_FORMAT | 0x00000001 ) +#define XMLERROR_STYLE_ATTR_VALUE ( XMLERROR_CLASS_FORMAT | 0x00000002 ) // API errors: #define XMLERROR_STYLE_PROP_VALUE ( XMLERROR_CLASS_API | 0x00000001 ) @@ -126,6 +127,7 @@ namespace com { namespace sun { namespace star { namespace uno { template class Sequence; } namespace uno { template class Reference; } namespace xml { namespace sax { class XLocator; } } + namespace xml { namespace sax { class SAXParseException; } } } } } class ErrorRecord; @@ -177,6 +179,13 @@ public: const ::com::sun::star::uno::Sequence< ::rtl::OUString> & rParams); /// parameters for error message + + /** + * throw a SAXParseException that describes the first error that matches + * the given mask + */ + void ThrowErrorAsSAXException( sal_Int32 nIdMask ) + throw( ::com::sun::star::xml::sax::SAXParseException ); }; diff --git a/xmloff/source/core/xmlerror.cxx b/xmloff/source/core/xmlerror.cxx index 832838438f7a..dfe3819d160b 100644 --- a/xmloff/source/core/xmlerror.cxx +++ b/xmloff/source/core/xmlerror.cxx @@ -2,9 +2,9 @@ * * $RCSfile: xmlerror.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: dvo $ $Date: 2001-09-24 14:05:34 $ + * last change: $Author: dvo $ $Date: 2001-09-28 16:39:54 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -75,6 +75,14 @@ #include #endif +#ifndef _COM_SUN_STAR_XML_SAX_SAXPARSEEXCEPTION_HPP_ +#include +#endif + +#ifndef _COM_SUN_STAR_UNO_ANY_HXX_ +#include +#endif + #ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_ #include #endif @@ -85,12 +93,12 @@ - - using ::rtl::OUString; +using ::com::sun::star::uno::Any; using ::com::sun::star::uno::Sequence; using ::com::sun::star::uno::Reference; using ::com::sun::star::xml::sax::XLocator; +using ::com::sun::star::xml::sax::SAXParseException; // @@ -203,3 +211,23 @@ void XMLErrors::AddRecord( AddRecord( nId, rParams, sEmpty, -1, -1, sEmpty, sEmpty ); } +void XMLErrors::ThrowErrorAsSAXException(sal_Int32 nIdMask) + throw( SAXParseException ) +{ + // search first error/warning that matches the nIdMask + for( ErrorList::iterator aIter = aErrors.begin(); + aIter != aErrors.end(); + aIter++ ) + { + if ( (aIter->nId & nIdMask) != 0 ) + { + // we throw the error + ErrorRecord& rErr = aErrors[0]; + Any aAny; + aAny <<= rErr.aParams; + throw SAXParseException( + rErr.sExceptionMessage, NULL, aAny, + rErr.sPublicId, rErr.sSystemId, rErr.nRow, rErr.nColumn ); + } + } +} diff --git a/xmloff/source/core/xmlimp.cxx b/xmloff/source/core/xmlimp.cxx index 32d59b8b46d5..e35b32bcc3da 100644 --- a/xmloff/source/core/xmlimp.cxx +++ b/xmloff/source/core/xmlimp.cxx @@ -2,9 +2,9 @@ * * $RCSfile: xmlimp.cxx,v $ * - * $Revision: 1.58 $ + * $Revision: 1.59 $ * - * last change: $Author: sab $ $Date: 2001-09-25 10:29:18 $ + * last change: $Author: dvo $ $Date: 2001-09-28 16:39:54 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -511,6 +511,11 @@ void SAL_CALL SvXMLImport::endDocument( void ) throw( xml::sax::SAXException, uno::RuntimeException) { RTL_LOGFILE_TRACE_AUTHOR( "xmloff", LOGFILE_AUTHOR, "} SvXMLImport::startDocument" ); + + if ( pXMLErrors != NULL ) + { + pXMLErrors->ThrowErrorAsSAXException( XMLERROR_FLAG_SEVERE ); + } } void SAL_CALL SvXMLImport::startElement( const OUString& rName, @@ -1312,12 +1317,14 @@ void SvXMLImport::SetError( if ( ( nId & XMLERROR_FLAG_SEVERE ) != 0 ) mnErrorFlags |= ERROR_DO_NOTHING; - // create error lsit on demand + // create error list on demand if ( pXMLErrors == NULL ) pXMLErrors = new XMLErrors(); // save error information - pXMLErrors->AddRecord( nId, rMsgParams, rExceptionMessage, rLocator ); + // use document locator (if none supplied) + pXMLErrors->AddRecord( nId, rMsgParams, rExceptionMessage, + rLocator.is() ? rLocator : xLocator ); } void SvXMLImport::SetError( diff --git a/xmloff/source/style/xmlimppr.cxx b/xmloff/source/style/xmlimppr.cxx index 4fd08d251472..e1a82f47dee2 100644 --- a/xmloff/source/style/xmlimppr.cxx +++ b/xmloff/source/style/xmlimppr.cxx @@ -2,9 +2,9 @@ * * $RCSfile: xmlimppr.cxx,v $ * - * $Revision: 1.21 $ + * $Revision: 1.22 $ * - * last change: $Author: dvo $ $Date: 2001-09-21 16:27:53 $ + * last change: $Author: dvo $ $Date: 2001-09-28 16:39:54 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -277,6 +277,20 @@ void SvXMLImportPropertyMapper::importXML( else rProperties[nReference] = aNewProperty; } + else + { + // warn about unknown value (unless it's a + // multi property; then we get another chance) + if( (nFlags & MID_FLAG_MULTI_PROPERTY) == 0 ) + { + Sequence aSeq(2); + aSeq[0] = rAttrName; + aSeq[1] = rValue; + rImport.SetError( XMLERROR_FLAG_WARNING | + XMLERROR_STYLE_ATTR_VALUE, + aSeq ); + } + } } } else