XML_HTMLSax3
[ class tree: XML_HTMLSax3 ] [ index: XML_HTMLSax3 ] [ all elements ]

Source for file States.php

Documentation is available at States.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. //
  4. // +----------------------------------------------------------------------+
  5. // | PHP Version 4                                                        |
  6. // +----------------------------------------------------------------------+
  7. // | Copyright (c) 1997-2002 The PHP Group                                |
  8. // +----------------------------------------------------------------------+
  9. // | This source file is subject to version 2.02 of the PHP license,      |
  10. // | that is bundled with this package in the file LICENSE, and is        |
  11. // | available at through the world-wide-web at                           |
  12. // | http://www.php.net/license/3_0.txt.                                  |
  13. // | If you did not receive a copy of the PHP license and are unable to   |
  14. // | obtain it through the world-wide-web, please send a note to          |
  15. // | license@php.net so we can mail you a copy immediately.               |
  16. // +----------------------------------------------------------------------+
  17. // | Authors: Alexander Zhukov <alex@veresk.ru> Original port from Python |
  18. // | Authors: Harry Fuecks <hfuecks@phppatterns.com> Port to PEAR + more  |
  19. // | Authors: Many @ Sitepointforums Advanced PHP Forums                  |
  20. // +----------------------------------------------------------------------+
  21. //
  22. // $Id: States.php 22138 2007-06-01 10:19:14Z markwest $
  23. //
  24. /**
  25. * Parsing states.
  26. @package XML_HTMLSax3
  27. @version $Id: States.php 22138 2007-06-01 10:19:14Z markwest $
  28. */
  29. /**
  30. * Define parser states
  31. */
  32. define('XML_HTMLSAX3_STATE_STOP'0);
  33. define('XML_HTMLSAX3_STATE_START'1);
  34. define('XML_HTMLSAX3_STATE_TAG'2);
  35. define('XML_HTMLSAX3_STATE_OPENING_TAG'3);
  36. define('XML_HTMLSAX3_STATE_CLOSING_TAG'4);
  37. define('XML_HTMLSAX3_STATE_ESCAPE'6);
  38. define('XML_HTMLSAX3_STATE_JASP'7);
  39. define('XML_HTMLSAX3_STATE_PI'8);
  40. /**
  41. * StartingState searches for the start of any XML tag
  42. @package XML_HTMLSax3
  43. @access protected
  44. */
  45.     /**
  46.     * @param XML_HTMLSax3_StateParser subclass
  47.     * @return constant XML_HTMLSAX3_STATE_TAG
  48.     * @access protected
  49.     */
  50.     function parse(&$context{
  51.         $data $context->scanUntilString('<');
  52.         if ($data != ''{
  53.             $context->handler_object_data->
  54.                 {$context->handler_method_data}($context->htmlsax$data);
  55.         }
  56.         $context->IgnoreCharacter();
  57.         return XML_HTMLSAX3_STATE_TAG;
  58.     }
  59. }
  60. /**
  61. * Decides which state to move one from after StartingState
  62. @package XML_HTMLSax3
  63. @access protected
  64. */
  65.     /**
  66.     * @param XML_HTMLSax3_StateParser subclass
  67.     * @return constant the next state to move into
  68.     * @access protected
  69.     */
  70.     function parse(&$context{
  71.         switch($context->ScanCharacter()) {
  72.         case '/':
  73.             return XML_HTMLSAX3_STATE_CLOSING_TAG;
  74.             break;
  75.         case '?':
  76.             return XML_HTMLSAX3_STATE_PI;
  77.             break;
  78.         case '%':
  79.             return XML_HTMLSAX3_STATE_JASP;
  80.             break;
  81.         case '!':
  82.             return XML_HTMLSAX3_STATE_ESCAPE;
  83.             break;
  84.         default:
  85.             $context->unscanCharacter();
  86.             return XML_HTMLSAX3_STATE_OPENING_TAG;
  87.         }
  88.     }
  89. }
  90. /**
  91. * Dealing with closing XML tags
  92. @package XML_HTMLSax3
  93. @access protected
  94. */
  95.     /**
  96.     * @param XML_HTMLSax3_StateParser subclass
  97.     * @return constant XML_HTMLSAX3_STATE_START
  98.     * @access protected
  99.     */
  100.     function parse(&$context{
  101.         $tag $context->scanUntilCharacters('/>');
  102.         if ($tag != ''{
  103.             $char $context->scanCharacter();
  104.             if ($char == '/'{
  105.                 $char $context->scanCharacter();
  106.                 if ($char != '>'{
  107.                     $context->unscanCharacter();
  108.                 }
  109.             }
  110.             $context->handler_object_element->
  111.                 {$context->handler_method_closing}($context->htmlsax$tagFALSE);
  112.         }
  113.         return XML_HTMLSAX3_STATE_START;
  114.     }
  115. }
  116. /**
  117. * Dealing with opening XML tags
  118. @package XML_HTMLSax3
  119. @access protected
  120. */
  121.     /**
  122.     * Handles attributes
  123.     * @param string attribute name
  124.     * @param string attribute value
  125.     * @return void 
  126.     * @access protected
  127.     * @see XML_HTMLSax3_AttributeStartState
  128.     */
  129.     function parseAttributes(&$context{
  130.         $Attributes array();
  131.     
  132.         $context->ignoreWhitespace();
  133.         $attributename $context->scanUntilCharacters("=/> \n\r\t");
  134.         while ($attributename != ''{
  135.             $attributevalue NULL;
  136.             $context->ignoreWhitespace();
  137.             $char $context->scanCharacter();
  138.             if ($char == '='{
  139.                 $context->ignoreWhitespace();
  140.                 $char $context->ScanCharacter();
  141.                 if ($char == '"'{
  142.                     $attributevalue$context->scanUntilString('"');
  143.                     $context->IgnoreCharacter();
  144.                 else if ($char == "'"{
  145.                     $attributevalue $context->scanUntilString("'");
  146.                     $context->IgnoreCharacter();
  147.                 else {
  148.                     $context->unscanCharacter();
  149.                     $attributevalue =
  150.                         $context->scanUntilCharacters("> \n\r\t");
  151.                 }
  152.             else if ($char !== NULL{
  153.                 $attributevalue NULL;
  154.                 $context->unscanCharacter();
  155.             }
  156.             $Attributes[$attributename$attributevalue;
  157.             
  158.             $context->ignoreWhitespace();
  159.             $attributename $context->scanUntilCharacters("=/> \n\r\t");
  160.         }
  161.         return $Attributes;
  162.     }
  163.  
  164.     /**
  165.     * @param XML_HTMLSax3_StateParser subclass
  166.     * @return constant XML_HTMLSAX3_STATE_START
  167.     * @access protected
  168.     */
  169.     function parse(&$context{
  170.         $tag $context->scanUntilCharacters("/> \n\r\t");
  171.         if ($tag != ''{
  172.             $this->attrs array();
  173.             $Attributes $this->parseAttributes($context);
  174.             $char $context->scanCharacter();
  175.             if ($char == '/'{
  176.                 $char $context->scanCharacter();
  177.                 if ($char != '>'{
  178.                     $context->unscanCharacter();
  179.                 }
  180.                 $context->handler_object_element->
  181.                     {$context->handler_method_opening}($context->htmlsax$tag
  182.                     $AttributesTRUE);
  183.                 $context->handler_object_element->
  184.                     {$context->handler_method_closing}($context->htmlsax$tag
  185.                     TRUE);
  186.             else {
  187.                 $context->handler_object_element->
  188.                     {$context->handler_method_opening}($context->htmlsax$tag
  189.                     $AttributesFALSE);
  190.             }
  191.         }
  192.         return XML_HTMLSAX3_STATE_START;
  193.     }
  194. }
  195.  
  196. /**
  197. * Deals with XML escapes handling comments and CDATA correctly
  198. @package XML_HTMLSax3
  199. @access protected
  200. */
  201.     /**
  202.     * @param XML_HTMLSax3_StateParser subclass
  203.     * @return constant XML_HTMLSAX3_STATE_START
  204.     * @access protected
  205.     */
  206.     function parse(&$context{
  207.         $char $context->ScanCharacter();
  208.         if ($char == '-'{
  209.             $char $context->ScanCharacter();
  210.             if ($char == '-'{
  211.                 $context->unscanCharacter();
  212.                 $context->unscanCharacter();
  213.                 $text $context->scanUntilString('-->');
  214.                 $text .= $context->scanCharacter();
  215.                 $text .= $context->scanCharacter();
  216.             else {
  217.                 $context->unscanCharacter();
  218.                 $text $context->scanUntilString('>');
  219.             }
  220.         else if $char == '['{
  221.             $context->unscanCharacter();
  222.             $text $context->scanUntilString(']>');
  223.             $text.= $context->scanCharacter();
  224.         else {
  225.             $context->unscanCharacter();
  226.             $text $context->scanUntilString('>');
  227.         }
  228.  
  229.         $context->IgnoreCharacter();
  230.         if ($text != ''{
  231.             $context->handler_object_escape->
  232.             {$context->handler_method_escape}($context->htmlsax$text);
  233.         }
  234.         return XML_HTMLSAX3_STATE_START;
  235.     }
  236. }
  237. /**
  238. * Deals with JASP/ASP markup
  239. @package XML_HTMLSax3
  240. @access protected
  241. */
  242.     /**
  243.     * @param XML_HTMLSax3_StateParser subclass
  244.     * @return constant XML_HTMLSAX3_STATE_START
  245.     * @access protected
  246.     */
  247.     function parse(&$context{
  248.         $text $context->scanUntilString('%>');
  249.         if ($text != ''{
  250.             $context->handler_object_jasp->
  251.                 {$context->handler_method_jasp}($context->htmlsax$text);
  252.         }
  253.         $context->IgnoreCharacter();
  254.         $context->IgnoreCharacter();
  255.         return XML_HTMLSAX3_STATE_START;
  256.     }
  257. }
  258. /**
  259. * Deals with XML processing instructions
  260. @package XML_HTMLSax3
  261. @access protected
  262. */
  263.     /**
  264.     * @param XML_HTMLSax3_StateParser subclass
  265.     * @return constant XML_HTMLSAX3_STATE_START
  266.     * @access protected
  267.     */
  268.     function parse(&$context{
  269.         $target $context->scanUntilCharacters(" \n\r\t");
  270.         $data $context->scanUntilString('?>');
  271.         if ($data != ''{
  272.             $context->handler_object_pi->
  273.             {$context->handler_method_pi}($context->htmlsax$target$data);
  274.         }
  275.         $context->IgnoreCharacter();
  276.         $context->IgnoreCharacter();
  277.         return XML_HTMLSAX3_STATE_START;
  278.     }
  279. }

Documentation generated on Fri, 18 Jul 2008 21:58:20 +0200 by phpDocumentor 1.4.1