ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilFileXMLParser Class Reference

Exercise XML Parser which completes/updates a given exercise 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.
 setHandlers ($a_xml_parser)
 set event handlers
 handlerBeginTag ($a_xml_parser, $a_name, $a_attribs)
 handler for begin of element
 handlerEndTag ($a_xml_parser, $a_name)
 handler for end of element
 handlerCharacterData ($a_xml_parser, $a_data)
 handler for character data
 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.
 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.
 start ()
 starts parsing an changes object by side effect.
- Public Member Functions inherited from ilSaxParser
 ilSaxParser ($a_xml_file= '', $throwException=false)
 Constructor setup ILIAS global object public.
 setXMLContent ($a_xml_content)
 getXMLContent ()
 getInputType ()
 startParsing ()
 stores xml data in array
 createParser ()
 create parser
 setOptions ($a_xml_parser)
 set parser options
 openXMLFile ()
 open xml file
 parse ($a_xml_parser, $a_fp=null)
 parse xml file
 freeParser ($a_xml_parser)
 free xml parser handle
 setThrowException ($throwException)
 set error handling
- Public Member Functions inherited from PEAR
 PEAR ($error_class=null)
 Constructor.
 _PEAR ()
 Destructor (the emulated type of...).
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.
 registerShutdownFunc ($func, $args=array())
 Use this function to register a shutdown method for static classes.
 isError ($data, $code=null)
 Tell whether a value is a PEAR error.
 setErrorHandling ($mode=null, $options=null)
 Sets how errors generated by this object should be handled.
 expectError ($code= '*')
 This method is used to tell which errors you expect to get.
 popExpect ()
 This method pops one element off the expected error codes stack.
 _checkDelExpect ($error_code)
 This method checks unsets an error code if available.
 delExpect ($error_code)
 This method deletes all occurences of the specified element from the expected error codes stack.
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.
throwError ($message=null, $code=null, $userinfo=null)
 Simpler form of raiseError with fewer options.
 staticPushErrorHandling ($mode, $options=null)
 staticPopErrorHandling ()
 pushErrorHandling ($mode, $options=null)
 Push a new error handler on top of the error handler options stack.
 popErrorHandling ()
 Pop the last error handler used.
 loadExtension ($ext)
 OS independant PHP extension load.

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

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

Detailed Description

Exercise XML Parser which completes/updates a given exercise 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 41 of file class.ilFileXMLParser.php.

Member Function Documentation

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

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

{
global $ilErr;
global $ilLog;
switch($a_name)
{
case 'File':
if (isset($a_attribs["obj_id"]))
{
$read_obj_id = ilUtil::__extractId($a_attribs["obj_id"], IL_INST_ID);
if ($this->obj_id != -1 && (int) $read_obj_id != -1 && (int) $this->obj_id != (int) $read_obj_id)
{
throw new ilFileException ("Object IDs (xml $read_obj_id and argument ".$this->obj_id.") do not match!", ilFileException::$ID_MISMATCH);
}
}
if (isset($a_attribs["type"]))
{
$this->file->setFileType($a_attribs["type"]);
}
$this->file->setVersion($this->file->getVersion() + 1);
break;
case 'Content':
$this->tmpFilename = ilUtil::ilTempnam();
$this->isReadingFile = true;
#echo $a_attribs["mode"];
if (isset($a_attribs["mode"])) {
if ($a_attribs["mode"] == "GZIP")
{
if (!function_exists("gzread"))
throw new ilFileException ("Deflating with gzip is not supported", ilFileException::$ID_DEFLATE_METHOD_MISMATCH);
} elseif ($a_attribs["mode"] == "ZLIB")
{
if (!function_exists("gzuncompress"))
throw new ilFileException ("Deflating with zlib (compress/uncompress) is not supported", ilFileException::$ID_DEFLATE_METHOD_MISMATCH);
}
}
}
}

+ Here is the call graph for this function:

ilFileXMLParser::handlerCharacterData (   $a_xml_parser,
  $a_data 
)

handler for character data

Parameters
resource$a_xml_parserxml parser
string$a_datacharacter data

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

{
if($a_data != "\n")
{
if ($this->isReadingFile)
{
$handle = fopen ($this->tmpFilename, "a");
fwrite ($handle, $a_data);
fclose ($handle);
} else
$this->cdata .= $a_data;
}
}
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 189 of file class.ilFileXMLParser.php.

References $CONTENT_GZ_COMPRESSED, $CONTENT_ZLIB_COMPRESSED, ilFileException\$DECOMPRESSION_FAILED, $ilLog, ilFileUtils\_lookupMimeType(), elseif(), ilFileUtils\fastBase64Decode(), ilFileUtils\fastGunzip(), and ilUtil\ilTempnam().

{
$this->cdata = trim($this->cdata);
switch($a_name)
{
case 'File':
$this->result = true;
break;
case 'Filename':
if (strlen($this->cdata) == 0)
throw new ilFileException("Filename ist missing!");
$this->file->setFilename($this->cdata);
$this->file->setTitle($this->cdata);
break;
case 'Title':
$this->file->setTitle(trim($this->cdata));
break;
case 'Description':
$this->file->setDescription(trim($this->cdata));
break;
case 'Content':
$this->isReadingFile = false;
$baseDecodedFilename = ilUtil::ilTempnam();
if (!ilFileUtils::fastBase64Decode($this->tmpFilename, $baseDecodedFilename))
{
throw new ilFileException ("Base64-Decoding failed", ilFileException::$DECOMPRESSION_FAILED);
}
{
if (!ilFileUtils::fastGunzip ($baseDecodedFilename, $this->tmpFilename))
{
throw new ilFileException ("Deflating with fastzunzip failed", ilFileException::$DECOMPRESSION_FAILED);
}
unlink ($baseDecodedFilename);
}
{
if (!ilFileUtils::fastGunzip ($baseDecodedFilename, $this->tmpFilename))
{
throw new ilFileException ("Deflating with fastDecompress failed", ilFileException::$DECOMPRESSION_FAILED);
}
unlink ($baseDecodedFilename);
}
else
{
$this->tmpFilename = $baseDecodedFilename;
}
//$this->content = $content;
$this->file->setFileSize(filesize($this->tmpFilename)); // strlen($this->content));
// if no file type is given => lookup mime type
if(!$this->file->getFileType())
{
global $ilLog;
#$ilLog->write(__METHOD__.': Trying to detect mime type...');
include_once('./Services/Utilities/classes/class.ilFileUtils.php');
$this->file->setFileType(ilFileUtils::_lookupMimeType($this->tmpFilename));
}
break;
}
$this->cdata = '';
return;
}

+ Here is the call graph for this function:

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

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

{
$this->file = $file;
$this->setXMLContent($a_xml_data);
$this->obj_id = $obj_id;
$this->result = false;
$this->mode = $mode;
}

+ Here is the call graph for this function:

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

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

Referenced by updateFileContents().

{
global $ilLog;
#$ilLog->write(__METHOD__.' '.filesize($this->tmpFilename));
if (filesize ($this->tmpFilename) == 0) {
return;
}
$filedir = $this->file->getDirectory($this->file->getVersion());
#$ilLog->write(__METHOD__.' '.$filedir);
if (!is_dir($filedir))
{
$this->file->createDirectory();
ilUtil::makeDir($filedir);
}
$filename = $filedir."/".$this->file->getFileName();
if (file_exists($filename))
unlink($filename);
return rename($this->tmpFilename, $filename);
// @file_put_contents($filename, $this->content);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilFileXMLParser::setHandlers (   $a_xml_parser)

set event handlers

Parameters
resourcereference to the xml parser private

Reimplemented from ilSaxParser.

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

{
xml_set_object($a_xml_parser,$this);
xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
}
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 333 of file class.ilFileXMLParser.php.

References ilSaxParser\startParsing().

{
$this->startParsing();
return $this->result > 0;
}

+ Here is the call graph for this function:

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

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

{
if ($this->setFileContents())
{
require_once("classes/class.ilHistory.php");
ilHistory::_createEntry($this->file->getId(), "replace", $this->file->getFilename().",".$this->file->getVersion());
$this->file->addNewsNotification("file_updated");
}
}

+ Here is the call graph for this function:

Field Documentation

ilFileXMLParser::$CONTENT_GZ_COMPRESSED = 1
static

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

Referenced by handlerBeginTag(), and handlerEndTag().

ilFileXMLParser::$CONTENT_NOT_COMPRESSED = 0
static

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

Referenced by handlerBeginTag().

ilFileXMLParser::$CONTENT_ZLIB_COMPRESSED = 2
static

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

Referenced by handlerBeginTag(), and handlerEndTag().

ilFileXMLParser::$file

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

Referenced by ilFileXMLParser().

ilFileXMLParser::$mode

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

Referenced by ilFileXMLParser().

ilFileXMLParser::$obj_id

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

Referenced by ilFileXMLParser().

ilFileXMLParser::$result

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

ilFileXMLParser::$tmpFilename

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


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