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. | |
Data Fields | |
| $file | |
| $obj_id | |
| $result | |
| $mode | |
| $tmpFilename | |
Static Public Attributes | |
| static | $CONTENT_NOT_COMPRESSED = 0 |
| static | $CONTENT_GZ_COMPRESSED = 1 |
| static | $CONTENT_ZLIB_COMPRESSED = 2 |
Exercise XML Parser which completes/updates a given exercise by an xml string.
Definition at line 41 of file class.ilFileXMLParser.php.
| ilFileXMLParser::handlerBeginTag | ( | $ | a_xml_parser, | |
| $ | a_name, | |||
| $ | a_attribs | |||
| ) |
handler for begin of element
| resource | $a_xml_parser xml parser | |
| string | $a_name element name | |
| array | $a_attribs element attributes array |
| ilFileException | when 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, ilUtil::__extractId(), and ilUtil::ilTempnam().
{
global $ilErr;
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->mode = ilFileXMLParser::$CONTENT_NOT_COMPRESSED;
$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);
$this->mode = ilFileXMLParser::$CONTENT_GZ_COMPRESSED;
} 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);
$this->mode = ilFileXMLParser::$CONTENT_ZLIB_COMPRESSED;
}
}
}
}
Here is the call graph for this function:| ilFileXMLParser::handlerCharacterData | ( | $ | a_xml_parser, | |
| $ | a_data | |||
| ) |
handler for character data
| resource | $a_xml_parser xml parser | |
| string | $a_data character data |
Definition at line 253 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
| resource | $a_xml_parser xml parser | |
| string | $a_name element name |
Definition at line 187 of file class.ilFileXMLParser.php.
References $CONTENT_GZ_COMPRESSED, $CONTENT_ZLIB_COMPRESSED, ilFileException::$DECOMPRESSION_FAILED, $ilLog, ilFileUtils::_lookupMimeType(), ilFileUtils::fastBase64Decode(), ilFileUtils::fastGunzip(), and ilUtil::ilTempnam().
{
switch($a_name)
{
case 'File':
$this->result = true;
break;
case 'Filename':
$this->file->setFilename(trim($this->cdata));
$this->file->setTitle(trim($this->cdata));
break;
case 'Title':
$this->file->setTitle(trim($this->cdata));
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 ($this->mode == ilFileXMLParser::$CONTENT_GZ_COMPRESSED)
{
if (!ilFileUtils::fastGunzip ($baseDecodedFilename, $this->tmpFilename))
{
throw new ilFileException ("Deflating with fastzunzip failed", ilFileException::$DECOMPRESSION_FAILED);
}
unlink ($baseDecodedFilename);
}elseif ($this->mode == ilFileXMLParser::$CONTENT_ZLIB_COMPRESSED) {
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.
| ilObjFile | $file existing file object | |
| string | $a_xml_file xml data | |
| int | $obj_id obj 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().
{
parent::ilSaxParser();
$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 272 of file class.ilFileXMLParser.php.
References $filename, and ilUtil::makeDir().
Referenced by updateFileContents().
{
if (filesize ($this->tmpFilename) == 0) {
return;
}
$filedir = $this->file->getDirectory($this->file->getVersion());
if (!is_dir($filedir))
{
$this->file->createDirectory();
ilUtil::makeDir($filedir);
}
$filename = $filedir."/".$this->file->getFileName();
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
| resource | reference 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.
| ilFileException | when obj id != - 1 and if it it does not match the id in the xml |
Definition at line 313 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 296 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: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.
1.7.1