001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.camel.model.dataformat; 018 019import javax.xml.bind.annotation.XmlAccessType; 020import javax.xml.bind.annotation.XmlAccessorType; 021import javax.xml.bind.annotation.XmlAttribute; 022import javax.xml.bind.annotation.XmlRootElement; 023 024import org.apache.camel.CamelContext; 025import org.apache.camel.model.DataFormatDefinition; 026import org.apache.camel.spi.DataFormat; 027import org.apache.camel.spi.Metadata; 028 029/** 030 * The MIME Multipart data format can marshal a Camel message with attachments into a Camel message 031 * having a MIME-Multipart message as message body (and no attachments), and vise-versa when unmarshalling. 032 */ 033@Metadata(firstVersion = "2.17.0", label = "dataformat,transformation", title = "MIME Multipart") 034@XmlRootElement(name = "mime-multipart") 035@XmlAccessorType(XmlAccessType.FIELD) 036public class MimeMultipartDataFormat extends DataFormatDefinition { 037 038 @XmlAttribute 039 @Metadata(defaultValue = "mixed") 040 private String multipartSubType = "mixed"; 041 @XmlAttribute 042 private Boolean multipartWithoutAttachment; 043 @XmlAttribute 044 private Boolean headersInline; 045 @XmlAttribute 046 private String includeHeaders; 047 @XmlAttribute 048 private Boolean binaryContent; 049 050 public MimeMultipartDataFormat() { 051 super("mime-multipart"); 052 } 053 054 @Override 055 protected void configureDataFormat(DataFormat dataFormat, CamelContext camelContext) { 056 if (getMultipartSubType() != null) { 057 setProperty(camelContext, dataFormat, "multipartSubType", getMultipartSubType()); 058 } 059 if (getMultipartWithoutAttachment() != null) { 060 setProperty(camelContext, dataFormat, "multipartWithoutAttachment", getMultipartWithoutAttachment()); 061 } 062 if (getHeadersInline() != null) { 063 setProperty(camelContext, dataFormat, "headersInline", getHeadersInline()); 064 } 065 if (getIncludeHeaders() != null) { 066 setProperty(camelContext, dataFormat, "includeHeaders", getIncludeHeaders()); 067 } 068 if (getBinaryContent() != null) { 069 setProperty(camelContext, dataFormat, "binaryContent", getBinaryContent()); 070 } 071 } 072 073 public String getMultipartSubType() { 074 return multipartSubType; 075 } 076 077 /** 078 * Specify the subtype of the MIME Multipart. 079 * <p> 080 * Default is "mixed". 081 */ 082 public void setMultipartSubType(String multipartSubType) { 083 this.multipartSubType = multipartSubType; 084 } 085 086 public Boolean getMultipartWithoutAttachment() { 087 return multipartWithoutAttachment; 088 } 089 090 /** 091 * Defines whether a message without attachment is also marshaled into a 092 * MIME Multipart (with only one body part). 093 * <p> 094 * Default is "false". 095 */ 096 public void setMultipartWithoutAttachment(Boolean multipartWithoutAttachment) { 097 this.multipartWithoutAttachment = multipartWithoutAttachment; 098 } 099 100 public Boolean getHeadersInline() { 101 return headersInline; 102 } 103 104 /** 105 * Defines whether the MIME-Multipart headers are part of the message body 106 * (true) or are set as Camel headers (false). 107 * <p> 108 * Default is "false". 109 */ 110 public void setHeadersInline(Boolean headersInline) { 111 this.headersInline = headersInline; 112 } 113 114 public Boolean getBinaryContent() { 115 return binaryContent; 116 } 117 118 /** 119 * A regex that defines which Camel headers are also included as MIME headers 120 * into the MIME multipart. This will only work if headersInline is set to true. 121 * <p> 122 * Default is to include no headers 123 */ 124 public void setIncludeHeaders(String includeHeaders) { 125 this.includeHeaders = includeHeaders; 126 } 127 128 public String getIncludeHeaders() { 129 return includeHeaders; 130 } 131 132 /** 133 * Defines whether the content of binary parts in the MIME multipart is 134 * binary (true) or Base-64 encoded (false) 135 * <p> 136 * Default is "false". 137 */ 138 public void setBinaryContent(Boolean binaryContent) { 139 this.binaryContent = binaryContent; 140 } 141}