| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
class patXMLPretty_Engine_Classic extends patXMLPretty_Engine |
|---|
| 4 |
{ |
|---|
| 5 |
|
|---|
| 6 |
* Stores the name of the engine |
|---|
| 7 |
* |
|---|
| 8 |
* @access private |
|---|
| 9 |
* @var string |
|---|
| 10 |
*/ |
|---|
| 11 |
var $name = 'Classic'; |
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
* Stores the generated output line by line |
|---|
| 15 |
* |
|---|
| 16 |
* @access private |
|---|
| 17 |
* @var array |
|---|
| 18 |
*/ |
|---|
| 19 |
var $output = array(); |
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
* Stores a list of all external files present in the XML |
|---|
| 23 |
* |
|---|
| 24 |
* @access private |
|---|
| 25 |
* @var array |
|---|
| 26 |
*/ |
|---|
| 27 |
var $externalFiles = array(); |
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
* Stores the current tag depth in the |
|---|
| 31 |
* parsing stage |
|---|
| 32 |
* |
|---|
| 33 |
* @access private |
|---|
| 34 |
* @var int |
|---|
| 35 |
*/ |
|---|
| 36 |
var $depth = 0; |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
* Stack of tags found in the current parsing stage |
|---|
| 40 |
* |
|---|
| 41 |
* @access private |
|---|
| 42 |
* @var array |
|---|
| 43 |
*/ |
|---|
| 44 |
var $tagStack = array(); |
|---|
| 45 |
|
|---|
| 46 |
function parse( $xmlSource ) |
|---|
| 47 |
{ |
|---|
| 48 |
return array(); |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
$parser = xml_parser_create(); |
|---|
| 52 |
xml_set_object( $parser, $this ); |
|---|
| 53 |
xml_set_element_handler( $parser, '_handle_startElement', '_handle_endElement' ); |
|---|
| 54 |
xml_set_character_data_handler( $parser, '_handle_characterData' ); |
|---|
| 55 |
xml_set_external_entity_ref_handler( $parser, '_handle_externalEntity' ); |
|---|
| 56 |
xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, false ); |
|---|
| 57 |
|
|---|
| 58 |
$success = @xml_parse( $parser, $xmlSource ); |
|---|
| 59 |
if( !$success ) { |
|---|
| 60 |
$error = patErrorManager::raiseError( |
|---|
| 61 |
PATXMLPRETTY_ERROR_XML_PARSING_FAILED, |
|---|
| 62 |
'XML parsing failed', |
|---|
| 63 |
'XML Error ['.xml_error_string( xml_get_error_code( $parser ) ).'] '. |
|---|
| 64 |
'at line ['.xml_get_current_line_number( $parser ).']' |
|---|
| 65 |
); |
|---|
| 66 |
|
|---|
| 67 |
xml_parser_free( $parser ); |
|---|
| 68 |
return $error; |
|---|
| 69 |
} |
|---|
| 70 |
|
|---|
| 71 |
echo '<pre>'; |
|---|
| 72 |
print_r( $this->elementsCollection ); |
|---|
| 73 |
echo '</pre>'; |
|---|
| 74 |
|
|---|
| 75 |
xml_parser_free( $parser ); |
|---|
| 76 |
$result = true; |
|---|
| 77 |
return $result; |
|---|
| 78 |
} |
|---|
| 79 |
|
|---|
| 80 |
var $elementsCollection = array(); |
|---|
| 81 |
|
|---|
| 82 |
var $infoStack = array(); |
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
* Handler for XML start elements |
|---|
| 86 |
* |
|---|
| 87 |
* @access private |
|---|
| 88 |
* @param int |
|---|
| 89 |
* @param string |
|---|
| 90 |
* @param array |
|---|
| 91 |
* @see endElement() |
|---|
| 92 |
*/ |
|---|
| 93 |
function _handle_startElement( $parser, $name, $attributes ) |
|---|
| 94 |
{ |
|---|
| 95 |
$parent = $this->lastOpenedTag; |
|---|
| 96 |
array_push( $this->tagStack, $name ); |
|---|
| 97 |
|
|---|
| 98 |
$path = implode( '.', array_slice( $this->tagStack, 0, $this->depth ) ); |
|---|
| 99 |
$tagInfo = array( |
|---|
| 100 |
'name' => $name, |
|---|
| 101 |
'attributes' => $attributes, |
|---|
| 102 |
'parent' => $parent, |
|---|
| 103 |
'path' => $path |
|---|
| 104 |
); |
|---|
| 105 |
|
|---|
| 106 |
array_push( $this->infoStack, $tagInfo ); |
|---|
| 107 |
|
|---|
| 108 |
$this->renderer->renderOpeningTag( $name, $attributes, $this->depth ); |
|---|
| 109 |
|
|---|
| 110 |
$this->mode = 'startElement'; |
|---|
| 111 |
$this->lastOpenedTag = $name; |
|---|
| 112 |
$this->depth++; |
|---|
| 113 |
} |
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
function _handle_endElement( $parser, $name ) |
|---|
| 123 |
|
|---|
| 124 |
$this->depth--; |
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
array_pop( $this->tagStack ); |
|---|
| 128 |
$tagInfo = array_pop( $this->infoStack ); |
|---|
| 129 |
|
|---|
| 130 |
is_array( $this->elementsCollection[$tagInfo['path']] ) ) { |
|---|
| 131 |
$this->elementsCollection[$tagInfo['path']] = array(); |
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
$this->elementsCollection[$tagInfo['path']][] = $tagInfo; |
|---|
| 135 |
|
|---|
| 136 |
$this->renderer->renderClosingTag( $name, $this->depth ); |
|---|
| 137 |
true; |
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
function _handle_characterData( $parser, $data ) |
|---|
| 148 |
|
|---|
| 149 |
$this->configReader->hideCDATA( $data ) ) { |
|---|
| 150 |
$data = str_repeat( "*", strlen( $data ) ); |
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
$tag = array_pop( $this->tagStack ); |
|---|
| 154 |
array_push( $this->tagStack, $tag ); |
|---|
| 155 |
$this->renderer->renderCDATA( $tag, $data, $this->depth ); |
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 |
function _handle_externalEntity( $parser, $openEntityNames, $base, $systemId, $publicId ) |
|---|
| 169 |
|
|---|
| 170 |
$systemId ) |
|---|
| 171 |
|
|---|
| 172 |
array_push( $this->externalFiles, $systemId ); |
|---|
| 173 |
|
|---|
| 174 |
$this->configReader->parseEntities() ) { |
|---|
| 175 |
$this->_parseFile( $systemId ); |
|---|
| 176 |
|
|---|
| 177 |
$url = $GLOBALS["PHP_SELF"]."?file=".$systemId; |
|---|
| 178 |
$this->output[] = array( "indent" => $this->configReader->getIndent( $this->depth ), |
|---|
| 179 |
"tag" => "<b><a href=\"".$url."\" onMouseOver=\"popUp('Click to show source of the external entity.')\" onMouseOut=\"hidePopUp();\"><font color=\"".$this->configReader->getColor( 'externalEntity' )."\">&".$openEntityNames.";</font></a></b> <font color=\"".$this->configReader->getColor( 'externalEntity' )."\">(".$systemId.")</font>" ); |
|---|
| 180 |
|
|---|
| 181 |
$this->mode = "endElement"; |
|---|
| 182 |
|
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
true; |
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
?> |
|---|