Package org.apache.tapestry.util

Examples of org.apache.tapestry.util.ContentType


    public void renderResponse(IRequestCycle cycle)
        throws IOException
    {
        _localeManager.persistLocale();
       
        ContentType contentType = new ContentType(CONTENT_TYPE
                + ";charset=" + cycle.getInfrastructure().getOutputEncoding());
       
        String encoding = contentType.getParameter(ENCODING_KEY);
       
        if (encoding == null)
        {
            encoding = cycle.getEngine().getOutputEncoding();
           
            contentType.setParameter(ENCODING_KEY, encoding);
        }
       
        PrintWriter printWriter = _webResponse.getPrintWriter(contentType);
       
        _writer = _markupWriterSource.newMarkupWriter(printWriter, contentType);
View Full Code Here


public class TestContentType extends TapestryTestCase
{

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

        assertEquals("The base type of the ContentType is invalid", "text", contentType
                .getBaseType());

        assertEquals("The html type of the ContentType is invalid", "html", contentType
                .getSubType());

        assertEquals("The mime type of the ContentType is invalid", "text/html", contentType
                .getMimeType());

        String[] parameterNames = contentType.getParameterNames();
        assertEquals(
                "The number of parameter names of the ContentType is invalid",
                1,
                parameterNames.length);

        assertEquals(
                "The parameter names of the ContentType are invalid",
                "charset",
                parameterNames[0]);

        String charset = contentType.getParameter("charset");
        assertEquals("The charset parameter of the ContentType is invalid", "utf-8", charset);

        String nonexistant = contentType.getParameter("nonexistant");
        assertTrue(
                "ContentType does not return null for a non-existant parameter",
                nonexistant == null);
    }
View Full Code Here

                nonexistant == null);
    }

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

        assertEquals("The base type of the ContentType is invalid", "text", contentType
                .getBaseType());

        assertEquals("The html type of the ContentType is invalid", "html", contentType
                .getSubType());

        assertEquals("The mime type of the ContentType is invalid", "text/html", contentType
                .getMimeType());

        String[] parameterNames = contentType.getParameterNames();
        assertEquals(
                "The number of parameter names of the ContentType is invalid",
                0,
                parameterNames.length);

        String charset = contentType.getParameter("charset");
        assertTrue("The charset parameter of the ContentType is invalid", charset == null);
    }
View Full Code Here

        assertTrue("The charset parameter of the ContentType is invalid", charset == null);
    }

    public void testUnparsing1() throws Exception
    {
        ContentType contentType = new ContentType();

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

        assertEquals(
                "ContentType does not generate a valid String representation",
                "text/html;charset=utf-8",
                contentType.unparse());
    }
View Full Code Here

                contentType.unparse());
    }

    public void testUnparsing2() throws Exception
    {
        ContentType contentType = new ContentType();

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

        assertEquals(
                "ContentType does not generate a valid String representation",
                "text/html",
                contentType.unparse());
    }
View Full Code Here

    {
        if (translatorSource == null || contentType == null || encoding == null)
            throw new IllegalArgumentException(
                Tapestry.getMessage("AbstractMarkupWriter.missing-constructor-parameters"));

        ContentType contentTypeObject = generateFullContentType(contentType, encoding);
        _contentType = contentTypeObject.unparse();
       
        encoding = contentTypeObject.getParameter("charset");
        _translator = translatorSource.getTranslator(encoding);
       
        setOutputStream(stream, encoding);
    }
View Full Code Here

        String contentType,
        OutputStream stream)
    {
        this(translatorSource, contentType);

        ContentType contentTypeObject = new ContentType(contentType);
        String encoding = contentTypeObject.getParameter("charset");

        setOutputStream(stream, encoding);
    }
View Full Code Here

    {
        if (translatorSource == null || contentType == null)
            throw new IllegalArgumentException(
                Tapestry.getMessage("AbstractMarkupWriter.missing-constructor-parameters"));

        ContentType contentTypeObject = generateFullContentType(contentType, DEFAULT_ENCODING);
        _contentType = contentTypeObject.unparse();
       
        String encoding = contentTypeObject.getParameter("charset");
        _translator = translatorSource.getTranslator(encoding);
    }
View Full Code Here

     * @param encoding The value of the charset parameter of the content type if it is not already present.
     * @return The content type containing a charset parameter, e.g. text/html;charset=utf-8
     */
    private ContentType generateFullContentType(String contentType, String encoding)
    {
        ContentType contentTypeObject = new ContentType(contentType);
        if (contentTypeObject.getParameter("charset") == null)
            contentTypeObject.setParameter("charset", encoding);
        return contentTypeObject;
    }
View Full Code Here

        try {
            _response.setDateHeader("Expires", EXPIRES);
            _response.setHeader("Cache-Control", "public, max-age=" + (MONTH_SECONDS * 3));
            _response.setContentLength(data.length);

            os = _response.getOutputStream(new ContentType("image/" + type));

            os.write(data);

        finally {
            try {
View Full Code Here

TOP

Related Classes of org.apache.tapestry.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.