2 use NCIP::Configuration;
9 use Object::Tiny qw{xmldoc config namespace ils};
11 our $VERSION = '0.01';
12 our $strict_validation = 0; # move to config file
21 my $nicp = NCIP->new($config_dir);
29 my $class = ref $proto || $proto;
30 my $config_dir = shift;
32 my $config = NCIP::Configuration->new($config_dir);
33 $self->{config} = $config;
34 $self->{namespace} = $config->('NCIP.namespace.value');
36 # load the ILS dependent module
37 my $module = 'NCIP::ILS::' . $config->('NCIP.ils.value');
38 load $module || die "Can not load ILS module $module";
39 my $ils = $module->new( name => $config->('NCIP.ils.value') );
40 $self->{'ils'} = $ils;
41 return bless $self, $class;
45 =head2 process_request()
47 my $response = $ncip->process_request($xml);
55 my ($request_type) = $self->handle_initiation($xml);
56 unless ($request_type) {
58 # We have invalid xml, or we can't figure out what kind of request this is
60 warn "We can't find request type";
65 my $handler = NCIP::Handler->new(
67 namespace => $self->namespace(),
68 type => $request_type,
72 return $handler->handle( $self->xmldoc );
75 =head2 handle_initiation
79 sub handle_initiation {
84 $dom = XML::LibXML->load_xml( string => $xml );
87 warn "Invalid xml, caught error: $_";
90 # should check validity with validate at this point
91 if ( $strict_validation && !$self->validate($dom) ) {
93 # we want strict validation, bail out if dom doesnt validate
94 warn " Not valid xml";
99 my $request_type = $self->parse_request($dom);
101 # do whatever we should do to initiate, then hand back request_type
103 $self->{xmldoc} = $dom;
104 return $request_type;
108 warn "We have no DOM";
116 # this should perhaps be in it's own module
123 warn "Bad xml, caught error: $_";
127 # we could validate against the dtd here, might be good?
128 # my $dtd = XML::LibXML::Dtd->parse_string($dtd_str);
129 # $dom->validate($dtd);
130 # perhaps we could check the ncip version and validate that too
137 my $nodes = $dom->getElementsByTagNameNS( $self->namespace(), 'NCIPMessage' );
139 my @childnodes = $nodes->[0]->childNodes();
140 if ( $childnodes[1] ) {
141 return $childnodes[1]->localname();