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;
40 return $this->StatusString;
49 return self::HashForFile($this->FileName);
59 return strtoupper(md5($FileName));
68 return $this->XmlVal(
"name");
77 return $this->XmlVal(
"description");
86 return $this->XmlVal(
"url");
95 return $this->XmlVal(
"version");
116 return isset($this->Xml->qualifier->name)
117 ? (string)$this->Xml->qualifier->name :
"";
127 return isset($this->Xml->qualifier->namespace)
128 ? (string)$this->Xml->qualifier->namespace :
"";
138 return isset($this->Xml->qualifier->url)
139 ? (string)$this->Xml->qualifier->url :
"";
148 return isset($this->Xml->owner->name)
149 ? (string)$this->Xml->owner->name :
"";
158 return isset($this->Xml->owner->url)
159 ? (string)$this->Xml->owner->url :
"";
168 $Terms = $this->ExtractTermSet($this->Xml);
170 # return array of terms to caller 181 $Terms = $this->BuildTermList(
"", $TermTree);
185 # ---- PRIVATE INTERFACE ------------------------------------------------- 188 private $StatusString;
195 private function XmlVal($ValueName)
197 return isset($this->Xml->{$ValueName})
198 ? (
string)$this->Xml->{$ValueName} :
"";
206 private function ExtractTermSet($Tree)
208 # make sure a valid SimpleXMLElement was given and return an empty 210 if (!($Tree instanceof SimpleXMLElement))
216 foreach ($Tree->term as $Term)
218 if (isset($Term->value))
220 $Terms[(string)$Term->value] = $this->ExtractTermSet($Term);
224 $Terms[(string)$Term] = array();
236 private function BuildTermList($Prefix, $TermTree)
239 foreach ($TermTree as $Term => $Children)
242 $NewTerm = strlen($Prefix) ? $Prefix.
" -- ".$Term : $Term;
244 $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.
__construct($FileName)
Object constructor.