Skip to content

Commit

Permalink
Resource (add): setIndex() method / getFormat (fix): improved n-trip…
Browse files Browse the repository at this point in the history
…les detection / RemoteStore (tweak): improved error check for empty results
  • Loading branch information
Benjamin Nowack committed Oct 16, 2009
1 parent 6b619da commit d5c7b58
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ARC2_Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ function setURI($uri) {
$this->uri = $uri;
}

function setIndex($index) {
$this->index = $index;
}

function setProps($props, $s = '') {
if (!$s) $s = $this->uri;
$this->index[$s] = $props;
Expand Down
10 changes: 9 additions & 1 deletion ARC2_getFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ function ARC2_getFormat($v, $mtype = '', $ext = '') {
$r = (!$r && preg_match('/\/(x\-)?turtle/', $mtype)) ? 'turtle' : $r;
$r = (!$r && preg_match('/\/rdf\+n3/', $mtype)) ? 'n3' : $r;
/* xml sniffing */
if (!$r && preg_match('/^\s*\<[^\s]/s', $v) && (preg_match('/\<\/[a-z0-9\_\:\-]+\>/i', $v) || preg_match('/\sxmlns\:?/', $v))) {
if (
!$r &&
/* starts with angle brackets */
preg_match('/^\s*\<[^\s]/s', $v) &&
/* has an xmlns:* declaration or a matching pair of tags */
(preg_match('/\sxmlns\:?/', $v) || preg_match('/\<([^\s]+).+\<\/\\1\>/s', $v)) &&
/* not a typical ntriples/turtle/n3 file */
!preg_match('/\.\s*$/s', $v)
) {
while (preg_match('/^\s*\<\?xml[^\r\n]+\?\>\s*/s', $v)) {
$v = preg_replace('/^\s*\<\?xml[^\r\n]+\?\>\s*/s', '', $v);
}
Expand Down
1 change: 1 addition & 0 deletions store/ARC2_RemoteStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function query($q, $result_format = '', $src = '', $keep_bnode_ids = 0, $log_que
return $this->v('rows', array(), $r['result']);
}
if ($result_format == 'row') {
if (!isset($r['result']['rows'])) return array();
return $r['result']['rows'] ? $r['result']['rows'][0] : array();
}
return $r;
Expand Down

0 comments on commit d5c7b58

Please sign in to comment.