/** * Normalizes the value of the "style" attribute and saves it. * * @param \DOMElement $node * * @return void */ private function normalizeStyleAttributes(\DOMElement $node) { $normalizedOriginalStyle = preg_replace_callback('/[A-z\\-]+(?=\\:)/S', function (array $m) { return strtolower($m[0]); }, $node->getAttribute('style')); // in order to not overwrite existing style attributes in the HTML, we // have to save the original HTML styles $nodePath = $node->getNodePath(); if (!isset($this->styleAttributesForNodes[$nodePath])) { $this->styleAttributesForNodes[$nodePath] = $this->parseCssDeclarationsBlock($normalizedOriginalStyle); $this->visitedNodes[$nodePath] = $node; } $node->setAttribute('style', $normalizedOriginalStyle); }
/** * Retorna o nível do nó. * @param \DOMElement $node * @return int */ public function getNodeLevel(\DOMElement $node) { return count(explode('/', $node->getNodePath())) - 1; }
/** * Returns form node unique identifier. * * @param \DOMElement $form * * @return string */ private function getFormNodeId(\DOMElement $form) { return md5($form->getLineNo() . $form->getNodePath() . $form->nodeValue); }
/** * @param DOMElement $objElement * @param $objParent * @param $strClassName * @param $arrParameters * @param $strName * @return class_model */ protected function createFixtureObject(DOMElement $objElement, $objParent, $strClassName, $arrParameters, $strName) { $strParentId = $objParent === null ? $this->getDefaultRootId($strClassName) : $objParent->getStrSystemid(); // resolve references foreach ($arrParameters as $strKey => $strValue) { if (substr($strValue, 0, 11) == 'objectlist:') { $strRef = trim(substr($strValue, 11)); $arrRefs = explode(",", $strRef); $arrParameters[$strKey] = array(); foreach ($arrRefs as $strRefKey) { $objRef = $this->getObject($strRefKey); if ($objRef instanceof class_model) { $arrParameters[$strKey][] = $objRef; } else { throw new RuntimeException('Object "' . $strName . '" refers to an non existing object (' . $objElement->getNodePath() . ')'); } } } else { if (substr($strValue, 0, 4) == 'ref:') { $strRef = trim(substr($strValue, 4)); $objRef = $this->getObject($strRef); if ($objRef instanceof class_model) { $arrParameters[$strKey] = $objRef->getStrSystemid(); } else { throw new RuntimeException('Object "' . $strName . '" refers to an non existing object (' . $objElement->getNodePath() . ')'); } } } } $objObject = $this->createObject($strClassName, $strParentId, array(), $arrParameters, false); return $objObject; }
/** * * Parse value of the object * * @param Object $obj * @param DOMElement $element * * @return DOMElement */ private function parseObjectValue($obj, $element) { $this->logger->debug("Start with:" . $element->getNodePath()); $refl = new \ReflectionClass($obj); $classDocs = $this->parseDocComments($refl->getDocComment()); $classProps = $refl->getProperties(); $namespace = $classDocs['xmlNamespace']; foreach ($classProps as $prop) { $propDocs = $this->parseDocComments($prop->getDocComment()); //print_r($prop->getDocComment()); if (is_object($prop->getValue($obj))) { $code = ''; //print($propDocs['xmlName']."\n"); if (array_key_exists('xmlNamespace', $propDocs)) { $code = $this->getNsCode($propDocs['xmlNamespace']); $el = $this->dom->createElement($code . ":" . $propDocs['xmlName']); $el = $this->parseObjectValue($prop->getValue($obj), $el); } else { $el = $this->dom->createElement($propDocs['xmlName']); $el = $this->parseObjectValue($prop->getValue($obj), $el); } //print_r("Value is object in Parse\n"); $element->appendChild($el); } else { //Next function fixes SDK-78 $this->castToStringZero($prop, $obj); // end if ($prop->getValue($obj) != '') { if ($propDocs['xmlType'] == 'element') { $el = ''; $code = $this->getNsCode($propDocs['xmlNamespace']); $value = $prop->getValue($obj); if (is_array($value)) { // Strip the class prefix, if one exists if ($this->classPrefix && 0 == strpos($propDocs['xmlName'], $this->classPrefix)) { $propDocs['xmlName'] = substr($propDocs['xmlName'], strlen($this->classPrefix)); } $this->logger->debug("Creating element:" . $code . ":" . $propDocs['xmlName']); $this->logger->debug(print_r($value, true)); foreach ($value as $node) { $this->logger->debug(print_r($node, true)); $el = $this->dom->createElement($code . ":" . $propDocs['xmlName']); $arrNode = $this->parseObjectValue($node, $el); $element->appendChild($arrNode); } } else { //SDK-39 $el = $this->dom->createElement($code . ":" . $propDocs['xmlName'], $value); $element->appendChild($el); } //print_r("Added element ".$propDocs['xmlName']." with NS = ".$propDocs['xmlNamespace']." \n"); } elseif ($propDocs['xmlType'] == 'attribute') { $atr = $this->dom->createAttribute($propDocs['xmlName']); $text = $this->dom->createTextNode($prop->getValue($obj)); $atr->appendChild($text); $element->appendChild($atr); } elseif ($propDocs['xmlType'] == 'value') { $this->logger->debug(print_r($prop->getValue($obj), true)); $txtNode = $this->dom->createTextNode($prop->getValue($obj)); $element->appendChild($txtNode); } } } } return $element; }
/** * Retrieve visibility * * @param \DOMElement $element * @return type */ public function retriveVisibility(\DOMElement $element) { $name = $this->engine->query($element->getNodePath() . '/dia:attribute[@name="visibility"]/dia:enum'); $propertyVisibility = $name->item(0)->attributes->getNamedItem('val')->nodeValue; return self::$propertyVisibilityTypes[$propertyVisibility]; }
/** * Normalizes the value of the "style" attribute and saves it. * * @param \DOMElement $node * * @return void */ private function normalizeStyleAttributes(\DOMElement $node) { $normalizedOriginalStyle = $node->getAttribute('style'); // in order to not overwrite existing style attributes in the HTML, we // have to save the original HTML styles $nodePath = $node->getNodePath(); if (!isset($this->styleAttributesForNodes[$nodePath])) { $this->styleAttributesForNodes[$nodePath] = $this->parseCssDeclarationBlock($normalizedOriginalStyle); $this->visitedNodes[$nodePath] = $node; } $node->setAttribute('style', $normalizedOriginalStyle); }
/** * Parse conditions that are used to see whether you are allowed to perform certain actions on the scheme * * @param One_Scheme $scheme * @param DOMXPath $xpath * @param DOMElement $element * @param string $name name of the rule * @return One_Permission_Rule */ protected static function parseCondition(One_Scheme $scheme, DOMXPath $xpath, DOMElement $element, $name = NULL) { foreach (array('rule', 'and', 'or') as $roa) { $currs = $xpath->query($element->getNodePath() . '/' . $roa); if ($currs->length > 0) { $curr = $currs->item(0); if ($roa == 'and' || $roa == 'or') { $p = new One_Permission_Rule_Joiner(array('type' => $roa, 'not' => $curr->getAttribute('not') == 'not' ? true : false)); $rules = $curr->getElementsByTagName('rule'); if ($rules->length > 0) { for ($i = 0; $i < $rules->length; $i++) { $rule = $rules->item($i); $p->addRule(new One_Permission_Rule(array('type' => $rule->getAttribute('type'), 'not' => $rule->getAttribute('not') == 'not' ? true : false))); } unset($rule); } if ($curr->getElementsByTagName('and')->length > 0 || $curr->getElementsByTagName('or')->length > 0) { $p->addRule(self::parseCondition($curr, $scheme)); } } else { if ($roa == 'rule') { $p = new One_Permission_Rule(array('type' => $curr->getAttribute('type'), 'not' => $curr->getAttribute('not') == 'not' ? true : false)); } } } } if (!is_null($name)) { $tasks = explode(';', $name); foreach ($tasks as $task) { if (trim($task) != '') { $scheme->addRule($task, $p); } } } return $p; }