src/share/jaxws_classes/javax/xml/soap/AttachmentPart.java

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 368
0989ad8c0860
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package javax.xml.soap;
aoqi@0 27
aoqi@0 28 import java.io.InputStream;
aoqi@0 29 import java.io.Reader;
aoqi@0 30 import java.util.Iterator;
aoqi@0 31
aoqi@0 32 import javax.activation.DataHandler;
aoqi@0 33
aoqi@0 34 /**
aoqi@0 35 * A single attachment to a <code>SOAPMessage</code> object. A <code>SOAPMessage</code>
aoqi@0 36 * object may contain zero, one, or many <code>AttachmentPart</code> objects.
aoqi@0 37 * Each <code>AttachmentPart</code> object consists of two parts,
aoqi@0 38 * application-specific content and associated MIME headers. The
aoqi@0 39 * MIME headers consists of name/value pairs that can be used to
aoqi@0 40 * identify and describe the content.
aoqi@0 41 * <p>
aoqi@0 42 * An <code>AttachmentPart</code> object must conform to certain standards.
aoqi@0 43 * <OL>
aoqi@0 44 * <LI>It must conform to <a href="http://www.ietf.org/rfc/rfc2045.txt">
aoqi@0 45 * MIME [RFC2045] standards</a>
aoqi@0 46 * <LI>It MUST contain content
aoqi@0 47 * <LI>The header portion MUST include the following header:
aoqi@0 48 * <UL>
aoqi@0 49 * <LI><code>Content-Type</code><br>
aoqi@0 50 * This header identifies the type of data in the content of an
aoqi@0 51 * <code>AttachmentPart</code> object and MUST conform to [RFC2045].
aoqi@0 52 * The following is an example of a Content-Type header:
aoqi@0 53 * <PRE>
aoqi@0 54 * Content-Type: application/xml
aoqi@0 55 * </PRE>
aoqi@0 56 * The following line of code, in which <code>ap</code> is an
aoqi@0 57 * <code>AttachmentPart</code> object, sets the header shown in
aoqi@0 58 * the previous example.
aoqi@0 59 * <PRE>
aoqi@0 60 * ap.setMimeHeader("Content-Type", "application/xml");
aoqi@0 61 * </PRE>
aoqi@0 62 * <p>
aoqi@0 63 * </UL>
aoqi@0 64 * </OL>
aoqi@0 65 * <p>
aoqi@0 66 * There are no restrictions on the content portion of an <code>
aoqi@0 67 * AttachmentPart</code> object. The content may be anything from a
aoqi@0 68 * simple plain text object to a complex XML document or image file.
aoqi@0 69 *
aoqi@0 70 * <p>
aoqi@0 71 * An <code>AttachmentPart</code> object is created with the method
aoqi@0 72 * <code>SOAPMessage.createAttachmentPart</code>. After setting its MIME headers,
aoqi@0 73 * the <code>AttachmentPart</code> object is added to the message
aoqi@0 74 * that created it with the method <code>SOAPMessage.addAttachmentPart</code>.
aoqi@0 75 *
aoqi@0 76 * <p>
aoqi@0 77 * The following code fragment, in which <code>m</code> is a
aoqi@0 78 * <code>SOAPMessage</code> object and <code>contentStringl</code> is a
aoqi@0 79 * <code>String</code>, creates an instance of <code>AttachmentPart</code>,
aoqi@0 80 * sets the <code>AttachmentPart</code> object with some content and
aoqi@0 81 * header information, and adds the <code>AttachmentPart</code> object to
aoqi@0 82 * the <code>SOAPMessage</code> object.
aoqi@0 83 * <PRE>
aoqi@0 84 * AttachmentPart ap1 = m.createAttachmentPart();
aoqi@0 85 * ap1.setContent(contentString1, "text/plain");
aoqi@0 86 * m.addAttachmentPart(ap1);
aoqi@0 87 * </PRE>
aoqi@0 88 *
aoqi@0 89 *
aoqi@0 90 * <p>
aoqi@0 91 * The following code fragment creates and adds a second
aoqi@0 92 * <code>AttachmentPart</code> instance to the same message. <code>jpegData</code>
aoqi@0 93 * is a binary byte buffer representing the jpeg file.
aoqi@0 94 * <PRE>
aoqi@0 95 * AttachmentPart ap2 = m.createAttachmentPart();
aoqi@0 96 * byte[] jpegData = ...;
aoqi@0 97 * ap2.setContent(new ByteArrayInputStream(jpegData), "image/jpeg");
aoqi@0 98 * m.addAttachmentPart(ap2);
aoqi@0 99 * </PRE>
aoqi@0 100 * <p>
aoqi@0 101 * The <code>getContent</code> method retrieves the contents and header from
aoqi@0 102 * an <code>AttachmentPart</code> object. Depending on the
aoqi@0 103 * <code>DataContentHandler</code> objects present, the returned
aoqi@0 104 * <code>Object</code> can either be a typed Java object corresponding
aoqi@0 105 * to the MIME type or an <code>InputStream</code> object that contains the
aoqi@0 106 * content as bytes.
aoqi@0 107 * <PRE>
aoqi@0 108 * String content1 = ap1.getContent();
aoqi@0 109 * java.io.InputStream content2 = ap2.getContent();
aoqi@0 110 * </PRE>
aoqi@0 111 *
aoqi@0 112 * The method <code>clearContent</code> removes all the content from an
aoqi@0 113 * <code>AttachmentPart</code> object but does not affect its header information.
aoqi@0 114 * <PRE>
aoqi@0 115 * ap1.clearContent();
aoqi@0 116 * </PRE>
aoqi@0 117 */
aoqi@0 118
aoqi@0 119 public abstract class AttachmentPart {
aoqi@0 120 /**
aoqi@0 121 * Returns the number of bytes in this <code>AttachmentPart</code>
aoqi@0 122 * object.
aoqi@0 123 *
aoqi@0 124 * @return the size of this <code>AttachmentPart</code> object in bytes
aoqi@0 125 * or -1 if the size cannot be determined
aoqi@0 126 * @exception SOAPException if the content of this attachment is
aoqi@0 127 * corrupted of if there was an exception while trying
aoqi@0 128 * to determine the size.
aoqi@0 129 */
aoqi@0 130 public abstract int getSize() throws SOAPException;
aoqi@0 131
aoqi@0 132 /**
aoqi@0 133 * Clears out the content of this <code>AttachmentPart</code> object.
aoqi@0 134 * The MIME header portion is left untouched.
aoqi@0 135 */
aoqi@0 136 public abstract void clearContent();
aoqi@0 137
aoqi@0 138 /**
aoqi@0 139 * Gets the content of this <code>AttachmentPart</code> object as a Java
aoqi@0 140 * object. The type of the returned Java object depends on (1) the
aoqi@0 141 * <code>DataContentHandler</code> object that is used to interpret the bytes
aoqi@0 142 * and (2) the <code>Content-Type</code> given in the header.
aoqi@0 143 * <p>
aoqi@0 144 * For the MIME content types "text/plain", "text/html" and "text/xml", the
aoqi@0 145 * <code>DataContentHandler</code> object does the conversions to and
aoqi@0 146 * from the Java types corresponding to the MIME types.
aoqi@0 147 * For other MIME types,the <code>DataContentHandler</code> object
aoqi@0 148 * can return an <code>InputStream</code> object that contains the content data
aoqi@0 149 * as raw bytes.
aoqi@0 150 * <p>
aoqi@0 151 * A SAAJ-compliant implementation must, as a minimum, return a
aoqi@0 152 * <code>java.lang.String</code> object corresponding to any content
aoqi@0 153 * stream with a <code>Content-Type</code> value of
aoqi@0 154 * <code>text/plain</code>, a
aoqi@0 155 * <code>javax.xml.transform.stream.StreamSource</code> object corresponding to a
aoqi@0 156 * content stream with a <code>Content-Type</code> value of
aoqi@0 157 * <code>text/xml</code>, a <code>java.awt.Image</code> object
aoqi@0 158 * corresponding to a content stream with a
aoqi@0 159 * <code>Content-Type</code> value of <code>image/gif</code> or
aoqi@0 160 * <code>image/jpeg</code>. For those content types that an
aoqi@0 161 * installed <code>DataContentHandler</code> object does not understand, the
aoqi@0 162 * <code>DataContentHandler</code> object is required to return a
aoqi@0 163 * <code>java.io.InputStream</code> object with the raw bytes.
aoqi@0 164 *
aoqi@0 165 * @return a Java object with the content of this <code>AttachmentPart</code>
aoqi@0 166 * object
aoqi@0 167 *
aoqi@0 168 * @exception SOAPException if there is no content set into this
aoqi@0 169 * <code>AttachmentPart</code> object or if there was a data
aoqi@0 170 * transformation error
aoqi@0 171 */
aoqi@0 172 public abstract Object getContent() throws SOAPException;
aoqi@0 173
aoqi@0 174 /**
aoqi@0 175 * Gets the content of this <code>AttachmentPart</code> object as an
aoqi@0 176 * InputStream as if a call had been made to <code>getContent</code> and no
aoqi@0 177 * <code>DataContentHandler</code> had been registered for the
aoqi@0 178 * <code>content-type</code> of this <code>AttachmentPart</code>.
aoqi@0 179 *<p>
aoqi@0 180 * Note that reading from the returned InputStream would result in consuming
aoqi@0 181 * the data in the stream. It is the responsibility of the caller to reset
aoqi@0 182 * the InputStream appropriately before calling a Subsequent API. If a copy
aoqi@0 183 * of the raw attachment content is required then the {@link #getRawContentBytes} API
aoqi@0 184 * should be used instead.
aoqi@0 185 *
aoqi@0 186 * @return an <code>InputStream</code> from which the raw data contained by
aoqi@0 187 * the <code>AttachmentPart</code> can be accessed.
aoqi@0 188 *
aoqi@0 189 * @throws SOAPException if there is no content set into this
aoqi@0 190 * <code>AttachmentPart</code> object or if there was a data
aoqi@0 191 * transformation error.
aoqi@0 192 *
aoqi@0 193 * @since SAAJ 1.3
aoqi@0 194 * @see #getRawContentBytes
aoqi@0 195 */
aoqi@0 196 public abstract InputStream getRawContent() throws SOAPException;
aoqi@0 197
aoqi@0 198 /**
aoqi@0 199 * Gets the content of this <code>AttachmentPart</code> object as a
aoqi@0 200 * byte[] array as if a call had been made to <code>getContent</code> and no
aoqi@0 201 * <code>DataContentHandler</code> had been registered for the
aoqi@0 202 * <code>content-type</code> of this <code>AttachmentPart</code>.
aoqi@0 203 *
aoqi@0 204 * @return a <code>byte[]</code> array containing the raw data of the
aoqi@0 205 * <code>AttachmentPart</code>.
aoqi@0 206 *
aoqi@0 207 * @throws SOAPException if there is no content set into this
aoqi@0 208 * <code>AttachmentPart</code> object or if there was a data
aoqi@0 209 * transformation error.
aoqi@0 210 *
aoqi@0 211 * @since SAAJ 1.3
aoqi@0 212 */
aoqi@0 213 public abstract byte[] getRawContentBytes() throws SOAPException;
aoqi@0 214
aoqi@0 215 /**
aoqi@0 216 * Returns an <code>InputStream</code> which can be used to obtain the
aoqi@0 217 * content of <code>AttachmentPart</code> as Base64 encoded
aoqi@0 218 * character data, this method would base64 encode the raw bytes
aoqi@0 219 * of the attachment and return.
aoqi@0 220 *
aoqi@0 221 * @return an <code>InputStream</code> from which the Base64 encoded
aoqi@0 222 * <code>AttachmentPart</code> can be read.
aoqi@0 223 *
aoqi@0 224 * @throws SOAPException if there is no content set into this
aoqi@0 225 * <code>AttachmentPart</code> object or if there was a data
aoqi@0 226 * transformation error.
aoqi@0 227 *
aoqi@0 228 * @since SAAJ 1.3
aoqi@0 229 */
aoqi@0 230 public abstract InputStream getBase64Content() throws SOAPException;
aoqi@0 231
aoqi@0 232 /**
aoqi@0 233 * Sets the content of this attachment part to that of the given
aoqi@0 234 * <code>Object</code> and sets the value of the <code>Content-Type</code>
aoqi@0 235 * header to the given type. The type of the
aoqi@0 236 * <code>Object</code> should correspond to the value given for the
aoqi@0 237 * <code>Content-Type</code>. This depends on the particular
aoqi@0 238 * set of <code>DataContentHandler</code> objects in use.
aoqi@0 239 *
aoqi@0 240 *
aoqi@0 241 * @param object the Java object that makes up the content for
aoqi@0 242 * this attachment part
aoqi@0 243 * @param contentType the MIME string that specifies the type of
aoqi@0 244 * the content
aoqi@0 245 *
aoqi@0 246 * @exception IllegalArgumentException may be thrown if the contentType
aoqi@0 247 * does not match the type of the content object, or if there
aoqi@0 248 * was no <code>DataContentHandler</code> object for this
aoqi@0 249 * content object
aoqi@0 250 *
aoqi@0 251 * @see #getContent
aoqi@0 252 */
aoqi@0 253 public abstract void setContent(Object object, String contentType);
aoqi@0 254
aoqi@0 255 /**
aoqi@0 256 * Sets the content of this attachment part to that contained by the
aoqi@0 257 * <code>InputStream</code> <code>content</code> and sets the value of the
aoqi@0 258 * <code>Content-Type</code> header to the value contained in
aoqi@0 259 * <code>contentType</code>.
aoqi@0 260 * <P>
aoqi@0 261 * A subsequent call to getSize() may not be an exact measure
aoqi@0 262 * of the content size.
aoqi@0 263 *
aoqi@0 264 * @param content the raw data to add to the attachment part
aoqi@0 265 * @param contentType the value to set into the <code>Content-Type</code>
aoqi@0 266 * header
aoqi@0 267 *
aoqi@0 268 * @exception SOAPException if an there is an error in setting the content
aoqi@0 269 * @exception NullPointerException if <code>content</code> is null
aoqi@0 270 * @since SAAJ 1.3
aoqi@0 271 */
aoqi@0 272 public abstract void setRawContent(InputStream content, String contentType) throws SOAPException;
aoqi@0 273
aoqi@0 274 /**
aoqi@0 275 * Sets the content of this attachment part to that contained by the
aoqi@0 276 * <code>byte[]</code> array <code>content</code> and sets the value of the
aoqi@0 277 * <code>Content-Type</code> header to the value contained in
aoqi@0 278 * <code>contentType</code>.
aoqi@0 279 *
aoqi@0 280 * @param content the raw data to add to the attachment part
aoqi@0 281 * @param contentType the value to set into the <code>Content-Type</code>
aoqi@0 282 * header
aoqi@0 283 * @param offset the offset in the byte array of the content
aoqi@0 284 * @param len the number of bytes that form the content
aoqi@0 285 *
aoqi@0 286 * @exception SOAPException if an there is an error in setting the content
aoqi@0 287 * or content is null
aoqi@0 288 * @since SAAJ 1.3
aoqi@0 289 */
aoqi@0 290 public abstract void setRawContentBytes(
aoqi@0 291 byte[] content, int offset, int len, String contentType)
aoqi@0 292 throws SOAPException;
aoqi@0 293
aoqi@0 294
aoqi@0 295 /**
aoqi@0 296 * Sets the content of this attachment part from the Base64 source
aoqi@0 297 * <code>InputStream</code> and sets the value of the
aoqi@0 298 * <code>Content-Type</code> header to the value contained in
aoqi@0 299 * <code>contentType</code>, This method would first decode the base64
aoqi@0 300 * input and write the resulting raw bytes to the attachment.
aoqi@0 301 * <P>
aoqi@0 302 * A subsequent call to getSize() may not be an exact measure
aoqi@0 303 * of the content size.
aoqi@0 304 *
aoqi@0 305 * @param content the base64 encoded data to add to the attachment part
aoqi@0 306 * @param contentType the value to set into the <code>Content-Type</code>
aoqi@0 307 * header
aoqi@0 308 *
aoqi@0 309 * @exception SOAPException if an there is an error in setting the content
aoqi@0 310 * @exception NullPointerException if <code>content</code> is null
aoqi@0 311 *
aoqi@0 312 * @since SAAJ 1.3
aoqi@0 313 */
aoqi@0 314 public abstract void setBase64Content(
aoqi@0 315 InputStream content, String contentType) throws SOAPException;
aoqi@0 316
aoqi@0 317
aoqi@0 318 /**
aoqi@0 319 * Gets the <code>DataHandler</code> object for this <code>AttachmentPart</code>
aoqi@0 320 * object.
aoqi@0 321 *
aoqi@0 322 * @return the <code>DataHandler</code> object associated with this
aoqi@0 323 * <code>AttachmentPart</code> object
aoqi@0 324 *
aoqi@0 325 * @exception SOAPException if there is no data in
aoqi@0 326 * this <code>AttachmentPart</code> object
aoqi@0 327 */
aoqi@0 328 public abstract DataHandler getDataHandler()
aoqi@0 329 throws SOAPException;
aoqi@0 330
aoqi@0 331 /**
aoqi@0 332 * Sets the given <code>DataHandler</code> object as the data handler
aoqi@0 333 * for this <code>AttachmentPart</code> object. Typically, on an incoming
aoqi@0 334 * message, the data handler is automatically set. When
aoqi@0 335 * a message is being created and populated with content, the
aoqi@0 336 * <code>setDataHandler</code> method can be used to get data from
aoqi@0 337 * various data sources into the message.
aoqi@0 338 *
aoqi@0 339 * @param dataHandler the <code>DataHandler</code> object to be set
aoqi@0 340 *
aoqi@0 341 * @exception IllegalArgumentException if there was a problem with
aoqi@0 342 * the specified <code>DataHandler</code> object
aoqi@0 343 */
aoqi@0 344 public abstract void setDataHandler(DataHandler dataHandler);
aoqi@0 345
aoqi@0 346
aoqi@0 347 /**
aoqi@0 348 * Gets the value of the MIME header whose name is "Content-ID".
aoqi@0 349 *
aoqi@0 350 * @return a <code>String</code> giving the value of the
aoqi@0 351 * "Content-ID" header or <code>null</code> if there
aoqi@0 352 * is none
aoqi@0 353 * @see #setContentId
aoqi@0 354 */
aoqi@0 355 public String getContentId() {
aoqi@0 356 String[] values = getMimeHeader("Content-ID");
aoqi@0 357 if (values != null && values.length > 0)
aoqi@0 358 return values[0];
aoqi@0 359 return null;
aoqi@0 360 }
aoqi@0 361
aoqi@0 362 /**
aoqi@0 363 * Gets the value of the MIME header whose name is "Content-Location".
aoqi@0 364 *
aoqi@0 365 * @return a <code>String</code> giving the value of the
aoqi@0 366 * "Content-Location" header or <code>null</code> if there
aoqi@0 367 * is none
aoqi@0 368 */
aoqi@0 369 public String getContentLocation() {
aoqi@0 370 String[] values = getMimeHeader("Content-Location");
aoqi@0 371 if (values != null && values.length > 0)
aoqi@0 372 return values[0];
aoqi@0 373 return null;
aoqi@0 374 }
aoqi@0 375
aoqi@0 376 /**
aoqi@0 377 * Gets the value of the MIME header whose name is "Content-Type".
aoqi@0 378 *
aoqi@0 379 * @return a <code>String</code> giving the value of the
aoqi@0 380 * "Content-Type" header or <code>null</code> if there
aoqi@0 381 * is none
aoqi@0 382 */
aoqi@0 383 public String getContentType() {
aoqi@0 384 String[] values = getMimeHeader("Content-Type");
aoqi@0 385 if (values != null && values.length > 0)
aoqi@0 386 return values[0];
aoqi@0 387 return null;
aoqi@0 388 }
aoqi@0 389
aoqi@0 390 /**
aoqi@0 391 * Sets the MIME header whose name is "Content-ID" with the given value.
aoqi@0 392 *
aoqi@0 393 * @param contentId a <code>String</code> giving the value of the
aoqi@0 394 * "Content-ID" header
aoqi@0 395 *
aoqi@0 396 * @exception IllegalArgumentException if there was a problem with
aoqi@0 397 * the specified <code>contentId</code> value
aoqi@0 398 * @see #getContentId
aoqi@0 399 */
aoqi@0 400 public void setContentId(String contentId)
aoqi@0 401 {
aoqi@0 402 setMimeHeader("Content-ID", contentId);
aoqi@0 403 }
aoqi@0 404
aoqi@0 405
aoqi@0 406 /**
aoqi@0 407 * Sets the MIME header whose name is "Content-Location" with the given value.
aoqi@0 408 *
aoqi@0 409 *
aoqi@0 410 * @param contentLocation a <code>String</code> giving the value of the
aoqi@0 411 * "Content-Location" header
aoqi@0 412 * @exception IllegalArgumentException if there was a problem with
aoqi@0 413 * the specified content location
aoqi@0 414 */
aoqi@0 415 public void setContentLocation(String contentLocation)
aoqi@0 416 {
aoqi@0 417 setMimeHeader("Content-Location", contentLocation);
aoqi@0 418 }
aoqi@0 419
aoqi@0 420 /**
aoqi@0 421 * Sets the MIME header whose name is "Content-Type" with the given value.
aoqi@0 422 *
aoqi@0 423 * @param contentType a <code>String</code> giving the value of the
aoqi@0 424 * "Content-Type" header
aoqi@0 425 *
aoqi@0 426 * @exception IllegalArgumentException if there was a problem with
aoqi@0 427 * the specified content type
aoqi@0 428 */
aoqi@0 429 public void setContentType(String contentType)
aoqi@0 430 {
aoqi@0 431 setMimeHeader("Content-Type", contentType);
aoqi@0 432 }
aoqi@0 433
aoqi@0 434 /**
aoqi@0 435 * Removes all MIME headers that match the given name.
aoqi@0 436 *
aoqi@0 437 * @param header the string name of the MIME header/s to
aoqi@0 438 * be removed
aoqi@0 439 */
aoqi@0 440 public abstract void removeMimeHeader(String header);
aoqi@0 441
aoqi@0 442 /**
aoqi@0 443 * Removes all the MIME header entries.
aoqi@0 444 */
aoqi@0 445 public abstract void removeAllMimeHeaders();
aoqi@0 446
aoqi@0 447
aoqi@0 448 /**
aoqi@0 449 * Gets all the values of the header identified by the given
aoqi@0 450 * <code>String</code>.
aoqi@0 451 *
aoqi@0 452 * @param name the name of the header; example: "Content-Type"
aoqi@0 453 * @return a <code>String</code> array giving the value for the
aoqi@0 454 * specified header
aoqi@0 455 * @see #setMimeHeader
aoqi@0 456 */
aoqi@0 457 public abstract String[] getMimeHeader(String name);
aoqi@0 458
aoqi@0 459
aoqi@0 460 /**
aoqi@0 461 * Changes the first header entry that matches the given name
aoqi@0 462 * to the given value, adding a new header if no existing header
aoqi@0 463 * matches. This method also removes all matching headers but the first. <p>
aoqi@0 464 *
aoqi@0 465 * Note that RFC822 headers can only contain US-ASCII characters.
aoqi@0 466 *
aoqi@0 467 * @param name a <code>String</code> giving the name of the header
aoqi@0 468 * for which to search
aoqi@0 469 * @param value a <code>String</code> giving the value to be set for
aoqi@0 470 * the header whose name matches the given name
aoqi@0 471 *
aoqi@0 472 * @exception IllegalArgumentException if there was a problem with
aoqi@0 473 * the specified mime header name or value
aoqi@0 474 */
aoqi@0 475 public abstract void setMimeHeader(String name, String value);
aoqi@0 476
aoqi@0 477
aoqi@0 478 /**
aoqi@0 479 * Adds a MIME header with the specified name and value to this
aoqi@0 480 * <code>AttachmentPart</code> object.
aoqi@0 481 * <p>
aoqi@0 482 * Note that RFC822 headers can contain only US-ASCII characters.
aoqi@0 483 *
aoqi@0 484 * @param name a <code>String</code> giving the name of the header
aoqi@0 485 * to be added
aoqi@0 486 * @param value a <code>String</code> giving the value of the header
aoqi@0 487 * to be added
aoqi@0 488 *
aoqi@0 489 * @exception IllegalArgumentException if there was a problem with
aoqi@0 490 * the specified mime header name or value
aoqi@0 491 */
aoqi@0 492 public abstract void addMimeHeader(String name, String value);
aoqi@0 493
aoqi@0 494 /**
aoqi@0 495 * Retrieves all the headers for this <code>AttachmentPart</code> object
aoqi@0 496 * as an iterator over the <code>MimeHeader</code> objects.
aoqi@0 497 *
aoqi@0 498 * @return an <code>Iterator</code> object with all of the Mime
aoqi@0 499 * headers for this <code>AttachmentPart</code> object
aoqi@0 500 */
aoqi@0 501 public abstract Iterator getAllMimeHeaders();
aoqi@0 502
aoqi@0 503 /**
aoqi@0 504 * Retrieves all <code>MimeHeader</code> objects that match a name in
aoqi@0 505 * the given array.
aoqi@0 506 *
aoqi@0 507 * @param names a <code>String</code> array with the name(s) of the
aoqi@0 508 * MIME headers to be returned
aoqi@0 509 * @return all of the MIME headers that match one of the names in the
aoqi@0 510 * given array as an <code>Iterator</code> object
aoqi@0 511 */
aoqi@0 512 public abstract Iterator getMatchingMimeHeaders(String[] names);
aoqi@0 513
aoqi@0 514 /**
aoqi@0 515 * Retrieves all <code>MimeHeader</code> objects whose name does
aoqi@0 516 * not match a name in the given array.
aoqi@0 517 *
aoqi@0 518 * @param names a <code>String</code> array with the name(s) of the
aoqi@0 519 * MIME headers not to be returned
aoqi@0 520 * @return all of the MIME headers in this <code>AttachmentPart</code> object
aoqi@0 521 * except those that match one of the names in the
aoqi@0 522 * given array. The nonmatching MIME headers are returned as an
aoqi@0 523 * <code>Iterator</code> object.
aoqi@0 524 */
aoqi@0 525 public abstract Iterator getNonMatchingMimeHeaders(String[] names);
aoqi@0 526 }

mercurial