ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilSaxParser Class Reference

Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and implement their own handler methods. More...

+ Inheritance diagram for ilSaxParser:
+ Collaboration diagram for ilSaxParser:

Public Member Functions

 __construct ($a_xml_file='', $throwException=false)
 Constructor setup ILIAS global object public. More...
 
 setXMLContent ($a_xml_content)
 
 getXMLContent ()
 
 getInputType ()
 
 startParsing ()
 stores xml data in array More...
 
 createParser ()
 create parser More...
 
 setOptions ($a_xml_parser)
 set parser options More...
 
 setHandlers ($a_xml_parser)
 set event handler should be overwritten by inherited class private More...
 
 openXMLFile ()
 open xml file More...
 
 parse ($a_xml_parser, $a_fp=null)
 parse xml file More...
 
 freeParser ($a_xml_parser)
 free xml parser handle More...
 
 setThrowException ($throwException)
 set error handling More...
 
- Public Member Functions inherited from PEAR
 __construct ($error_class=null)
 Constructor. More...
 
 _PEAR ()
 Destructor (the emulated type of...). More...
 
 registerShutdownFunc ($func, $args=array())
 Use this function to register a shutdown method for static classes. More...
 
 isError ($data, $code=null)
 Tell whether a value is a PEAR error. More...
 
 expectError ($code=' *')
 This method is used to tell which errors you expect to get. More...
 
 popExpect ()
 This method pops one element off the expected error codes stack. More...
 
 _checkDelExpect ($error_code)
 This method checks unsets an error code if available. More...
 
 delExpect ($error_code)
 This method deletes all occurences of the specified element from the expected error codes stack. More...
 
