Back to index

d-push  2.0
Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes
WBXMLEncoder Class Reference
Inheritance diagram for WBXMLEncoder:
Inheritance graph
[legend]
Collaboration diagram for WBXMLEncoder:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 WBXMLEncoder ($output)
 startWBXML ()
 Puts the WBXML header on the stream.
 startTag ($tag, $attributes=false, $nocontent=false)
 Puts a StartTag on the output stack.
 endTag ()
 Puts an EndTag on the stack.
 content ($content)
 Puts content on the output stack.

Protected Attributes

 $dtd
 The WBXML DTDs.

Private Member Functions

 _outputStack ()
 
Private WBXMLEncoder stuff
 _startTag ($tag, $attributes=false, $nocontent=false)
 Outputs an actual start tag.
 _content ($content)
 Outputs actual data.
 _endTag ()
 Outputs an actual end tag.
 outByte ($byte)
 Outputs a byte.
 outMBUInt ($uint)
 Outputs a string table.
 outTermStr ($content)
 Outputs content with string terminator.
 outAttributes ()
 Output attributes We don't actually support this, because to do so, we would have to build a string table before sending the data (but we can't because we're streaming), so we'll just send an END, which just terminates the attribute list with 0 attributes.
 outSwitchPage ($page)
 Switches the codepage.
 getMapping ($tag)
 Get the mapping for a tag.
 splitTag ($fulltag)
 Split a tag from a the fulltag (namespace + tag)
 logStartTag ($tag, $attr, $nocontent)
 Logs a StartTag to ZLog.
 logEndTag ()
 Logs a EndTag to ZLog.
 logContent ($content)
 Logs content to ZLog.

Private Attributes

 $_dtd
 $_out
 $_tagcp
 $_attrcp
 $logStack = array()
 $_stack

Detailed Description

Definition at line 45 of file wbxmlencoder.php.


Member Function Documentation

WBXMLEncoder::_content ( content) [private]

Outputs actual data.

private

Returns:

