1 package WebPAC::Normalize::XML;
6 use base qw/WebPAC::Common WebPAC::Normalize/;
14 WebPAC::Normalize::XML - apply XML normalisaton rules
22 our $VERSION = '0.01';
26 This module uses C<conf/normalize/*.xml> files to perform normalisation
35 Read normalisation rules defined using XML from C<conf/normalize/*.xml> and
38 my $n = new WebPAC::Normalize::XML;
41 xml_file => '/path/to/conf/normalize/isis.xml',
44 C<tag> defines tag to use within C<xml_file>
46 C<xml_file> defines path to normalize XML.
55 my $log = $self->_get_logger();
57 foreach my $req (qw/tag xml_file/) {
58 $log->logconfess("need argument $req") unless $arg->{$req};
61 $self->{'tag'} = $arg->{'tag'};
62 my $xml_file = $arg->{'xml_file'};
64 $log->info("using $xml_file tag <",$self->{'tag'},">");
66 $log->logdie("normalisation xml file '$xml_file' doesn't exist!") if (! -e $xml_file);
68 $self->{'import_xml_file'} = $xml_file;
70 $self->{'import_xml'} = XMLin($xml_file,
71 ForceArray => [ $self->{'tag'}, $self->{'tags'}, 'config', 'format' ],
74 $log->debug("import xml is ",sub { Dumper($self->{'import_xml'}) });
82 Convert string from UTF-8 to code page defined in C<import_xml>.
84 my $text = $n->_x('utf8 text');
86 Default application code page is C<ISO-8859-2>. You will probably want to
87 change that when creating new instance of object based on this one.
93 my $utf8 = shift || return;
95 # create UTF-8 convertor for import_xml files
96 $self->{'utf2cp'} ||= Text::Iconv->new('UTF-8' ,$self->{'code_page'} || 'ISO-8859-2');
98 return $self->{'utf2cp'}->convert($utf8) ||
99 $self->_get_logger()->logwarn("can't convert '$utf8'");
105 Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
107 =head1 COPYRIGHT & LICENSE
109 Copyright 2005 Dobrica Pavlinusic, All Rights Reserved.
111 This program is free software; you can redistribute it and/or modify it
112 under the same terms as Perl itself.
116 1; # End of WebPAC::Normalize::XML