Package org.apache.james.mime4j.dom

Examples of org.apache.james.mime4j.dom.Entity


            multipart.addBodyPart(bodyPart, 2 * i + 1);
        }

        // For no particular reason remove the second binary body part (now
        // at index four).
        Entity removed = multipart.removeBodyPart(4);

        // The removed body part no longer has a parent entity it belongs to so
        // it should be disposed of.
        removed.dispose();

        // Set some headers on the transformed message
        message.createMessageId(HOSTNAME);
        message.setSubject("Transformed message");
        message.setDate(new Date());
View Full Code Here


     * @see org.apache.james.mime4j.parser.ContentHandler#startMultipart(org.apache.james.mime4j.stream.BodyDescriptor)
     */
    public void startMultipart(final BodyDescriptor bd) throws MimeException {
        expect(Entity.class);

        final Entity e = (Entity) stack.peek();
        final String subType = bd.getSubType();
        final Multipart multiPart = new MultipartImpl(subType);
        e.setBody(multiPart);
        stack.push(multiPart);
    }
View Full Code Here

            body = bodyFactory.textBody(is, bd.getCharset());
        } else {
            body = bodyFactory.binaryBody(is);
        }

        Entity entity = ((Entity) stack.peek());
        entity.setBody(body);
    }
View Full Code Here

            return out;
        }
    }

    private ContentTypeField getContentType(Multipart multipart) {
        Entity parent = multipart.getParent();
        if (parent == null)
            throw new IllegalArgumentException(
                    "Missing parent entity in multipart");

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

        ContentTypeField contentType = (ContentTypeField) header
View Full Code Here

     * @throws IndexOutOfBoundsException
     *             if the index is out of range (index < 0 || index >=
     *             getCount()).
     */
    public Entity removeBodyPart(int index) {
        Entity bodyPart = bodyParts.remove(index);
        bodyPart.setParent(null);
        return bodyPart;
    }
View Full Code Here

     */
    public Entity replaceBodyPart(Entity bodyPart, int index) {
        if (bodyPart == null)
            throw new IllegalArgumentException();

        Entity replacedEntity = bodyParts.set(index, bodyPart);
        if (bodyPart == replacedEntity)
            throw new IllegalArgumentException(
                    "Cannot replace body part with itself");

        bodyPart.setParent(parent);
        replacedEntity.setParent(null);

        return replacedEntity;
    }
View Full Code Here

import junit.framework.TestCase;

public class EntityTest extends TestCase {

    public void testSetBody() throws Exception {
        Entity entity = new BodyPart();
        assertNull(entity.getBody());

        Body body = new BasicBodyFactory().textBody("test");
        assertNull(body.getParent());

        entity.setBody(body);
        assertSame(body, entity.getBody());
        assertSame(entity, body.getParent());
    }
View Full Code Here

        assertSame(body, entity.getBody());
        assertSame(entity, body.getParent());
    }

    public void testSetBodyTwice() throws Exception {
        Entity entity = new BodyPart();

        Body b1 = new BasicBodyFactory().textBody("foo");
        Body b2 = new BasicBodyFactory().textBody("bar");

        entity.setBody(b1);
        try {
            entity.setBody(b2);
            fail();
        } catch (IllegalStateException expected) {
        }
    }
View Full Code Here

        } catch (IllegalStateException expected) {
        }
    }

    public void testRemoveBody() throws Exception {
        Entity entity = new BodyPart();
        Body body = new BasicBodyFactory().textBody("test");
        entity.setBody(body);

        Body removed = entity.removeBody();
        assertSame(body, removed);

        assertNull(entity.getBody());
        assertNull(removed.getParent());
    }
View Full Code Here

        assertSame(original.getEpilogue(), copy.getEpilogue());
        assertSame(original.getSubType(), copy.getSubType());
        assertEquals(1, copy.getBodyParts().size());
        assertNull(copy.getParent());

        Entity bodyPartCopy = copy.getBodyParts().iterator().next();
        assertNotSame(bodyPart, bodyPartCopy);

        assertSame(parent, bodyPart.getParent());
        assertNull(bodyPartCopy.getParent());
    }
View Full Code Here

TOP

Related Classes of org.apache.james.mime4j.dom.Entity

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.