1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 5 * This Source Code Form is subject to the terms of the Mozilla Public 6 * License, v. 2.0. If a copy of the MPL was not distributed with this 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 11 * Licensed to the Apache Software Foundation (ASF) under one or more 12 * contributor license agreements. See the NOTICE file distributed 13 * with this work for additional information regarding copyright 14 * ownership. The ASF licenses this file to you under the Apache 15 * License, Version 2.0 (the "License"); you may not use this file 16 * except in compliance with the License. You may obtain a copy of 17 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 18 */ 19 20 #ifndef INCLUDED_XMLOFF_XMLERROR_HXX 21 #define INCLUDED_XMLOFF_XMLERROR_HXX 22 23 #include <sal/types.h> 24 #include <rtl/ustring.hxx> 25 #include <o3tl/typed_flags_set.hxx> 26 27 #include <vector> 28 29 // masks for the error ID fields 30 #define XMLERROR_MASK_FLAG 0xF0000000 31 #define XMLERROR_MASK_CLASS 0x00FF0000 32 #define XMLERROR_MASK_NUMBER 0x0000FFFF 33 34 // error flags: 35 #define XMLERROR_FLAG_WARNING 0x10000000 36 #define XMLERROR_FLAG_ERROR 0x20000000 37 #define XMLERROR_FLAG_SEVERE 0x40000000 38 39 // error classes: Error ID 40 #define XMLERROR_CLASS_IO 0x00010000 41 #define XMLERROR_CLASS_FORMAT 0x00020000 42 #define XMLERROR_CLASS_API 0x00040000 43 #define XMLERROR_CLASS_OTHER 0x00080000 44 45 // error numbers, listed by error class 46 // Within each class, errors should be numbered consecutively. Please 47 // always add to error code below the appropriate comment. 48 49 // I/O errors: 50 51 // format errors: 52 #define XMLERROR_SAX ( XMLERROR_CLASS_FORMAT | 0x00000001 ) 53 #define XMLERROR_STYLE_ATTR_VALUE ( XMLERROR_CLASS_FORMAT | 0x00000002 ) 54 #define XMLERROR_NO_INDEX_ALLOWED_HERE ( XMLERROR_CLASS_FORMAT | 0x00000003 ) 55 #define XMLERROR_PARENT_STYLE_NOT_ALLOWED ( XMLERROR_CLASS_FORMAT | 0x00000004 ) 56 #define XMLERROR_ILLEGAL_EVENT (XMLERROR_CLASS_FORMAT | 0x00000005 ) 57 #define XMLERROR_NAMESPACE_TROUBLE (XMLERROR_CLASS_FORMAT | 0x00000006 ) 58 59 #define XMLERROR_XFORMS_NO_SCHEMA_SUPPORT ( XMLERROR_CLASS_FORMAT | XMLERROR_FLAG_WARNING | 0x00000007 ) 60 #define XMLERROR_XFORMS_UNKNOWN ( XMLERROR_CLASS_FORMAT | XMLERROR_FLAG_WARNING | 0x00000008 ) 61 #define XMLERROR_XFORMS_ONLY_ONE_INSTANCE_ELEMENT ( XMLERROR_CLASS_FORMAT | XMLERROR_FLAG_WARNING | 0x00000009 ) 62 #define XMLERROR_UNKNOWN_ATTRIBUTE ( XMLERROR_CLASS_FORMAT | XMLERROR_FLAG_WARNING | 0x0000000a ) 63 #define XMLERROR_UNKNOWN_ELEMENT ( XMLERROR_CLASS_FORMAT | XMLERROR_FLAG_WARNING | 0x0000000b ) 64 #define XMLERROR_UNKNOWN_CHARACTERS ( XMLERROR_CLASS_FORMAT | XMLERROR_FLAG_WARNING | 0x0000000c ) 65 #define XMLERROR_UNKNOWN_ROOT (XMLERROR_CLASS_FORMAT | 0x0000000d ) 66 67 // API errors: 68 #define XMLERROR_STYLE_PROP_VALUE ( XMLERROR_CLASS_API | 0x00000001 ) 69 #define XMLERROR_STYLE_PROP_UNKNOWN ( XMLERROR_CLASS_API | 0x00000002 ) 70 #define XMLERROR_STYLE_PROP_OTHER ( XMLERROR_CLASS_API | 0x00000003 ) 71 #define XMLERROR_API ( XMLERROR_CLASS_API | 0x00000004 ) 72 73 // other errors: 74 #define XMLERROR_CANCEL ( XMLERROR_CLASS_OTHER | 0x00000001 ) 75 76 // 16bit error flag constants for use in the 77 // SvXMLExport/SvXMLImport error flags 78 enum class SvXMLErrorFlags { 79 NO = 0x0000, 80 DO_NOTHING = 0x0001, 81 ERROR_OCCURRED = 0x0002, 82 WARNING_OCCURRED = 0x0004, 83 }; 84 85 namespace o3tl 86 { 87 template<> struct typed_flags<SvXMLErrorFlags> : is_typed_flags<SvXMLErrorFlags, 0x7> {}; 88 } 89 90 namespace com::sun::star { 91 namespace uno { template<class X> class Sequence; } 92 namespace uno { template<class X> class Reference; } 93 namespace xml::sax { class XLocator; } 94 } 95 96 class ErrorRecord; 97 98 /** 99 * The XMLErrors is used to collect all errors and warnings that occur 100 * for appropriate processing. 101 */ 102 class XMLErrors 103 { 104 /// definition of type for error list 105 typedef ::std::vector<ErrorRecord> ErrorList; 106 107 ErrorList aErrors; /// list of error records 108 109 public: 110 111 XMLErrors(); 112 ~XMLErrors(); 113 114 /// add a new entry to the list of error messages 115 void AddRecord( 116 sal_Int32 nId, /// error ID == error flags + error class + error number 117 const css::uno::Sequence< OUString> & rParams, /// parameters for error message 118 const OUString& rExceptionMessage, /// original exception string 119 sal_Int32 nRow, /// XLocator: file row number 120 sal_Int32 nColumn, /// XLocator: file column number 121 const OUString& rPublicId, /// XLocator: file public ID 122 const OUString& rSystemId ); /// XLocator: file system ID 123 124 void AddRecord( 125 sal_Int32 nId, /// error ID == error flags + error class + error number 126 const css::uno::Sequence<OUString> & rParams, /// parameters for error message 127 const OUString& rExceptionMessage, /// original exception string 128 const css::uno::Reference<css::xml::sax::XLocator> & rLocator); /// location 129 130 /** 131 * throw a SAXParseException that describes the first error that matches 132 * the given mask 133 */ 134 /// @throws css::xml::sax::SAXParseException 135 void ThrowErrorAsSAXException( sal_Int32 nIdMask ); 136 }; 137 138 #endif 139 140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 141