5 # Part of the Collection Workflow Integration System (CWIS) 6 # Copyright 2007-2016 Edward Almasy and Internet Scout Research Group 7 # http://scout.wisc.edu/cwis/ 15 # ---- PUBLIC INTERFACE -------------------------------------------------- 24 # if provided filename is not found 25 if (!file_exists($FileName))
27 # look in configured search paths 28 foreach (self::$SearchPaths as $Path)
30 $TestPath = $Path.
"/".$FileName;
31 if (file_exists($TestPath))
33 $FileName = $TestPath;
40 $this->FileName = $FileName;
42 # attempt to load vocabulary from file 43 $this->Xml = simplexml_load_file($FileName);
45 # set error code if load failed 46 $this->StatusString = ($this->Xml === FALSE) ?
"XML Load Failed" :
"OK";
47 $this->Xml = isset($this->Xml->vocabulary) ? $this->Xml->vocabulary : $this->Xml;
55 return $this->StatusString;
64 return self::HashForFile($this->FileName);
74 return strtoupper(md5($FileName));
83 return $this->XmlVal(
"name");
92 return $this->XmlVal(
"description");
101 return $this->XmlVal(
"url");
110 return $this->XmlVal(
"version");
131 return isset($this->Xml->qualifier->name)
132 ? (string)$this->Xml->qualifier->name :
"";
142 return isset($this->Xml->qualifier->namespace)
143 ? (string)$this->Xml->qualifier->namespace :
"";
153 return isset($this->Xml->qualifier->url)
154 ? (string)$this->Xml->qualifier->url :
"";
163 return isset($this->Xml->owner->name)
164 ? (string)$this->Xml->owner->name :
"";
173 return isset($this->Xml->owner->url)
174 ? (string)$this->Xml->owner->url :
"";
183 $Terms = $this->ExtractTermSet($this->Xml);
185 # return array of terms to caller 196 $Terms = $this->BuildTermList(
"", $TermTree);
207 if ($NewValue !== NULL)
209 self::$SearchPaths = $NewValue;
211 return self::$SearchPaths;
214 # ---- PRIVATE INTERFACE ------------------------------------------------- 217 private $StatusString;
219 private static $SearchPaths = array();
226 private function XmlVal($ValueName)
228 return isset($this->Xml->{$ValueName})
229 ? (
string)$this->Xml->{$ValueName} :
"";
237 private function ExtractTermSet($Tree)
239 # make sure a valid SimpleXMLElement was given and return an empty 241 if (!($Tree instanceof SimpleXMLElement))
247 foreach ($Tree->term as $Term)
249 if (isset($Term->value))
251 $Terms[(string)$Term->value] = $this->ExtractTermSet($Term);
255 $Terms[(string)$Term] = array();
267 private function BuildTermList($Prefix, $TermTree)
270 foreach ($TermTree as $Term => $Children)
273 $NewTerm = strlen($Prefix) ? $Prefix.
" -- ".$Term : $Term;
275 $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.
static FileSearchPaths($NewValue=NULL)
Get/set the list of paths where vocabulary files will be searched for.
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.