line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
### |
3
|
|
|
|
|
|
|
# AxKit XSP taglib for character conversion |
4
|
|
|
|
|
|
|
# Robin Berjon |
5
|
|
|
|
|
|
|
# 03/08/2001 - v0.02 |
6
|
|
|
|
|
|
|
# 18/07/2001 - v0.01 |
7
|
|
|
|
|
|
|
### |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package AxKit::XSP::CharsetConv; |
10
|
1
|
|
|
1
|
|
602
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
11
|
1
|
|
|
1
|
|
1613
|
use Apache::AxKit::CharsetConv qw(); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use vars qw($VERSION $NS); |
14
|
|
|
|
|
|
|
$VERSION = '0.02'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use base qw(Apache::AxKit::Language::XSP); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# define the namespace we use (RDDL there one of these days) |
19
|
|
|
|
|
|
|
$NS = 'http://xmlns.knowscape.com/xsp/CharsetConv'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,# |
23
|
|
|
|
|
|
|
#`,`, Parser subs `,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,# |
24
|
|
|
|
|
|
|
#```````````````````````````````````````````````````````````````````# |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub parse_start { |
27
|
|
|
|
|
|
|
my $e = shift; |
28
|
|
|
|
|
|
|
my $tag = shift; |
29
|
|
|
|
|
|
|
my %attr = @_; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
if ($tag eq 'charset-convert') { |
32
|
|
|
|
|
|
|
$attr{from} ||= 'iso-8859-1'; |
33
|
|
|
|
|
|
|
$attr{to} ||= 'utf-8'; |
34
|
|
|
|
|
|
|
$e->append_to_script("{ #start charset-convert\n"); |
35
|
|
|
|
|
|
|
$e->append_to_script(" my \$charconv = Apache::AxKit::CharsetConv->new('$attr{from}','$attr{to}');\n"); |
36
|
|
|
|
|
|
|
$e->append_to_script(" my \$to_convert = ''"); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
else { |
39
|
|
|
|
|
|
|
die "Unknown tag $tag in CharsetConv taglib"; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
return ''; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub parse_end { |
46
|
|
|
|
|
|
|
my $e = shift; |
47
|
|
|
|
|
|
|
my $tag = shift; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
if ($tag eq 'charset-convert') { |
50
|
|
|
|
|
|
|
$e->append_to_script(";\n"); |
51
|
|
|
|
|
|
|
$e->start_expr; |
52
|
|
|
|
|
|
|
$e->append_to_script(" \$charconv->convert(\$to_convert);"); |
53
|
|
|
|
|
|
|
$e->end_expr; |
54
|
|
|
|
|
|
|
$e->append_to_script("} # end of charset-convs\n"); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
return ''; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub parse_char { |
61
|
|
|
|
|
|
|
my $e = shift; |
62
|
|
|
|
|
|
|
my $txt = shift; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
$txt =~ s/\|/\\\|/; |
65
|
|
|
|
|
|
|
$e->append_to_script(" . q|$txt|"); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
return ''; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub parse_comment {} |
71
|
|
|
|
|
|
|
sub parse_final {} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,# |
77
|
|
|
|
|
|
|
#`,`, Documentation `,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,# |
78
|
|
|
|
|
|
|
#```````````````````````````````````````````````````````````````````# |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=pod |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 NAME |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
AxKit::XSP::CharsetConv - AxKit XSP taglib for charset conversion |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 SYNOPSIS |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Add the CharsetConv namespace to your XSP C<> tag: |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
language='Perl' |
92
|
|
|
|
|
|
|
xmlns:xsp='http://apache.org/xsp/core/v1' |
93
|
|
|
|
|
|
|
xmlns:conv='http://xmlns.knowscape.com/xsp/CharsetConv'> |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
And add the taglib to AxKit (via httpd.conf or .htaccess): |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
AxAddXSPTaglib AxKit::XSP::CharsetConv |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 DESCRIPTION |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
The XSP CharsetConv taglib implements character set conversion as |
102
|
|
|
|
|
|
|
implemented in iconv(), through the Apache::AxKit::CharsetConv module |
103
|
|
|
|
|
|
|
that comes with your standard AxKit install. You may wish to use it |
104
|
|
|
|
|
|
|
to convert data from misc. sources (databases, files, browser posts, |
105
|
|
|
|
|
|
|
the environment, etc...) that are not UTF-8 yet need to be included in |
106
|
|
|
|
|
|
|
the output of your XSP. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 Tag Reference |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
There is only one tag provided by this taglib: charset-convert. It |
111
|
|
|
|
|
|
|
has two mandatory attributes, from and to, which are the character |
112
|
|
|
|
|
|
|
codes to convert (surprise) from and to. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
The to attribute defaults to UTF-8, which usually makes sense. The from |
115
|
|
|
|
|
|
|
attribute on the other hand defaults to ISO-8859-1. While this default |
116
|
|
|
|
|
|
|
is very eurocentric, it would have been an arbitrary choice no matter |
117
|
|
|
|
|
|
|
what my choice would have been... so I picked the one that's most |
118
|
|
|
|
|
|
|
useful to me :-) |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 AUTHOR |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Robin Berjon, robin@knowscape.com |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 COPYRIGHT |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Copyright (c) 2001 Robin Berjon. All rights reserved. This program is |
127
|
|
|
|
|
|
|
free software; you can redistribute it and/or modify it under the same |
128
|
|
|
|
|
|
|
terms as Perl itself. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |