ILIAS  release_4-4 Revision
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

 ilFileXMLParser (& $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
 ilSaxParser ($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
 PEAR ($error_class=null)
 Constructor. More...
 
 _PEAR ()
 Destructor (the emulated type of...). More...
 
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...
 
 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...
 
 setErrorHandling ($mode=null, $options=null)
 Sets how errors generated by this object should be handled. 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

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

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(), 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  $this->file->setVersion($this->file->getVersion() + 1);
159  break;
160  case 'Content':
161  $this->tmpFilename = ilUtil::ilTempnam();
163  $this->isReadingFile = true;
164 #echo $a_attribs["mode"];
165  if (isset($a_attribs["mode"]))
166  {
167  if($a_attribs["mode"] == "GZIP")
168  {
169  if (!function_exists("gzread"))
170  throw new ilFileException ("Deflating with gzip is not supported", ilFileException::$ID_DEFLATE_METHOD_MISMATCH);
171 
173  }
174  elseif ($a_attribs["mode"] == "ZLIB")
175  {
176  if (!function_exists("gzuncompress"))
177  throw new ilFileException ("Deflating with zlib (compress/uncompress) is not supported", ilFileException::$ID_DEFLATE_METHOD_MISMATCH);
178 
180  }
181  elseif ($a_attribs["mode"] == "COPY")
182  {
183  $this->mode = ilFileXMLParser::$CONTENT_COPY;
184  }
185  // begin-patch fm
186  elseif($a_attribs['mode'] == 'REST')
187  {
188  $this->mode = ilFileXMLParser::$CONTENT_REST;
189  }
190  // end-patch fm
191  }
192  }
193  }
Class to report exception.
static ilTempnam()
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 306 of file class.ilFileXMLParser.php.

References $CONTENT_COPY, and $CONTENT_REST.

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

◆ 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 203 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(), getImportDirectory(), and ilUtil\ilTempnam().

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

◆ ilFileXMLParser()

ilFileXMLParser::ilFileXMLParser ( $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, and ilSaxParser\setXMLContent().

87  {
88  parent::ilSaxParser();
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  }
setXMLContent($a_xml_content)
+ Here is the call graph for this function:

◆ 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 327 of file class.ilFileXMLParser.php.

References $filename, $ilLog, and ilUtil\makeDir().

Referenced by updateFileContents().

328  {
329  global $ilLog;
330 
331  #$ilLog->write(__METHOD__.' '.filesize($this->tmpFilename));
332 
333  if (filesize ($this->tmpFilename) == 0) {
334  return;
335  }
336 
337  $filedir = $this->file->getDirectory($this->file->getVersion());
338  #$ilLog->write(__METHOD__.' '.$filedir);
339 
340  if (!is_dir($filedir))
341  {
342  $this->file->createDirectory();
343  ilUtil::makeDir($filedir);
344  }
345 
346  $filename = $filedir."/".$this->file->getFileName();
347  if (file_exists($filename))
348  unlink($filename);
349 //echo "-".$this->tmpFilename."-".$filename."-"; exit;
350  return rename($this->tmpFilename, $filename);
351  // @file_put_contents($filename, $this->content);
352  }
$filename
Definition: buildRTE.php:89
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
+ 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 377 of file class.ilFileXMLParser.php.

References ilSaxParser\startParsing().

377  {
378  $this->startParsing();
379  return $this->result > 0;
380  }
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 360 of file class.ilFileXMLParser.php.

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

361  {
362  if ($this->setFileContents())
363  {
364  require_once("./Services/History/classes/class.ilHistory.php");
365  ilHistory::_createEntry($this->file->getId(), "replace", $this->file->getFilename().",".$this->file->getVersion());
366  $this->file->addNewsNotification("file_updated");
367  }
368  }
_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 ilFileXMLParser().

◆ $mode

ilFileXMLParser::$mode

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

Referenced by ilFileXMLParser().

◆ $obj_id

ilFileXMLParser::$obj_id

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

Referenced by ilFileXMLParser().

◆ $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: