ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 @access 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 @access 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@databay>
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 @access public.

Reimplemented in ilCourseXMLParser, ilSCORM13MDImporter, ilAdvancedMDParser, ilCategoryXmlParser, ilContainerReferenceXmlParser, ilObjectXMLParser, ilXMLChecker, ilChatroomXMLParser, ilFolderXmlParser, ilForumXMLParser, and ilWebLinkXmlParser.

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

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)

References $ilias, $lng, and $throwException.

Member Function Documentation

◆ createParser()

ilSaxParser::createParser ( )

create parser

@access private

Exceptions
ilSaxParserExceptionor ILIAS Error

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

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

References handleError().

Referenced by startParsing().

+ 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

@access private

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

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 }

Referenced by startParsing().

+ Here is the caller graph for this function:

◆ getInputType()

ilSaxParser::getInputType ( )

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

94 {
95 return $this->input_type;
96 }

References $input_type.

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

+ Here is the caller graph for this function:

◆ getXMLContent()

ilSaxParser::getXMLContent ( )

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

89 {
90 return $this->xml_content;
91 }

References $xml_content.

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

+ 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.

213 {
214 if ($this->throwException) {
215 require_once('./Services/Xml/exceptions/class.ilSaxParserException.php');
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 }
SaxParserException thrown by ilSaxParser if property throwException is set.
$code
Definition: example_050.php:99
catch(Exception $e) $message

References $code, and $message.

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

+ Here is the caller graph for this function:

◆ openXMLFile()

ilSaxParser::openXMLFile ( )

open xml file

@access private

Exceptions
ilSaxParserExceptionor ILIAS Error

Reimplemented in ilQTIParser.

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

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 }

References handleError().

Referenced by startParsing().

+ 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

@access private

Exceptions
ilSaxParserExceptionor ILIAS Error

Reimplemented in ilXMLChecker, SurveyImportParser, and ilObjectXMLParser.

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

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 }
$data
Definition: bench.php:6
$errorCode

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

Referenced by startParsing().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setHandlers()

◆ setOptions()

ilSaxParser::setOptions (   $a_xml_parser)

set parser options

@access private

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

150 {
151 xml_parser_set_option($a_xml_parser, XML_OPTION_CASE_FOLDING, false);
152 }

Referenced by startParsing().

+ 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.

244 {
245 $this->throwException = $throwException;
246 }

References $throwException.

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

+ Here is the caller graph for this function:

◆ setXMLContent()

◆ startParsing()

ilSaxParser::startParsing ( )

stores xml data in array

@access private

Exceptions
ilSaxParserExceptionor ILIAS Error

Reimplemented in ilCategoryImportParser, ilCategoryXmlParser, ilGroupXMLParser, ilContObjParser, ilSCORMPackageParser, ilAdvancedMDRecordParser, ilXMLChecker, ilPluginReader, ilContainerReferenceXmlParser, ilSimpleXMLTableDataParser, ilDataSetImportParser, ilExportFileParser, ilManifestParser, ilQTIParser, ilStyleImportParser, SurveyImportParser, and ilUserImportParser.

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

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 }
openXMLFile()
open xml file
freeParser($a_xml_parser)
free xml parser handle
parse($a_xml_parser, $a_fp=null)
parse xml file
setHandlers($a_xml_parser)
set event handler should be overwritten by inherited class @access private
createParser()
create parser
setOptions($a_xml_parser)
set parser options

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

Referenced by ilModuleReader\getModules(), ilServiceReader\getServices(), ilSCORM13MDImporter\import(), ilExerciseXMLParser\start(), ilFileXMLParser\start(), ilFolderXmlParser\start(), ilForumXMLParser\start(), ilLearningSequenceXMLParser\start(), ilWebLinkXmlParser\start(), and ilSoapMailXmlParser\start().

+ 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: