/[webpac2]/trunk/lib/WebPAC/Normalize/XML.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/WebPAC/Normalize/XML.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 252 by dpavlin, Thu Dec 15 17:01:04 2005 UTC revision 269 by dpavlin, Fri Dec 16 21:09:48 2005 UTC
# Line 7  use base qw/WebPAC::Common WebPAC::Norma Line 7  use base qw/WebPAC::Common WebPAC::Norma
7  use XML::Simple;  use XML::Simple;
8  use Data::Dumper;  use Data::Dumper;
9  use Text::Iconv;  use Text::Iconv;
10    use YAML qw/Dump LoadFile/;
11    
12  =head1 NAME  =head1 NAME
13    
14  WebPAC::Normalize::XML - apply XML normalisaton rules  WebPAC::Normalize::XML - apply XML or YAML normalisaton rules
15    
16  =head1 VERSION  =head1 VERSION
17    
18  Version 0.02  Version 0.03
19    
20  =cut  =cut
21    
22  our $VERSION = '0.02';  our $VERSION = '0.03';
23    
24  =head1 SYNOPSIS  =head1 SYNOPSIS
25    
# Line 42  parse it. Line 43  parse it.
43    
44  C<tag> defines tag to use within C<xml_file>  C<tag> defines tag to use within C<xml_file>
45    
46  C<xml_file> defines path to normalize XML.  C<xml_file> defines path to normalize XML
47    
48  C<tags> define additional tags that can be forced (and an be array).  C<tags> define additional tags that can be forced (and an be array).
49    
# Line 78  sub open { Line 79  sub open {
79    
80          $log->debug("import xml is ",sub { Dumper($self->{'import_xml'}) }, $self->{lookup} ? " using lookups" : "lookups disabled");          $log->debug("import xml is ",sub { Dumper($self->{'import_xml'}) }, $self->{lookup} ? " using lookups" : "lookups disabled");
81    
82            #print STDERR Dump($self->{import_xml});
83    
84          return $self;          return $self;
85  }  }
86    
87    =head2 open_yaml
88    
89    Read normalisation rules defined in YAML file located usually at
90    C<conf/normalize/*.yml> and parse it.
91    
92     my $n = new WebPAC::Normalize::XML;
93     $n->open_yaml(
94            tag => 'isis',
95            path => '/path/to/conf/normalize/isis.yml',
96     );
97    
98    =cut
99    
100    sub open_yaml {
101            my $self = shift;
102    
103            my $arg = {@_};
104    
105            my $log = $self->_get_logger();
106    
107            foreach my $req (qw/tag path/) {
108                    $log->logconfess("need argument $req") unless $arg->{$req};
109            }
110    
111        my $path = $arg->{path};
112            $self->{tag} = $arg->{tag};
113    
114            $log->logdie("normalisation yaml file '$path' doesn't exist!") if (! -e $path);
115    
116            $log->info("using $path normalization YAML");
117    
118        $self->{'import_xml'} = LoadFile( $path ) || $log->die("can't load $path: $!");
119    
120            $log->debug("import yaml is ",sub { Dumper($self->{'import_xml'}) }, $self->{lookup} ? " using lookups" : "lookups disabled");
121    
122            $self->{_skip_x} = 1;
123    
124            return $self;
125    }
126    
127  =head2 _x  =head2 _x
128    
# Line 96  change that when creating new instance o Line 138  change that when creating new instance o
138  sub _x {  sub _x {
139          my $self = shift;          my $self = shift;
140          my $utf8 = shift || return;          my $utf8 = shift || return;
141            return $utf8 if ($self->{_skip_x});
142    
143          # create UTF-8 convertor for import_xml files          # create UTF-8 convertor for import_xml files
144          $self->{'utf2cp'} ||= Text::Iconv->new('UTF-8' ,$self->{'code_page'} || 'ISO-8859-2');          $self->{'utf2cp'} ||= Text::Iconv->new('UTF-8' ,$self->{'code_page'} || 'ISO-8859-2');

Legend:
Removed from v.252  
changed lines
  Added in v.269

  ViewVC Help
Powered by ViewVC 1.1.26