Validator class + format files, not used yet.

This commit is contained in:
tomas 2005-02-25 03:24:38 +00:00
parent e751f9084f
commit 16b5bc2a84
3 changed files with 648 additions and 0 deletions

View File

@ -0,0 +1,180 @@
<?php
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: tomas $
Version : $Revision: 1.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/Validator.php,v $
------------------------------------------------------------------------------*/
define('VAL_ROOT', 110);
define('VAL_NOREQ', 111);
define('VAL_NOONEOF', 112);
define('VAL_UNKNOWNE', 113);
define('VAL_UNKNOWNA', 114);
define('VAL_NOTDEF', 115);
#require_once "";
/**
*
*/
class Validator{
/**
*
*/
var $format = '';
/**
*
*/
var $data = '';
/**
*
*/
var $anode = '';
/**
*
*/
function Validator($format)
{
$this->format = $format;
}
/**
*
*/
function validate(&$data)
{
$this->data =& $data;
$r = $this->validateNode($data, $this->format['_root']);
return $r;
}
/**
*
*/
function validateNode(&$node, $fname)
{
$dname = strtolower(($node->ns? $node->ns.":" : '').$node->name);
$format =& $this->format;
if(DEBUG) echo"\nVAL::validateNode: 1 $dname/$fname\n";
if($dname != $fname) return $this->_err(VAL_ROOT);
if(!isset($format[$fname])) return $this->_err(VAL_NOTDEF, $fname);
$attrs = array();
foreach($node->attrs as $i=>$attr){
$attrs[$attr->name] =& $node->attrs[$i];
$permr = (
isset($format[$fname]['attrs']['required']) ?
array_search($attr->name, $format[$fname]['attrs']['required']) :
FALSE
);
$permi = (
isset($format[$fname]['attrs']['implied']) ?
array_search($attr->name, $format[$fname]['attrs']['implied']) :
FALSE
);
if($permr===FALSE && $permi===FALSE)
return $this->_err(VAL_UNKNOWNA, $attr->name);
//else{ var_dump($permr); var_dump($permi); }
}
if(isset($format[$fname]['attrs'])){
$fattrs =& $format[$fname]['attrs'];
if(isset($fattrs['required'])){
foreach($fattrs['required'] as $i=>$attr){
if(!isset($childs[$attr])) return $this->_err(VAL_NOREQ, $attr);
}
}
}
$childs = array();
foreach($node->children as $i=>$ch){
$chname = strtolower(($ch->ns? $ch->ns.":" : '').$ch->name);
$childs[$chname] =& $node->children[$i];
$permo = (
isset($format[$fname]['childs']['optional']) ?
array_search($chname, $format[$fname]['childs']['optional']) :
FALSE
);
$permr = (
isset($format[$fname]['childs']['required']) ?
array_search($chname, $format[$fname]['childs']['required']) :
FALSE
);
$perm1 = (
isset($format[$fname]['childs']['oneof']) ?
array_search($chname, $format[$fname]['childs']['oneof']) :
FALSE
);
if($permo===FALSE && $permr===FALSE && $perm1===FALSE)
return $this->_err(VAL_UNKNOWNE, $chname);
}
//var_dump($childs);
if(isset($format[$fname]['childs'])){
$fchilds =& $format[$fname]['childs'];
if(isset($fchilds['required'])){
foreach($fchilds['required'] as $i=>$ch){
if(!isset($childs[$ch])) return $this->_err(VAL_NOREQ, $ch);
}
}
if(isset($fchilds['oneof'])){
$one = FALSE;
foreach($fchilds['oneof'] as $i=>$ch){
if(isset($childs[$ch])) $one = TRUE;
}
if(!$one) return $this->_err(VAL_NOONEOF);
}
}
foreach($childs as $chname=>$ch){
$r = $this->validateNode($childs[$chname], $chname);
if(PEAR::isError($r)) return $r;
}
return TRUE;
}
/**
*
*/
function _err($errno, $par='')
{
$msg = array(
110=>'Wrong root element',
111=>'Required object missing',
112=>'One-of object missing',
113=>'Unknown element',
114=>'Unknown attribute',
115=>'Not defined',
);
return PEAR::raiseError(
"Validator: {$msg[$errno]} #$errno ($par)"
);
}
/**
*
* /
function ()
{
}
*/
}
?>

View File

