/[suikacvs]/messaging/manakai/lib/Message/Markup/XML/Error.pm
Suika

Contents of /messaging/manakai/lib/Message/Markup/XML/Error.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Tue Jun 17 12:25:07 2003 UTC (23 years, 1 month ago) by wakaba
Branch: MAIN
Changes since 1.1: +5 -1 lines
Raise error if Name contains colon

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 wakaba 1.2 ERR_PREDEFINED_ENTITY => {
160     description => 'Predefined entity (%s) must be declared as of the XML specification defined (%s)',
161     level => 'wfc',
162     },
163 wakaba 1.1 ## Validity error
164     VC_ENTITY_DECLARED => {
165     description => 'Entity %s should (or must to be valid) be declared before it is referred',
166     level => 'vc',
167     },
168     VC_NOTATION_DECLARED => {
169     description => 'Notation %s should (or must to be valid) be declared',
170     level => 'vc',
171     },
172     VC_UNIQUE_NOTATION_NAME => {
173     description => 'Notation %s is already declared',
174     level => 'warn',
175     },
176     ## Namespace well-formedness error
177     NC_PREFIX_NOT_DEFINED => {
178     description => 'Undeclared namespace prefix (%s) is used',
179     level => 'nswfc',
180     },
181     NS_SYNTAX_NAME_IS_NCNAME => {
182     description => 'Name with colon (%s) cannot be used within namespaced XML document',
183     level => 'nswfc',
184     },
185     ## Namespace validity error
186     ## XML warning
187     WARN_PREDEFINED_ENTITY_NOT_DECLARED => {
188     description => 'Predefined general entity (%s) should be declared before it is referred for interoperability',
189     level => 'warn',
190     },
191     WARN_UNICODE_COMPAT_CHARACTER => {
192     description => sub {
193     my $r = sprintf 'Use of the character U+%04X is deprecated, since it is classified as compatible character in the Unicode Standard',
194     $_[1]->{t};
195     $_[1]->{t} = undef;
196     $r;
197     },
198     level => 'warn',
199     },
200     WARN_UNICODE_NONCHARACTER => {
201     description => sub {
202     my $r = sprintf 'Use of the code point U+%04X is deprecated, since it is noncharacter in the Unicode Standard',
203     $_[1]->{t};
204     $_[1]->{t} = undef;
205     $r;
206     },
207     level => 'warn',
208     },
209     WARN_UNICODE_XML_NOT_SUITABLE_CHARACTER => {
210     description => sub {
211     my $r = sprintf 'Use of the character U+%04X is deprecated by W3C Note unicode-xml',
212     $_[1]->{t};
213     $_[1]->{t} = undef;
214     $r;
215     },
216     level => 'warn',
217     },
218     WARN_UNIQUE_ENTITY_NAME => {
219     description => 'General entity %s is already declared',
220     level => 'warn',
221     },
222     WARN_UNIQUE_PARAMETER_ENTITY_NAME => {
223     description => 'Parameter entity %s is already declared',
224     level => 'warn',
225     },
226     ## Implementation's warning
227     ## Misc
228     UNKNOWN => {
229     description => 'Unknown error',
230     level => 'wfc',
231     },
232     );
233     ## TODO: error handling should be customizable (hookable) by user of this module
234     sub raise ($$%) {
235     my (undef, $o, %err) = @_;
236     my $error_type = $_Error{$err{type}} || $_Error{UNKNOWN};
237     my $error_msg = ref $error_type->{description} ? &{$error_type->{description}} ($o, \%err)
238     : $error_type->{description};
239     my @err_msg;
240     ref $err{t} eq 'ARRAY' ? @err_msg = @{$err{t}} : defined $err{t} ? @err_msg = $err{t} : undef;
241     $error_msg .= ' (%s)' if scalar (@err_msg) && ($error_msg !~ /%s/);
242     $error_msg = sprintf $error_msg, @err_msg;
243     $error_msg = "Line $o->{line}, position $o->{pos}: " . $error_msg;
244     $error_msg = 'Entity '.($err{entity}||$o->{entity}) . ": " . $error_msg if ($err{entity}||$o->{entity});
245     require Carp;
246     Carp::carp ($error_msg);
247     #Carp::croak ("Line $o->{line}, position $o->{pos}: ".$error_msg);
248     }
249    
250     =head1 LICENSE
251    
252     Copyright 2003 Wakaba <[email protected]>
253    
254     This program is free software; you can redistribute it and/or
255     modify it under the same terms as Perl itself.
256    
257     =cut
258    
259 wakaba 1.2 1; # $Date: 2003/06/16 09:58:26 $

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24