Package org.apache.tapestry.internal.util

Examples of org.apache.tapestry.internal.util.ContentType


public class ContentTypeTest extends Assert
{
    @Test
    public void simple_equals()
    {
        ContentType master = new ContentType("text/html");

        assertFalse(master.equals(null));
        assertFalse(master.equals(this));
        assertTrue(master.equals(master));
        assertTrue(master.equals(new ContentType("text/html")));
        assertFalse(master.equals(new ContentType("foo/bar")));
        assertFalse(master.equals(new ContentType("text/plain")));
    }
View Full Code Here


    }

    @Test
    public void equals_with_parameters()
    {
        ContentType master = new ContentType("text/html;charset=utf-8");

        assertFalse(master.equals(new ContentType("text/html")));
        assertTrue(master.equals(new ContentType("text/html;charset=utf-8")));
        assertFalse(master.equals(new ContentType("text/html;charset=utf-8;foo=bar")));

        // Check that keys are case insensitive

        assertTrue(master.equals(new ContentType("text/html;Charset=utf-8")));

        master = new ContentType("text/html;foo=bar;biff=bazz");

        assertTrue(master.equals(new ContentType("text/html;foo=bar;biff=bazz")));
        assertTrue(master.equals(new ContentType("text/html;Foo=bar;Biff=bazz")));
        assertTrue(master.equals(new ContentType("text/html;biff=bazz;foo=bar")));
    }
View Full Code Here

    }

    @Test
    public void parse_with_parameters() throws Exception
    {
        ContentType contentType = new ContentType("text/html;charset=utf-8");

        assertEquals(contentType.getBaseType(), "text");

        assertEquals(contentType.getSubType(), "html");

        assertEquals(contentType.getMimeType(), "text/html");

        List<String> parameterNames = contentType.getParameterNames();
        assertEquals(parameterNames.size(), 1);

        assertEquals(parameterNames.get(0), "charset");

        String charset = contentType.getParameter("charset");
        assertEquals(charset, "utf-8");

        String nonexistant = contentType.getParameter("nonexistant");
        assertTrue(nonexistant == null);
    }
View Full Code Here

    }

    @Test
    public void parse_without_parameters() throws Exception
    {
        ContentType contentType = new ContentType("text/html");

        assertEquals(contentType.getBaseType(), "text");

        assertEquals(contentType.getSubType(), "html");

        assertEquals(contentType.getMimeType(), "text/html");

        assertTrue(contentType.getParameterNames().isEmpty());
    }
View Full Code Here

    }

    @Test
    public void unparse_with_parameters() throws Exception
    {
        ContentType contentType = new ContentType();

        contentType.setBaseType("text");
        contentType.setSubType("html");
        contentType.setParameter("charset", "utf-8");

        assertEquals(contentType.unparse(), "text/html;charset=utf-8");
    }
View Full Code Here

    }

    @Test
    public void unparse_no_parameters() throws Exception
    {
        ContentType contentType = new ContentType();

        contentType.setBaseType("text");
        contentType.setSubType("html");

        assertEquals(contentType.unparse(), "text/html");
    }
View Full Code Here

    }

    @Test
    public void to_string_is_unparse()
    {
        ContentType contentType = new ContentType();

        contentType.setBaseType("text");
        contentType.setSubType("html");
        contentType.setParameter("charset", "utf-8");

        assertEquals(contentType.toString(), contentType.unparse());
    }
View Full Code Here

        ComponentResources pageResources = page.getRootComponent().getComponentResources();

        String contentTypeString = _metaDataLocator.findMeta(
                TapestryConstants.RESPONSE_CONTENT_TYPE,
                pageResources);
        ContentType contentType = new ContentType(contentTypeString);

        // Make sure thre's always a charset specified.
       
        String encoding = contentType.getParameter(CHARSET);
        if (encoding == null)
        {
            encoding = _metaDataLocator
                    .findMeta(TapestryConstants.RESPONSE_ENCODING, pageResources);
            contentType.setParameter(CHARSET, encoding);
        }

        // Eventually we'll have to do work to figure out the correct markup type, content type,
        // whatever. Right now its defaulting to plain HTML.

        MarkupWriter writer = _markupWriterFactory.newMarkupWriter();

        _markupRenderer.renderPageMarkup(page, writer);

        PrintWriter pw = response.getPrintWriter(contentType.toString());

        writer.toMarkup(pw);

        pw.flush();
    }
View Full Code Here

        ComponentResources pageResources = page.getRootElement().getComponentResources();

        String contentTypeString = _locator.findMeta(
                TapestryConstants.RESPONSE_CONTENT_TYPE,
                pageResources);
        ContentType contentType = new ContentType(contentTypeString);

        String encoding = contentType.getParameter("charset");

        if (encoding == null)
            encoding = _locator.findMeta(TapestryConstants.RESPONSE_ENCODING, pageResources);

        _request.setEncoding(encoding);
View Full Code Here

        _metaDataLocator = metaDataLocator;
    }

    public void renderPageResponse(Page page, Response response) throws IOException
    {
        ContentType contentType = findResponseContentType(page);

        // Eventually we'll have to do work to figure out the correct markup type, content type,
        // whatever. Right now its defaulting to plain HTML.

        MarkupWriter writer = _markupWriterFactory.newMarkupWriter();

        _markupRenderer.renderPageMarkup(page, writer);

        PrintWriter pw = response.getPrintWriter(contentType.toString());

        writer.toMarkup(pw);

        pw.flush();
    }
View Full Code Here

TOP

Related Classes of org.apache.tapestry.internal.util.ContentType

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.