001/*
002 * Copyright 2002-2012 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.oxm.mime;
018
019import javax.activation.DataHandler;
020
021/**
022 * Represents a container for MIME attachments
023 * Concrete implementations might adapt a SOAPMessage or an email message.
024 *
025 * @author Arjen Poutsma
026 * @since 3.0
027 * @see <a href="https://www.w3.org/TR/2005/REC-xop10-20050125/">XML-binary Optimized Packaging</a>
028 */
029public interface MimeContainer {
030
031        /**
032         * Indicate whether this container is a XOP package.
033         * @return {@code true} when the constraints specified in
034         * <a href="https://www.w3.org/TR/2005/REC-xop10-20050125/#identifying_xop_documents">Identifying XOP Documents</a>
035         * are met
036         * @see <a href="https://www.w3.org/TR/2005/REC-xop10-20050125/#xop_packages">XOP Packages</a>
037         */
038        boolean isXopPackage();
039
040        /**
041         * Turn this message into a XOP package.
042         * @return {@code true} when the message actually is a XOP package
043         * @see <a href="https://www.w3.org/TR/2005/REC-xop10-20050125/#xop_packages">XOP Packages</a>
044         */
045        boolean convertToXopPackage();
046
047        /**
048         * Add the given data handler as an attachment to this container.
049         * @param contentId  the content id of the attachment
050         * @param dataHandler the data handler containing the data of the attachment
051         */
052        void addAttachment(String contentId, DataHandler dataHandler);
053
054        /**
055         * Return the attachment with the given content id, or {@code null} if not found.
056         * @param contentId the content id
057         * @return the attachment, as a data handler
058         */
059        DataHandler getAttachment(String contentId);
060
061}