ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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, ilGroupXMLParser, ilContainerReferenceXmlParser, ilObjectXMLParser, ilMailImportParser, ilXMLChecker, 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 {
74 $this->xml_file = $a_xml_file;
75 $this->input_type = 'file';
76 }
77
78 $this->throwException = $throwException;
79 $this->ilias = &$ilias;
80 $this->lng = &$lng;
81 }
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 {
141 $this->handleError("Cannot create an XML parser handle",$this->ilias->error_obj->FATAL);
142 }
143 return $xml_parser;
144 }
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 239 of file class.ilSaxParser.php.

240 {
241 if(!xml_parser_free($a_xml_parser))
242 {
243 $this->ilias->raiseError("Error freeing xml parser handle ",$this->ilias->error_obj->FATAL);
244 }
245 }

Referenced by startParsing().

+ Here is the caller graph for this function:

◆ getInputType()

ilSaxParser::getInputType ( )

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

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

References $input_type.

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

+ Here is the caller graph for this function:

◆ getXMLContent()

ilSaxParser::getXMLContent ( )

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

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

References $xml_content.

Referenced by ilXMLChecker\parse(), SurveyImportParser\parse(), SurveyImportParserPre38\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 218 of file class.ilSaxParser.php.

218 {
219 if ($this->throwException) {
220 require_once ('./Services/Xml/exceptions/class.ilSaxParserException.php');
221 throw new ilSaxParserException ($message, $code);
222 } else {
223 if (is_object($this->ilias))
224 {
225 $this->ilias->raiseError($message, $code);
226 }
227 else
228 {
229 die($message);
230 }
231 }
232 return false;
233 }
SaxParserException thrown by ilSaxParser if property throwException is set.
$code
Definition: example_050.php:99

References $code.

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 169 of file class.ilSaxParser.php.

170 {
171 if(!($fp = fopen($this->xml_file,'r')))
172 {
173 $this->handleError("Cannot open xml file \"".$this->xml_file."\"",$this->ilias->error_obj->FATAL);
174 }
175 return $fp;
176 }

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, SurveyImportParserPre38, and ilObjectXMLParser.

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

184 {
185 switch($this->getInputType())
186 {
187 case 'file':
188
189 while($data = fread($a_fp,4096))
190 {
191 $parseOk = xml_parse($a_xml_parser,$data,feof($a_fp));
192 }
193 break;
194
195 case 'string':
196 $parseOk = xml_parse($a_xml_parser,$this->getXMLContent());
197 break;
198 }
199 if(!$parseOk
200 && (xml_get_error_code($a_xml_parser) != XML_ERROR_NONE))
201 {
202 $errorCode = xml_get_error_code($a_xml_parser);
203 $line = xml_get_current_line_number($a_xml_parser);
204 $col = xml_get_current_column_number($a_xml_parser);
205 $this->handleError("XML Parse Error: ".xml_error_string($errorCode)." at line ".$line.", col ". $col . " (Code: ".$errorCode.")" ,$this->ilias->error_obj->FATAL);
206 }
207 return true;
208
209 }

References $data, 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 150 of file class.ilSaxParser.php.

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

Referenced by startParsing().

+ Here is the caller graph for this function:

◆ setThrowException()

ilSaxParser::setThrowException (   $throwException)

set error handling

Parameters
$error_handler

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

253 {
254 $this->throwException = $throwException;
255 }

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, ilMailImportParser, ilQTIParser, ilStyleImportParser, SurveyImportParser, SurveyImportParserPre38, and ilUserImportParser.

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

106 {
107 $xml_parser = $this->createParser();
108 $this->setOptions($xml_parser);
109 $this->setHandlers($xml_parser);
110
111 switch($this->getInputType())
112 {
113 case 'file':
114 $fp = $this->openXMLFile();
115 $this->parse($xml_parser,$fp);
116 break;
117
118 case 'string':
119 $this->parse($xml_parser);
120 break;
121
122 default:
123 $this->handleError("No input type given. Set filename in constructor or choose setXMLContent()",
124 $this->ilias->error_obj->FATAL);
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(), 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: