Applies $cssRules to $this->domDocument, limited to the rules that actually apply to the document.

@param \DOMXPath $xPath
@param string[][] $cssRules The "uninlineable" array of CSS rules returned by `parseCssRules`

@return void
322397
private function copyUninlineableCssToStyleNode(\DOMXPath $xPath, array $cssRules)
    {
        $cssRulesRelevantForDocument = \array_filter(
            $cssRules,
            function (array $cssRule) use ($xPath) {
                $selector = $cssRule['selector'];
                if ($cssRule['hasUnmatchablePseudo']) {
                    $selector = $this->removeUnmatchablePseudoComponents($selector);
                }
                return $this->existsMatchForCssSelector($xPath, $selector);
            }
        );

        if ($cssRulesRelevantForDocument === []) {
            // avoid adding empty style element (or including unneeded class dependency)
            return;
        }

        $cssConcatenator = new CssConcatenator();
        foreach ($cssRulesRelevantForDocument as $cssRule) {
            $cssConcatenator->append([$cssRule['selector']], $cssRule['declarationsBlock'], $cssRule['media']);
        }

        $this->addStyleElementToDocument($cssConcatenator->getCss());
    }
1362354
public function siblings($css = null)
    {
        $query = $this->_document->getQuery();

        $nodes = [];
        foreach ($this->_nodes as $node) {
            $cur_xpath = $node->getNodePath();
            foreach ($query->css('parent::' . ($css ?: '*'), $node) as $node2) {
                /**
                 * @var \DOMNode $node2
                 */
                /** @noinspection SlowArrayOperationsInLoopInspection */
                if ($node2->getNodePath() !== $cur_xpath) {
                    $nodes[$node2->getNodePath()] = $node2;
                }
            }
        }

        return new SelectorList($this, array_values($nodes));
    }
1371735
protected function prepareIndex(DOMElement $table, DOMXPath $xpath, Table $schemaTable)
    {
        $indexes = $xpath->query(sprintf('/database/table[@name="%s"]/index', $table->getAttribute('name')));

        /** @var DOMElement $index */
        foreach ($indexes as $index) {
            $indexColumns = $index->getElementsByTagName('index-column');
            $indexName = $index->getAttribute('name');
            $indexType = $index->getAttribute('type');

            $tmpIndexColumns = [];
            /** @var DOMElement $indexColumn */
            foreach ($indexColumns as $indexColumn) {
                $tmpIndexColumns[] = $indexColumn->getAttribute('name');
            }

            if (empty(trim($indexType))) {
                $indexType = 'index';
            }

            if (empty(trim($indexName))) {
                $indexName = sprintf(
                    '%s_%s_%s',
                    $table->getAttribute('name'),
                    implode('_', $tmpIndexColumns),
                    $indexType
                );
            }

            $schemaTable->addIndex(
                $indexName,
                [
                    'type' => $indexType,
                    'columns' => $tmpIndexColumns
                ]
            );
        }
    }
518777
private function parsePathsSettings(\DOMNode $paths) {

		if(is_null($this->paths)) {
			$this->paths = [];
		}

		foreach($paths->getElementsByTagName('path') as $path) {

			$id = $path->getAttribute('id');
			$subdir = $path->getAttribute('subdir') ?: '';

			if(!$id || !$subdir) {
				continue;
			}

			$subdir = '/' . trim($subdir, '/') . '/';

			// additional attributes are currently ignored

			$this->paths[$id] = ['subdir' => $subdir];

		}

	}
1073615
public function replaceExternalCss($html, array $stylesheets)
    {
        foreach ($stylesheets['links'] as $key => $stylesheet) {
            $newTag = str_replace(
                $stylesheets['actual_links'][$key],
                $stylesheet,
                $stylesheets['tags'][$key]
            );

            $html = str_replace($stylesheets['tags'][$key], $newTag, $html);
        }

        return $html;
    }
1098713
protected function addStyleElementToDocument($css)
    {
        $styleElement = $this->domDocument->createElement('style', $css);
        $styleAttribute = $this->domDocument->createAttribute('type');
        $styleAttribute->value = 'text/css';
        $styleElement->appendChild($styleAttribute);

        $headElement = $this->getHeadElement();
        $headElement->appendChild($styleElement);
    }
226645
protected function process()
    {
        $this->clearAllCaches();
        $this->purgeVisitedNodes();

        $xPath = new \DOMXPath($this->domDocument);
        $this->removeUnprocessableTags();
        $this->normalizeStyleAttributesOfAllNodes($xPath);

        // grab any existing style blocks from the html and append them to the existing CSS
        // (these blocks should be appended so as to have precedence over conflicting styles in the existing CSS)
        $allCss = $this->css;
        if ($this->isStyleBlocksParsingEnabled) {
            $allCss .= $this->getCssFromAllStyleNodes($xPath);
        }

        $excludedNodes = $this->getNodesToExclude($xPath);
        $cssRules = $this->parseCssRules($allCss);
        foreach ($cssRules['inlineable'] as $cssRule) {
            try {
                $nodesMatchingCssSelectors = $xPath->query($this->cssSelectorConverter->toXPath($cssRule['selector']));
            } catch (SyntaxErrorException $e) {
                if ($this->debug) {
                    throw $e;
                }
                continue;
            }

            /** @var \DOMElement $node */
            foreach ($nodesMatchingCssSelectors as $node) {
                if (\in_array($node, $excludedNodes, true)) {
                    continue;
                }
                $this->copyInlineableCssToStyleAttribute($node, $cssRule);
            }
        }

        if ($this->isInlineStyleAttributesParsingEnabled) {
            $this->fillStyleAttributesWithMergedStyles();
        }
        $this->postProcess($xPath);

        $this->removeImportantAnnotationFromAllInlineStyles($xPath);

        $this->copyUninlineableCssToStyleNode($xPath, $cssRules['uninlineable']);
    }
1135734
public function apply(array &$tokens)
		{
		$r = 0;
		for ($i = 0, $l = count($tokens); $i < $l; $i++)
			{
			// Only look for ruleset start rules
			if (get_class($tokens[$i]) !== "CssRulesetStartToken") { continue; }
			// Look for the corresponding ruleset end
			$endIndex = false;
			for ($ii = $i + 1; $ii < $l; $ii++)
				{
				if (get_class($tokens[$ii]) !== "CssRulesetEndToken") { continue; }
				$endIndex = $ii;
				break;
				}
			if (!$endIndex) { break; }
			$startIndex = $i;
			$i = $endIndex;
			// Skip if there's only one token in this ruleset
			if ($endIndex - $startIndex <= 2) { continue; }
			// Ensure that everything between the start and end is a declaration token, for safety
			for ($ii = $startIndex + 1; $ii < $endIndex; $ii++)
				{
				if (get_class($tokens[$ii]) !== "CssRulesetDeclarationToken") { continue(2); }
				}
			$declarations = array_slice($tokens, $startIndex + 1, $endIndex - $startIndex - 1);
			// Check whether a sort is required
			$sortRequired = $lastPropertyName = false;
			foreach ($declarations as $declaration)	
				{
				if ($lastPropertyName)
					{
					if (strcmp($lastPropertyName, $declaration->Property) > 0)
						{
						$sortRequired = true;
						break;
						}
					}
				$lastPropertyName = $declaration->Property;
				}
			if (!$sortRequired) { continue; }
			// Arrange the declarations alphabetically by name
			usort($declarations, array(__CLASS__, "userDefinedSort1"));
			// Update "IsLast" property
			for ($ii = 0, $ll = count($declarations) - 1; $ii <= $ll; $ii++)
				{
				if ($ii == $ll)
					{
					$declarations[$ii]->IsLast = true;
					}
				else
					{
					$declarations[$ii]->IsLast = false;
					}
				}
			// Splice back into the array.
			array_splice($tokens, $startIndex + 1, $endIndex - $startIndex - 1, $declarations);
			$r += $endIndex - $startIndex - 1;
			}
		return $r;
		}
1371848
public function grabAttributeFromXmlElement($cssOrXPath, $attribute)
    {
        $el = (new XmlStructure($this->connectionModule->_getResponseContent()))->matchElement($cssOrXPath);
        if (!$el->hasAttribute($attribute)) {
            $this->fail("Attribute not found in element matched by '$cssOrXPath'");
        }
        return $el->getAttribute($attribute);
    }
1298008
public function doubleClick($cssOrXPath)
    {
        $el = $this->matchFirstOrFail($this->getBaseElement(), $cssOrXPath);
        $this->webDriver->getMouse()->doubleClick($el->getCoordinates());
    }
347257
public static function run($strSettingsXmlFilePath)
    {
        if (!defined('QCUBED_CODE_GENERATING')) {
            define('QCUBED_CODE_GENERATING', true);
        }

        Codegen::$CodeGenArray = array();
        Codegen::$SettingsFilePath = $strSettingsXmlFilePath;

        if (!file_exists($strSettingsXmlFilePath)) {
            Codegen::$RootErrors = 'FATAL ERROR: CodeGen Settings XML File (' . $strSettingsXmlFilePath . ') was not found.';
            return;
        }

        if (!is_file($strSettingsXmlFilePath)) {
            Codegen::$RootErrors = 'FATAL ERROR: CodeGen Settings XML File (' . $strSettingsXmlFilePath . ') was not found.';
            return;
        }

        // Try Parsing the Xml Settings File
        try {
            $errorHandler = new Error\Handler('\\QCubed\\Codegen\\QcubedHandleCodeGenParseError', E_ALL);
            Codegen::$SettingsXml = new \SimpleXMLElement(file_get_contents($strSettingsXmlFilePath));
            $errorHandler->restore();
        } catch (\Exception $objExc) {
            Codegen::$RootErrors .= 'FATAL ERROR: Unable to parse CodeGenSettings XML File: ' . $strSettingsXmlFilePath;
            Codegen::$RootErrors .= "\r\n";
            Codegen::$RootErrors .= $objExc->getMessage();
            return;
        }

        // Application Name
        Codegen::$ApplicationName = Codegen::lookupSetting(Codegen::$SettingsXml, 'name', 'application');

        // Codegen Defaults
        Codegen::$PreferredRenderMethod = Codegen::lookupSetting(Codegen::$SettingsXml, 'formgen',
            'preferredRenderMethod');
        Codegen::$CreateMethod = Codegen::lookupSetting(Codegen::$SettingsXml, 'formgen', 'createMethod');
        Codegen::$DefaultButtonClass = Codegen::lookupSetting(Codegen::$SettingsXml, 'formgen', 'buttonClass');

        if (!Codegen::$DefaultButtonClass) {
            Codegen::$RootErrors .= "CodeGen Settings XML Fatal Error: buttonClass was not defined\r\n";
            return;
        }

        // Iterate Through DataSources
        if (Codegen::$SettingsXml->dataSources->asXML()) {
            foreach (Codegen::$SettingsXml->dataSources->children() as $objChildNode) {
                switch (dom_import_simplexml($objChildNode)->nodeName) {
                    case 'database':
                        Codegen::$CodeGenArray[] = new DatabaseCodeGen($objChildNode);
                        break;
                    case 'restService':
                        Codegen::$CodeGenArray[] = new RestServiceCodeGen($objChildNode);
                        break;
                    default:
                        Codegen::$RootErrors .= sprintf("Invalid Data Source Type in CodeGen Settings XML File (%s): %s\r\n",
                            $strSettingsXmlFilePath, dom_import_simplexml($objChildNode)->nodeName);
                        break;
                }
            }
        }
    }
208399
public function replaceExternalCss($html, array $stylesheets)
    {
        foreach ($stylesheets['links'] as $key => $stylesheet) {
            if (!$this->isExternalStylesheet($stylesheet)) {
                $html = str_replace(
                    $stylesheets['tags'][$key],
                    $this->getStylesheetContent($stylesheet),
                    $html
                );
            }
        }

        return $html;
    }
370187
public function validate(\DOMDocument $document, $xsdPath)
    {
        $state = libxml_use_internal_errors(true);
        $result = $document->schemaValidate($xsdPath);
        $this->errors = $this->extractErrors();
        libxml_use_internal_errors($state);

        return $result;
    }
485882
public function setXSL($xsl, $isFile = false)
    {
        $this->_xsl = ($isFile ? file_get_contents($xsl) : $xsl);
    }
928286
private function setTemplatesPath($templatesPath)
    {
        $this->templatesPath = $templatesPath;
        if (!is_readable($this->templatesPath)) {
            $this->error("Template Root Path ({$this->templatesPath}) does not exist or not readable.");
        }
    }
46373
public function focus($xpath) {
    $element = $this->findElement($xpath, 1);
    $this->browser->trigger($element["page_id"], $element["ids"][0], "focus");
  }
1265672
private function getCssFromAllStyleNodes(\DOMXPath $xPath)
    {
        $styleNodes = $xPath->query('//style');

        if ($styleNodes === false) {
            return '';
        }

        $css = '';
        /** @var \DOMNode $styleNode */
        foreach ($styleNodes as $styleNode) {
            $css .= "\n\n" . $styleNode->nodeValue;
            $styleNode->parentNode->removeChild($styleNode);
        }

        return $css;
    }