protected function generateTemplates(Webspace $webspace)
    {
        $defaultErrorTemplates = 0;

        foreach ($this->xpath->query('/x:webspace/x:theme/x:error-templates/x:error-template') as $errorTemplateNode) {
            /* @var \DOMNode $errorTemplateNode */
            $template = $errorTemplateNode->nodeValue;
            if (null !== ($codeNode = $errorTemplateNode->attributes->getNamedItem('code'))) {
                $webspace->addTemplate('error-' . $codeNode->nodeValue, $template);
            } elseif (null !== ($defaultNode = $errorTemplateNode->attributes->getNamedItem('default'))) {
                $default = 'true' === $defaultNode->nodeValue;
                if (!$default) {
                    throw new InvalidDefaultErrorTemplateException($template, $this->webspace->getKey());
                }
                ++$defaultErrorTemplates;
                $webspace->addTemplate('error', $template);
            } else {
                throw new InvalidErrorTemplateException($template, $this->webspace->getKey());
            }
        }

        // only one or none default error-template is legal
        if ($defaultErrorTemplates > 1) {
            throw new InvalidAmountOfDefaultErrorTemplateException($this->webspace->getKey());
        }

        return $webspace;
    }