PageRenderTime 22ms CodeModel.GetById 13ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/framework/core/xml/PropertyList.php

http://zoop.googlecode.com/
PHP | 106 lines | 101 code | 4 blank | 1 comment | 5 complexity | f9326849d661f2ec9915c5b3ab8a0f75 MD5 | raw file
  1<?
  2class PropertyList
  3{
  4	public $data;
  5	
  6	function PropertyList($filename)
  7	{
  8		$doc = new XmlDom();
  9		$rootNode = $doc->parseFile($filename);
 10		$this->handlePList($rootNode);
 11	}
 12	
 13	function handlePList($curNode)
 14	{
 15		$children = $curNode->getChildren();
 16		for($thisNode = $children->current(); $children->valid(); $thisNode = $children->next())
 17		{
 18			if($thisNode->getName() != '#text')
 19			{
 20				$this->data = array();
 21				$this->handleDict($thisNode, $this->data);
 22			}
 23		}
 24	}
 25	
 26	function handleDict($curNode, &$dataNode)
 27	{
 28		$curKey = NULL;
 29		$children = $curNode->getChildren();
 30		for($thisNode = $children->current(); $children->valid(); $thisNode = $children->next())
 31		{
 32			{
 33				switch($thisNode->getName())
 34				{
 35					case 'key':
 36						$nodeContent = $thisNode->getTextContent();
 37						$curKey = $nodeContent['content'];
 38						break;
 39					//	these next 4 could probably just be one rule
 40					case 'string':
 41						assert($curKey !== NULL);
 42						$nodeContent = $thisNode->getTextContent();
 43						$dataNode[$curKey] = $nodeContent['content'];
 44						$curKey = NULL;
 45						break;
 46					case 'integer':
 47						assert($curKey !== NULL);
 48						$nodeContent = $thisNode->getTextContent();
 49						$dataNode[$curKey] = $nodeContent['content'];
 50						$curKey = NULL;
 51						break;
 52					case 'real':
 53						assert($curKey !== NULL);
 54						$nodeContent = $thisNode->getTextContent();
 55						$dataNode[$curKey] = $nodeContent['content'];
 56						$curKey = NULL;
 57						break;
 58					case 'true':
 59						assert($curKey !== NULL);
 60						$dataNode[$curKey] = 1;
 61						$curKey = NULL;
 62						break;
 63					case 'false':
 64						assert($curKey !== NULL);
 65						$dataNode[$curKey] = 0;
 66						$curKey = NULL;
 67						break;
 68					case 'dict':
 69						assert($curKey !== NULL);
 70						$dataNode[$curKey] = array();
 71						$this->handleDict($thisNode, $dataNode[$curKey]);
 72						$curKey = NULL;
 73						break;
 74					case 'array':
 75						assert($curKey !== NULL);
 76						$dataNode[$curKey] = array();
 77						$this->handleArray($thisNode, $dataNode[$curKey]);
 78						$curKey = NULL;
 79						break;
 80				}
 81			}
 82		}
 83	}
 84	
 85	function handleArray($curNode, &$dataNode)
 86	{
 87		$children = $curNode->getChildren();
 88		for($thisNode = $children->current(); $children->valid(); $thisNode = $children->next())
 89		{
 90			{
 91				switch($thisNode->getName())
 92				{
 93					case 'dict':
 94						$newDict = array();
 95						$this->handleDict($thisNode, $newDict);
 96						$dataNode[] = $newDict;
 97						break;
 98					case 'string':
 99						$dataNode[] = $thisNode->getTextContent();
100						break;
101				}
102			}
103		}
104	}
105}
106?>