5 # Part of the Collection Workflow Integration System (CWIS)
6 # Copyright 2007-2013 Edward Almasy and Internet Scout Research Group
7 # http://scout.wisc.edu/cwis/
15 # ---- PUBLIC INTERFACE --------------------------------------------------
25 $this->FileName = $FileName;
27 # attempt to load vocabulary from file
28 $this->Xml = simplexml_load_file($FileName);
30 # set error code if load failed
31 $this->StatusString = ($this->Xml === FALSE) ?
"XML Load Failed" :
"OK";
32 $this->Xml = isset($this->Xml->vocabulary) ? $this->Xml->vocabulary : $this->Xml;
38 function Status() {
return $this->StatusString; }
46 return self::HashForFile($this->FileName);
56 return strtoupper(md5($FileName));
63 function Name() {
return $this->XmlVal(
"name"); }
69 function Description() {
return $this->XmlVal(
"description"); }
75 function Url() {
return $this->XmlVal(
"url"); }
81 function Version() {
return $this->XmlVal(
"version"); }
101 return isset($this->Xml->qualifier->name)
102 ? (string)$this->Xml->qualifier->name :
"";
112 return isset($this->Xml->qualifier->namespace)
113 ? (string)$this->Xml->qualifier->namespace :
"";
123 return isset($this->Xml->qualifier->url)
124 ? (string)$this->Xml->qualifier->url :
"";
133 return isset($this->Xml->owner->name)
134 ? (string)$this->Xml->owner->name :
"";
143 return isset($this->Xml->owner->url)
144 ? (string)$this->Xml->owner->url :
"";
153 $Terms = $this->ExtractTermSet($this->Xml);
155 # return array of terms to caller
166 $Terms = $this->BuildTermList(
"", $TermTree);
170 # ---- PRIVATE INTERFACE -------------------------------------------------
173 private $StatusString;
180 private function XmlVal($ValueName)
182 return isset($this->Xml->{$ValueName})
183 ? (
string)$this->Xml->{$ValueName} :
"";
191 private function ExtractTermSet($Tree)
193 # make sure a valid SimpleXMLElement was given and return an empty
195 if (!($Tree instanceof SimpleXMLElement))
201 foreach ($Tree->term as $Term)
203 if (isset($Term->value))
205 $Terms[(string)$Term->value] = $this->ExtractTermSet($Term);
209 $Terms[(string)$Term] = array();
221 private function BuildTermList($Prefix, $TermTree)
224 foreach ($TermTree as $Term => $Children)
227 $NewTerm = strlen($Prefix) ? $Prefix.
" -- ".$Term : $Term;
229 $Terms = array_merge($Terms, $this->BuildTermList($NewTerm, $Children));
static HashForFile($FileName=NULL)
Get hash string for specified vocabulary file name.
Status()
Get string indicate status of last action.
Description()
Get vocabulary description.
HasQualifier()
Get whether vocabulary has associated qualifier.
OwnerName()
Get name of owning (maintaining) organization.
QualifierName()
Get qualifier name.
QualifierNamespace()
Get qualifier namespace.
TermArray()
Get vocabulary terms as multi-dimensional array.
Hash()
Get hash string for vocabulary (generated from file name).
Name()
Get vocabulary name.
OwnerUrl()
Get primary URL for owning (maintaining) organization.
TermList()
Get vocabulary terms as flat array with double-dash separators.
Url()
Get URL attached to vocabulary.
QualifierUrl()
Get qualifier URL.
Version()
Get version number for vocabulary.
Vocabulary($FileName)
Object constructor.