|
@@ -1,5 +1,5 @@
|
|
<?php
|
|
<?php
|
|
-// Copyright (C) 2015 Combodo SARL
|
|
|
|
|
|
+// Copyright (C) 2015-2016 Combodo SARL
|
|
//
|
|
//
|
|
// This file is part of iTop.
|
|
// This file is part of iTop.
|
|
//
|
|
//
|
|
@@ -24,6 +24,7 @@
|
|
*/
|
|
*/
|
|
|
|
|
|
require_once(APPROOT.'application/utils.inc.php');
|
|
require_once(APPROOT.'application/utils.inc.php');
|
|
|
|
+require_once(APPROOT.'core/designdocument.class.inc.php');
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -54,7 +55,7 @@ require_once(APPROOT.'application/utils.inc.php');
|
|
* ...
|
|
* ...
|
|
* }
|
|
* }
|
|
*/
|
|
*/
|
|
-class ModuleDesign extends DOMDocument
|
|
|
|
|
|
+class ModuleDesign extends \Combodo\iTop\DesignDocument
|
|
{
|
|
{
|
|
/**
|
|
/**
|
|
* @param string|null $sDesignSourceId Identifier of the section module_design (generally a module name), null to build an empty design
|
|
* @param string|null $sDesignSourceId Identifier of the section module_design (generally a module name), null to build an empty design
|
|
@@ -62,8 +63,7 @@ class ModuleDesign extends DOMDocument
|
|
*/
|
|
*/
|
|
public function __construct($sDesignSourceId = null)
|
|
public function __construct($sDesignSourceId = null)
|
|
{
|
|
{
|
|
- parent::__construct('1.0', 'UTF-8');
|
|
|
|
- $this->Init();
|
|
|
|
|
|
+ parent::__construct();
|
|
|
|
|
|
if (!is_null($sDesignSourceId))
|
|
if (!is_null($sDesignSourceId))
|
|
{
|
|
{
|
|
@@ -72,19 +72,8 @@ class ModuleDesign extends DOMDocument
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Overloadable. Called prior to data loading.
|
|
|
|
- */
|
|
|
|
- protected function Init()
|
|
|
|
- {
|
|
|
|
- $this->registerNodeClass('DOMElement', 'ModuleDesignElement');
|
|
|
|
-
|
|
|
|
- $this->formatOutput = true; // indent (must be loaded with option LIBXML_NOBLANKS)
|
|
|
|
- $this->preserveWhiteSpace = true; // otherwise the formatOutput option would have no effect
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
* Gets the data where the compiler has left them...
|
|
* Gets the data where the compiler has left them...
|
|
- * @param $sDesignSourceId Identifier of the section module_design (generally a module name)
|
|
|
|
|
|
+ * @param $sDesignSourceId String Identifier of the section module_design (generally a module name)
|
|
* @throws Exception
|
|
* @throws Exception
|
|
*/
|
|
*/
|
|
protected function LoadFromCompiledDesigns($sDesignSourceId)
|
|
protected function LoadFromCompiledDesigns($sDesignSourceId)
|
|
@@ -128,213 +117,4 @@ class ModuleDesign extends DOMDocument
|
|
throw new Exception("Invalid XML in '$sFile'. Errors: ".implode(', ', $aDisplayErrors));
|
|
throw new Exception("Invalid XML in '$sFile'. Errors: ".implode(', ', $aDisplayErrors));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Overload of the standard API
|
|
|
|
- */
|
|
|
|
- public function load($filename, $options = 0)
|
|
|
|
- {
|
|
|
|
- parent::load($filename, LIBXML_NOBLANKS);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Overload of the standard API
|
|
|
|
- */
|
|
|
|
- public function save($filename, $options = 0)
|
|
|
|
- {
|
|
|
|
- $this->documentElement->setAttribute('xmlns:xsi', "http://www.w3.org/2001/XMLSchema-instance");
|
|
|
|
- return parent::save($filename, LIBXML_NOBLANKS);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Create an HTML representation of the DOM, for debugging purposes
|
|
|
|
- * @param bool|false $bReturnRes Echoes or returns the HTML representation
|
|
|
|
- * @return mixed void or the HTML representation of the DOM
|
|
|
|
- */
|
|
|
|
- public function Dump($bReturnRes = false)
|
|
|
|
- {
|
|
|
|
- $sXml = $this->saveXML();
|
|
|
|
- if ($bReturnRes)
|
|
|
|
- {
|
|
|
|
- return $sXml;
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- echo "<pre>\n";
|
|
|
|
- echo htmlentities($sXml);
|
|
|
|
- echo "</pre>\n";
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Quote and escape strings for use within an XPath expression
|
|
|
|
- * Usage: DesignDocument::GetNodes('class[@id='.DesignDocument::XPathQuote($sId).']');
|
|
|
|
- * @param $sValue The value to be quoted
|
|
|
|
- * @return string to be used within an XPath
|
|
|
|
- */
|
|
|
|
- public static function XPathQuote($sValue)
|
|
|
|
- {
|
|
|
|
- if (strpos($sValue, '"') !== false)
|
|
|
|
- {
|
|
|
|
- $aParts = explode('"', $sValue);
|
|
|
|
- $sRet = 'concat("'.implode('", \'"\', "', $aParts).'")';
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- $sRet = '"'.$sValue.'"';
|
|
|
|
- }
|
|
|
|
- return $sRet;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Extracts some nodes from the DOM
|
|
|
|
- * @param string $sXPath A XPath expression
|
|
|
|
- * @param DesignNode|null $oContextNode The node to start the search from
|
|
|
|
- * @return DOMNodeList
|
|
|
|
- */
|
|
|
|
- public function GetNodes($sXPath, $oContextNode = null)
|
|
|
|
- {
|
|
|
|
- $oXPath = new DOMXPath($this);
|
|
|
|
- if (is_null($oContextNode))
|
|
|
|
- {
|
|
|
|
- $oResult = $oXPath->query($sXPath);
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- $oResult = $oXPath->query($sXPath, $oContextNode);
|
|
|
|
- }
|
|
|
|
- return $oResult;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * An alternative to getNodePath, that gives the id of nodes instead of the position within the children
|
|
|
|
- */
|
|
|
|
- public static function GetItopNodePath($oNode)
|
|
|
|
- {
|
|
|
|
- if ($oNode instanceof DOMDocument) return '';
|
|
|
|
-
|
|
|
|
- $sId = $oNode->getAttribute('id');
|
|
|
|
- $sNodeDesc = ($sId != '') ? $oNode->nodeName.'['.$sId.']' : $oNode->nodeName;
|
|
|
|
- return self::GetItopNodePath($oNode->parentNode).'/'.$sNodeDesc;
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * ModuleDesignElement: helper to read/change the DOM
|
|
|
|
- * @package ModelFactory
|
|
|
|
- */
|
|
|
|
-class ModuleDesignElement extends DOMElement
|
|
|
|
-{
|
|
|
|
- /**
|
|
|
|
- * Extracts some nodes from the DOM
|
|
|
|
- * @param string $sXPath A XPath expression
|
|
|
|
- * @return DOMNodeList
|
|
|
|
- */
|
|
|
|
- public function GetNodes($sXPath)
|
|
|
|
- {
|
|
|
|
- return $this->ownerDocument->GetNodes($sXPath, $this);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Create an HTML representation of the DOM, for debugging purposes
|
|
|
|
- * @param bool|false $bReturnRes Echoes or returns the HTML representation
|
|
|
|
- * @return mixed void or the HTML representation of the DOM
|
|
|
|
- */
|
|
|
|
- public function Dump($bReturnRes = false)
|
|
|
|
- {
|
|
|
|
- $oDoc = new ModuleDesign();
|
|
|
|
- $oClone = $oDoc->importNode($this->cloneNode(true), true);
|
|
|
|
- $oDoc->appendChild($oClone);
|
|
|
|
-
|
|
|
|
- $sXml = $oDoc->saveXML($oClone);
|
|
|
|
- if ($bReturnRes)
|
|
|
|
- {
|
|
|
|
- return $sXml;
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- echo "<pre>\n";
|
|
|
|
- echo htmlentities($sXml);
|
|
|
|
- echo "</pre>\n";
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Returns the node directly under the given node
|
|
|
|
- * @param $sTagName
|
|
|
|
- * @param bool|true $bMustExist
|
|
|
|
- * @return null
|
|
|
|
- * @throws DOMFormatException
|
|
|
|
- */
|
|
|
|
- public function GetUniqueElement($sTagName, $bMustExist = true)
|
|
|
|
- {
|
|
|
|
- $oNode = null;
|
|
|
|
- foreach($this->childNodes as $oChildNode)
|
|
|
|
- {
|
|
|
|
- if ($oChildNode->nodeName == $sTagName)
|
|
|
|
- {
|
|
|
|
- $oNode = $oChildNode;
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if ($bMustExist && is_null($oNode))
|
|
|
|
- {
|
|
|
|
- throw new DOMFormatException('Missing unique tag: '.$sTagName);
|
|
|
|
- }
|
|
|
|
- return $oNode;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Returns the node directly under the current node, or null if missing
|
|
|
|
- * @param $sTagName
|
|
|
|
- * @return null
|
|
|
|
- * @throws DOMFormatException
|
|
|
|
- */
|
|
|
|
- public function GetOptionalElement($sTagName)
|
|
|
|
- {
|
|
|
|
- return $this->GetUniqueElement($sTagName, false);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Returns the TEXT of the current node (possibly from several child nodes)
|
|
|
|
- * @param null $sDefault
|
|
|
|
- * @return null|string
|
|
|
|
- */
|
|
|
|
- public function GetText($sDefault = null)
|
|
|
|
- {
|
|
|
|
- $sText = null;
|
|
|
|
- foreach($this->childNodes as $oChildNode)
|
|
|
|
- {
|
|
|
|
- if ($oChildNode instanceof DOMText)
|
|
|
|
- {
|
|
|
|
- if (is_null($sText)) $sText = '';
|
|
|
|
- $sText .= $oChildNode->wholeText;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (is_null($sText))
|
|
|
|
- {
|
|
|
|
- return $sDefault;
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- return $sText;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Get the TEXT value from a child node
|
|
|
|
- * @param string $sTagName
|
|
|
|
- * @param string|null $sDefault
|
|
|
|
- * @return string
|
|
|
|
- */
|
|
|
|
- public function GetChildText($sTagName, $sDefault = null)
|
|
|
|
- {
|
|
|
|
- $sRet = $sDefault;
|
|
|
|
- if ($oChild = $this->GetOptionalElement($sTagName))
|
|
|
|
- {
|
|
|
|
- $sRet = $oChild->GetText($sDefault);
|
|
|
|
- }
|
|
|
|
- return $sRet;
|
|
|
|
- }
|
|
|
|
}
|
|
}
|