ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilFileXMLParser Class Reference

Exercise XML Parser which completes/updates a given file by an xml string. More...

+ Inheritance diagram for ilFileXMLParser:
+ Collaboration diagram for ilFileXMLParser:

Public Member Functions

 __construct (& $file, $a_xml_data, $obj_id=-1, $mode=0)
 Constructor. More...
 
 setImportDirectory ($a_val)
 Set import directory. More...
 
 getImportDirectory ()
 Get import directory. More...
 
 setHandlers ($a_xml_parser)
 set event handlers More...
 
 handlerBeginTag ($a_xml_parser, $a_name, $a_attribs)
 handler for begin of element More...
 
 handlerEndTag ($a_xml_parser, $a_name)
 handler for end of element More...
 
 handlerCharacterData ($a_xml_parser, $a_data)
 handler for character data More...
 
 setFileContents ()
 update file according to filename and version, does not update history has to be called after (!) file save for new objects, since file storage will be initialised with obj id. More...
 
 updateFileContents ()
 update file according to filename and version and create history entry has to be called after (!) file save for new objects, since file storage will be initialised with obj id. More...
 
 start ()
 starts parsing an changes object by side effect. More...
 
- Public Member Functions inherited from ilSaxParser
 __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...
 

Static Public Member Functions

static normalizeRelativePath ($path)
 Normalize relative directories in a path. More...
 
- 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...
 

Data Fields

 $file
 
 $obj_id
 
 $result
 
 $mode
 
 $tmpFilename
 
- Data Fields inherited from ilSaxParser
 $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()
 

Static Public Attributes

static $CONTENT_NOT_COMPRESSED = 0
 
static $CONTENT_GZ_COMPRESSED = 1
 
static $CONTENT_ZLIB_COMPRESSED = 2
 
static $CONTENT_COPY = 4
 
static $CONTENT_REST = 5
 

Additional Inherited Members

- Protected Member Functions inherited from ilSaxParser
 handleError ($message, $code)
 use given error handler to handle error message or internal ilias error message handle More...
 

Detailed Description

Exercise XML Parser which completes/updates a given file by an xml string.

Author
Roland Küstermann rolan.nosp@m.d@ku.nosp@m.ester.nosp@m.mann.nosp@m..com
Version
Id
class.ilObjectXMLParser.php 12811 2006-12-08 18:37:44Z akill

Definition at line 22 of file class.ilFileXMLParser.php.

Constructor & Destructor Documentation

◆ __construct()

ilFileXMLParser::__construct ( $file,
  $a_xml_data,
  $obj_id = -1,
  $mode = 0 
)

Constructor.

Parameters
ilObjFile$fileexisting file object
string$a_xml_filexml data
int$obj_idobj id of exercise which is to be updated public

Definition at line 86 of file class.ilFileXMLParser.php.

References $file, $mode, $obj_id, file, and ilSaxParser\setXMLContent().

87  {
88  parent::__construct();
89  $this->file = $file;
90  $this->setXMLContent($a_xml_data);
91  $this->obj_id = $obj_id;
92  $this->result = false;
93  $this->mode = $mode;
94  }
Reload workbook from saved file
setXMLContent($a_xml_content)
+ Here is the call graph for this function:

Member Function Documentation

◆ getImportDirectory()

ilFileXMLParser::getImportDirectory ( )

Get import directory.

Returns
string import directory

Definition at line 111 of file class.ilFileXMLParser.php.

Referenced by handlerEndTag().

112  {
113  return $this->importDirectory;
114  }
+ Here is the caller graph for this function:

◆ handlerBeginTag()

ilFileXMLParser::handlerBeginTag (   $a_xml_parser,
  $a_name,
  $a_attribs 
)

handler for begin of element

Parameters
resource$a_xml_parserxml parser
string$a_nameelement name
array$a_attribselement attributes array
Exceptions
ilFileExceptionwhen obj id != - 1 and if it it does not match the id in the xml or deflation mode is not supported

Definition at line 137 of file class.ilFileXMLParser.php.

References $CONTENT_COPY, $CONTENT_GZ_COMPRESSED, $CONTENT_NOT_COMPRESSED, $CONTENT_REST, $CONTENT_ZLIB_COMPRESSED, ilFileException\$ID_DEFLATE_METHOD_MISMATCH, ilFileException\$ID_MISMATCH, $ilErr, $ilLog, ilUtil\__extractId(), file, and ilUtil\ilTempnam().

138  {
139  global $ilErr;
140 
141  global $ilLog;
142 
143  switch($a_name)
144  {
145  case 'File':
146  if (isset($a_attribs["obj_id"]))
147  {
148  $read_obj_id = ilUtil::__extractId($a_attribs["obj_id"], IL_INST_ID);
149  if ($this->obj_id != -1 && (int) $read_obj_id != -1 && (int) $this->obj_id != (int) $read_obj_id)
150  {
151  throw new ilFileException ("Object IDs (xml $read_obj_id and argument ".$this->obj_id.") do not match!", ilFileException::$ID_MISMATCH);
152  }
153  }
154  if (isset($a_attribs["type"]))
155  {
156  $this->file->setFileType($a_attribs["type"]);
157  }
158  break;
159  case 'Content':
160  $this->tmpFilename = ilUtil::ilTempnam();
162  $this->isReadingFile = true;
163 #echo $a_attribs["mode"];
164  if (isset($a_attribs["mode"]))
165  {
166  if($a_attribs["mode"] == "GZIP")
167  {
168  if (!function_exists("gzread"))
169  throw new ilFileException ("Deflating with gzip is not supported", ilFileException::$ID_DEFLATE_METHOD_MISMATCH);
170 
172  }
173  elseif ($a_attribs["mode"] == "ZLIB")
174  {
175  if (!function_exists("gzuncompress"))
176  throw new ilFileException ("Deflating with zlib (compress/uncompress) is not supported", ilFileException::$ID_DEFLATE_METHOD_MISMATCH);
177 
179  }
180  elseif ($a_attribs["mode"] == "COPY")
181  {
182  $this->mode = ilFileXMLParser::$CONTENT_COPY;
183  }
184  // begin-patch fm
185  elseif($a_attribs['mode'] == 'REST')
186  {
187  $this->mode = ilFileXMLParser::$CONTENT_REST;
188  }
189  // end-patch fm
190  }
191  }
192  }
global $ilErr
Definition: raiseError.php:16
Class to report exception.
Reload workbook from saved file
static ilTempnam($a_temp_path=null)
Create a temporary file in an ILIAS writable directory.
static __extractId($ilias_id, $inst_id)
extract ref id from role title, e.g.
+ Here is the call graph for this function:

◆ handlerCharacterData()

ilFileXMLParser::handlerCharacterData (   $a_xml_parser,
  $a_data 
)

handler for character data

Parameters
resource$a_xml_parserxml parser
string$a_datacharacter data

Definition at line 309 of file class.ilFileXMLParser.php.

References $CONTENT_COPY, and $CONTENT_REST.

310  {
311  if($a_data != "\n")
312  {
313  // begin-patch fm
314  if ($this->isReadingFile && $this->mode != ilFileXMLParser::$CONTENT_COPY && $this->mode != ilFileXMLParser::$CONTENT_REST)
315  // begin-patch fm
316  {
317  $handle = fopen($this->tmpFilename, "a");
318  fwrite ($handle, $a_data);
319  fclose ($handle);
320  } else
321  $this->cdata .= $a_data;
322  }
323  }

◆ handlerEndTag()

ilFileXMLParser::handlerEndTag (   $a_xml_parser,
  $a_name 
)

handler for end of element

Parameters
resource$a_xml_parserxml parser
string$a_nameelement name

Definition at line 202 of file class.ilFileXMLParser.php.

References $CONTENT_COPY, $CONTENT_GZ_COMPRESSED, $CONTENT_REST, $CONTENT_ZLIB_COMPRESSED, ilFileException\$DECOMPRESSION_FAILED, $GLOBALS, $ilLog, ilFileUtils\_lookupMimeType(), ilFileUtils\fastBase64Decode(), ilFileUtils\fastGunzip(), file, getImportDirectory(), and ilUtil\ilTempnam().

203  {
204  $this->cdata = trim($this->cdata);
205 
206  $GLOBALS['ilLog']->write(__METHOD__.': '.$this->cdata);
207 
208  switch($a_name)
209  {
210  case 'File':
211  $this->result = true;
212  break;
213  case 'Filename':
214  if (strlen($this->cdata) == 0)
215  throw new ilFileException("Filename ist missing!");
216 
217  $this->file->setFilename(basename(self::normalizeRelativePath($this->cdata)));
218  $this->file->setTitle($this->cdata);
219 
220  break;
221  case 'Title':
222  $this->file->setTitle(trim($this->cdata));
223  break;
224  case 'Description':
225  $this->file->setDescription(trim($this->cdata));
226  break;
227  case 'Rating':
228  $this->file->setRating((bool)$this->cdata);
229  break;
230  case 'Content':
231  $GLOBALS['ilLog']->write($this->mode);
232  $this->isReadingFile = false;
233  $baseDecodedFilename = ilUtil::ilTempnam();
234  if ($this->mode == ilFileXMLParser::$CONTENT_COPY)
235  {
236  $this->tmpFilename = $this->getImportDirectory()."/".self::normalizeRelativePath($this->cdata);
237  }
238  // begin-patch fm
239  elseif($this->mode == ilFileXMLParser::$CONTENT_REST)
240  {
241  include_once './Services/WebServices/Rest/classes/class.ilRestFileStorage.php';
242  $storage = new ilRestFileStorage();
243  $this->tmpFilename = $storage->getStoredFilePath(self::normalizeRelativePath($this->cdata));
244  if(!ilFileUtils::fastBase64Decode($this->tmpFilename, $baseDecodedFilename))
245  {
246  throw new ilFileException("Base64-Decoding failed", ilFileException::$DECOMPRESSION_FAILED);
247  }
248  $this->tmpFilename = $baseDecodedFilename;
249  }
250  // end-patch fm
251  else
252  {
253  if (!ilFileUtils::fastBase64Decode($this->tmpFilename, $baseDecodedFilename))
254  {
255  throw new ilFileException ("Base64-Decoding failed", ilFileException::$DECOMPRESSION_FAILED);
256  }
257  if ($this->mode == ilFileXMLParser::$CONTENT_GZ_COMPRESSED)
258  {
259  if (!ilFileUtils::fastGunzip ($baseDecodedFilename, $this->tmpFilename))
260  {
261  throw new ilFileException ("Deflating with fastzunzip failed", ilFileException::$DECOMPRESSION_FAILED);
262  }
263  unlink ($baseDecodedFilename);
264  }
265  elseif ($this->mode == ilFileXMLParser::$CONTENT_ZLIB_COMPRESSED)
266  {
267  if (!ilFileUtils::fastGunzip ($baseDecodedFilename, $this->tmpFilename))
268  {
269  throw new ilFileException ("Deflating with fastDecompress failed", ilFileException::$DECOMPRESSION_FAILED);
270  }
271  unlink ($baseDecodedFilename);
272  }
273  else
274  {
275  $this->tmpFilename = $baseDecodedFilename;
276  }
277  }
278  //$this->content = $content;
279  // see #17211
280  if (is_file($this->tmpFilename))
281  {
282  $this->file->setFileSize(filesize($this->tmpFilename)); // strlen($this->content));
283  }
284 
285  // if no file type is given => lookup mime type
286  if(!$this->file->getFileType())
287  {
288  global $ilLog;
289 
290  #$ilLog->write(__METHOD__.': Trying to detect mime type...');
291  include_once('./Services/Utilities/classes/class.ilFileUtils.php');
292  $this->file->setFileType(ilFileUtils::_lookupMimeType($this->tmpFilename));
293  }
294 
295  break;
296  }
297 
298  $this->cdata = '';
299 
300  return;
301  }
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
static _lookupMimeType($a_file)
Class to report exception.
Reload workbook from saved file
static ilTempnam($a_temp_path=null)
Create a temporary file in an ILIAS writable directory.
File storage handling.
fastBase64Decode($filein, $fileout)
decodes base encoded file row by row to prevent memory exhaust
fastGunzip($in, $out)
fast uncompressing the file with the zlib-extension without memory consumption
getImportDirectory()
Get import directory.
+ Here is the call graph for this function:

◆ normalizeRelativePath()

static ilFileXMLParser::normalizeRelativePath (   $path)
static

Normalize relative directories in a path.

Source: https://github.com/thephpleague/flysystem/blob/master/src/Util.php#L96 Workaround until we have

Parameters
string$path
Exceptions
LogicException
Returns
string

Definition at line 399 of file class.ilFileXMLParser.php.

References $path.

399  {
400  $path = str_replace('\\', '/', $path);
401 
402  while (preg_match('#\p{C}+|^\./#u', $path)) {
403  $path = preg_replace('#\p{C}+|^\./#u', '', $path);
404  }
405 
406  $parts = [];
407  foreach (explode('/', $path) as $part) {
408  switch ($part) {
409  case '':
410  case '.':
411  break;
412  case '..':
413  array_pop($parts);
414  break;
415  default:
416  $parts[] = $part;
417  break;
418  }
419  }
420 
421  return implode('/', $parts);
422  }
$path
Definition: aliased.php:25

◆ setFileContents()

ilFileXMLParser::setFileContents ( )

update file according to filename and version, does not update history has to be called after (!) file save for new objects, since file storage will be initialised with obj id.

Definition at line 330 of file class.ilFileXMLParser.php.

References $filename, file, ilLoggerFactory\getLogger(), ilUtil\makeDir(), and ilFileUtils\rename().

Referenced by updateFileContents().