@ -0,0 +1,360 @@
<?php
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: tomas $
Version : $Revision: 1.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/audioClipFormat.php,v $
------------------------------------------------------------------------------*/
$audioClipFormat = array(
'_root'=>'audioclip',
'audioclip'=>array(
'childs'=>array(
'required'=>array('metadata'),
),
),
'metadata'=>array(
'childs'=>array(
'required'=>array(
'dc:title', 'dcterms:extent'
),
'optional'=>array(
'dc:identifier',
'dc:creator', 'dc:source', 'ls:genre',
'ls:year', 'dc:type', 'dc:description', 'dc:format',
'ls:bpm', 'ls:rating', 'ls:encoded_by', 'ls:track_num',
'ls:disc_num', 'ls:disc_num', 'dc:publisher', 'ls:composer',
'ls:bitrate', 'ls:channels', 'ls:samplerate', 'ls:encoder',
'ls:crc', 'ls:lyrics', 'ls:orchestra', 'ls:conductor',
'ls:lyricist', 'ls:originallyricist', 'ls:radiostationname',
'ls:audiofileinfourl', 'ls:artisturl', 'ls:audiosourceurl',
'ls:radiostationurl', 'ls:buycdurl', 'ls:isrcnumber',
'ls:catalognumber', 'ls:originalartist', 'dc:rights',
'ls:license', 'dc:title', 'dcterms:temporal',
'dcterms:spatial', 'dcterms:entity', 'dc:description',
'dc:creator', 'dc:subject', 'dc:type', 'dc:format',
'dc:contributor', 'dc:language', 'dc:rights',
'dcterms:ispartof', 'dc:date', 'dcterms:extent',
'dc:publisher',
// extra
'dcterms:alternative',
),
),
'namespaces'=>array(
'dc'=>"http://purl.org/dc/elements/1.1/",
'dcterms'=>"http://purl.org/dc/terms/",
'xbmf'=>"http://www.streamonthefly.org/xbmf",
'xsi'=>"http://www.w3.org/2001/XMLSchema-instance",
'xml'=>"http://www.w3.org/XML/1998/namespace",
),
),
'dc:identifier'=>array(
'type'=>'Text',
'auto'=>TRUE,
),
'dc:title'=>array(
'type'=>'Text',
'attrs'=>array('implied'=>array('xml:lang')),
),
'dcterms:alternative'=>array(
'type'=>'Text',
'attrs'=>array('implied'=>array('xml:lang')),
),
'dcterms:extent'=>array(
'type'=>'Time',
),
'dc:creator'=>array(
'type'=>'Text',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'dc:source'=>array(
'type'=>'Text',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'ls:genre'=>array(
'type'=>'Menu',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'ls:year'=>array(
'type'=>'Menu',
'area'=>'Music',
),
'dc:type'=>array(
'type'=>'Menu',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'dc:description'=>array(
'type'=>'Longtext',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'dc:format'=>array(
'type'=>'Menu',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'ls:bpm'=>array(
'type'=>'Number',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'ls:rating'=>array(
'type'=>'Number',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'ls:encoded_by'=>array(
'type'=>'Text',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'ls:track_num'=>array(
'type'=>'Menu',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'ls:disc_num'=>array(
'type'=>'Menu',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'ls:disc_num'=>array(
'type'=>'Menu',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'dc:publisher'=>array(
'type'=>'Text',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'ls:composer'=>array(
'type'=>'Text',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'ls:bitrate'=>array(
'type'=>'Number',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'ls:channels'=>array(
'type'=>'Menu',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'ls:samplerate'=>array(
'type'=>'Menu',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'ls:encoder'=>array(
'type'=>'Text',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'ls:crc'=>array(
'type'=>'Number',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'ls:lyrics'=>array(
'type'=>'Longtext',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'ls:orchestra'=>array(
'type'=>'Text',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'ls:conductor'=>array(
'type'=>'Text',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'ls:lyricist'=>array(
'type'=>'Text',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'ls:originallyricist'=>array(
'type'=>'Text',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'ls:radiostationname'=>array(
'type'=>'Text',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'ls:audiofileinfourl'=>array(
'type'=>'URL',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'ls:artisturl'=>array(
'type'=>'URL',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'ls:audiosourceurl'=>array(
'type'=>'URL',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'ls:radiostationurl'=>array(
'type'=>'URL',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'ls:buycdurl'=>array(
'type'=>'URL',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'ls:isrcnumber'=>array(
'type'=>'Number',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'ls:catalognumber'=>array(
'type'=>'Number',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'ls:originalartist'=>array(
'type'=>'Text',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'dc:rights'=>array(
'type'=>'Text',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'ls:license'=>array(
'type'=>'Text',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'dc:title'=>array(
'type'=>'Text',
'area'=>'Talk',
'attrs'=>array('implied'=>array('xml:lang')),
),
'dcterms:temporal'=>array(
'type'=>'Time/Date',
'area'=>'Talk',
'attrs'=>array('implied'=>array('xml:lang')),
),
'dcterms:spatial'=>array(
'type'=>'Menu',
'area'=>'Talk',
'attrs'=>array('implied'=>array('xml:lang')),
),
'dcterms:entity'=>array(
'type'=>'Text',
'area'=>'Talk',
'attrs'=>array('implied'=>array('xml:lang')),
),
'dc:description'=>array(
'type'=>'Longtext',
'area'=>'Talk',
'attrs'=>array('implied'=>array('xml:lang')),
),
'dc:creator'=>array(
'type'=>'Menu',
'area'=>'Talk',
'attrs'=>array('implied'=>array('xml:lang')),
),
'dc:subject'=>array(
'type'=>'Text',
'area'=>'Talk',
'attrs'=>array('implied'=>array('xml:lang')),
),
'dc:type'=>array(
'type'=>'Menu',
'area'=>'Talk',
'attrs'=>array('implied'=>array('xml:lang')),
),
'dc:format'=>array(
'type'=>'Menu',
'area'=>'Talk',
'attrs'=>array('implied'=>array('xml:lang')),
),
'dc:contributor'=>array(
'type'=>'Text',
'area'=>'Talk',
'attrs'=>array('implied'=>array('xml:lang')),
),
'dc:language'=>array(
'type'=>'Menu',
'area'=>'Talk',
'attrs'=>array('implied'=>array('xml:lang')),
),
'dc:rights'=>array(
'type'=>'Menu',
'area'=>'Talk',
'attrs'=>array('implied'=>array('xml:lang')),
),
'dcterms:ispartof'=>array(
'type'=>'Text',
'area'=>'Talk',
'attrs'=>array('implied'=>array('xml:lang')),
),
'dc:date'=>array(
'type'=>'Date',
'area'=>'Talk',
'attrs'=>array('implied'=>array('xml:lang')),
),
'dcterms:extent'=>array(
'type'=>'Time',
'area'=>'Talk',
'attrs'=>array('implied'=>array('xml:lang')),
),
'dc:publisher'=>array(
'type'=>'Text',
'area'=>'Talk',
'attrs'=>array('implied'=>array('xml:lang')),
),
/*
''=>array(
'type'=>'',
'area'=>'',
'attrs'=>array(),
),
*/
);
/*
?
ls:filename Text auto
*/
?>

View File

@ -0,0 +1,108 @@
<?php
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: tomas $
Version : $Revision: 1.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/playlistFormat.php,v $
------------------------------------------------------------------------------*/
$playlistFormat = array(
'_root'=>'playlist',
'playlist'=>array(
'childs'=>array(
'repeatable'=>array('playlistelement'),
'optional'=>array('metadata'),
),
'attrs'=>array(
'required'=>array('id', 'playlength'),
'implied'=>array('title'),
),
),
'playlistelement'=>array(
'childs'=>array(
'oneof'=>array('audioclip', 'playlist'),
'optional'=>array('fadeinfo'),
),
'attrs'=>array(
'required'=>array('id', 'relativeoffset'),
),
),
'audioclip'=>array(
'childs'=>array(
'optional'=>array('metadata'),
),
'attrs'=>array(
'implied'=>array('id', 'title', 'playlength'),
),
),
'fadeinfo'=>array(
'attrs'=>array(
'required'=>array('id', 'fadein', 'fadeout'),
),
),
'metadata'=>array(
'childs'=>array(
'optional'=>array(
'dc:title', 'dcterms:extent', 'dc:creator', 'dc:description',
),
),
'namespaces'=>array(
'dc'=>"http://purl.org/dc/elements/1.1/",
'dcterms'=>"http://purl.org/dc/terms/",
'xbmf'=>"http://www.streamonthefly.org/xbmf",
'xsi'=>"http://www.w3.org/2001/XMLSchema-instance",
'xml'=>"http://www.w3.org/XML/1998/namespace",
),
),
'dc:title'=>array(
'type'=>'Text',
'attrs'=>array('implied'=>array('xml:lang')),
),
'dcterms:extent'=>array(
'type'=>'Time',
),
'dc:creator'=>array(
'type'=>'Text',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
'dc:description'=>array(
'type'=>'Longtext',
'area'=>'Music',
'attrs'=>array('implied'=>array('xml:lang')),
),
/*
''=>array(
'childs'=>array(''),
'attrs'=>array('implied'=>array()),
),
*/
);
/*
?
ls:filename Text auto
*/
?>