Definition at line 221 of file wbxmlencoder.php.

                                        {
        $this->logContent($content);
        $this->outByte(WBXML_STR_I);
        $this->outTermStr($content);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

WBXMLEncoder::_endTag ( ) [private]

Outputs an actual end tag.

private

Returns:

Definition at line 233 of file wbxmlencoder.php.

                               {
        $this->logEndTag();
        $this->outByte(WBXML_END);
    }

Here is the call graph for this function:

Here is the caller graph for this function:


Private WBXMLEncoder stuff

Output any tags on the stack that haven't been output yet

private

Returns:

Definition at line 173 of file wbxmlencoder.php.

                                    {
        for($i=0;$i<count($this->_stack);$i++) {
            if(!$this->_stack[$i]['sent']) {
                $this->_startTag($this->_stack[$i]['tag'], $this->_stack[$i]['attributes'], $this->_stack[$i]['nocontent']);
                $this->_stack[$i]['sent'] = true;
            }
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

WBXMLEncoder::_startTag ( tag,
attributes = false,
nocontent = false 
) [private]

Outputs an actual start tag.

private

Returns:

Definition at line 188 of file wbxmlencoder.php.

                                                                              {
        $this->logStartTag($tag, $attributes, $nocontent);

        $mapping = $this->getMapping($tag);

        if(!$mapping)
            return false;

        if($this->_tagcp != $mapping["cp"]) {
            $this->outSwitchPage($mapping["cp"]);
            $this->_tagcp = $mapping["cp"];
        }

        $code = $mapping["code"];
        if(isset($attributes) && is_array($attributes) && count($attributes) > 0) {
            $code |= 0x80;
        }

        if(!isset($nocontent) || !$nocontent)
            $code |= 0x40;

        $this->outByte($code);

        if($code & 0x80)
            $this->outAttributes($attributes);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

WBXMLEncoder::content ( content)

Puts content on the output stack.

Parameters:
$contentpublic
Returns:
string

Definition at line 152 of file wbxmlencoder.php.

                                      {
        // We need to filter out any \0 chars because it's the string terminator in WBXML. We currently
        // cannot send \0 characters within the XML content anywhere.
        $content = str_replace("\0","",$content);

        if("x" . $content == "x")
            return;
        $this->_outputStack();
        $this->_content($content);
    }

Here is the call graph for this function:

Puts an EndTag on the stack.

public

Returns:

Definition at line 135 of file wbxmlencoder.php.

                             {
        $stackelem = array_pop($this->_stack);

        // Only output end tags for items that have had a start tag sent
        if($stackelem['sent']) {
            $this->_endTag();
        }
    }

Here is the call graph for this function:

WBXMLEncoder::getMapping ( tag) [private]

Get the mapping for a tag.

Parameters:
$tagprivate
Returns:
array

Definition at line 319 of file wbxmlencoder.php.

                                      {
        $mapping = array();

        $split = $this->splitTag($tag);

        if(isset($split["ns"])) {
            $cp = $this->_dtd["namespaces"][$split["ns"]];
        }
        else {
            $cp = 0;
        }

        $code = $this->_dtd["codes"][$cp][$split["tag"]];

        $mapping["cp"] = $cp;
        $mapping["code"] = $code;

        return $mapping;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

WBXMLEncoder::logContent ( content) [private]

Logs content to ZLog.

Parameters:
$contentprivate
Returns:

Definition at line 413 of file wbxmlencoder.php.

                                          {
        if(!WBXML_DEBUG)
            return;

        $spaces = str_repeat(" ", count($this->logStack));
        ZLog::Write(LOGLEVEL_WBXML,"O " . $spaces . $content);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

WBXMLEncoder::logEndTag ( ) [private]

Logs a EndTag to ZLog.

private

Returns:

Definition at line 396 of file wbxmlencoder.php.

                                 {
        if(!WBXML_DEBUG)
            return;

        $spaces = str_repeat(" ", count($this->logStack));
        $tag = array_pop($this->logStack);
        ZLog::Write(LOGLEVEL_WBXML,"O " . $spaces . "</$tag>");
    }

Here is the call graph for this function:

Here is the caller graph for this function:

WBXMLEncoder::logStartTag ( tag,
attr,
nocontent 
) [private]

Logs a StartTag to ZLog.

Parameters:
$tag
$attr
$nocontentprivate
Returns:

Definition at line 377 of file wbxmlencoder.php.

                                                          {
        if(!WBXML_DEBUG)
            return;

        $spaces = str_repeat(" ", count($this->logStack));
        if($nocontent)
            ZLog::Write(LOGLEVEL_WBXML,"O " . $spaces . " <$tag/>");
        else {
            array_push($this->logStack, $tag);
            ZLog::Write(LOGLEVEL_WBXML,"O " . $spaces . " <$tag>");
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Output attributes We don't actually support this, because to do so, we would have to build a string table before sending the data (but we can't because we're streaming), so we'll just send an END, which just terminates the attribute list with 0 attributes.

private

Returns:

Definition at line 294 of file wbxmlencoder.php.

                                     {
        $this->outByte(WBXML_END);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

WBXMLEncoder::outByte ( byte) [private]

Outputs a byte.

Parameters:
$byteprivate
Returns:

Definition at line 246 of file wbxmlencoder.php.

                                    {
        fwrite($this->_out, chr($byte));
    }

Here is the caller graph for this function:

WBXMLEncoder::outMBUInt ( uint) [private]

Outputs a string table.

Parameters:
$uintprivate
Returns:

Definition at line 258 of file wbxmlencoder.php.

                                      {
        while(1) {
            $byte = $uint & 0x7f;
            $uint = $uint >> 7;
            if($uint == 0) {
                $this->outByte($byte);
                break;
            } else {
                $this->outByte($byte | 0x80);
            }
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

WBXMLEncoder::outSwitchPage ( page) [private]

Switches the codepage.

Parameters:
$pageprivate
Returns:

Definition at line 306 of file wbxmlencoder.php.

                                          {
        $this->outByte(WBXML_SWITCH_PAGE);
        $this->outByte($page);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

WBXMLEncoder::outTermStr ( content) [private]

Outputs content with string terminator.

Parameters:
$contentprivate
Returns:

Definition at line 279 of file wbxmlencoder.php.

                                          {
        fwrite($this->_out, $content);
        fwrite($this->_out, chr(0));
    }

Here is the caller graph for this function:

WBXMLEncoder::splitTag ( fulltag) [private]

Split a tag from a the fulltag (namespace + tag)

Parameters:
$fulltagprivate
Returns:
array keys: 'ns' (namespace), 'tag' (tag)

Definition at line 347 of file wbxmlencoder.php.

                                        {
        $ns = false;
        $pos = strpos($fulltag, chr(58)); // chr(58) == ':'

        if($pos) {
            $ns = substr($fulltag, 0, $pos);
            $tag = substr($fulltag, $pos+1);
        }
        else {
            $tag = $fulltag;
        }

        $ret = array();
        if($ns)
            $ret["ns"] = $ns;
        $ret["tag"] = $tag;

        return $ret;
    }

Here is the caller graph for this function:

WBXMLEncoder::startTag ( tag,
attributes = false,
nocontent = false 
)

Puts a StartTag on the output stack.

Parameters:
$tag
$attributes
$nocontentpublic
Returns:

Definition at line 110 of file wbxmlencoder.php.

                                                                            {
        $stackelem = array();

        if(!$nocontent) {
            $stackelem['tag'] = $tag;
            $stackelem['attributes'] = $attributes;
            $stackelem['nocontent'] = $nocontent;
            $stackelem['sent'] = false;

            array_push($this->_stack, $stackelem);

            // If 'nocontent' is specified, then apparently the user wants to force
            // output of an empty tag, and we therefore output the stack here
        } else {
            $this->_outputStack();
            $this->_startTag($tag, $attributes, $nocontent);
        }
    }

Here is the call graph for this function:

Puts the WBXML header on the stream.

public

Returns:

Definition at line 91 of file wbxmlencoder.php.

                                 {
        header("Content-Type: application/vnd.ms-sync.wbxml");

        $this->outByte(0x03); // WBXML 1.3
        $this->outMBUInt(0x01); // Public ID 1
        $this->outMBUInt(106); // UTF-8
        $this->outMBUInt(0x00); // string table length (0)
    }

Here is the call graph for this function:

Definition at line 62 of file wbxmlencoder.php.

                                          {
        // make sure WBXML_DEBUG is defined. It should be at this point
        if (!defined('WBXML_DEBUG')) define('WBXML_DEBUG', false);

        $this->_out = $output;

        $this->_tagcp = 0;
        $this->_attrcp = 0;

        // reverse-map the DTD
        foreach($this->dtd["namespaces"] as $nsid => $nsname) {
            $this->_dtd["namespaces"][$nsname] = $nsid;
        }

        foreach($this->dtd["codes"] as $cp => $value) {
            $this->_dtd["codes"][$cp] = array();
            foreach($this->dtd["codes"][$cp] as $tagid => $tagname) {
                $this->_dtd["codes"][$cp][$tagname] = $tagid;
            }
        }
        $this->_stack = array();
    }

Member Data Documentation

Definition at line 50 of file wbxmlencoder.php.

Definition at line 46 of file wbxmlencoder.php.

Definition at line 47 of file wbxmlencoder.php.

Definition at line 60 of file wbxmlencoder.php.

Definition at line 49 of file wbxmlencoder.php.

WBXMLDefs::$dtd [protected, inherited]

The WBXML DTDs.

Definition at line 83 of file wbxmldefs.php.

WBXMLEncoder::$logStack = array() [private]

Definition at line 52 of file wbxmlencoder.php.


The documentation for this class was generated from the following file: