ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
ilWebLinkXmlParser Class Reference

XML parser for weblink xml. More...

+ Inheritance diagram for ilWebLinkXmlParser:
+ Collaboration diagram for ilWebLinkXmlParser:

Public Member Functions

 __construct ($webr, $xml)
 Constructor. More...
 
 setWebLink (ilObject $webl)
 set weblink More...
 
 getWebLink ()
 Get weblink object. More...
 
 setMode ($a_mode)
 Set parsing mode. More...
 
 getMode ()
 Return parsing mode. More...
 
 start ()
 
 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...
 
- Public Member Functions inherited from ilMDSaxParser
 ilMDSaxParser ($a_xml_file='')
 Constructor. More...
 
 enableMDParsing ($a_status)
 
 getMDParsingStatus ()
 
 setMDObject (&$md)
 
getMDObject ()
 
 inMetaData ()
 
 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...
 
 __getCharacterData ()
 
 __pushParent (&$md_obj)
 
__popParent ()
 
__getParent ()
 
 ilMDSaxParser ($a_xml_file='')
 Constructor. More...
 
 setMDObject (&$md)
 
 inMetaData ()
 
 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...
 
 __getCharacterData ()
 
 __pushParent (&$md_obj)
 
__popParent ()
 
__getParent ()
 
- Public Member Functions inherited from ilSaxParser
 ilSaxParser ($a_xml_file='', $throwException=false)
 Constructor setup ILIAS global object @access 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 @access 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

const MODE_UNDEFINED = 0
 
const MODE_UPDATE = 1
 
const MODE_CREATE = 2
 
- Data Fields inherited from ilMDSaxParser
 $md_in_md = false
 
 $md_chr_data = ''
 
 $md_cur_el = null
 
 $md_parsing_enabled = null
 
 $md = null
 
 $md_gen
 
- 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()
 

Private Attributes

 $webl
 
 $mode = self::MODE_UNDEFINED
 
 $in_metadata = false
 

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

XML parser for weblink xml.

Author
Stefan Meyer smeye.nosp@m.r.il.nosp@m.ias@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 20 of file class.ilWebLinkXmlParser.php.

Constructor & Destructor Documentation

◆ __construct()

ilWebLinkXmlParser::__construct (   $webr,
  $xml 
)

Constructor.

Definition at line 34 of file class.ilWebLinkXmlParser.php.

35 {
36 parent::__construct();
37 $this->setXMLContent($xml);
38 $this->setWebLink($webr);
39
40 $this->setMDObject(new ilMD($this->getWebLink()->getId(),$this->getWebLink()->getId(),'webr'));
41 $this->setThrowException(true);
42 }
setThrowException($throwException)
set error handling
setXMLContent($a_xml_content)
getWebLink()
Get weblink object.
setWebLink(ilObject $webl)
set weblink

References getWebLink(), ilMDSaxParser\setMDObject(), ilSaxParser\setThrowException(), setWebLink(), and ilSaxParser\setXMLContent().

+ Here is the call graph for this function:

Member Function Documentation

◆ getMode()

ilWebLinkXmlParser::getMode ( )

Return parsing mode.

Returns

Definition at line 77 of file class.ilWebLinkXmlParser.php.

References $mode.

Referenced by handlerBeginTag().

+ Here is the caller graph for this function:

◆ getWebLink()

ilWebLinkXmlParser::getWebLink ( )

Get weblink object.

Returns
ilObject

Definition at line 58 of file class.ilWebLinkXmlParser.php.

References $webl.

Referenced by __construct(), handlerBeginTag(), and handlerEndTag().

+ Here is the caller graph for this function:

◆ handlerBeginTag()

ilWebLinkXmlParser::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

Reimplemented from ilMDSaxParser.

Definition at line 114 of file class.ilWebLinkXmlParser.php.

115 {
116 global $ilErr;
117
118 if($this->in_metadata)
119 {
120 parent::handlerBeginTag($a_xml_parser,$a_name,$a_attribs);
121 return;
122 }
123
124 switch($a_name)
125 {
126 case "MetaData":
127 $this->in_metadata = true;
128
129 // Delete old meta data
130 $md = new ilMD($this->getWebLink()->getId(),0,'webr');
131 $md->deleteAll();
132
133 parent::handlerBeginTag($a_xml_parser,$a_name,$a_attribs);
134 break;
135
136 case 'WebLink':
137
138 $this->current_link_update = false;
139 $this->current_link_delete = false;
140 $this->current_parameters = array();
141
142 if($this->getMode() == self::MODE_CREATE or (isset($a_attribs['action']) and $a_attribs['action'] == 'Create'))
143 {
144 // New weblink
145 $this->current_link = new ilLinkResourceItems($this->getWebLink()->getId());
146 }
147 elseif($this->getMode() == self::MODE_UPDATE and $a_attribs['action'] == 'Delete')
148 {
149 $this->current_link_delete = true;
150 $this->current_link = new ilLinkResourceItems($this->getWebLink()->getId());
151 $this->current_link->delete($a_attribs['id']);
152 break;
153 }
154 elseif($this->getMode() == self::MODE_UPDATE and ($a_attribs['action'] == 'Update' or !isset($a_attribs['action'])))
155 {
156 $this->current_link = new ilLinkResourceItems($this->getWebLink()->getId());
157 $this->current_link->readItem($a_attribs['id']);
158 $this->current_link_update = true;
159
160 // Delete all dynamic parameter
161 include_once './Modules/WebResource/classes/class.ilParameterAppender.php';
162 foreach(ilParameterAppender::getParameterIds($this->getWebLink()->getId(), $a_attribs['id']) as $param_id)
163 {
164 $param = new ilParameterAppender($this->getWebLink()->getId());
165 $param->delete($param_id);
166 }
167 }
168 else
169 {
170 throw new ilWebLinkXmlParserException('Invalid action given for element "Weblink"');
171 }
172
173 // Active
174 $this->current_link->setActiveStatus($a_attribs['active'] ? 1 : 0);
175
176 // Valid
177 if(!isset($a_attribs['valid']))
178 {
179 $valid = 1;
180 }
181 else
182 {
183 $valid = $a_attribs['valid'] ? 1 : 0;
184 }
185 $this->current_link->setValidStatus($valid);
186
187 // Disable check
188 $this->current_link->setDisableCheckStatus($a_attribs['disableValidation'] ? 1 : 0);
189 break;
190
191
192 case 'Sorting':
193
194 include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
195 $sort = new ilContainerSortingSettings($this->getWebLink()->getId());
196 $sort->delete();
197
198 switch($a_attribs['type'])
199 {
200 case 'Manual':
201 $sort->setSortMode(ilContainer::SORT_MANUAL);
202 break;
203
204 case 'Title':
205 default:
206 $sort->setSortMode(ilContainer::SORT_TITLE);
207 }
208 $sort->save();
209 break;
210
211 case 'WebLinks':
212 case 'Title':
213 case 'Description':
214 case 'Target':
215 // Nothing to do
216 break;
217
218 case 'DynamicParameter':
219
220 $param = new ilParameterAppender($this->getWebLink()->getId());
221 $param->setName($a_attribs['name']);
222
223 switch($a_attribs['type'])
224 {
225 case 'userName':
226# $GLOBALS['ilLog']->write("VALUE: ".LINKS_LOGIN);
227 $param->setValue(LINKS_LOGIN);
228 break;
229
230 case 'userId':
231# $GLOBALS['ilLog']->write("VALUE: ".LINKS_USER_ID);
232 $param->setValue(LINKS_USER_ID);
233 break;
234
235 case 'matriculation':
236# $GLOBALS['ilLog']->write("VALUE: ".LINKS_MATRICULATION);
237 $param->setValue(LINKS_MATRICULATION);
238 break;
239
240 default:
241 throw new ilWebLinkXmlParserException('Invalid attribute "type" given for element "Dynamic parameter". Aborting');
242 break;
243 }
244
245 $this->current_parameters[] = $param;
246 break;
247 }
248 }
const LINKS_USER_ID
const LINKS_LOGIN
const LINKS_MATRICULATION
Class ilObjLinkResourceGUI.
Class ilParameterAppender.
static getParameterIds($a_webr_id, $a_link_id)
Get Parameter ids of link.
getMode()
Return parsing mode.
$valid

References $ilErr, ilMDSaxParser\$md, $valid, getMode(), ilParameterAppender\getParameterIds(), getWebLink(), LINKS_LOGIN, LINKS_MATRICULATION, LINKS_USER_ID, ilContainer\SORT_MANUAL, and ilContainer\SORT_TITLE.

+ Here is the call graph for this function:

◆ handlerCharacterData()

ilWebLinkXmlParser::handlerCharacterData (   $a_xml_parser,
  $a_data 
)

handler for character data

Parameters
resource$a_xml_parserxml parser
string$a_datacharacter data

Reimplemented from ilMDSaxParser.

Definition at line 346 of file class.ilWebLinkXmlParser.php.

347 {
348 if($this->in_metadata)
349 {
350 parent::handlerCharacterData($a_xml_parser,$a_data);
351 }
352
353 if($a_data != "\n")
354 {
355 // Replace multiple tabs with one space
356 $a_data = preg_replace("/\t+/"," ",$a_data);
357 $this->cdata .= $a_data;
358 }
359 }

