2 use NCIP::Configuration;
8 use Object::Tiny qw{xmldoc config namespace};
10 our $VERSION = '0.01';
11 our $nsURI = 'http://www.niso.org/2008/ncip';
20 my $nicp = NCIP->new($config_dir);
28 my $class = ref $proto || $proto;
29 my $config_dir = shift;
31 my $config = NCIP::Configuration->new($config_dir);
32 $self->{config} = $config;
33 $self->{namespace} = $nsURI;
34 return bless $self, $class;
38 =head2 process_request()
40 my $response = $ncip->process_request($xml);
48 my ($request_type) = $self->handle_initiation($xml);
49 unless ($request_type) {
51 # We have invalid xml, or we can't figure out what kind of request this is
57 my $handler = NCIP::Handler->new( $self->namespace(), $request_type );
58 return $handler->handle( $self->xmldoc );
61 =head2 handle_initiation
65 sub handle_initiation {
70 $dom = XML::LibXML->load_xml( string => $xml );
73 warn "Invalid xml, caught error: $_";
77 # should check validity with validate at this point
78 if ( $self->validate($dom) ) {
79 my $request_type = $self->parse_request($dom);
81 # do whatever we should do to initiate, then hand back request_type
83 $self->{xmldoc} = $dom;
90 # not valid throw error
101 # this should perhaps be in it's own module
108 warn "Bad xml, caught error: $_";
112 # we could validate against the dtd here, might be good?
113 # my $dtd = XML::LibXML::Dtd->parse_string($dtd_str);
114 # $dom->validate($dtd);
115 # perhaps we could check the ncip version and validate that too
122 my $nodes = $dom->getElementsByTagNameNS( $nsURI, 'NCIPMessage' );
124 my @childnodes = $nodes->[0]->childNodes();
125 if ( $childnodes[1] ) {
126 return $childnodes[1]->localname();