| 1 |
wakaba |
1.1 |
|
| 2 |
|
|
=head1 NAME
|
| 3 |
|
|
|
| 4 |
|
|
SuikaWiki::Markup::XML::Error --- SuikaWiki XML: Error handling module for SuikaWiki::Markup::XML::*
|
| 5 |
|
|
|
| 6 |
|
|
=head1 DESCRIPTION
|
| 7 |
|
|
|
| 8 |
|
|
This module is part of SuikaWiki XML support.
|
| 9 |
|
|
|
| 10 |
|
|
=cut
|
| 11 |
|
|
|
| 12 |
|
|
package SuikaWiki::Markup::XML::Error;
|
| 13 |
|
|
use strict;
|
| 14 |
|
|
our $VERSION = do{my @r=(q$Revision: 1.1 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
|
| 15 |
|
|
|
| 16 |
|
|
my %_Error = (
|
| 17 |
|
|
## Syntax errors
|
| 18 |
|
|
SYNTAX_DATA_OUT_OF_ROOT_ELEMENT => {
|
| 19 |
|
|
description => 'Invalid data or markup out of root element',
|
| 20 |
|
|
level => 'wfc',
|
| 21 |
|
|
},
|
| 22 |
|
|
SYNTAX_END_OF_MARKUP_NOT_FOUND => {
|
| 23 |
|
|
description => sub {
|
| 24 |
|
|
my ($o, $err) = @_;
|
| 25 |
|
|
my $o_start = $err->{t}->flag ('p_o_start');
|
| 26 |
|
|
my $r = $err->{t}->qname;
|
| 27 |
|
|
$r = sprintf 'line %d, position %d%s', $o_start->{line},
|
| 28 |
|
|
$o_start->{pos}, ($r ? '; '.$r : '') if ref $o_start;
|
| 29 |
|
|
$r ? $r = '; '.$r : 0;
|
| 30 |
|
|
$err->{t} = $err->{t}->node_type;
|
| 31 |
|
|
'Markup is not closed (%s'.$r.')';
|
| 32 |
|
|
},
|
| 33 |
|
|
level => 'wfc',
|
| 34 |
|
|
},
|
| 35 |
|
|
SYNTAX_END_TAG_NOT_FOUND => {
|
| 36 |
|
|
description => sub {
|
| 37 |
|
|
my ($o, $err) = @_;
|
| 38 |
|
|
my $o_start = $err->{t}->flag ('p_o_start');
|
| 39 |
|
|
my $r = '';
|
| 40 |
|
|
$r = sprintf 'line %d, position %d%s', $o_start->{line},
|
| 41 |
|
|
$o_start->{pos}, ($r ? '; '.$r : '') if ref $o_start;
|
| 42 |
|
|
$r ? $r = '; '.$r : 0;
|
| 43 |
|
|
$err->{t} = $err->{t}->qname;
|
| 44 |
|
|
'End tag of element (type = %s'.$r.') not found';
|
| 45 |
|
|
},
|
| 46 |
|
|
level => 'wfc',
|
| 47 |
|
|
},
|
| 48 |
|
|
SYNTAX_INVALID => {
|
| 49 |
|
|
description => 'This type of markup (%s) cannot appear here',
|
| 50 |
|
|
level => 'wfc',
|
| 51 |
|
|
},
|
| 52 |
|
|
SYNTAX_INVALID_CHAR => {
|
| 53 |
|
|
description => 'Invalid character (%s) at this context',
|
| 54 |
|
|
level => 'wfc',
|
| 55 |
|
|
},
|
| 56 |
|
|
SYNTAX_INVALID_DOCTYPE_POSITION => {
|
| 57 |
|
|
description => 'DOCTYPE declaration must be between xml declaration and the root element',
|
| 58 |
|
|
level => 'wfc',
|
| 59 |
|
|
},
|
| 60 |
|
|
SYNTAX_INVALID_KEYWORD => {
|
| 61 |
|
|
description => 'Invalid keyword (%s) at this context',
|
| 62 |
|
|
level => 'wfc',
|
| 63 |
|
|
},
|
| 64 |
|
|
SYNTAX_INVALID_LITERAL => {
|
| 65 |
|
|
description => 'Literal cannot be here ("%s")',
|
| 66 |
|
|
level => 'wfc',
|
| 67 |
|
|
},
|
| 68 |
|
|
SYNTAX_INVALID_MD => {
|
| 69 |
|
|
description => 'Invalid syntax of markup declaration',
|
| 70 |
|
|
level => 'wfc',
|
| 71 |
|
|
},
|
| 72 |
|
|
SYNTAX_INVALID_POSITION => {
|
| 73 |
|
|
description => sub {
|
| 74 |
|
|
my ($o) = shift;
|
| 75 |
|
|
'This type of markup (%s) cannot be used '.({
|
| 76 |
|
|
document_entity => 'out of DTD',
|
| 77 |
|
|
dtd_internal_subset => 'in the internal subset of DTD',
|
| 78 |
|
|
dtd_external_subset => 'in the external subset of DTD',
|
| 79 |
|
|
external_parsed_entity => 'in the external parsed entity',
|
| 80 |
|
|
general_external_parsed_entity => 'in the general external parsed entity',
|
| 81 |
|
|
}->{$o->{entity_type}||'document_entity'}||'in '.$o->{entity_type})},
|
| 82 |
|
|
level => 'wfc',
|
| 83 |
|
|
},
|
| 84 |
|
|
SYNTAX_LEGAL_CHARACTER => {
|
| 85 |
|
|
description => sub {
|
| 86 |
|
|
my $r = sprintf 'The character U-%08X is not a legal XML Char',
|
| 87 |
|
|
$_[1]->{t};
|
| 88 |
|
|
$_[1]->{t} = undef;
|
| 89 |
|
|
$r;
|
| 90 |
|
|
},
|
| 91 |
|
|
level => 'wfc',
|
| 92 |
|
|
},
|
| 93 |
|
|
SYNTAX_MD_NAME_NOT_FOUND => {
|
| 94 |
|
|
description => 'Name is required by this type of declaration',
|
| 95 |
|
|
level => 'wfc',
|
| 96 |
|
|
},
|
| 97 |
|
|
SYNTAX_MD_SYSID_NOT_FOUND => {
|
| 98 |
|
|
description => 'System identifier is required by this type of declaration',
|
| 99 |
|
|
level => 'wfc',
|
| 100 |
|
|
},
|
| 101 |
|
|
SYNTAX_PE_NDATA => {
|
| 102 |
|
|
description => 'Parameter entity must be a parsed entity',
|
| 103 |
|
|
level => 'wfc',
|
| 104 |
|
|
},
|
| 105 |
|
|
SYNTAX_XML_DECLARE => {
|
| 106 |
|
|
description => 'Syntax of XML (or text) declaration is invalid',
|
| 107 |
|
|
level => 'wfc',
|
| 108 |
|
|
},
|
| 109 |
|
|
SYNTAX_XML_DECLARE_NO_ATTR => {
|
| 110 |
|
|
description => 'XML (or text) declaration does not have pseudo attribute',
|
| 111 |
|
|
level => 'wfc',
|
| 112 |
|
|
},
|
| 113 |
|
|
SYNTAX_XML_DECLARE_POSITION => {
|
| 114 |
|
|
description => 'XML declaration must be at the top of the entity',
|
| 115 |
|
|
level => 'wfc',
|
| 116 |
|
|
},
|
| 117 |
|
|
## Well-formedness error
|
| 118 |
|
|
WFC_ELEMENT_TYPE_MATCH => {
|
| 119 |
|
|
description => 'End tag (type = %s) does not match with start tag (type = %s)',
|
| 120 |
|
|
level => 'wfc',
|
| 121 |
|
|
},
|
| 122 |
|
|
WFC_ENTITY_DECLARED => {
|
| 123 |
|
|
description => 'Entity (%s) must be declared before it is referred',
|
| 124 |
|
|
level => 'wfc',
|
| 125 |
|
|
},
|
| 126 |
|
|
WFC_LEGAL_CHARACTER => {
|
| 127 |
|
|
description => sub {
|
| 128 |
|
|
my $r = sprintf 'The character referred (U-%08X) is not a legal XML Char',
|
| 129 |
|
|
$_[1]->{t};
|
| 130 |
|
|
$_[1]->{t} = undef;
|
| 131 |
|
|
$r;
|
| 132 |
|
|
},
|
| 133 |
|
|
level => 'wfc',
|
| 134 |
|
|
},
|
| 135 |
|
|
WFC_NO_EXTERNAL_ENTITY_REFERENCE => {
|
| 136 |
|
|
description => 'Attribute value must not contain reference to an external entity',
|
| 137 |
|
|
level => 'wfc',
|
| 138 |
|
|
},
|
| 139 |
|
|
WFC_NO_LE_IN_ATTRIBUTE_VALUE => {
|
| 140 |
|
|
description => 'Attribute value must not contain a less-than sign (<)',
|
| 141 |
|
|
level => 'wfc',
|
| 142 |
|
|
},
|
| 143 |
|
|
WFC_NO_RECURSION => {
|
| 144 |
|
|
description => 'Parsed entity (%s) must not contain a recursive reference to itself',
|
| 145 |
|
|
level => 'wfc',
|
| 146 |
|
|
},
|
| 147 |
|
|
WFC_NO_LT_IN_ATTRIBUTE_VALUE => {
|
| 148 |
|
|
description => 'Replacement text of entity reference in an attribute value literal cannot contain LESS-THAN SIGN (<) itself',
|
| 149 |
|
|
level => 'wfc',
|
| 150 |
|
|
},
|
| 151 |
|
|
WFC_PE_IN_INTERNAL_SUBSET => {
|
| 152 |
|
|
description => 'Parameter entity (%s) cannot be referred in markup declaration in internal subset of DTD',
|
| 153 |
|
|
level => 'wfc',
|
| 154 |
|
|
},
|
| 155 |
|
|
WFC_UNIQUE_ATT_SPEC => {
|
| 156 |
|
|
description => 'Dupulicate attribute specification',
|
| 157 |
|
|
level => 'wfc',
|
| 158 |
|
|
},
|
| 159 |
|
|
## Validity error
|
| 160 |
|
|
VC_ENTITY_DECLARED => {
|
| 161 |
|
|
description => 'Entity %s should (or must to be valid) be declared before it is referred',
|
| 162 |
|
|
level => 'vc',
|
| 163 |
|
|
},
|
| 164 |
|
|
VC_NOTATION_DECLARED => {
|
| 165 |
|
|
description => 'Notation %s should (or must to be valid) be declared',
|
| 166 |
|
|
level => 'vc',
|
| 167 |
|
|
},
|
| 168 |
|
|
VC_UNIQUE_NOTATION_NAME => {
|
| 169 |
|
|
description => 'Notation %s is already declared',
|
| 170 |
|
|
level => 'warn',
|
| 171 |
|
|
},
|
| 172 |
|
|
## Namespace well-formedness error
|
| 173 |
|
|
NC_PREFIX_NOT_DEFINED => {
|
| 174 |
|
|
description => 'Undeclared namespace prefix (%s) is used',
|
| 175 |
|
|
level => 'nswfc',
|
| 176 |
|
|
},
|
| 177 |
|
|
NS_SYNTAX_NAME_IS_NCNAME => {
|
| 178 |
|
|
description => 'Name with colon (%s) cannot be used within namespaced XML document',
|
| 179 |
|
|
level => 'nswfc',
|
| 180 |
|
|
},
|
| 181 |
|
|
## Namespace validity error
|
| 182 |
|
|
## XML warning
|
| 183 |
|
|
WARN_PREDEFINED_ENTITY_NOT_DECLARED => {
|
| 184 |
|
|
description => 'Predefined general entity (%s) should be declared before it is referred for interoperability',
|
| 185 |
|
|
level => 'warn',
|
| 186 |
|
|
},
|
| 187 |
|
|
WARN_UNICODE_COMPAT_CHARACTER => {
|
| 188 |
|
|
description => sub {
|
| 189 |
|
|
my $r = sprintf 'Use of the character U+%04X is deprecated, since it is classified as compatible character in the Unicode Standard',
|
| 190 |
|
|
$_[1]->{t};
|
| 191 |
|
|
$_[1]->{t} = undef;
|
| 192 |
|
|
$r;
|
| 193 |
|
|
},
|
| 194 |
|
|
level => 'warn',
|
| 195 |
|
|
},
|
| 196 |
|
|
WARN_UNICODE_NONCHARACTER => {
|
| 197 |
|
|
description => sub {
|
| 198 |
|
|
my $r = sprintf 'Use of the code point U+%04X is deprecated, since it is noncharacter in the Unicode Standard',
|
| 199 |
|
|
$_[1]->{t};
|
| 200 |
|
|
$_[1]->{t} = undef;
|
| 201 |
|
|
$r;
|
| 202 |
|
|
},
|
| 203 |
|
|
level => 'warn',
|
| 204 |
|
|
},
|
| 205 |
|
|
WARN_UNICODE_XML_NOT_SUITABLE_CHARACTER => {
|
| 206 |
|
|
description => sub {
|
| 207 |
|
|
my $r = sprintf 'Use of the character U+%04X is deprecated by W3C Note unicode-xml',
|
| 208 |
|
|
$_[1]->{t};
|
| 209 |
|
|
$_[1]->{t} = undef;
|
| 210 |
|
|
$r;
|
| 211 |
|
|
},
|
| 212 |
|
|
level => 'warn',
|
| 213 |
|
|
},
|
| 214 |
|
|
WARN_UNIQUE_ENTITY_NAME => {
|
| 215 |
|
|
description => 'General entity %s is already declared',
|
| 216 |
|
|
level => 'warn',
|
| 217 |
|
|
},
|
| 218 |
|
|
WARN_UNIQUE_PARAMETER_ENTITY_NAME => {
|
| 219 |
|
|
description => 'Parameter entity %s is already declared',
|
| 220 |
|
|
level => 'warn',
|
| 221 |
|
|
},
|
| 222 |
|
|
## Implementation's warning
|
| 223 |
|
|
## Misc
|
| 224 |
|
|
UNKNOWN => {
|
| 225 |
|
|
description => 'Unknown error',
|
| 226 |
|
|
level => 'wfc',
|
| 227 |
|
|
},
|
| 228 |
|
|
);
|
| 229 |
|
|
## TODO: error handling should be customizable (hookable) by user of this module
|
| 230 |
|
|
sub raise ($$%) {
|
| 231 |
|
|
my (undef, $o, %err) = @_;
|
| 232 |
|
|
my $error_type = $_Error{$err{type}} || $_Error{UNKNOWN};
|
| 233 |
|
|
my $error_msg = ref $error_type->{description} ? &{$error_type->{description}} ($o, \%err)
|
| 234 |
|
|
: $error_type->{description};
|
| 235 |
|
|
my @err_msg;
|
| 236 |
|
|
ref $err{t} eq 'ARRAY' ? @err_msg = @{$err{t}} : defined $err{t} ? @err_msg = $err{t} : undef;
|
| 237 |
|
|
$error_msg .= ' (%s)' if scalar (@err_msg) && ($error_msg !~ /%s/);
|
| 238 |
|
|
$error_msg = sprintf $error_msg, @err_msg;
|
| 239 |
|
|
$error_msg = "Line $o->{line}, position $o->{pos}: " . $error_msg;
|
| 240 |
|
|
$error_msg = 'Entity '.($err{entity}||$o->{entity}) . ": " . $error_msg if ($err{entity}||$o->{entity});
|
| 241 |
|
|
require Carp;
|
| 242 |
|
|
Carp::carp ($error_msg);
|
| 243 |
|
|
#Carp::croak ("Line $o->{line}, position $o->{pos}: ".$error_msg);
|
| 244 |
|
|
}
|
| 245 |
|
|
|
| 246 |
|
|
=head1 LICENSE
|
| 247 |
|
|
|
| 248 |
|
|
Copyright 2003 Wakaba <[email protected]>
|
| 249 |
|
|
|
| 250 |
|
|
This program is free software; you can redistribute it and/or
|
| 251 |
|
|
modify it under the same terms as Perl itself.
|
| 252 |
|
|
|
| 253 |
|
|
=cut
|
| 254 |
|
|
|
| 255 |
|
|
1; # $Date: 2003/05/24 04:52:19 $
|