1: <?php
2: /**
3: * From Binary XML Content Format Specification Version 1.3, 25 July 2001
4: * found at http://www.wapforum.org
5: *
6: * Copyright 2003-2012 Horde LLC (http://www.horde.org/)
7: *
8: * See the enclosed file COPYING for license information (LGPL). If you
9: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
10: *
11: * @author Anthony Mills <amills@pyramid6.com>
12: * @package Xml_Wbxml
13: */
14: class Horde_Xml_Wbxml_ContentHandler
15: {
16: protected $_currentUri;
17: protected $_output = '';
18:
19: protected $_opaqueHandler;
20:
21: /**
22: * Charset.
23: */
24: protected $_charset = 'UTF-8';
25:
26: /**
27: * WBXML Version.
28: * 1, 2, or 3 supported
29: */
30: protected $_wbxmlVersion = 2;
31:
32: public function __construct()
33: {
34: $this->_currentUri = new Horde_Xml_Wbxml_LifoQueue();
35: }
36:
37: public function getCharsetStr()
38: {
39: return $this->_charset;
40: }
41:
42: public function setCharset($cs)
43: {
44: $this->_charset = $cs;
45: }
46:
47: public function getVersion()
48: {
49: return $this->_wbxmlVersion;
50: }
51:
52: public function setVersion($v)
53: {
54: $this->_wbxmlVersion = 2;
55: }
56:
57: public function getOutput()
58: {
59: return $this->_output;
60: }
61:
62: public function getOutputSize()
63: {
64: return strlen($this->_output);
65: }
66:
67: public function startElement($uri, $element, $attrs = array())
68: {
69: $this->_output .= '<' . $element;
70:
71: $currentUri = $this->_currentUri->top();
72:
73: if (((!$currentUri) || ($currentUri != $uri)) && $uri) {
74: $this->_output .= ' xmlns="' . $uri . '"';
75: }
76:
77: $this->_currentUri->push($uri);
78:
79: foreach ($attrs as $attr) {
80: $this->_output .= ' ' . $attr['attribute'] . '="' . $attr['value'] . '"';
81: }
82:
83: $this->_output .= '>';
84: }
85:
86: public function endElement($uri, $element)
87: {
88: $this->_output .= '</' . $element . '>';
89:
90: $this->_currentUri->pop();
91: }
92:
93: public function characters($str)
94: {
95: $this->_output .= htmlspecialchars($str);
96: }
97:
98: public function opaque($o)
99: {
100: $this->_output .= $o;
101: }
102:
103: public function setOpaqueHandler($opaqueHandler)
104: {
105: $this->_opaqueHandler = $opaqueHandler;
106: }
107:
108: public function removeOpaqueHandler()
109: {
110: unset($this->_opaqueHandler);
111: }
112:
113: public function createSubHandler()
114: {
115: $name = get_class($this); // clone current class
116: $sh = new $name();
117: $sh->setCharset($this->getCharsetStr());
118: $sh->setVersion($this->getVersion());
119: return $sh;
120: }
121: }
122: