Checks that $this->domDocument has a BODY element and adds it if it is missing.

@return void
483804
private function ensureExistenceOfBodyElement()
    {
        if ($this->domDocument->getElementsByTagName('body')->item(0) !== null) {
            return;
        }

        $htmlElement = $this->domDocument->getElementsByTagName('html')->item(0);
        $htmlElement->appendChild($this->domDocument->createElement('body'));
    }
44767
public function before()
    {
        $this->importNodes(\func_get_args(), function ($node, $imported_node) {
            if ($node->parentNode instanceof \DOMDocument) {
                throw new \Exception('Can not set before root element '.$node->tagName.' of document');
            }

            $node->parentNode->insertBefore($imported_node, $node);
        });

        return $this;
    }
879696
public function render(\DOMDocument $domDocument)
    {
        $frame = new Frame();
        $frame->setId($this->frameId);
        $frame->setAlign($this->hAlign, $this->vAlign);
        $frame->setPosition($this->startX, $this->startY);
        $frame->addClasses($this->frameClasses);
        $sizeY = 0;
        $sizeX = 0;
        /** @var Control $oldElement */
        $oldElement = null;
        foreach ($this->elements as $idx => $element) {

            if ($idx === 0) {
                $start = $this->getRelativeStartPosition($element);
            } else {
                $start = $this->getStartPosition($oldElement) + $this->margin;
            }

            if ($oldElement) {

                if ($oldElement->getHorizontalAlign() == "center" && $element->getHorizontalAlign() == "center") {
                    $element->setX($start + $oldElement->getWidth() + ($element->getWidth() / 2));
                } elseif ($oldElement->getHorizontalAlign() == "left" && $element->getHorizontalAlign() == "center") {
                    $element->setX($start + $oldElement->getWidth() + ($element->getWidth() / 2));
                } elseif ($oldElement->getHorizontalAlign() == "center" && $element->getHorizontalAlign() == "left") {
                    $element->setX($start + $oldElement->getWidth());
                } elseif ($oldElement->getHorizontalAlign() == "center" && $element->getHorizontalAlign() == "right") {
                    $element->setX($start + $oldElement->getWidth() + $element->getWidth());
                } elseif ($oldElement->getHorizontalAlign() == "right" && $element->getHorizontalAlign() == "right") {
                    $element->setX($start + $element->getWidth());
                } elseif ($oldElement->getHorizontalAlign() == "right" && $element->getHorizontalAlign() == "center") {
                    $element->setX($start + ($element->getWidth() / 2));
                } elseif ($oldElement->getHorizontalAlign() == "left" && $element->getHorizontalAlign() == "right") {
                    $element->setX($start + $oldElement->getWidth() + $element->getWidth());
                } elseif ($oldElement->getHorizontalAlign() == "right" && $element->getHorizontalAlign() == "left") {
                    $element->setX($start);
                } else {
                    $element->setX($start + $oldElement->getWidth());
                }
            } else {
                $element->setX($start);
            }

            if ((abs($element->getY()) + $element->getHeight()) > $sizeY) {
                $sizeY = abs($element->getY()) + $element->getHeight();
                $this->setHeight($sizeY);
            }
            $frame->addChild($element);
            $oldElement = $element;
            $sizeX += $element->getWidth() + $this->margin;
        }

        $this->setWidth($sizeX);

        return $frame->render($domDocument);
    }
89864
protected function parseBodyIsRequired()
    {
        return
            !isset($this->parseCondition) ||
            (isset($this->parseCondition['content_type']) && $this->parseCondition['content_type'] !==
                $this->getContentType()) ||
            (isset($this->parseCondition['size']) && $this->parseCondition['size'] !== $this->getBody()->getSize());
    }
654951
public function process(\DOMDocument $xml)
    {
        $xpath = new \DOMXPath($xml);
        $nodes = $xpath->query(
            '/project/file/class/docblock/tag[@name="method"]'
        );

        /** @var \DOMElement $node */
        foreach ($nodes as $node) {
            $class = $node->parentNode->parentNode;

            $method = new \DOMElement('method');
            $class->appendChild($method);

            // set basic information
            $method->setAttribute('final', 'false');
            $method->setAttribute('static', 'false');
            $method->setAttribute('visibility', 'public');
            $method->setAttribute('line', $node->getAttribute('line'));
            $method->appendChild(
                new \DOMElement('name', $node->getAttribute('method_name'))
            );

            // fill docblock
            $docblock = new \DOMElement('docblock');
            $method->appendChild($docblock);
            $docblock->appendChild(
                new \DOMElement('description', $node->getAttribute('description'))
            );
            $docblock->appendChild(new \DOMElement('long-description'));

            // for each argument; create an @param tag and an argument element
            /** @var \DOMElement $argument */
            foreach ($node->getElementsByTagName('argument') as $argument) {
                $param_tag = new \DOMElement('tag');
                $docblock->appendChild($param_tag);
                $param_tag->setAttribute('name', 'param');
                $param_tag->setAttribute(
                    'type',
                    $argument->getElementsByTagName('type')->item(0)->nodeValue
                );
                $param_tag->setAttribute(
                    'variable',
                    $argument->getElementsByTagName('name')->item(0)->nodeValue
                );
                $param_tag->setAttribute('line', $node->getAttribute('line'));

                $types = explode(
                    '|',
                    $argument->getElementsByTagName('type')->item(0)->nodeValue
                );

                foreach ($types as $type) {
                    $type_element = new \DOMElement('type', $type);
                    $param_tag->appendChild($type_element);
                }

                $argument_element = $argument->cloneNode(true);
                $method->appendChild($argument_element);
            }

            // add a tag 'magic'
            $magic_tag = new \DOMElement('tag');
            $docblock->appendChild($magic_tag);
            $magic_tag->setAttribute('name', 'magic');
            $magic_tag->setAttribute('line', $node->getAttribute('line'));

            // add a @return tag
            $return_tag = new \DOMElement('tag');
            $docblock->appendChild($return_tag);
            $return_tag->setAttribute('name', 'return');
            $return_tag->setAttribute('line', $node->getAttribute('line'));
            $return_tag->setAttribute('type', $node->getAttribute('type'));

            // add type sub elements to the param
            foreach (explode('|', $node->getAttribute('type')) as $type) {
                $type_element = new \DOMElement('type', $type);
                $return_tag->appendChild($type_element);
            }

            // remove the tag, it is unneeded
            $node->parentNode->removeChild($node);
            $docblock->appendChild($node);
        }

        return $xml;
    }
650826
protected function reinitBody()
    {
        if (!isset($this->body->childNodes)) {
            $this->body = $this->dom->createElement('body');
            $this->body->setInnerHtml($this->bodyCache);
        }
    }
460762
public function onDocumentStart()
    {
        $this->documentElement = new PHPTAL_Dom_Element('documentElement', 'http://xml.zope.org/namespaces/tal', array(), $this->getXmlnsState());
        $this->documentElement->setSource($this->file, $this->line);
        $this->_current = $this->documentElement;
    }
727154
private function ensureCurrentElementState()
    {
        if ($this->reader->nodeType !== XMLReader::ELEMENT) {
            $this->moveToNextElementByName($this->name);
        } elseif ($this->name && $this->name !== $this->reader->name) {
            $this->moveToNextElementByName($this->name);
        }
    }
1011062
protected function addTableBody()
	{
		$i   = 1;
		$cnt = count($this->table['rows']);
		while (++$i < $cnt)
		{
			$this->addTableRow('TD', $this->table['rows'][$i]);
		}

		$this->createBodyTags($this->table['rows'][2]['pos'], $this->pos);
	}
730685
private function buildBody()
    {
        // Build Body Element
        $this->body = $this->getHTMLDocument()->getHTMLFactory()->buildHtmlElement('div', '', '', 'ui-notification-body');
        $this->append($this->body);

        // Populate the notification icon
        $icon = $this->getHTMLDocument()->getHTMLFactory()->buildHtmlElement('span', '', '', 'ui-notification-icon');
        $this->appendToBody($icon);

        return $this;
    }
823760
protected function ensureAppended()
    {
        if (!$this->_appended) {
            $this->_parentElement->getDOM()->appendChild($this->_element);
            $this->_appended = true;
            $this->_parentElement->ensureAppended();
        }
    }
135551
protected function fillElement(DOMElement $element, BodyElement $bodyElement)
    {
        if (($id = $bodyElement->getId()) !== '') {
            $element->setAttribute('id', $id);
        }

        if (($class = $bodyElement->getClass()) !== '') {
            $element->setAttribute('class', $class);
        }

        if (($lang = $bodyElement->getLang()) !== '') {
            $element->setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:lang', $lang);
        }

        if (($label = $bodyElement->getLabel()) != '') {
            $element->setAttribute('label', $label);
        }
        
        $version = $this->getVersion();
        if (Version::compare($version, '2.2.0', '>=') === true && ($dir = $bodyElement->getDir()) !== Direction::AUTO && in_array($bodyElement->getQtiClassName(), self::$dirClasses) === true) {
            $element->setAttribute('dir', Direction::getNameByConstant($dir));
        }
    }
721163
protected function addClassBody(&$script)
    {
        $table = $this->getTable();

        $this->addAttributes($script);

        $this->addConstructor($script);

        $this->addCallOverload($script);
        $this->addSetIteratorOptions($script);
        $this->addGetIterator($script);

        $this->addGetNodeObj($script);
        $this->addGetNodePath($script);
        $this->addGetNodeIndex($script);
        $this->addGetNodeLevel($script);

        $this->addHasChildNode($script);
        $this->addGetChildNodeAt($script);
        $this->addGetFirstChildNode($script);
        $this->addGetLastChildNode($script);
        $this->addGetSiblingNode($script);

        $this->addGetParentNode($script);
        $this->addGetAncestors($script);
        $this->addIsRootNode($script);

        $this->addSetNew($script);
        $this->addSetDeleted($script);
        $this->addAddChildNode($script);
        $this->addMoveChildNode($script);
        $this->addSave($script);

        $this->addDelete($script);
        $this->addEquals($script);

        $this->addAttachParentNode($script);
        $this->addAttachChildNode($script);
        $this->addDetachParentNode($script);
        $this->addDetachChildNode($script);
        $this->addShiftChildNodes($script);
        $this->addInsertNewChildNode($script);

        $this->addAdjustStatus($script);
        $this->addAdjustNodePath($script);
    }
716976
private void addRootElement() {
        if (root instanceof Document) {
            // Get the single element child of the document node.
            // There could be a doctype node and comment nodes that we must skip.
            Element element = DOMHelper.getFirstChildElement(root);
            Assert.notNull(element, "there should be a root element!");
            result.add(element);
        } else {
            Assert.isTrue(root instanceof Element, "root must be a document or element node!");
            result.add(root);
        }
    }
1336569
protected function getHtmlAttachmentBody()
    {
        $html   = $this->getHtmlBody();

        $body = array();
        $body[] = 'Content-Type: multipart/mixed; boundary="'.$this->boundary[1].'"';
        $body[] = null;
        $body[] = '--'.$this->boundary[1];

        foreach ($html as $line) {
            $body[] = $line;
        }

        return $this->addAttachmentBody($body);
    }
526155
public function hasBodyPlaceholderEmpty()
    {
        if ($this->bodyKey !== null) {
            if (isset($this->stack[$this->bodyKey])) {
                if ($this->stack[$this->bodyKey]->getType() === View::PART_BODY_PLACEHOLDER) {
                    return true;
                }
            }
        }
        return false;
    }
935544
public function process()
    {
        // {{{ defines the xhtml template

        static $xhtml_template = '';

        if ($xhtml_template == '') {
            $doctype =
                '<!DOCTYPE html PUBLIC ' .
                '"-//W3C//DTD XHTML 1.0 Strict//EN" ' .
                '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' .
                "\n";

            $xhtml_template =
                $doctype .
                <<<XHTML
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
		<title>SwatXHTMLTextarea Content</title>
	</head>
	<body>
		<div>
		%s
		</div>
	</body>
</html>

XHTML;
        }

        // }}}

        parent::process();

        $ignore_validation_errors =
            $this->allow_ignore_validation_errors &&
            $this->ignore_errors_checkbox->value;

        $xhtml_content = sprintf($xhtml_template, $this->getXHTMLContent());

        $errors = libxml_use_internal_errors(true);

        $document = new DOMDocument();
        $document->loadXML(
            $xhtml_content,
            LIBXML_DTDLOAD | LIBXML_DTDATTR | LIBXML_DTDVALID
        );

        $xml_errors = libxml_get_errors();
        libxml_clear_errors();
        libxml_use_internal_errors($errors);

        if (count($xml_errors) > 0 && !$ignore_validation_errors) {
            $this->addMessage($this->getValidationErrorMessage($xml_errors));
            $this->has_validation_errors = true;
        }
    }