◆ handlerEndTag()

ilWebLinkXmlParser::handlerEndTag (   $a_xml_parser,
  $a_name 
)

handler for end of element

Parameters
resource$a_xml_parserxml parser
string$a_nameelement name
Exceptions
ilSaxParserExceptionif invalid xml structure is given
ilWebLinkXMLParserExceptionmissing elements

Reimplemented from ilMDSaxParser.

Definition at line 258 of file class.ilWebLinkXmlParser.php.

259 {
260 if($this->in_metadata)
261 {
262 parent::handlerEndTag($a_xml_parser,$a_name);
263 }
264
265 $GLOBALS['ilLog']->write(__METHOD__.': Called '.$a_name);
266
267 switch($a_name)
268 {
269 case 'MetaData':
270 $this->in_metadata = false;
271 parent::handlerEndTag($a_xml_parser,$a_name);
272 break;
273
274 case 'WebLinks':
275 $this->getWebLink()->MDUpdateListener('General');
276 $this->getWebLink()->update();
277 break;
278
279 case 'WebLink':
280
281 if($this->current_link_delete)
282 {
283 break;
284 }
285 if(!$this->current_link)
286 {
287 throw new ilSaxParserException('Invalid xml structure given. Missing start tag "WebLink"');
288 }
289 if(!$this->current_link->validate())
290 {
291 throw new ilWebLinkXmlParserException('Missing required elements "Title, Target"');
292 }
293
294 if($this->current_link_update)
295 {
296 $this->current_link->update();
297 }
298 else
299 {
300 $this->current_link->add();
301 }
302
303 // Save dynamic parameters
304 foreach($this->current_parameters as $param)
305 {
306 $param->add($this->current_link->getLinkId());
307 }
308
309 unset($this->current_link);
310 break;
311
312 case 'Title':
313 if($this->current_link)
314 {
315 $this->current_link->setTitle(trim($this->cdata));
316 }
317 break;
318
319 case 'Description':
320 if($this->current_link)
321 {
322 $this->current_link->setDescription(trim($this->cdata));
323 }
324 break;
325
326 case 'Target':
327 if($this->current_link)
328 {
329 $this->current_link->setTarget(trim($this->cdata));
330 }
331 break;
332 }
333
334 // Reset cdata
335 $this->cdata = '';
336 }
SaxParserException thrown by ilSaxParser if property throwException is set.
$GLOBALS['ct_recipient']

References $GLOBALS, and getWebLink().

+ Here is the call graph for this function:

◆ setHandlers()

ilWebLinkXmlParser::setHandlers (   $a_xml_parser)

set event handlers

Parameters
resourcereference to the xml parser @access private

Reimplemented from ilMDSaxParser.

Definition at line 100 of file class.ilWebLinkXmlParser.php.

101 {
102 xml_set_object($a_xml_parser,$this);
103 xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
104 xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
105 }

◆ setMode()

ilWebLinkXmlParser::setMode (   $a_mode)

Set parsing mode.

Parameters
int$a_mode
Returns

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

69 {
70 $this->mode = $a_mode;
71 }

◆ setWebLink()

ilWebLinkXmlParser::setWebLink ( ilObject  $webl)

set weblink

Parameters
ilObject$webl
Returns

Definition at line 49 of file class.ilWebLinkXmlParser.php.

50 {
51 $this->webl = $webl;
52 }

References $webl.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ start()

ilWebLinkXmlParser::start ( )
Returns
Exceptions
ilSaxParserExceptionif invalid xml structure is given
ilWebLinkXMLParserExceptionmissing elements

Definition at line 89 of file class.ilWebLinkXmlParser.php.

90 {
91 return $this->startParsing();
92 }
startParsing()
stores xml data in array

References ilSaxParser\startParsing().

+ Here is the call graph for this function:

Field Documentation

◆ $in_metadata

ilWebLinkXmlParser::$in_metadata = false
private

Definition at line 29 of file class.ilWebLinkXmlParser.php.

◆ $mode

ilWebLinkXmlParser::$mode = self::MODE_UNDEFINED
private

Definition at line 27 of file class.ilWebLinkXmlParser.php.

Referenced by getMode().

◆ $webl

ilWebLinkXmlParser::$webl
private

Definition at line 26 of file class.ilWebLinkXmlParser.php.

Referenced by getWebLink(), and setWebLink().

◆ MODE_CREATE

const ilWebLinkXmlParser::MODE_CREATE = 2

◆ MODE_UNDEFINED

const ilWebLinkXmlParser::MODE_UNDEFINED = 0

Definition at line 22 of file class.ilWebLinkXmlParser.php.

◆ MODE_UPDATE

const ilWebLinkXmlParser::MODE_UPDATE = 1

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