[sync] WBXML patch

Anthony Mills amills at gascard.net
Wed Feb 11 16:03:20 PST 2004


Here is a patch for the WBXML.  It adds support for using libwbxml.  I 
have not tested it yet.  I may get to test this evening.

Anthony

Index: Decoder.php
===================================================================
RCS file: /repository/framework/XML_WBXML/WBXML/Decoder.php,v
retrieving revision 1.16
diff -r1.16 Decoder.php
68a69,74
 >    
 >     /**
 >      * Use wbxml2xml from libwbxml.
 >      * @var String
 >      */
 >     var $_wbxml2xml = '/usr/local/bin/wbxml2xml -o ';
88,115c94
<         $this->_strpos = 0;
<         // Get Version Number from Section 5.4
<         // version = u_int8
<         // currently 1, 2 or 3
<         $this->_wbxmlVersion = $this->getVersionNumber($input);
<
<         // Get Document Public Idetifier from Section 5.5
<         // publicid = mb_u_int32 | (zero index)
<         // zero = u_int8
<         // Containing the value zero (0)
<         // The actual DPI is determined after the String Table is read.
<         $dpiStruct = $this->getDocumentPublicIdentifier($input);
<
<         // Get Charset from 5.6
<         // charset = mb_u_int32
<         $this->_charset = $this->getCharset($input);
<
<         // Get String Table from 5.7
<         // strb1 = length *byte
<         $this->_stringTable = $this->getStringTable($input, 
$this->_charset);
<
<         // Get Document Public Idetifier from Section 5.5.
<         $this->_dpi = 
$this->getDocumentPublicIdentifierImpl($dpiStruct['dpiType'],
<                                                              
$dpiStruct['dpiNumber'],
<                                                              
$this->_stringTable);
<
<         // Now the real fun begins.
<         // from Sections 5.2 and 5.8
---
 >         if (isset($this->_wbxml2xml)) {
117,126c96,157
<         // Default content handler.
<         $this->_ch = &new XML_WBXML_ContentHandler();
<
<         // Default content handler.
<         $this->_dtdManager = &new XML_WBXML_DTDManager();
<
<         // Get the starting DTD.
<         $this->_tagDTD = $this->_dtdManager->getInstance($this->_dpi);
<         if (!$this->_tagDTD) {
<             return $this->raiseError('No DTD found for ' . $this->_dpi);
---
 >             $tmp_id = mt_rand();
 >             $tmp_file = '/tmp' . DIRECTORY_SEPARATOR . 
'wbxml_decoder_' . $tmp_id;
 >            
 >             $fp = fopen($tmp_file . '.wbxml', 'wb');
 >             fwrite($fp, $input);
 >             fclose($fp);
 >            
 >             exec($this->_wbxml2xml . $tmp_file . '.xml ' . $tmp_file 
. '.wbxml');
 >
 >             $ret = file_get_contents($tmp_file . '.xml');
 >             unlink($tmp_file . '.xml');
 >             unlink($tmp_file . '.wbxml');
 >             return $ret;
 >         } else {
 >             $this->_strpos = 0;
 >             // Get Version Number from Section 5.4
 >             // version = u_int8
 >             // currently 1, 2 or 3
 >             $this->_wbxmlVersion = $this->getVersionNumber($input);
 >    
 >             // Get Document Public Idetifier from Section 5.5
 >             // publicid = mb_u_int32 | (zero index)
 >             // zero = u_int8
 >             // Containing the value zero (0)
 >             // The actual DPI is determined after the String Table is 
read.
 >             $dpiStruct = $this->getDocumentPublicIdentifier($input);
 >    
 >             // Get Charset from 5.6
 >             // charset = mb_u_int32
 >             $this->_charset = $this->getCharset($input);
 >    
 >             // Get String Table from 5.7
 >             // strb1 = length *byte
 >             $this->_stringTable = $this->getStringTable($input, 
$this->_charset);
 >    
 >             // Get Document Public Idetifier from Section 5.5.
 >             $this->_dpi = 
$this->getDocumentPublicIdentifierImpl($dpiStruct['dpiType'],
 >                                                                  // 
$dpiStruct['dpiNumber'],
 >                                                                  // 
$this->_stringTable);
 >    
 >             // Now the real fun begins.
 >             // from Sections 5.2 and 5.8
 >    
 >             // Default content handler.
 >             $this->_ch = &new XML_WBXML_ContentHandler();
 >    
 >             // Default content handler.
 >             $this->_dtdManager = &new XML_WBXML_DTDManager();
 >    
 >             // Get the starting DTD.
 >             $this->_tagDTD = 
$this->_dtdManager->getInstance($this->_dpi);
 >             if (!$this->_tagDTD) {
 >                 return $this->raiseError('No DTD found for ' . 
$this->_dpi);
 >             }
 >    
 >             $this->_attributeDTD = $this->_tagDTD;
 >    
 >             while ($this->_strpos < strlen($input)) {
 >                 $this->_decode($input);
 >             }
 >    
 >             return $this->_ch->getOutput();
128,135c159
<
<         $this->_attributeDTD = $this->_tagDTD;
<
<         while ($this->_strpos < strlen($input)) {
<             $this->_decode($input);
<         }
<
<         return $this->_ch->getOutput();
---
 > 

Index: Encoder.php
===================================================================
RCS file: /repository/framework/XML_WBXML/WBXML/Encoder.php,v
retrieving revision 1.20
diff -r1.20 Encoder.php
64a65,70
 >      * Use wbxml2xml from libwbxml.
 >      * @var String
 >      */
 >     var $_xml2wbxml = '/usr/local/bin/xml2wbxml -n -v 1.2 -o ';
 >    
 >     /**
85,98c91,124
<         // Create the XML parser and set method references.
<         $this->_parser = xml_parser_create_ns($this->_charset);
<         xml_set_object($this->_parser, $this);
<         xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, 
false);
<         xml_set_element_handler($this->_parser, '_startElement', 
'_endElement');
<         xml_set_character_data_handler($this->_parser, '_characters');
<         xml_set_default_handler($this->_parser, 'defaultHandler');
<         xml_set_processing_instruction_handler($this->_parser, '');
<         xml_set_external_entity_ref_handler($this->_parser, '');
<
<         if (!xml_parse($this->_parser, $xml)) {
<             return $this->raiseError(sprintf('XML error: %s at line %d',
<                                              
xml_error_string(xml_get_error_code($this->_parser)),
<                                              
xml_get_current_line_number($this->_parser)));
---
 >         if (isset($this->_xml2wbxml)) {
 >             $tmp_id = mt_rand();
 >             $tmp_file = '/tmp' . DIRECTORY_SEPARATOR . 
'wbxml_encoder_' . $tmp_id;
 >            
 >             $fp = fopen($tmp_file . '.xml', 'wb');
 >             fwrite($fp, $xml);
 >             fclose($fp);
 >            
 >             exec($this->_wbxml2xml . $tmp_file . '.wbxml ' . 
$tmp_file . '.xml');
 >        
 >             $ret = file_get_contents($tmp_file . '.wbxml');
 >             unlink($tmp_file . '.wbxml');
 >             unlink($tmp_file . '.xml');
 >             return $ret;
 >         } else {
 >             // Create the XML parser and set method references.
 >             $this->_parser = xml_parser_create_ns($this->_charset);
 >             xml_set_object($this->_parser, $this);
 >             xml_parser_set_option($this->_parser, 
XML_OPTION_CASE_FOLDING, false);
 >             xml_set_element_handler($this->_parser, '_startElement', 
'_endElement');
 >             xml_set_character_data_handler($this->_parser, 
'_characters');
 >             xml_set_default_handler($this->_parser, 'defaultHandler');
 >             xml_set_processing_instruction_handler($this->_parser, '');
 >             xml_set_external_entity_ref_handler($this->_parser, '');
 >    
 >             if (!xml_parse($this->_parser, $xml)) {
 >                 return $this->raiseError(sprintf('XML error: %s at 
line %d',
 >                                                  
xml_error_string(xml_get_error_code($this->_parser)),
 >                                                  
xml_get_current_line_number($this->_parser)));
 >             }
 >            
 >             xml_parser_free($this->_parser);       
 >            
 >             return $this->_output;
100,103d125
<
<         xml_parser_free($this->_parser);
<
<         return $this->_output;



More information about the sync mailing list