Package org.apache.tapestry5.dom

Examples of org.apache.tapestry5.dom.Element


     *
     * @param document to be updated
     */
    public void updateDocument(Document document)
    {
        Element root = document.getRootElement();

        // This can happen due to a catastrophic rendering error, such as a missing page template.
        if (root == null) return;

        // This only applies when the document is an HTML document. This may need to change in the
        // future, perhaps configurable, to allow for html and xhtml and perhaps others. Does SVG
        // use stylesheets?

        if (!root.getName().equals("html")) return;

        int stylesheets = includedStylesheets.size();

        if (stylesheets > 0)
        {
            Element head = root.find("head");

            if (head == null) head = root.elementAt(0, "head");

            for (int i = 0; i < stylesheets; i++)
                includedStylesheets.get(i).add(head, i);
        }

        Element body = root.find("body");

        if (body == null) return;

        // TAPESTRY-2364


        for (String scriptURL : scripts)
        {
            body.element("script", "src", scriptURL, "type", "text/javascript");
        }

        boolean blockNeeded = (developmentMode && !scripts.isEmpty()) || scriptBlock.length() > 0;

        if (blockNeeded)
        {
            Element e = body.element("script", "type", "text/javascript");
            e.raw("\n<!--\n");

            if (developmentMode)
                e.raw("Tapestry.DEBUG_ENABLED = true;\n");

            e.raw("Tapestry.onDOMLoaded(function() {\n");

            e.raw(scriptBlock.toString());

            e.raw("});\n");

            e.raw("// -->\n");
        }

    }
View Full Code Here


    @Test
    public void element_nesting()
    {
        MarkupWriter w = new MarkupWriterImpl();

        Element root = w.element("root");

        w.attributes("foo", "bar");

        w.write("before child");

        assertNotSame(w.element("nested"), root);

        w.write("inner text");

        assertSame(w.end(), root);

        w.write("after child");

        root.attribute("gnip", "gnop");

        assertEquals(w.toString(),
                     "<root foo=\"bar\" gnip=\"gnop\">before child<nested>inner text</nested>after child</root>");
    }
View Full Code Here

    @Test
    public void namespaced_elements_and_attributes()
    {
        MarkupWriter w = new MarkupWriterImpl(new XMLMarkupModel());

        Element root = w.elementNS("fredns", "root");

        assertSame(root.defineNamespace("fredns", "fred"), root);

        root.defineNamespace("barneyns", "barney");

        assertSame(w.attributeNS("fredns", "foo", "bar"), root);

        Element child = w.elementNS("barneyns", "child");

        assertSame(child.getParent(), root);

        w.end(); // child
        w.end(); // root

        assertEquals(w.toString(),
View Full Code Here

        public void render(MarkupWriter writer, RenderQueue queue)
        {
            rendering = false;

            Element current = writer.getElement();

            if (current != expectedElementAtCompletion)
                throw new TapestryException(StructureMessages.unbalancedElements(completeId), getLocation(), null);

            invoke(false, POST_RENDER_CLEANUP);
View Full Code Here

     *
     * @param document to be updated
     */
    public void updateDocument(Document document)
    {
        Element root = document.getRootElement();

        // If the document failed to render at all, that's a different problem and is reported elsewhere.

        if (root == null)
            return;

        addStylesheetsToHead(root, includedStylesheets);

        // only add the generator meta only to html documents

        boolean isHtmlRoot = root.getName().equals("html");

        if (!omitGeneratorMetaTag && isHtmlRoot)
        {
            Element head = findOrCreateElement(root, "head", true);

            Element existingMeta = head.find("meta");

            addElementBefore(head, existingMeta, "meta", "name", "generator", "content", tapestryBanner);
        }

        addScriptElements(root);
View Full Code Here

        String rootElementName = root.getName();

        if (!rootElementName.equals("html"))
            throw new RuntimeException(ServicesMessages.documentMissingHTMLRoot(rootElementName));

        Element head = findOrCreateElement(root, "head", true);

        // TAPESTRY-2364

        addScriptLinksForIncludedScripts(head, scripts);
View Full Code Here

     * @param atTop        if not found, create new element at top of root, or at bottom
     * @return the located element, or null
     */
    private Element findOrCreateElement(Element root, String childElement, boolean atTop)
    {
        Element container = root.find(childElement);

        // Create the element is it is missing.

        if (container == null)
            container = atTop ? root.elementAt(0, childElement) : root.element(childElement);
View Full Code Here

        }

        if (wrapped)
            block.append("});\n");

        Element e = body.element("script", "type", "text/javascript");

        e.raw(block.toString());

    }
View Full Code Here

    {
        // TAP5-1486

        // Find the first existing <script> tag if it exists.

        Element container = createTemporaryContainer(headElement, "script", "script-container");

        for (String script : scripts)
        {
            container.element("script", "type", "text/javascript", "src", script);
        }

        container.pop();
    }
View Full Code Here

        container.pop();
    }

    private static Element createTemporaryContainer(Element headElement, String existingElementName, String newElementName)
    {
        Element existingScript = headElement.find(existingElementName);

        // Create temporary container for the new <script> elements

        return addElementBefore(headElement, existingScript, newElementName);
    }
View Full Code Here

TOP

Related Classes of org.apache.tapestry5.dom.Element

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.