Skip to content
Snippets Groups Projects
Commit 1a804dd1 authored by alvaro's avatar alvaro
Browse files

Allowing services with slashes "/" in its name

parent 1b77a3eb
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,7 @@ LODSPeaKr ...@@ -3,7 +3,7 @@ LODSPeaKr
author: Alvaro Graves (alvaro@graves.cl) author: Alvaro Graves (alvaro@graves.cl)
version: 20121218 version: 20130206
[LODSPeaKr](http://lodspeakr.org) is a framework for creating Linked Data applications in a simple and easy way. You can see [several applications](http://alangrafu.github.com/lodspeakr/applications.html) created using LODSPeaKr. [LODSPeaKr](http://lodspeakr.org) is a framework for creating Linked Data applications in a simple and easy way. You can see [several applications](http://alangrafu.github.com/lodspeakr/applications.html) created using LODSPeaKr.
......
...@@ -15,45 +15,54 @@ class ServiceModule extends abstractModule{ ...@@ -15,45 +15,54 @@ class ServiceModule extends abstractModule{
return FALSE; return FALSE;
} }
//Use .extension at the end of the service to force a particular content type
if(strpos($qArr[0], '.')>0){
$aux = explode(".", $qArr[0]);
if(isset($aux[1])){
$contentTypes = $conf['http_accept'][$aux[1]];
if($contentTypes == null){
HTTPStatus::send406("Content type not acceptable\n");
}
$acceptContentType = $contentTypes[0];
}
$qArr[0] = $aux[0];
}
$extension = Utils::getExtension($acceptContentType); $extension = Utils::getExtension($acceptContentType);
$viewFile = null; $viewFile = null;
$lodspk['model'] = $conf['model']['directory'].'/'.$conf['service']['prefix'].'/'.$qArr[0].'/'; $tokens = $qArr;
$lodspk['view'] = $conf['view']['directory'].'/'.$conf['service']['prefix'].'/'.$qArr[0].'/'.$extension.'.template'; while(sizeof($tokens) > 0){
$lodspk['serviceName'] = $qArr[0]; $serviceName = join("%2F", $tokens);
$lodspk['componentName'] = $qArr[0]; //Use .extension at the end of the service to force a particular content type
$modelFile = $lodspk['model'].$extension.'.queries'; $lastSegment = end($tokens);
if(file_exists($lodspk['model'].$extension.'.queries')){ if(strpos($lastSegment, '.')>0){
if(!file_exists($lodspk['view'])){ $aux = explode(".", $lastSegment);
$viewFile = null; if(sizeof($aux)>1){
}else{ $requestExtension = array_pop($aux);
$viewFile = $lodspk['view']; $contentTypes = $conf['http_accept'][$requestExtension];
if($contentTypes != null){
$acceptContentType = $contentTypes[0];
$extension = $requestExtension;
}
}
$serviceName = join(".",$aux);
} }
return array($modelFile, $viewFile);
}elseif(file_exists($lodspk['model'].'queries')){
$modelFile = $lodspk['model'].'queries'; $lodspk['model'] = $conf['model']['directory'].'/'.$conf['service']['prefix'].'/'.$serviceName.'/';
if(!file_exists($lodspk['view'])){ $lodspk['view'] = $conf['view']['directory'].'/'.$conf['service']['prefix'].'/'.$serviceName.'/'.$extension.'.template';
$lodspk['resultRdf'] = true; $lodspk['serviceName'] = join("/", $tokens);
$viewFile = null; $lodspk['componentName'] = $lodspk['serviceName'];
}else{ $modelFile = $lodspk['model'].$extension.'.queries';
$viewFile = $lodspk['view']; if(file_exists($lodspk['model'].$extension.'.queries')){
if(!file_exists($lodspk['view'])){
$viewFile = null;
}else{
$viewFile = $lodspk['view'];
}
return array($modelFile, $viewFile);
}elseif(file_exists($lodspk['model'].'queries')){
$modelFile = $lodspk['model'].'queries';
if(!file_exists($lodspk['view'])){
$lodspk['resultRdf'] = true;
$viewFile = null;
}else{
$viewFile = $lodspk['view'];
}
return array($modelFile, $viewFile);
}elseif(file_exists($lodspk['model'])){
HTTPStatus::send406($uri);
exit(0);
} }
return array($modelFile, $viewFile); array_pop($tokens);
}elseif(file_exists($lodspk['model'])){
HTTPStatus::send406($uri);
exit(0);
} }
return FALSE; return FALSE;
} }
...@@ -69,7 +78,7 @@ class ServiceModule extends abstractModule{ ...@@ -69,7 +78,7 @@ class ServiceModule extends abstractModule{
$context = array(); $context = array();
$context['contentType'] = $acceptContentType; $context['contentType'] = $acceptContentType;
$context['endpoints'] = $endpoints; $context['endpoints'] = $endpoints;
$f = $this->getFunction($localUri); //$f = $this->getFunction($localUri);
$params = array(); $params = array();
$params = $this->getParams($localUri); $params = $this->getParams($localUri);
//$params[] = $context; //$params[] = $context;
...@@ -158,20 +167,22 @@ class ServiceModule extends abstractModule{ ...@@ -158,20 +167,22 @@ class ServiceModule extends abstractModule{
} }
protected function getFunction($uri){ /*protected function getFunction($uri){
global $conf; global $conf;
$count = 1; $count = 1;
$prefixUri = $conf['basedir']; $prefixUri = $conf['basedir'];
$aux = str_replace($prefixUri, '', $uri, $count); $aux = str_replace($prefixUri, '', $uri, $count);
$functionAndParams = explode('/', $aux); $functionAndParams = explode('/', $aux);
return $functionAndParams[0]; return $functionAndParams[0];
} }*/
protected function getParams($uri){ protected function getParams($uri){
global $conf; global $conf;
global $lodspk;
$count = 1; $count = 1;
$prefixUri = $conf['basedir']; $prefixUri = $conf['basedir'];
$functionAndParams = explode('/', str_replace($prefixUri, '', $uri, $count)); // echo $prefixUri.$lodspk['serviceName'];exit(0);
$functionAndParams = explode('/', str_replace($prefixUri.$lodspk['serviceName'], '', $uri, $count));
if(sizeof($functionAndParams) > 1){ if(sizeof($functionAndParams) > 1){
array_shift($functionAndParams); array_shift($functionAndParams);
return $functionAndParams; return $functionAndParams;
......
<?php <?php
$conf['version'] = '20121218'; $conf['version'] = '20130206';
$conf['output']['select'] = 'json'; $conf['output']['select'] = 'json';
$conf['output']['ask'] = 'json'; $conf['output']['ask'] = 'json';
$conf['output']['describe'] = 'rdf'; $conf['output']['describe'] = 'rdf';
......
...@@ -4,12 +4,14 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" ...@@ -4,12 +4,14 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
initToken='services' initToken='services'
cd $DIR cd $DIR
serviceName=${1/\//%2F}
#Check models #Check models
mainDir=$DIR/../../components/$initToken/$1/ mainDir=$DIR/../../components/$initToken/$serviceName/
if [ -e "$mainDir" ] if [ -e "$mainDir" ]
then then
echo "ERROR: This service $1 already exists." >&2 echo "ERROR: This service $serviceName already exists." >&2
exit 1 exit 1
else else
mkdir -p $mainDir mkdir -p $mainDir
...@@ -17,4 +19,4 @@ fi ...@@ -17,4 +19,4 @@ fi
cp -rf ../defaults/service/* $mainDir/ cp -rf ../defaults/service/* $mainDir/
echo $initToken.$1 created/modified successfully! >&2 echo $initToken.$serviceName created/modified successfully! >&2
...@@ -4,16 +4,18 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" ...@@ -4,16 +4,18 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
initToken='services' initToken='services'
serviceName=${1/\//%2F}
#Check models #Check models
mainDir=$DIR/../../components/$initToken/$1 mainDir=$DIR/../../components/$initToken/$serviceName
if [ ! -e "$mainDir" ] if [ ! -e "$mainDir" ]
then then
echo "ERROR: $initToken/ $1 doesn't exist in models. Operation aborted" >&2 echo "ERROR: $initToken/ $serviceName doesn't exist in models. Operation aborted" >&2
exit 1 exit 1
fi fi
rm -rf $mainDir rm -rf $mainDir
echo Service $1 deleted >&2 echo Service $serviceName deleted >&2
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment