Package org.apache.james.mime4j.field

Examples of org.apache.james.mime4j.field.ContentTypeField


        return charset;
    }
   
    protected String getBoundary() {
        Entity e = getParent();
        ContentTypeField cField = (ContentTypeField) e.getHeader().getField(
                Field.CONTENT_TYPE);
        return cField.getBoundary();
    }
View Full Code Here


        this.mode = mode;
    }

    protected Charset getCharset() {
        Entity e = getParent();
        ContentTypeField cField = (ContentTypeField) e.getHeader().getField(
                FieldName.CONTENT_TYPE);
        Charset charset = null;
       
        switch (this.mode) {
        case STRICT:
            charset = MIME.DEFAULT_CHARSET;
            break;
        case BROWSER_COMPATIBLE:
            if (cField.getCharset() != null) {
                charset = CharsetUtil.getCharset(cField.getCharset());
            } else {
                charset = CharsetUtil.getCharset(HTTP.DEFAULT_CONTENT_CHARSET);
            }
            break;
        }
View Full Code Here

        return charset;
    }
   
    protected String getBoundary() {
        Entity e = getParent();
        ContentTypeField cField = (ContentTypeField) e.getHeader().getField(
                FieldName.CONTENT_TYPE);
        return cField.getBoundary();
    }
View Full Code Here

        BasicConfigurator.resetConfiguration();
        BasicConfigurator.configure();
    }
   
    public void testMimeTypeWithSemiColonNoParams() throws Exception  {
        ContentTypeField f = null;
       
        f = (ContentTypeField) AbstractField.parse("Content-Type: text/html;");
        assertEquals("text/html", f.getMimeType());
    }
View Full Code Here

        f = (ContentTypeField) AbstractField.parse("Content-Type: text/html;");
        assertEquals("text/html", f.getMimeType());
    }
   
    public void testGetMimeType() throws Exception {
        ContentTypeField f = null;
       
        f = (ContentTypeField) AbstractField.parse("Content-Type: text/PLAIN");
        assertEquals("text/plain", f.getMimeType());
       
        f = (ContentTypeField) AbstractField.parse("content-type:   TeXt / html   ");
        assertEquals("text/html", f.getMimeType());
       
        f = (ContentTypeField) AbstractField.parse("CONTENT-TYPE:   x-app/yada ;"
                                                    + "  param = yada");
        assertEquals("x-app/yada", f.getMimeType());
       
        f = (ContentTypeField) AbstractField.parse("CONTENT-TYPE:   yada");
        assertEquals("", f.getMimeType());
    }
View Full Code Here

        f = (ContentTypeField) AbstractField.parse("CONTENT-TYPE:   yada");
        assertEquals("", f.getMimeType());
    }
   
    public void testGetMimeTypeStatic() throws Exception {
        ContentTypeField child = null;
        ContentTypeField parent = null;
       
        child = (ContentTypeField) AbstractField.parse("Content-Type: child/type");
        parent = (ContentTypeField) AbstractField.parse("Content-Type: parent/type");
        assertEquals("child/type", ContentTypeField.getMimeType(child, parent));
       
View Full Code Here

        parent = (ContentTypeField) AbstractField.parse("Content-Type: multipart/digest");
        assertEquals("message/rfc822", ContentTypeField.getMimeType(child, parent));
    }
   
    public void testGetCharsetStatic() throws Exception {
        ContentTypeField f = null;
       
        f = (ContentTypeField) AbstractField.parse("Content-Type: some/type; charset=iso8859-1");
        assertEquals("iso8859-1", ContentTypeField.getCharset(f));
       
        f = (ContentTypeField) AbstractField.parse("Content-Type: some/type;");
View Full Code Here

        f = (ContentTypeField) AbstractField.parse("Content-Type: some/type;");
        assertEquals("us-ascii", ContentTypeField.getCharset(f));
    }
   
    public void testGetParameter() throws Exception {
        ContentTypeField f = null;
       
        f = (ContentTypeField) AbstractField.parse("CONTENT-TYPE:   text / html ;"
                                                + "  boundary=yada yada");
        assertEquals("yada", f.getParameter("boundary"));
       
        f = (ContentTypeField) AbstractField.parse("Content-Type: x-app/yada;"
                                                + "  boUNdarY= \"ya:\\\"*da\"; "
                                                + "\tcharset\t =  us-ascii");
        assertEquals("ya:\"*da", f.getParameter("boundary"));
        assertEquals("us-ascii", f.getParameter("charset"));
       
        f = (ContentTypeField) AbstractField.parse("Content-Type: x-app/yada;  "
                            + "boUNdarY= \"ya \\\"\\\"\tda \\\"\"; "
                            + "\tcharset\t =  \"\\\"hepp\\\"  =us\t-ascii\"");
        assertEquals("ya \"\"\tda \"", f.getParameter("boundary"));
        assertEquals("\"hepp\"  =us\t-ascii", f.getParameter("charset"));
    }
View Full Code Here

     * @throws IOException
     *             if an I/O error occurs.
     */
    public void writeMultipart(Multipart multipart, OutputStream out)
            throws IOException {
        ContentTypeField contentType = getContentType(multipart);

        ByteSequence boundary = getBoundary(contentType);

        writeBytes(multipart.getPreambleRaw(), out);
        out.write(CRLF);
View Full Code Here

        Header header = parent.getHeader();
        if (header == null)
            throw new IllegalArgumentException(
                    "Missing header in parent entity");

        ContentTypeField contentType = (ContentTypeField) header
                .getField(FieldName.CONTENT_TYPE);
        if (contentType == null)
            throw new IllegalArgumentException(
                    "Content-Type field not specified");
View Full Code Here

TOP

Related Classes of org.apache.james.mime4j.field.ContentTypeField

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.