331  {
332  if(!file_exists($this->tmpFilename))
333  {
334  ilLoggerFactory::getLogger('file')->error(__METHOD__.' "'.$this->tmpFilename. '" file not found.');
335  return;
336  }
337 
338  if (filesize ($this->tmpFilename) == 0) {
339  return;
340  }
341 
342  $filedir = $this->file->getDirectory($this->file->getVersion());
343 
344  if (!is_dir($filedir))
345  {
346  $this->file->createDirectory();
347  ilUtil::makeDir($filedir);
348  }
349 
350  $filename = $filedir."/".$this->file->getFileName();
351 
352  if (file_exists($filename))
353  unlink($filename);
354  require_once('./Services/Utilities/classes/class.ilFileUtils.php');
355  return ilFileUtils::rename($this->tmpFilename, $filename);
356  }
static rename($a_source, $a_target)
Rename a file.
Reload workbook from saved file
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static getLogger($a_component_id)
Get component logger.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setHandlers()

ilFileXMLParser::setHandlers (   $a_xml_parser)

set event handlers

Parameters
resourcereference to the xml parser private

Definition at line 121 of file class.ilFileXMLParser.php.

122  {
123  xml_set_object($a_xml_parser,$this);
124  xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
125  xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
126  }

◆ setImportDirectory()

ilFileXMLParser::setImportDirectory (   $a_val)

Set import directory.

Parameters
stringimport directory

Definition at line 101 of file class.ilFileXMLParser.php.

102  {
103  $this->importDirectory = $a_val;
104  }

◆ start()

ilFileXMLParser::start ( )

starts parsing an changes object by side effect.

Exceptions
ilFileExceptionwhen obj id != - 1 and if it it does not match the id in the xml
Returns
boolean true, if no errors happend.

Definition at line 381 of file class.ilFileXMLParser.php.

References ilSaxParser\startParsing().

381  {
382  $this->startParsing();
383  return $this->result > 0;
384  }
startParsing()
stores xml data in array
+ Here is the call graph for this function:

◆ updateFileContents()

ilFileXMLParser::updateFileContents ( )

update file according to filename and version and create history entry has to be called after (!) file save for new objects, since file storage will be initialised with obj id.

Definition at line 364 of file class.ilFileXMLParser.php.

References ilHistory\_createEntry(), file, and setFileContents().

365  {
366  if ($this->setFileContents())
367  {
368  require_once("./Services/History/classes/class.ilHistory.php");
369  ilHistory::_createEntry($this->file->getId(), "replace", $this->file->getFilename().",".$this->file->getVersion());
370  $this->file->addNewsNotification("file_updated");
371  }
372  }
Reload workbook from saved file
static _createEntry($a_obj_id, $a_action, $a_info_params="", $a_obj_type="", $a_user_comment="", $a_update_last=false)
Creates a new history entry for an object.
setFileContents()
update file according to filename and version, does not update history has to be called after (!) fil...
+ Here is the call graph for this function:

Field Documentation

◆ $CONTENT_COPY

ilFileXMLParser::$CONTENT_COPY = 4
static

Definition at line 27 of file class.ilFileXMLParser.php.

Referenced by handlerBeginTag(), handlerCharacterData(), and handlerEndTag().

◆ $CONTENT_GZ_COMPRESSED

ilFileXMLParser::$CONTENT_GZ_COMPRESSED = 1
static

Definition at line 25 of file class.ilFileXMLParser.php.

Referenced by handlerBeginTag(), and handlerEndTag().

◆ $CONTENT_NOT_COMPRESSED

ilFileXMLParser::$CONTENT_NOT_COMPRESSED = 0
static

Definition at line 24 of file class.ilFileXMLParser.php.

Referenced by handlerBeginTag().

◆ $CONTENT_REST

ilFileXMLParser::$CONTENT_REST = 5
static

Definition at line 29 of file class.ilFileXMLParser.php.

Referenced by handlerBeginTag(), handlerCharacterData(), and handlerEndTag().

◆ $CONTENT_ZLIB_COMPRESSED

ilFileXMLParser::$CONTENT_ZLIB_COMPRESSED = 2
static

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

Referenced by handlerBeginTag(), and handlerEndTag().

◆ $file

ilFileXMLParser::$file

Definition at line 37 of file class.ilFileXMLParser.php.

Referenced by __construct().

◆ $mode

ilFileXMLParser::$mode

Definition at line 60 of file class.ilFileXMLParser.php.

Referenced by __construct().

◆ $obj_id

ilFileXMLParser::$obj_id

Definition at line 45 of file class.ilFileXMLParser.php.

Referenced by __construct().

◆ $result

ilFileXMLParser::$result

Definition at line 53 of file class.ilFileXMLParser.php.

◆ $tmpFilename

ilFileXMLParser::$tmpFilename

Definition at line 75 of file class.ilFileXMLParser.php.


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