raiseError ($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
 This method is a wrapper that returns an instance of the configured error class with this object's default error handling applied. More...
 
throwError ($message=null, $code=null, $userinfo=null)
 Simpler form of raiseError with fewer options. More...
 
 staticPushErrorHandling ($mode, $options=null)
 
 staticPopErrorHandling ()
 
 pushErrorHandling ($mode, $options=null)
 Push a new error handler on top of the error handler options stack. More...
 
 popErrorHandling ()
 Pop the last error handler used. More...
 
 loadExtension ($ext)
 OS independant PHP extension load. More...
 

Data Fields

 $input_type = null
 
 $xml_content = ''
 
 $ilias
 
 $lng
 
 $xml_file
 
 $throwException = false
 
- Data Fields inherited from PEAR
 $_debug = false
 
 $_default_error_mode = null
 
 $_default_error_options = null
 
 $_default_error_handler = ''
 
 $_error_class = 'PEAR_Error'
 
 $_expected_errors = array()
 

Protected Member Functions

 handleError ($message, $code)
 use given error handler to handle error message or internal ilias error message handle More...
 

Additional Inherited Members

- Static Public Member Functions inherited from PEAR
static & getStaticProperty ($class, $var)
 If you have a class that's mostly/entirely static, and you need static properties, you can use this method to simulate them. More...
 
static setErrorHandling ($mode=null, $options=null)
 Sets how errors generated by this object should be handled. More...
 

Detailed Description

Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and implement their own handler methods.

Author
Stefan Meyer <smeyer>
Version
$Id$

Definition at line 17 of file class.ilSaxParser.php.

Constructor & Destructor Documentation

◆ __construct()

ilSaxParser::__construct (   $a_xml_file = '',
  $throwException = false 
)

Constructor setup ILIAS global object public.

Definition at line 68 of file class.ilSaxParser.php.

References $ilias, $lng, and $throwException.

69  {
70  global $ilias, $lng;
71 
72  if ($a_xml_file) {
73  $this->xml_file = $a_xml_file;
74  $this->input_type = 'file';
75  }
76 
77  $this->throwException = $throwException;
78  $this->ilias = &$ilias;
79  $this->lng = &$lng;
80  }
redirection script todo: (a better solution should control the processing via a xml file) ...

Member Function Documentation

◆ createParser()

ilSaxParser::createParser ( )

create parser

private

Exceptions
ilSaxParserExceptionor ILIAS Error

Definition at line 135 of file class.ilSaxParser.php.

References handleError().

Referenced by startParsing().

136  {
137  $xml_parser = xml_parser_create("UTF-8");
138 
139  if ($xml_parser == false) {
140  $this->handleError("Cannot create an XML parser handle", $this->ilias->error_obj->FATAL);
141  }
142  return $xml_parser;
143  }
handleError($message, $code)
use given error handler to handle error message or internal ilias error message handle ...
redirection script todo: (a better solution should control the processing via a xml file) ...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ freeParser()

ilSaxParser::freeParser (   $a_xml_parser)

free xml parser handle

private

Definition at line 231 of file class.ilSaxParser.php.

Referenced by startParsing().

232  {
233  if (!xml_parser_free($a_xml_parser)) {
234  $this->ilias->raiseError("Error freeing xml parser handle ", $this->ilias->error_obj->FATAL);
235  }
236  }
redirection script todo: (a better solution should control the processing via a xml file) ...
+ Here is the caller graph for this function:

◆ getInputType()

ilSaxParser::getInputType ( )

Definition at line 93 of file class.ilSaxParser.php.

References $input_type.

Referenced by ilXMLChecker\parse(), SurveyImportParser\parse(), SurveyImportParserPre38\parse(), parse(), ilPluginReader\startParsing(), and startParsing().

94  {
95  return $this->input_type;
96  }
+ Here is the caller graph for this function:

◆ getXMLContent()

ilSaxParser::getXMLContent ( )

Definition at line 88 of file class.ilSaxParser.php.

References $xml_content.

Referenced by ilXMLChecker\parse(), SurveyImportParser\parse(), SurveyImportParserPre38\parse(), and parse().

89  {
90  return $this->xml_content;
91  }
+ Here is the caller graph for this function:

◆ handleError()

ilSaxParser::handleError (   $message,
  $code 
)
protected

use given error handler to handle error message or internal ilias error message handle

Parameters
string$message
string$code
Exceptions
ilSaxParserExceptionor ILIAS Error

Definition at line 212 of file class.ilSaxParser.php.

References $code, and $message.

Referenced by createParser(), openXMLFile(), parse(), and startParsing().

213  {
214  if ($this->throwException) {
215  require_once('./Services/Xml/exceptions/class.ilSaxParserException.php');
216  throw new ilSaxParserException($message, $code);
217  } else {
218  if (is_object($this->ilias)) {
219  $this->ilias->raiseError($message, $code);
220  } else {
221  die($message);
222  }
223  }
224  return false;
225  }
$code
Definition: example_050.php:99
SaxParserException thrown by ilSaxParser if property throwException is set.
catch(Exception $e) $message
redirection script todo: (a better solution should control the processing via a xml file) ...
+ Here is the caller graph for this function:

◆ openXMLFile()

ilSaxParser::openXMLFile ( )

open xml file

private

Exceptions
ilSaxParserExceptionor ILIAS Error

Definition at line 168 of file class.ilSaxParser.php.

References handleError().

Referenced by startParsing().

169  {
170  if (!($fp = fopen($this->xml_file, 'r'))) {
171  $this->handleError("Cannot open xml file \"" . $this->xml_file . "\"", $this->ilias->error_obj->FATAL);
172  }
173  return $fp;
174  }
handleError($message, $code)
use given error handler to handle error message or internal ilias error message handle ...
redirection script todo: (a better solution should control the processing via a xml file) ...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse()

ilSaxParser::parse (   $a_xml_parser,
  $a_fp = null 
)

parse xml file

private

Exceptions
ilSaxParserExceptionor ILIAS Error

Definition at line 181 of file class.ilSaxParser.php.

References $data, $errorCode, getInputType(), getXMLContent(), and handleError().

Referenced by startParsing().

182  {
183  switch ($this->getInputType()) {
184  case 'file':
185 
186  while ($data = fread($a_fp, 4096)) {
187  $parseOk = xml_parse($a_xml_parser, $data, feof($a_fp));
188  }
189  break;
190 
191  case 'string':
192  $parseOk = xml_parse($a_xml_parser, $this->getXMLContent());
193  break;
194  }
195  if (!$parseOk
196  && (xml_get_error_code($a_xml_parser) != XML_ERROR_NONE)) {
197  $errorCode = xml_get_error_code($a_xml_parser);
198  $line = xml_get_current_line_number($a_xml_parser);
199  $col = xml_get_current_column_number($a_xml_parser);
200  $this->handleError("XML Parse Error: " . xml_error_string($errorCode) . " at line " . $line . ", col " . $col . " (Code: " . $errorCode . ")", $this->ilias->error_obj->FATAL);
201  }
202  return true;
203  }
handleError($message, $code)
use given error handler to handle error message or internal ilias error message handle ...
redirection script todo: (a better solution should control the processing via a xml file) ...
$errorCode
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setHandlers()

ilSaxParser::setHandlers (   $a_xml_parser)

set event handler should be overwritten by inherited class private

Definition at line 158 of file class.ilSaxParser.php.

Referenced by startParsing().

159  {
160  echo 'ilSaxParser::setHandlers() must be overwritten';
161  }
+ Here is the caller graph for this function:

◆ setOptions()

ilSaxParser::setOptions (   $a_xml_parser)

set parser options

private

Definition at line 149 of file class.ilSaxParser.php.

Referenced by startParsing().

150  {
151  xml_parser_set_option($a_xml_parser, XML_OPTION_CASE_FOLDING, false);
152  }
+ Here is the caller graph for this function:

◆ setThrowException()

ilSaxParser::setThrowException (   $throwException)

set error handling

Parameters
$error_handler

Definition at line 243 of file class.ilSaxParser.php.

References $throwException.

Referenced by ilSoapMailXmlParser\__construct(), ilFolderXmlParser\__construct(), and ilWebLinkXmlParser\__construct().

244  {
245  $this->throwException = $throwException;
246  }
+ Here is the caller graph for this function:

◆ setXMLContent()

◆ startParsing()

ilSaxParser::startParsing ( )

stores xml data in array

private

Exceptions
ilSaxParserExceptionor ILIAS Error

Definition at line 104 of file class.ilSaxParser.php.

References createParser(), freeParser(), getInputType(), handleError(), openXMLFile(), parse(), setHandlers(), and setOptions().

Referenced by ilMD\cloneMD(), ilSCORM13Package\dbImportLM(), ilSCORM13Package\dbImportSco(), ilModuleReader\getModules(), ilServiceReader\getServices(), ilSCORM13MDImporter\import(), ilSoapMailXmlParser\start(), ilFolderXmlParser\start(), ilWebLinkXmlParser\start(), ilExerciseXMLParser\start(), ilFileXMLParser\start(), and ilForumXMLParser\start().

105  {
106  $xml_parser = $this->createParser();
107  $this->setOptions($xml_parser);
108  $this->setHandlers($xml_parser);
109 
110  switch ($this->getInputType()) {
111  case 'file':
112  $fp = $this->openXMLFile();
113  $this->parse($xml_parser, $fp);
114  break;
115 
116  case 'string':
117  $this->parse($xml_parser);
118  break;
119 
120  default:
121  $this->handleError(
122  "No input type given. Set filename in constructor or choose setXMLContent()",
123  $this->ilias->error_obj->FATAL
124  );
125  break;
126  }
127  $this->freeParser($xml_parser);
128  }
setOptions($a_xml_parser)
set parser options
freeParser($a_xml_parser)
free xml parser handle
handleError($message, $code)
use given error handler to handle error message or internal ilias error message handle ...
redirection script todo: (a better solution should control the processing via a xml file) ...
parse($a_xml_parser, $a_fp=null)
parse xml file
openXMLFile()
open xml file
setHandlers($a_xml_parser)
set event handler should be overwritten by inherited class private
createParser()
create parser
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $ilias

◆ $input_type

ilSaxParser::$input_type = null

Definition at line 26 of file class.ilSaxParser.php.

Referenced by getInputType().

◆ $lng

◆ $throwException

ilSaxParser::$throwException = false

◆ $xml_content

ilSaxParser::$xml_content = ''

Definition at line 34 of file class.ilSaxParser.php.

Referenced by getXMLContent().

◆ $xml_file

ilSaxParser::$xml_file

Definition at line 55 of file class.ilSaxParser.php.


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