ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilWebLinkXmlWriter.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once "./Services/Xml/classes/class.ilXmlWriter.php";
5 
15 {
16  private $add_header = true;
17 
18  private $obj_id = 0;
19  private $weblink = null;
20 
24  public function __construct($a_add_header)
25  {
26  $this->add_header = $a_add_header;
27  parent::__construct();
28  }
29 
35  public function setObjId($a_obj_id)
36  {
37  $this->obj_id = $a_obj_id;
38  }
39 
45  public function write()
46  {
47  $this->init();
48  if ($this->add_header) {
49  $this->buildHeader();
50  }
51  $this->weblink->toXML($this);
52  }
53 
58  protected function buildHeader()
59  {
60  $this->xmlSetDtdDef("<!DOCTYPE WebLinks PUBLIC \"-//ILIAS//DTD WebLinkAdministration//EN\" \"" . ILIAS_HTTP_PATH . "/xml/ilias_weblinks_5_1.dtd\">");
61  $this->xmlSetGenCmt("WebLink Object");
62  $this->xmlHeader();
63 
64  return true;
65  }
66 
67 
73  protected function init()
74  {
75  $this->xmlClear();
76 
77  if (!$this->obj_id) {
78  throw new UnexpectedValueException('No obj_id given: ');
79  }
80  include_once './Services/Object/classes/class.ilObjectFactory.php';
81  if (!$this->weblink = ilObjectFactory::getInstanceByObjId($this->obj_id, false)) {
82  throw new UnexpectedValueException('Invalid obj_id given: ' . $this->obj_id);
83  }
84  if ($this->weblink->getType() != 'webr') {
85  throw new UnexpectedValueException('Invalid obj_id given. Object is not of type webr');
86  }
87  }
88 }
xmlSetGenCmt($genCmt)
Sets generated comment.
xmlSetDtdDef($dtdDef)
Sets dtd definition.
XML writer class.
__construct($a_add_header)
Constructor.
xmlHeader()
Writes xml header public.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
XML writer for weblinks.
xmlClear()
clears xmlStr public
buildHeader()
Build XML header.
setObjId($a_obj_id)
Set obj_id of weblink object.