Package org.apache.james.mime4j.field

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


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


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

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

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

        f = (ContentTypeField) Field.parse("Content-Type: some/type;");
        assertEquals("us-ascii", ContentTypeField.getCharset(f));
    }
   
    public void testGetParameter() {
        ContentTypeField f = null;
       
        f = (ContentTypeField) Field.parse("CONTENT-TYPE:   text / html ;"
                                                + "  boundary=yada yada");
        assertEquals("yada", f.getParameter("boundary"));
       
        f = (ContentTypeField) Field.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) Field.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 MimeException if case of a MIME protocol violation
     */
    public void writeTo(final OutputStream out, int mode) throws IOException, MimeException {
        Entity e = getParent();
       
        ContentTypeField cField = (ContentTypeField) e.getHeader().getField(
                Field.CONTENT_TYPE);
        if (cField == null || cField.getBoundary() == null) {
            throw new MimeException("Multipart boundary not specified");
        }
        String boundary = cField.getBoundary();

        Charset charset = null;
        if (mode == MessageUtils.LENIENT) {
            if (cField != null && cField.getCharset() != null) {
                charset = CharsetUtil.getCharset(cField.getCharset());
            } else {
                charset = MessageUtils.ISO_8859_1;
            }
        } else {
            charset = MessageUtils.DEFAULT_CHARSET;
View Full Code Here

     * Content-Type field is set for this <code>Entity</code>.
     *
     * @return the MIME type.
     */
    public String getMimeType() {
        ContentTypeField child =
            (ContentTypeField) getHeader().getField(Field.CONTENT_TYPE);
        ContentTypeField parent = getParent() != null
            ? (ContentTypeField) getParent().getHeader().
                                                getField(Field.CONTENT_TYPE)
            : null;
       
        return ContentTypeField.getMimeType(child, parent);
View Full Code Here

     * method returns <code>false</code> if no boundary exists.
     *
     * @return <code>true</code> on match, <code>false</code> otherwise.
     */
    public boolean isMultipart() {
        ContentTypeField f =
            (ContentTypeField) getHeader().getField(Field.CONTENT_TYPE);
        return f != null && f.getBoundary() != null
            && getMimeType().startsWith(ContentTypeField.TYPE_MULTIPART_PREFIX);
    }
View Full Code Here

     * @throws MimeException if case of a MIME protocol violation
     */
    public void writeTo(final OutputStream out, int mode) throws IOException, MimeException {
        Charset charset = null;
        if (mode == MessageUtils.LENIENT) {
            final ContentTypeField contentTypeField = ((ContentTypeField) getField(Field.CONTENT_TYPE));
            if (contentTypeField == null) {
                charset = MessageUtils.DEFAULT_CHARSET;
            } else {
                final String contentTypeFieldCharset = contentTypeField.getCharset();
                if (contentTypeField != null && contentTypeFieldCharset != null) {
                    charset = CharsetUtil.getCharset(contentTypeFieldCharset);
                } else {
                    charset = MessageUtils.ISO_8859_1;
                }
View Full Code Here

        this.mode = mode;
    }

    protected Charset getCharset() {
        Entity e = getParent();
        ContentTypeField cField = (ContentTypeField) e.getHeader().getField(
                Field.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

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.