#91636# improved error handlings

- throw SAXParseException for any severe errors found during import
- generate warnings for illegal style attribute values
This commit is contained in:
Daniel Vogelheim 2001-09-28 15:39:54 +00:00
parent c375054cfa
commit d5cde56df4
4 changed files with 71 additions and 13 deletions

View file

@ -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 X> class Sequence; }
namespace uno { template<class X> 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 );
};

View file

@ -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 <com/sun/star/xml/sax/XLocator.hpp>
#endif
#ifndef _COM_SUN_STAR_XML_SAX_SAXPARSEEXCEPTION_HPP_
#include <com/sun/star/xml/sax/SAXParseException.hpp>
#endif
#ifndef _COM_SUN_STAR_UNO_ANY_HXX_
#include <com/sun/star/uno/Any.hxx>
#endif
#ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_
#include <com/sun/star/uno/Reference.hxx>
#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 );
}
}
}

View file

@ -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(

View file

@ -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<OUString> aSeq(2);
aSeq[0] = rAttrName;
aSeq[1] = rValue;
rImport.SetError( XMLERROR_FLAG_WARNING |
XMLERROR_STYLE_ATTR_VALUE,
aSeq );
}
}
}
}
else