diff options
Diffstat (limited to 'vendor/ilias')
| -rw-r--r-- | vendor/ilias/class.ilObjectXMLParser.php | 322 | ||||
| -rw-r--r-- | vendor/ilias/class.ilSaxParser.php | 257 |
2 files changed, 0 insertions, 579 deletions
diff --git a/vendor/ilias/class.ilObjectXMLParser.php b/vendor/ilias/class.ilObjectXMLParser.php deleted file mode 100644 index f5e6368..0000000 --- a/vendor/ilias/class.ilObjectXMLParser.php +++ /dev/null @@ -1,322 +0,0 @@ -<?php -/* - +-----------------------------------------------------------------------------+ - | ILIAS open source | - +-----------------------------------------------------------------------------+ - | Copyright (c) 1998-2001 ILIAS open source, University of Cologne | - | | - | This program is free software; you can redistribute it and/or | - | modify it under the terms of the GNU General Public License | - | as published by the Free Software Foundation; either version 2 | - | of the License, or (at your option) any later version. | - | | - | This program is distributed in the hope that it will be useful, | - | but WITHOUT ANY WARRANTY; without even the implied warranty of | - | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | - | GNU General Public License for more details. | - | | - | You should have received a copy of the GNU General Public License | - | along with this program; if not, write to the Free Software | - | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | - +-----------------------------------------------------------------------------+ -*/ - - -/** -* Object XML Parser -* -* @author Stefan Meyer <meyer@leifos.com> -* @version $Id$ -* -* @extends ilSaxParser -*/ - -//include_once './Services/Xml/classes/class.ilSaxParser.php'; -//include_once('./webservice/soap/classes/class.ilObjectXMLException.php'); - -class ilObjectXMLParser extends ilSaxParser -{ - var $object_data = array(); - - private $ref_id; - private $parent_id; - - /** - * Constructor - * - * @param object $a_content_object must be of type ilObjContentObject - * ilObjTest or ilObjQuestionPool - * @param string $a_xml_file xml data - * @param string $a_subdir subdirectory in import directory - * @access public - */ - function __construct($a_xml_data = '', $throwException = false) - { - parent::__construct('', $throwException); - $this->setXMLContent($a_xml_data); - } - - function getObjectData() - { - return $this->object_data ? $this->object_data : array(); - } - - /** - * parse xml file - * - * @access private - * @throws ilSaxParserException - * @throws ilObjectXMLException - */ - function parse($a_xml_parser,$a_fp = null) - { - parent::parse($a_xml_parser,$a_fp); - } - - - /** - * set event handlers - * - * @param resource reference to the xml parser - * @access private - */ - function setHandlers($a_xml_parser) - { - 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'); - } - - - - - /** - * handler for begin of element - * - * @param resource $a_xml_parser xml parser - * @param string $a_name element name - * @param array $a_attribs element attributes array - */ - function handlerBeginTag($a_xml_parser,$a_name,$a_attribs) - { - switch($a_name) - { - case 'Objects': - $this->curr_obj = -1; - break; - - case 'Object': - ++$this->curr_obj; - - $this->addProperty__('type',$a_attribs['type']); - $this->addProperty__('obj_id',is_numeric($a_attribs['obj_id'])?(int) $a_attribs["obj_id"] : ilUtil::__extractId($a_attribs["obj_id"], IL_INST_ID)); - break; - - case 'Title': - break; - - case 'Description': - break; - - case 'Owner': - break; - - case 'CreateDate': - break; - - case 'LastUpdate': - break; - - case 'ImportId': - break; - - case 'References': - $this->time_target = array(); - $this->ref_id = $a_attribs["ref_id"]; - $this->parent_id = $a_attribs['parent_id']; - $this->operations = array(); - break; - - case 'TimeTarget': - $this->time_target['timing_type'] = $a_attribs['type']; - break; - - case 'Timing': - $this->time_target['timing_visibility'] = $a_attribs['visibility']; - if(isset($a_attribs['starting_time'])) - { - $this->time_target['starting_time'] = $a_attribs['starting_time']; - } - if(isset($a_attribs['ending_time'])) - { - $this->time_target['ending_time'] = $a_attribs['ending_time']; - } - - if($a_attribs['ending_time'] < $a_attribs['starting_time']) - throw new ilObjectXMLException('Starting time must be earlier than ending time.'); - break; - - case 'Suggestion': - $this->time_target['changeable'] = $a_attribs['changeable']; - - - if(isset($a_attribs['starting_time'])) - { - $this->time_target['suggestion_start'] = $a_attribs['starting_time']; - } - if(isset($a_attribs['ending_time'])) - { - $this->time_target['suggestion_end'] = $a_attribs['ending_time']; - } - if(isset($a_attribs['earliest_start'])) - { - $this->time_target['earliest_start'] = $a_attribs['earliest_start']; - } - if(isset($a_attribs['latest_end'])) - { - $this->time_target['latest_end'] = $a_attribs['latest_end']; - } - - if($a_attribs['latest_end'] < $a_attribs['earliest_start']) - throw new ilObjectXMLException('Earliest start time must be earlier than latest ending time.'); - if($a_attribs['ending_time'] < $a_attribs['starting_time']) - throw new ilObjectXMLException('Starting time must be earlier than ending time.'); - break; - - //////////////////////////////////////////// - ///////////// MODIFIED ///////////////////// - //////////////////////////////////////////// - case 'Operation': - $this->operations[] = $a_attribs['operations']; - break; - //////////////////////////////////////////// - } - } - - /** - * handler for end of element - * - * @param resource $a_xml_parser xml parser - * @param string $a_name element name - */ - function handlerEndTag($a_xml_parser,$a_name) - { - switch($a_name) - { - case 'Objects': - break; - - case 'Object': - break; - - case 'Title': - $this->addProperty__('title',trim($this->cdata)); - break; - - case 'Description': - $this->addProperty__('description',trim($this->cdata)); - break; - - case 'Owner': - $this->addProperty__('owner',trim($this->cdata)); - break; - - case 'CreateDate': - $this->addProperty__('create_date',trim($this->cdata)); - break; - - case 'LastUpdate': - $this->addProperty__('last_update',trim($this->cdata)); - break; - - case 'ImportId': - $this->addProperty__('import_id',trim($this->cdata)); - break; - - case 'References': - $this->addReference__($this->ref_id,$this->parent_id,$this->time_target); - break; - //////////////////////////////////////////// - ///////////// MODIFIED ///////////////////// - //////////////////////////////////////////// - case 'Operation': - $this->addOperation__(trim($this->cdata)); - break; - //////////////////////////////////////////// - } - - $this->cdata = ''; - - return; - } - - /** - * handler for character data - * - * @param resource $a_xml_parser xml parser - * @param string $a_data character data - */ - function handlerCharacterData($a_xml_parser,$a_data) - { - if($a_data != "\n") - { - // Replace multiple tabs with one space - $a_data = preg_replace("/\t+/"," ",$a_data); - - $this->cdata .= $a_data; - } - - - } - - // PRIVATE - function addProperty__($a_name,$a_value) - { - $this->object_data[$this->curr_obj][$a_name] = $a_value; - } - - /** - * @throws ilObjectXMLException - */ - function addReference__($a_ref_id,$a_parent_id,$a_time_target) - { - $reference['ref_id'] = $a_ref_id; - $reference['parent_id'] = $a_parent_id; - $reference['time_target'] = $a_time_target; - - if(isset($reference['time_target']['changeable']) and $reference['time_target']['changeable']) - { - if(!isset($reference['time_target']['earliest_start']) or !isset($reference['time_target']['latest_end'])) - { - throw new ilObjectXMLException('Missing attributes: "earliest_start" and "latest_end" required for attribute "changeable"'); - } - if(!isset($reference['time_target']['suggestion_start']) or !isset($reference['time_target']['suggestion_end'])) - { - throw new ilObjectXMLException('Missing attributes: "starting_time" and "ending_time" required for attribute "changeable"'); - } - if(($reference['time_target']['earliest_start'] < $reference['time_target']['suggestion_start']) or - ($reference['time_target']['earliest_start'] > $reference['time_target']['suggestion_end'])) - { - throw new ilObjectXMLException('Invalid attributes: "earliest_start" must be within "starting_time" and "ending_time"'); - } - if(($reference['time_target']['latest_end'] < $reference['time_target']['suggestion_start']) or - ($reference['time_target']['latest_end'] > $reference['time_target']['suggestion_end'])) - { - throw new ilObjectXMLException('Invalid attributes: "latest_end" must be within "starting_time" and "ending_time"'); - } - } - - $this->object_data[$this->curr_obj]['references'][] = $reference; - } - - //////////////////////////////////////////// - ///////////// MODIFIED ///////////////////// - //////////////////////////////////////////// - function addOperation__($a_value) - { - if($a_value) - $this->object_data[$this->curr_obj]['references'][$this->reference_count]["operations"][] = $a_value; - } - //////////////////////////////////////////// -} -?> diff --git a/vendor/ilias/class.ilSaxParser.php b/vendor/ilias/class.ilSaxParser.php deleted file mode 100644 index a963f1b..0000000 --- a/vendor/ilias/class.ilSaxParser.php +++ /dev/null @@ -1,257 +0,0 @@ -<?php -/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */ - - -/** -* 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$ -* -* @extends PEAR -*/ - - -class ilSaxParser -{ - /** - * XML-Content type 'file' or 'string' - * If you choose file set the filename in constructor - * If you choose 'String' call the constructor with no argument and use setXMLContent() - * @var string - * @access private - */ - var $input_type = null; - - /** - * XML-Content in case of content type 'string' - - * @var string - * @access private - */ - var $xml_content = ''; - - /** - * ilias object - * @var object ilias - * @access private - */ - var $ilias; - - /** - * language object - * @var object language - * @access private - */ - var $lng; - - /** - * xml filename - * @var filename - * @access private - */ - var $xml_file; - - /** - * error handler which handles error messages (used if parsers are called from soap) - * - * @var boolean - */ - var $throwException = false; - /** - * Constructor - * setup ILIAS global object - * @access public - */ - function __construct($a_xml_file = '', $throwException = false) - { - global $ilias, $lng; - - if($a_xml_file) - { - $this->xml_file = $a_xml_file; - $this->input_type = 'file'; - } - - $this->throwException = $throwException; - $this->ilias = &$ilias; - $this->lng = &$lng; - } - - function setXMLContent($a_xml_content) - { - $this->xml_content = $a_xml_content; - $this->input_type = 'string'; - } - - function getXMLContent() - { - return $this->xml_content; - } - - function getInputType() - { - return $this->input_type; - } - - /** - * stores xml data in array - * - * @access private - * @throws ilSaxParserException or ILIAS Error - */ - function startParsing() - { - $xml_parser = $this->createParser(); - $this->setOptions($xml_parser); - $this->setHandlers($xml_parser); - - switch($this->getInputType()) - { - case 'file': - $fp = $this->openXMLFile(); - $this->parse($xml_parser,$fp); - break; - - case 'string': - $this->parse($xml_parser); - break; - - default: - $this->handleError("No input type given. Set filename in constructor or choose setXMLContent()", - $this->ilias->error_obj->FATAL); - break; - } - $this->freeParser($xml_parser); - } - /** - * create parser - * - * @access private - * @throws ilSaxParserException or ILIAS Error - */ - function createParser() - { - $xml_parser = xml_parser_create("UTF-8"); - - if($xml_parser == false) - { - $this->handleError("Cannot create an XML parser handle",$this->ilias->error_obj->FATAL); - } - return $xml_parser; - } - /** - * set parser options - * - * @access private - */ - function setOptions($a_xml_parser) - { - xml_parser_set_option($a_xml_parser,XML_OPTION_CASE_FOLDING,false); - } - /** - * set event handler - * should be overwritten by inherited class - * @access private - */ - function setHandlers($a_xml_parser) - { - echo 'ilSaxParser::setHandlers() must be overwritten'; - } - /** - * open xml file - * - * @access private - * @throws ilSaxParserException or ILIAS Error - */ - function openXMLFile() - { - if(!($fp = fopen($this->xml_file,'r'))) - { - $this->handleError("Cannot open xml file \"".$this->xml_file."\"",$this->ilias->error_obj->FATAL); - } - return $fp; - } - /** - * parse xml file - * - * @access private - * @throws ilSaxParserException or ILIAS Error - */ - function parse($a_xml_parser,$a_fp = null) - { - switch($this->getInputType()) - { - case 'file': - - while($data = fread($a_fp,4096)) - { - $parseOk = xml_parse($a_xml_parser,$data,feof($a_fp)); - } - break; - - case 'string': - $parseOk = xml_parse($a_xml_parser,$this->getXMLContent()); - break; - } - if(!$parseOk - && (xml_get_error_code($a_xml_parser) != XML_ERROR_NONE)) - { - $errorCode = xml_get_error_code($a_xml_parser); - $line = xml_get_current_line_number($a_xml_parser); - $col = xml_get_current_column_number($a_xml_parser); - $this->handleError("XML Parse Error: ".xml_error_string($errorCode)." at line ".$line.", col ". $col . " (Code: ".$errorCode.")" ,$this->ilias->error_obj->FATAL); - } - return true; - - } - - /** - * use given error handler to handle error message or internal ilias error message handle - * - * @param string $message - * @param string $code - * @throws ilSaxParserException or ILIAS Error - */ - protected function handleError($message, $code) { - if ($this->throwException) { - require_once ('./Services/Xml/exceptions/class.ilSaxParserException.php'); - throw new ilSaxParserException ($message, $code); - } else { - if (is_object($this->ilias)) - { - $this->ilias->raiseError($message, $code); - } - else - { - die($message); - } - } - return false; - } - /** - * free xml parser handle - * - * @access private - */ - function freeParser($a_xml_parser) - { - if(!xml_parser_free($a_xml_parser)) - { - $this->ilias->raiseError("Error freeing xml parser handle ",$this->ilias->error_obj->FATAL); - } - } - - /** - * set error handling - * - * @param $error_handler - */ - public function setThrowException ($throwException) - { - $this->throwException = $throwException; - } -} -?> |
