Changeset 9
- Timestamp:
- 08/26/06 21:18:47 (2 years ago)
- Files:
-
- trunk/XJConf/DefinedTag.php (modified) (5 diffs)
- trunk/XJConf/DefinitionParser.php (modified) (7 diffs)
- trunk/XJConf/GenericTag.php (modified) (17 diffs)
- trunk/XJConf/Tag.php (modified) (1 diff)
- trunk/XJConf/XJConfLoader.php (modified) (1 diff)
- trunk/XJConf/XmlParser.php (modified) (13 diffs)
- trunk/XJConf/exceptions/InvalidNamespaceDefinitionException.php (modified) (1 diff)
- trunk/XJConf/exceptions/InvalidTagDefinitionException.php (modified) (1 diff)
- trunk/XJConf/exceptions/MissingAttributeException.php (modified) (1 diff)
- trunk/XJConf/exceptions/UnknownNamespaceException.php (modified) (1 diff)
- trunk/XJConf/exceptions/UnknownTagException.php (modified) (1 diff)
- trunk/XJConf/exceptions/UnsupportedOperationException.php (modified) (1 diff)
- trunk/XJConf/exceptions/ValueConversionException.php (modified) (1 diff)
- trunk/XJConf/exceptions/XJConfException.php (modified) (1 diff)
- trunk/XJConf/ext/Extension.php (modified) (1 diff)
- trunk/XJConf/ext/xinc/XInclude.php (modified) (2 diffs)
- trunk/XJConf/ext/xinc/XIncludeException.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/XJConf/DefinedTag.php
r2 r9 1 <? 1 <?php 2 /** 3 * Contains data of tag in the default namespace. 4 * 5 * @author Stephan Schmidt <me@schst.net> 6 * @author Frank Kleine <frank.kleine@schlund.de> 7 */ 2 8 XJConfLoader::load('Tag', 3 9 'definitions.TagDefinition' 4 10 ); 5 11 /** 6 * Generic Tag wrapper that can be used by extensions to dynamically add 7 * children to other tags. 12 * Contains data of tag in the default namespace. 8 13 * 9 * @ author Stephan Schmidt <me@schst.net>14 * @package XJConf 10 15 */ 11 16 class DefinedTag implements Tag … … 63 68 $this->name = $name; 64 69 $this->atts = $atts; 70 } 71 72 /** 73 * Get the name of the tag 74 * 75 * @return name of the tag 76 */ 77 public function getName() 78 { 79 return $this->name; 80 } 81 82 /** 83 * Set the key 84 * 85 * @param string $key 86 */ 87 public function setKey($key) 88 { 89 $this->key = $key; 90 } 91 92 /** 93 * Get the key under which the value will be stored 94 * 95 * @return string 96 */ 97 public function getKey() 98 { 99 return $this->tagDef->getKey($this); 100 } 101 102 /** 103 * Add text data 104 * 105 * @param string $buf 106 * @return int new length of data 107 */ 108 public function addData($buf) 109 { 110 $this->data .= $buf; 111 return strlen($this->data); 112 } 113 114 /** 115 * Get the character data of the tag 116 * 117 * @return character data 118 */ 119 public function getData() 120 { 121 return $this->data; 122 } 123 124 /** 125 * Check, whether the tag has a certain attribute 126 * 127 * @param string $name 128 * @return boolean 129 */ 130 public function hasAttribute($name) 131 { 132 return isset($this->atts[$name]); 133 } 134 135 /** 136 * get an attribute 137 * 138 * @param string $name name of the attribute 139 * @return string value of the attribute 140 */ 141 public function getAttribute($name) 142 { 143 if ($this->hasAttribute($name) == true) { 144 return $this->atts[$name]; 145 } 146 147 return null; 65 148 } 66 149 … … 76 159 return count($this->children); 77 160 } 78 79 /**80 * Add text data81 *82 * @param string $buf83 * @return int new length of data84 */85 public function addData($buf)86 {87 $this->data .= $buf;88 return strlen($this->data);89 }90 91 /**92 * Check, whether the tag has a certain attribute93 *94 * @param string $name95 * @return boolean96 */97 public function hasAttribute($name)98 {99 return isset($this->atts[$name]);100 }101 102 /**103 * get an attribute104 *105 * @param string $name name of the attribute106 * @return string value of the attribute107 */108 public function getAttribute($name)109 {110 if ($this->hasAttribute($name) == true) {111 return $this->atts[$name];112 }113 114 return null;115 }116 117 /**118 * Get all children of the tag119 *120 * @return array121 */122 public function getChildren()123 {124 return $this->children;125 }126 161 127 162 /** … … 143 178 144 179 /** 145 * Get the name of the tag 146 * 147 * @return name of the tag 148 */ 149 public function getName() 150 { 151 return $this->name; 152 } 153 154 /** 155 * Get the character data of the tag 156 * 157 * @return character data 158 */ 159 public function getData() 160 { 161 return $this->data; 162 } 180 * Get all children of the tag 181 * 182 * @return array 183 */ 184 public function getChildren() 185 { 186 return $this->children; 187 } 188 189 /** 190 * Set the content (overrides the character data) 191 * 192 * @param mixed $content 193 */ 194 public function setContent($content) 195 { 196 $this->content = $content; 197 } 198 199 /** 200 * Get the content 201 * 202 * @return mixed 203 */ 204 public function getContent() 205 { 206 if (null != $this->content) { 207 return $this->content; 208 } 209 210 return $this->getData(); 211 } 212 213 /** 214 * Fetch the value 215 * 216 * @return mixed the value of the tag 217 */ 218 public function getConvertedValue() 219 { 220 return $this->tagDef->convertValue($this); 221 } 222 223 /** 224 * Get the type of the value 225 * 226 * @param Tag $tag 227 * @return string 228 */ 229 public function getValueType(Tag $tag) 230 { 231 return $this->tagDef->getValueType($tag); 232 } 233 234 /** 235 * Get the setter method 236 * 237 * @return string 238 */ 239 public function getSetterMethod() 240 { 241 return $this->tagDef->getSetterMethod(); 242 } 243 244 /** 245 * Checks, whether the tag supports indexed children 246 * 247 * @return boolean 248 */ 249 public function supportsIndexedChildren() 250 { 251 return $this->tagDef->supportsIndexedChildren(); 252 } 163 253 164 254 /** … … 181 271 return $this->tagDef; 182 272 } 183 184 /**185 * Fetch the value186 *187 * @return mixed the value of the tag188 */189 public function getConvertedValue()190 {191 return $this->tagDef->convertValue($this);192 }193 194 /**195 * Get the key under which the value will be stored196 */197 public function getKey()198 {199 return $this->tagDef->getKey($this);200 }201 202 /**203 * Get the type of the value204 *205 * @return string206 */207 public function getValueType(Tag $tag)208 {209 return $this->tagDef->getValueType($tag);210 }211 212 /**213 * Set the key214 *215 * @param string $key216 */217 public function setKey($key)218 {219 $this->key = $key;220 }221 222 /**223 * Get the setter method224 */225 public function getSetterMethod()226 {227 return $this->tagDef->getSetterMethod();228 }229 230 /**231 * Set the content (overrides the character data)232 *233 * @param mixed $content234 */235 public function setContent($content)236 {237 $this->content = $content;238 }239 240 /**241 * Get the content242 *243 * @return mixed244 */245 public function getContent()246 {247 if (null != $this->content) {248 return $this->content;249 }250 251 return $this->getData();252 }253 254 /**255 * Checks, whether the tag supports indexed children256 *257 * @return boolean258 */259 public function supportsIndexedChildren()260 {261 return $this->tagDef->supportsIndexedChildren();262 }263 273 } 264 274 ?> trunk/XJConf/DefinitionParser.php
r4 r9 1 1 <?php 2 /** 3 * Parse tag definitions files. 4 * 5 * @author Stephan Schmidt <stephan.schmidt@schlund.de> 6 * @author Frank Kleine <frank.kleine@schlund.de> 7 */ 2 8 XJConfLoader::load('definitions.AttributeDefinition', 3 9 'definitions.CDataDefinition', … … 14 20 * Parse tag definitions files. 15 21 * 16 * @author Stephan Schmidt <stephan.schmidt@schlund.de> 22 * This parser reads xml files that define the tags used by other 23 * xml documents which describe a data structure. 24 * 25 * @package XJConf 17 26 */ 18 27 class DefinitionParser 19 28 { 29 /** 30 * this tag defines a namespace 31 */ 20 32 const TAG_NAMESPACE = 'namespace'; 21 22 33 /** 23 * Stack for currently open definitions34 * stack for currently open definitions 24 35 * 25 36 * @var array<Definition> 26 37 */ 27 38 private $defStack = array(); 28 39 /** 40 * stack for currently opened definition handlers 41 * 42 * @var DefinitionHandler 43 */ 29 44 private $defHandlerStack = array(); 30 31 45 /** 32 46 * Constant for the default namespace 33 47 */ 34 48 const DEFAULT_NAMESPACE = '__default'; 35 36 49 /** 37 50 * The current namespace … … 40 53 */ 41 54 private $currentNamespace; 42 43 55 /** 44 56 * All extracted namespace definitions … … 47 59 */ 48 60 private $defs; 49 61 /** 62 * the real xml parser 63 * 64 * @var XMLReader 65 */ 50 66 private $reader; 51 67 /** 68 * list of node types, used for compatibility between PHP 5.0 and 5.1 69 * 70 * @var array 71 */ 52 72 private $nodeTypes = array(); 53 73 54 55 74 /** 56 75 * constructor 76 * 77 * Sets the node types depending on your PHP version using the constants 78 * defined by the XMLReader PHP extension. 57 79 */ 58 80 public function __construct() 59 81 { 60 $this->defs = new NamespaceDefinitions();82 $this->defs = new NamespaceDefinitions(); 61 83 $this->currentNamespace = self::DEFAULT_NAMESPACE; 62 84 … … 73 95 } 74 96 } 75 97 98 /** 99 * returns the current namespace 100 * 101 * @return string 102 */ 76 103 public function getCurrentNamespace() 77 104 { 78 105 return $this->currentNamespace; 79 106 } 80 107 108 /** 109 * returns the list of created namespace definitions 110 * 111 * @return NamespaceDefinitions 112 */ 81 113 public function getNamespaceDefinitions() 82 114 { 83 115 return $this->defs; 84 116 } 85 117 118 /** 119 * returns the definition stack 120 * 121 * @return array<Definition> 122 */ 86 123 public function &getDefStack() 87 124 { 88 125 return $this->defStack; 89 126 } 90 127 128 /** 129 * initializes the parser 130 */ 91 131 private function initParser() 92 132 { … … 155 195 private function startElement($namespaceURI, $sName, $atts) 156 196 { 197 // a new namespace 157 198 if (self::TAG_NAMESPACE == $sName) { 158 199 if (isset($atts['uri']) == false) { 159 200 throw new InvalidNamespaceDefinitionException('The <' . self::TAG_NAMESPACE . '> tag is missing the uri attribute.'); 160 201 } 161 202 203 // change current namespace to new namespace 162 204 $this->currentNamespace = $atts['uri']; 163 205 return; 164 206 } 165 207 208 // create the appropriate definition handler and use this 209 // to create the required definition 166 210 $defHandler = DefinitionHandlerFactory::create($sName, $this); 167 211 $def = $defHandler->startElement($namespaceURI, $sName, $atts); … … 180 224 * Fetches the TagDefinition from the stack and 181 225 * adds it to the NamespaceDefinition object. 226 * 227 * @param string $namespaceURI namespace of end tag 228 * @param string $sName name of end tag 182 229 */ 183 230 private function endElement($namespaceURI, $sName) 184 231 { 185 232 // namespace definition ends, switch back to default namespace 186 233 if (self::TAG_NAMESPACE == $sName) { 187 234 $this->currentNamespace = self::DEFAULT_NAMESPACE; 188 235 return; 189 236 } 190 237 238 // use definition handler to finalize the definition of the current tag 191 239 $defHandler = array_pop($this->defHandlerStack); 192 240 $defHandler->endElement($namespaceURI, $sName); trunk/XJConf/GenericTag.php
r2 r9 1 1 <?php 2 XJConfLoader::load('Tag');3 2 /** 4 3 * Generic Tag wrapper that can be used by extensions to dynamically add … … 7 6 * @author Stephan Schmidt <me@schst.net> 8 7 */ 8 XJConfLoader::load('Tag'); 9 /** 10 * Generic Tag wrapper that can be used by extensions to dynamically add 11 * children to other tags. 12 * 13 * @package XJConf 14 */ 9 15 class GenericTag implements Tag 10 16 { 11 12 17 /** 13 18 * name of the tag … … 15 20 * @var string 16 21 */ 17 private $name = null; 18 22 private $name = null; 19 23 /** 20 24 * character data … … 22 26 * @var string 23 27 */ 24 private $data = null; 25 28 private $data = null; 26 29 /** 27 30 * content of the tag (overrides data) … … 29 32 * @var mixed 30 33 */ 31 private $content = null; 32 34 private $content = null; 33 35 /** 34 36 * attributes of the tag … … 36 38 * @var array 37 39 */ 38 private $atts = array(); 39 40 private $atts = array(); 40 41 /** 41 42 * Children of the tag … … 44 45 */ 45 46 private $children = array(); 46 47 47 /** 48 48 * value of the tag … … 50 50 * @var mixed 51 51 */ 52 private $value = null; 53 52 private $value = null; 54 53 /** 55 54 * Key of the tag … … 57 56 * @var string 58 57 */ 59 private $key = null; 60 61 /** 62 * Create a new tag without attributes 63 * 64 * @param name name of the tag 58 private $key = null; 59 60 /** 61 * Create a new tag with or without attributes 62 * 63 * @param string $name name of the tag 64 * @param array $atts optional list of attributes 65 65 */ 66 66 public function __construct($name, $atts = array()) … … 69 69 $this->atts = $atts; 70 70 } 71 71 72 /** 73 * Get the name of the tag 74 * 75 * @return string 76 */ 77 public function getName() 78 { 79 return $this->name; 80 } 81 82 /** 83 * Set the key 84 * 85 * @param string $key 86 */ 87 public function setKey($key) 88 { 89 $this->key = $key; 90 } 91 92 /** 93 * Get the key under which the value will be stored 94 * 95 * @return string 96 */ 97 public function getKey() 98 { 99 return $this->key; 100 } 101 72 102 /** 73 103 * Add text data … … 81 111 return strlen($this->data); 82 112 } 113 114 /** 115 * Get the character data of the tag 116 * 117 * @return string 118 */ 119 public function getData() 120 { 121 return $this->data; 122 } 83 123 84 124 /** … … 107 147 return null; 108 148 } 109 110 /** 111 * Get all children of the tag 112 * 113 * @return array 114 */ 115 public function getChildren() 116 { 117 return $this->children; 118 } 119 149 150 /** 151 * Add a new child to this tag. 152 * 153 * @param Tag $child child to add 154 * @return int number of childs added 155 */ 156 public function addChild(Tag $child) 157 { 158 array_push($this->children, $child); 159 return count($this->children); 160 } 161 120 162 /** 121 163 * Get the child with a specific name … … 134 176 return null; 135 177 } 136 137 /** 138 * Get the name of the tag 139 * 140 * @return name of the tag 141 */ 142 public function getName() 143 { 144 return $this->name; 145 } 146 147 /** 148 * Get the character data of the tag 149 * 150 * @return character data 151 */ 152 public function getData() 153 { 154 return $this->data; 155 } 156 157 /** 158 * Add a new child to this tag. 159 * 160 * @param Tag $child child to add 161 * @return int number of childs added 162 */ 163 public function addChild(Tag $child) 164 { 165 array_push($this->children, $child); 166 return count($this->children); 167 } 168 178 179 /** 180 * Get all children of the tag 181 * 182 * @return array 183 */ 184 public function getChildren() 185 { 186 return $this->children; 187 } 188 189 /** 190 * Set the content (overrides the character data) 191 * 192 * @param mixed $content 193 */ 194 public function setContent($content) 195 { 196 $this->content = $content; 197 } 198 199 /** 200 * Get the content 201 * 202 * @return mixed 203 */ 204 public function getContent() 205 { 206 if (null != $this->content) { 207 return $this->content; 208 } 209 210 return $this->getData(); 211 } 212 169 213 /** 170 214 * Fetch the value … … 176 220 return $this->value; 177 221 } 178 179 /** 180 * Get the key under which the value will be stored 181 * 182 * @return string 183 */ 184 public function getKey() 185 { 186 return $this->key; 187 } 188 189 /** 190 * Set the value of the tag 191 * 192 * @param mixed 193 */ 194 public function setValue($value) 195 { 196 $this->value = $value; 197 } 198 222 199 223 /** 200 224 * Get the type of the value … … 214 238 return gettype($this->value); 215 239 } 216 217 /** 218 * Set the key 219 * 220 * @param string $key 221 */ 222 public function setKey($key) 223 { 224 $this->key = $key; 225 } 226 240 227 241 /** 228 242 * Get the setter method … … 236 250 } 237 251 238 /**239 * Set the content (overrides the character data)240 *241 * @param mixed $content242 */243 public function setContent($content)244 {245 $this->content = $content;246 }247 248 /**249 * Get the content250 *251 * @return mixed252 */253 public function getContent()254 {255 if (null != $this->content) {256 return $this->content;257 }258 259 return $this->getData();260 }261 262 252 /** 263 253 * Checks, whether the tag supports indexed children … … 268 258 { 269 259 return true; 270 } 260 } 261 262 /** 263 * Set the value of the tag 264 * 265 * @param mixed 266 */ 267 public function setValue($value) 268 { 269 $this->value = $value; 270 } 271 271 } 272 272 ?> trunk/XJConf/Tag.php
r2 r9 1 1 <?php 2 /** 3 * Interface for holding tag data. 4 * 5 * @author Stephan Schmidt <me@schst.net> 6 * @author Frank Kleine <frank.kleine@schlund.de> 7 */ 8 /** 9 * Interface for holding tag data. 10 * 11 * @package XJConf 12 */ 2 13 interface Tag 3 14 { 15 /** 16 * Get the name of the tag 17 * 18 * @return name of the tag 19 */ 20 public function getName(); 21 22 /** 23 * Get the key under which the value will be stored 24 * 25 * @return string 26 */ 27 public function getKey(); 28 29 /** 30 * Add text data 31 * 32 * @param string $buf 33 * @return int new length of data 34 */ 35 public function addData($buf); 36 37 /** 38 * Get the character data of the tag 39 * 40 * @return character data 41 */ 42 public function getData(); 43 44 /** 45 * Check, whether the tag has a certain attribute 46 * 47 * @param string $name 48 * @return boolean 49 */ 50 public function hasAttribute($name); 51 52 /** 53 * get an attribute 54 * 55 * @param string $name name of the attribute 56 * @return string value of the attribute 57 */ 58 public function getAttribute($name); 59 60 /** 61 * Add a new child to this tag. 62 * 63 * @param child child to add 64 * @return int number of childs added 65 */ 4 66 public function addChild(Tag $child); 5 public function addData($buf); 67 68 /** 69 * Get the child with a specific name 70 * 71 * @param string $name 72 * @return Tag 73 */ 74 public function getChild($name); 75 76 /** 77 * Get all children of the tag 78 * 79 * @return array 80 */ 81 public function getChildren(); 82 83 /** 84 * Set the content (overrides the character data) 85 * 86 * @param mixed $content 87 */ 6 88 public function setContent($content); 7 public function hasAttribute($name);8 public function getAttribute($name);9 public function getChildren();10 public function getChild($name);11 public function getName();12 public function getData();89 90 /** 91 * Get the content 92 * 93 * @return mixed 94 */ 13 95 public function getContent(); 96 97 /** 98 * Fetch the value 99 * 100 * @return mixed the value of the tag 101 */ 14 102 public function getConvertedValue(); 103 104 /** 105 * Get the type of the value 106 * 107 * @param Tag $tag 108 * @return string 109 */ 15 110 public function getValueType(Tag $tag); 16 public function getKey(); 111 112 /** 113 * Get the setter method 114 * 115 * @return string 116 */ 17 117 public function getSetterMethod(); 118 119 /** 120 * Checks, whether the tag supports indexed children 121 * 122 * @return boolean 123 */ 18 124 public function supportsIndexedChildren(); 19 125 } trunk/XJConf/XJConfLoader.php
r2 r9 1 1 <?php 2 /** 3 * Class loader for all XJConf classes. 4 * 5 * @author Frank Kleine <frank.kleine@schlund.de> 6 */ 7 /** 8 * Class loader for all XJConf classes. 9 * 10 * The class loader takes care that all class files are only loaded once. It 11 * allows all classes to include the required files without knowing where they 12 * reside or if they have been loaded before. 13 * 14 * @package XJConf 15 */ 2 16 class XJConfLoader 3 17 { trunk/XJConf/XmlParser.php
r4 r9 1 1 <?php 2 /** 3 * Parser that reads xml files and generates the data structure. 4 * 5 * @author Stephan Schmidt <stephan.schmidt@schlund.de> 6 * @author Frank Kleine <frank.kleine@schlund.de> 7 */ 2 8 XJConfLoader::load('DefinedTag', 3 9 'GenericTag', … … 7 13 'exceptions.UnknownTagException' 8 14 ); 15 /** 16 * Parser that reads xml files and generates the data structure. 17 * 18 * This parser reads xml files using the tag definitions and 19 * created the data structure and objects described by tag 20 * definitions and the xml file. 21 * 22 * @package XJConf 23 */ 9 24 class XmlParser 10 25 { 26 /** 27 * the list of tags that have to be processed 28 * 29 * @var array<Tag> 30 */ 11 31 private $tagStack = array(); 12 32 /** 33 * hashmap of generated data types 34 * 35 * @var array<String, mixed> 36 */ 13 37 private $config = array(); 14 38 /** 39 * a listof defined namespaces
