diff --git a/webservice/atompub/index.php b/webservice/atompub/index.php index f70ac0d..a694f8b 100644 --- a/webservice/atompub/index.php +++ b/webservice/atompub/index.php @@ -68,6 +68,7 @@ define('KT_ATOM_LIB_FOLDER','../classes/atompub/'); * Includes */ include_once('../../ktapi/ktapi.inc.php'); +include_once(KT_ATOM_LIB_FOLDER.'XMLns2array.inc.php'); include_once(KT_ATOM_LIB_FOLDER.'KT_atom_server.inc.php'); include_once('demodms/KT_atom_service_helper.inc.php'); //Containing helper bridge functions to KtAPI include_once(KT_ATOM_LIB_FOLDER.'KT_atom_baseDoc.inc.php'); //Containing the parent class allowing easy XML manipulation @@ -91,6 +92,8 @@ $APP=new KT_atom_server(); * ServiceClass :This is the class name of the class to be instantiated when this service is accessed * Title :This is the title given to the service/collection in the servicedocument */ +$APP->addWorkspaceTag('dms','atom:title','Standard DMS'); + $APP->registerService('DMS','fulltree','KT_atom_service_fulltree','Full Document Tree'); $APP->registerService('DMS','folder','KT_atom_service_folder','Folder Detail'); $APP->registerService('DMS','document','KT_atom_service_document','Document Detail'); @@ -102,5 +105,6 @@ $APP->execute(); //Render the resulting feed response $APP->render(); +//print_r($APP); ?> \ No newline at end of file diff --git a/webservice/classes/atompub/KT_atom_server.inc.php b/webservice/classes/atompub/KT_atom_server.inc.php index 7d8b708..8b2adb8 100644 --- a/webservice/classes/atompub/KT_atom_server.inc.php +++ b/webservice/classes/atompub/KT_atom_server.inc.php @@ -1,6 +1,7 @@ setStatus(KT_atom_service::STATUS_NOT_FOUND); $this->output=$serviceObject->render(); } + $this->serviceObject=$serviceObject; } - public function registerService($workspace=NULL,$serviceName=NULL,$serviceClass=NULL,$title=NULL){ - $workspace=strtolower(trim($workspace)); + + public function registerService($workspaceCode=NULL,$serviceName=NULL,$serviceClass=NULL,$title=NULL){ + $workspaceCode=strtolower(trim($workspaceCode)); $serviceName=strtolower(trim($serviceName)); $serviceRecord=array( @@ -55,7 +62,12 @@ class KT_atom_server{ 'title' =>$title ); - $this->services[$workspace][$serviceName]=$serviceRecord; + $this->services[$workspaceCode][$serviceName]=$serviceRecord; + } + + public function addWorkspaceTag($workspaceCode=NULL,$TagName=NULL,$tagValue=NULL){ + if(!isset($this->workspaceDetail[$workspaceCode]))$this->workspaceDetail[$workspaceCode]=array(); + $this->workspaceDetail[$workspaceCode][$TagName]=$tagValue; } public function getRegisteredService($workspace,$serviceName=NULL){ @@ -69,7 +81,18 @@ class KT_atom_server{ foreach($this->services as $workspace=>$collection){ //Creating the Default Workspace for use with standard atomPub Clients - $ws=$service->newWorkspace($workspace); + $ws=$service->newWorkspace(); + + $hadDetail=false; + if(isset($this->workspaceDetail[$workspace]))if(is_array($this->workspaceDetail[$workspace])){ + foreach ($this->workspaceDetail[$workspace] as $wsTag=>$wsValue){ + $ws->appendChild($service->newElement($wsTag,$wsValue)); + $hadDetail=true; + } + } + if(!$hadDetail){ + $ws->appendChild($service->newElement('atom:title',$workspace)); + } foreach($collection as $serviceName=>$serviceInstance){ $col=$service->newCollection(KT_APP_BASE_URI.$workspace.'/'.$serviceName.'/',$serviceInstance['title'],$ws); diff --git a/webservice/classes/atompub/KT_atom_service.inc.php b/webservice/classes/atompub/KT_atom_service.inc.php index aef7d96..0e46afe 100644 --- a/webservice/classes/atompub/KT_atom_service.inc.php +++ b/webservice/classes/atompub/KT_atom_service.inc.php @@ -60,7 +60,11 @@ class KT_atom_service{ } protected function xml2array($xml){ - $array=json_decode(json_encode(@simplexml_load_string($xml)),true); //TODO - XML2ARRAY Translation + if(class_exists('')){ + $array=XMLns2array::parse($xml); + }else{ + $array=json_decode(json_encode(@simplexml_load_string($xml)),true); + } return $array; } diff --git a/webservice/classes/atompub/KT_atom_serviceDoc.inc.php b/webservice/classes/atompub/KT_atom_serviceDoc.inc.php index 94e2109..cbde304 100644 --- a/webservice/classes/atompub/KT_atom_serviceDoc.inc.php +++ b/webservice/classes/atompub/KT_atom_serviceDoc.inc.php @@ -32,7 +32,7 @@ * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices * must display the words "Powered by KnowledgeTree" and retain the original * copyright notice. - * Contributor( s): + * Contributor( s): * Mark Holtzhausen * */ @@ -45,17 +45,17 @@ include_once('KT_atom_baseDoc.inc.php'); class KT_atom_serviceDoc extends KT_atom_baseDoc { - + protected $baseURI=NULL; protected $service=NULL; - + public function __construct($baseURI=NULL){ parent::__construct(); $this->constructServiceDocumentHeaders(); $this->baseURI=$baseURI; } - + protected function constructServiceDocumentHeaders(){ $service=$this->newElement('service'); $service->appendChild($this->newAttr('xmlns','http://www.w3.org/2007/app')); @@ -63,14 +63,14 @@ class KT_atom_serviceDoc extends KT_atom_baseDoc { $this->service=&$service; $this->DOM->appendChild($this->service); } - + public function &newWorkspace($title=NULL){ $ws=$this->newElement('workspace'); - $ws->appendChild($this->newElement('atom:title',$title)); + if($title)$ws->appendChild($this->newElement('atom:title',$title)); $this->service->appendChild($ws); - return $ws; + return $ws; } - + public function &newCollection($url=NULL,$title=NULL,&$ws=NULL){ $collection=$this->newElement('collection'); $collection->appendChild($this->newAttr('href',$url)); @@ -78,7 +78,7 @@ class KT_atom_serviceDoc extends KT_atom_baseDoc { if(isset($ws))$ws->appendChild($collection); return $collection; } - + public function &newAccept($docType=NULL,&$collection=NULL){ if($docType){ $accept=$this->newElement('accept',$docType); @@ -88,12 +88,12 @@ class KT_atom_serviceDoc extends KT_atom_baseDoc { if($collection)$collection->appendChild($accept); return $accept; } - - + + public function getAPPdoc(){ return $this->formatXmlString(trim($this->DOM->saveXML())); } - + } diff --git a/webservice/classes/atompub/XMLns2array.inc.php b/webservice/classes/atompub/XMLns2array.inc.php new file mode 100644 index 0000000..93ac07c --- /dev/null +++ b/webservice/classes/atompub/XMLns2array.inc.php @@ -0,0 +1,98 @@ +getNamespaces(true); + return self::parsetag($xml); + } + + /** + * Parse a single tag recursively calling self to parse children. + * + * @param SimpleXMLElement $xml The SimpleXMLElement to convert to an array + * @return Array + */ + private static function parsetag($xml){ + $array=array(); + $array['@attributes']=self::getAttributes($xml); + $array['@children']=array(); + if(self::hasChildren($xml)){ + $children=self::getChildren($xml); + $tmpChildren=array(); + foreach($children as $fullChildName=>$childCollection){ + $childName=split(':',$fullChildName); + $fullChildName=trim($fullChildName,' :'); + foreach($childCollection as $child){ + $childParsed=self::parsetag($child); + if(!isset($tmpChildren[$fullChildName]))$tmpChildren[$fullChildName]=array(); + $tmpChildren[$fullChildName][]=$childParsed; + } + $array['@children']=array_merge($array['@children'],$tmpChildren); + } + }else{ + $array['@value']=(string)$xml; + } + return $array; + } + + /** + * Tests whether a node has children + * + * @param SimpleXMLElement $xml The node to test + * @return Array + */ + private static function hasChildren($xml){ + return count(self::getChildren($xml))>0; + } + + /** + * Gets the attributes of a node + * + * @param SimpleXMLElement $xml The node to process + * @return Array + */ + private static function getAttributes($xml){ + $attr=array(); + foreach(self::$namespaces as $namespace=>$uri){ + $nsAttrs=(array)$xml->attributes($uri); + $nsAttrs=isset($nsAttrs['@attributes'])?$nsAttrs['@attributes']:array(); + foreach($nsAttrs as $nsAttr=>$nsAttrVal){ + $attr[$namespace.':'.$nsAttr]=$nsAttrVal; + } + } + return $attr; + } + + /** + * Returns the children of a node + * + * @param SimpleXMLElement $xml The node to process + * @return unknown + */ + private static function getChildren($xml){ + $children=array(); + foreach(self::$namespaces as $namespace=>$uri){ + $nsChildren=$xml->children($uri); + foreach($nsChildren as $nsChild){ + $childRealName=$namespace.':'.$nsChild->getName(); + if(!isset($children[$childRealName]))$children[$childRealName]=array(); + if(!is_array($children[$childRealName]))$children[$childRealName]=array(); + $children[$childRealName][]=$nsChild; + } + } + return $children; + } + +} +?> \ No newline at end of file