1. Toby Inkster
  2. p5-rdf-wot-validation

Commits

Toby Inkster  committed 700a57b

Use RDF::Trine and RDF::Query instead of RDF::Redland.

  • Participants
  • Parent commits 1f23055
  • Branches RDF-WOT-Validation

Comments (0)

Files changed (1)

File testing/trust.pl

View file
  • Ignore whitespace
 use IPC::Open3;
 use LWP::Simple;
 use LWP::UserAgent;
-use RDF::Redland;
+use RDF::Trine;
+use RDF::Query;
 use URI;
 
 sub new
 {
-	my $klass = shift;
-	my $uri   = shift;
-	my $data  = shift;
-	my $type  = shift || 'application/rdf+xml';
+	my $klass  = shift;
+	my $uri    = shift;
+	my $data   = shift;
+	my $parser = shift;
 	
 	unless ($data)
 	{
 		if ($response->is_success)
 		{
 			$data = $response->content;
-			$type = $response->header('Content-Type');
-			
+			my $type = $response->header('Content-Type');
 			$type = 'application/rdf+xml'
 				if $type =~ /text\/plain/ || !$type;
+			
+			unless (defined $parser)
+			{
+				$parser = RDF::Trine::Parser::RDFJSON->new
+					if $type =~ m`application/((x-)?rdf\+)?json`i;
+				$parser = RDF::Trine::Parser::Turtle->new
+					if $type =~ m`(application|text)/(x-)?(turtle|n3|plain)`i;
+				$parser = RDF::Trine::Parser::RDFXML->new
+					unless defined $parser;
+			}
 		}
 		else
 		{
 		}
 	}
 	
-	my $storage = RDF::Redland::Storage->new("hashes", "test", "new='yes',hash-type='memory'");
-	my $model   = RDF::Redland::Model->new($storage, "");
-	my $parser  = RDF::Redland::Parser->new(undef, $type);
-	$parser->parse_string_into_model($data, RDF::Redland::URI->new($uri), $model);
+	unless (defined $parser)
+	{
+		$parser = RDF::Trine::Parser::RDFJSON->new
+			if $data =~ /^\s*{/;
+		$parser = RDF::Trine::Parser::RDFXML->new
+			if (!defined $parser) && substr $data, 0, 1024 =~ /<rdf:RDF/;
+		$parser = RDF::Trine::Parser::Turtle->new
+			if (!defined $parser) && substr $data, 0, 1024 =~ /@(prefix|base)/;
+		$parser = RDF::Trine::Parser::RDFXML->new
+			unless defined $parser;
+	}
+	
+	my $model = RDF::Trine::Model->new( RDF::Trine::Store->temporary_store );
+	$parser->parse_into_model($uri, $data, $model);
 	
 	my $self  = {};
 	
 	my $query = sprintf("SELECT ?a WHERE {<%s> <%s> ?a . }",
 		$self->{'uri'},
 		'http://xmlns.com/wot/0.1/assurance');
-	my $qh = RDF::Redland::Query->new($query, undef, undef, 'sparql');
+	my $qh = RDF::Query->new($query);
 	my $qr = $qh->execute($self->{'model'});
 	
-	while(!$qr->finished)
+	while(my $row = $qr->next)
 	{
-		my $assurance = $qr->binding_value_by_name('a');
-		my $assurance_uri = $assurance->uri->as_string;
+		my $assurance_uri = $row->{'a'}->uri;
 		$self->check_uri($assurance_uri);
 		$qr->next_result;
 	}
 	{
 		return $self->check_sig_pgp($siguri, $sig);
 	}
-	elsif ($siguri =~ /(\/MD5SUMS?|\.MD5)$/)
+	elsif ($siguri =~ /(\/MD5SUMS?|\.MD5)$/i)
 	{
 		return $self->check_sig_hash($siguri, $sig, 'MD5')
 	}
-	elsif ($siguri =~ /(\/SHA1SUMS?|\.SHA1?)$/)
+	elsif ($siguri =~ /(\/SHA1SUMS?|\.SHA1?)$/i)
 	{
 		return $self->check_sig_hash($siguri, $sig, 'SHA1')
 	}