Esempio n. 1
0
static inline PassRefPtr<Element> createXHTMLParserErrorHeader(Document* doc, const String& errorMessages)
{
    RefPtr<Element> reportElement = doc->createElement(QualifiedName(nullAtom, "parsererror", xhtmlNamespaceURI), true);

    AttributeVector reportAttributes;
    reportAttributes.append(Attribute(styleAttr, "display: block; white-space: pre; border: 2px solid #c77; padding: 0 1em 0 1em; margin: 1em; background-color: #fdd; color: black"));
    reportElement->parserSetAttributes(reportAttributes, FragmentScriptingNotAllowed);

    RefPtr<Element> h3 = doc->createElement(h3Tag, true);
    reportElement->parserAddChild(h3.get());
    h3->parserAddChild(doc->createTextNode("This page contains the following errors:"));

    RefPtr<Element> fixed = doc->createElement(divTag, true);
    AttributeVector fixedAttributes;
    fixedAttributes.append(Attribute(styleAttr, "font-family:monospace;font-size:12px"));
    fixed->parserSetAttributes(fixedAttributes, FragmentScriptingNotAllowed);
    reportElement->parserAddChild(fixed.get());

    fixed->parserAddChild(doc->createTextNode(errorMessages));

    h3 = doc->createElement(h3Tag, true);
    reportElement->parserAddChild(h3.get());
    h3->parserAddChild(doc->createTextNode("Below is a rendering of the page up to the first error."));

    return reportElement.release();
}
Esempio n. 2
0
void XMLErrors::insertErrorMessageBlock()
{
    // One or more errors occurred during parsing of the code. Display an error block to the user above
    // the normal content (the DOM tree is created manually and includes line/col info regarding
    // where the errors are located)

    // Create elements for display
    RefPtr<Element> documentElement = m_document->documentElement();
    if (!documentElement) {
        RefPtr<Element> rootElement = m_document->createElement(htmlTag, true);
        RefPtr<Element> body = m_document->createElement(bodyTag, true);
        rootElement->parserAddChild(body);
        m_document->parserAddChild(rootElement);
        if (m_document->attached() && !rootElement->attached())
            rootElement->attach();
        documentElement = body.get();
    }
#if ENABLE(SVG)
    else if (documentElement->namespaceURI() == SVGNames::svgNamespaceURI) {
        RefPtr<Element> rootElement = m_document->createElement(htmlTag, true);
        RefPtr<Element> body = m_document->createElement(bodyTag, true);
        rootElement->parserAddChild(body);

        documentElement->parentNode()->parserRemoveChild(documentElement.get());
        if (documentElement->attached())
            documentElement->detach();

        body->parserAddChild(documentElement);
        m_document->parserAddChild(rootElement.get());

        if (m_document->attached())
            // In general, rootElement shouldn't be attached right now, but it will be if there is a style element
            // in the SVG content.
            rootElement->reattach();

        documentElement = body.get();
    }
#endif

    String errorMessages = m_errorMessages.toString();
    RefPtr<Element> reportElement = createXHTMLParserErrorHeader(m_document, errorMessages);

#if ENABLE(XSLT)
    if (m_document->transformSourceDocument()) {
        AttributeVector attributes;
        attributes.append(Attribute(styleAttr, "white-space: normal"));
        RefPtr<Element> paragraph = m_document->createElement(pTag, true);
        paragraph->parserSetAttributes(attributes, FragmentScriptingNotAllowed);
        paragraph->parserAddChild(m_document->createTextNode("This document was created as the result of an XSL transformation. The line and column numbers given are from the transformed result."));
        reportElement->parserAddChild(paragraph.release());
    }
#endif

    Node* firstChild = documentElement->firstChild();
    if (firstChild)
        documentElement->parserInsertBefore(reportElement, documentElement->firstChild());
    else
        documentElement->parserAddChild(reportElement);

    if (documentElement->attached() && !reportElement->attached())
        reportElement->attach();

    m_document->updateStyleIfNeeded();
}