Package org.apache.tapestry5

Examples of org.apache.tapestry5.MarkupWriter


    }

    @Test(expectedExceptions = IllegalStateException.class)
    public void define_namespace_with_no_current_element()
    {
        MarkupWriter w = new MarkupWriterImpl();

        w.defineNamespace("foo", "bar");
    }
View Full Code Here


    }

    @Test(expectedExceptions = IllegalStateException.class)
    public void end_with_no_current_element()
    {
        MarkupWriter w = new MarkupWriterImpl();

        w.end();
    }
View Full Code Here

    }

    @Test(expectedExceptions = IllegalStateException.class)
    public void attributes_with_no_current_element()
    {
        MarkupWriter w = new MarkupWriterImpl();

        w.attributes("fail", "now");
    }
View Full Code Here

    }

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

        w.element("root");

        assertNull(w.end());
    }
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.getContainer(), root);

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

        assertEquals(
                w.toString(),
                "<?xml version=\"1.0\"?>\n<fred:root fred:foo=\"bar\" xmlns:barney=\"barneyns\" xmlns:fred=\"fredns\"><barney:child/></fred:root>");
    }
View Full Code Here

    }

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

        w.element("root");
        w.write("Normal Text ");
        w.cdata("< & >");
        w.write("More Normal Text");

        assertEquals(w.toString(),
                "<?xml version=\"1.0\"?>\n<root>Normal Text <![CDATA[< & >]]>More Normal Text</root>");
    }
View Full Code Here

    }

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

        MarkupWriterListener l = new MarkupWriterListener()
        {
            public void elementDidStart(Element element)
            {
                element.text("[Start: " + element.getName() + "]");
            }

            public void elementDidEnd(Element element)
            {
                element.text("[End: " + element.getName() + "]");
            }
        };

        w.element("root");
        w.element("no-listener");

        w.write("before listener");

        w.addListener(l);

        w.element("listener");
        w.write("before n-w-l");
        w.element("nested-with-listener");
        w.write("n-w-l text");
        w.end();
        w.write("after n-w-l");
        w.end();

        w.removeListener(l);

        w.write("after listener");

        w.end();
        w.end();

        // Because we are invoking Element.text(), the text added by the listener is appended to the body of the
        // element,
        // which is correct but may not be what you'd expect.

        assertEquals(
                w.toString(),
                "<?xml version=\"1.0\"?>\n"
                        + "<root><no-listener>before listener<listener>[Start: listener]before n-w-l<nested-with-listener>[Start: nested-with-listener]n-w-l text[End: nested-with-listener]</nested-with-listener>after n-w-l[End: listener]</listener>after listener</no-listener></root>");
    }
View Full Code Here

            ContentType pageContentType = (ContentType) request.getAttribute(InternalConstants.CONTENT_TYPE_ATTRIBUTE_NAME);

            ContentType contentType = new ContentType(InternalConstants.JSON_MIME_TYPE, outputEncoding);

            MarkupWriter writer = factory.newPartialMarkupWriter(pageContentType);

            JSONObject reply = new JSONObject();

            // ... and here, the pipeline eventually reaches the PRQ to let it render the root render command.
View Full Code Here

        TranslatorSource ts = mockTranslatorSource();
        FormSupport fs = mockFormSupport();
        Translator translator = mockTranslator("maptrans", Map.class);
        Messages globalMessages = mockMessages();
        MessageFormatter formatter = mockMessageFormatter();
        MarkupWriter writer = mockMarkupWriter();
        String label = "Field Label";
        String message = "Woops, did it again.";
        AnnotationProvider ap = mockAnnotationProvider(null);

        train_findByType(ts, propertyType, translator);
View Full Code Here

TOP

Related Classes of org.apache.tapestry5.MarkupWriter

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.