FileDocCategorySizeDatePackage
MimeHeaders.javaAPI DocApache Axis 1.49448Sat Apr 22 18:57:28 BST 2006javax.xml.soap

MimeHeaders

public class MimeHeaders extends Object
A container for MimeHeader objects, which represent the MIME headers present in a MIME part of a message.

This class is used primarily when an application wants to retrieve specific attachments based on certain MIME headers and values. This class will most likely be used by implementations of AttachmentPart and other MIME dependent parts of the JAXM API.

see
SOAPMessage#getAttachments() SOAPMessage.getAttachments()
see
AttachmentPart AttachmentPart

Fields Summary
private Vector
headers
A Vector containing the headers as MimeHeader instances.
Constructors Summary
public MimeHeaders()
Constructs a default MimeHeaders object initialized with an empty Vector object.

        headers = new Vector();
    
Methods Summary
public voidaddHeader(java.lang.String name, java.lang.String value)
Adds a MimeHeader object with the specified name and value to this MimeHeaders object's list of headers.

Note that RFC822 headers can contain only US-ASCII characters.

param
name a String with the name of the header to be added
param
value a String with the value of the header to be added
throws
java.lang.IllegalArgumentException if there was a problem in the mime header name or value being added


        if ((name == null) || name.equals("")) {
            throw new IllegalArgumentException(
                "Illegal MimeHeader name");
        }

        int i = headers.size();

        for (int j = i - 1; j >= 0; j--) {
            MimeHeader mimeheader = (MimeHeader) headers.elementAt(j);

            if (mimeheader.getName().equalsIgnoreCase(name)) {
                headers.insertElementAt(new MimeHeader(name, value), j + 1);

                return;
            }
        }

        headers.addElement(new MimeHeader(name, value));
    
public java.util.IteratorgetAllHeaders()
Returns all the headers in this MimeHeaders object.

return
an Iterator object over this MimeHeaders object's list of MimeHeader objects

        return headers.iterator();
    
public java.lang.String[]getHeader(java.lang.String name)
Returns all of the values for the specified header as an array of String objects.

param
name the name of the header for which values will be returned
return
a String array with all of the values for the specified header
see
#setHeader(java.lang.String, java.lang.String) setHeader(java.lang.String, java.lang.String)


        Vector vector = new Vector();

        for (int i = 0; i < headers.size(); i++) {
            MimeHeader mimeheader = (MimeHeader) headers.elementAt(i);

            if (mimeheader.getName().equalsIgnoreCase(name)
                    && (mimeheader.getValue() != null)) {
                vector.addElement(mimeheader.getValue());
            }
        }

        if (vector.size() == 0) {
            return null;
        } else {
            String as[] = new String[vector.size()];

            vector.copyInto(as);

            return as;
        }
    
public java.util.IteratorgetMatchingHeaders(java.lang.String[] names)
Returns all the MimeHeader objects whose name matches a name in the given array of names.

param
names an array of String objects with the names for which to search
return
an Iterator object over the MimeHeader objects whose name matches one of the names in the given list

        return new MatchingIterator(names, true);
    
public java.util.IteratorgetNonMatchingHeaders(java.lang.String[] names)
Returns all of the MimeHeader objects whose name does not match a name in the given array of names.

param
names an array of String objects with the names for which to search
return
an Iterator object over the MimeHeader objects whose name does not match one of the names in the given list

        return new MatchingIterator(names, false);
    
public voidremoveAllHeaders()
Removes all the header entries from this MimeHeaders object.

        headers.removeAllElements();
    
public voidremoveHeader(java.lang.String name)
Remove all MimeHeader objects whose name matches the the given name.

param
name a String with the name of the header for which to search


        for (int i = 0; i < headers.size(); i++) {
            MimeHeader mimeheader = (MimeHeader) headers.elementAt(i);

            if (mimeheader.getName().equalsIgnoreCase(name)) {
                headers.removeElementAt(i--);
            }
        }
    
public voidsetHeader(java.lang.String name, java.lang.String value)
Replaces the current value of the first header entry whose name matches the given name with the given value, adding a new header if no existing header name matches. This method also removes all matching headers after the first one.

Note that RFC822 headers can contain only US-ASCII characters.

param
name a String with the name of the header for which to search
param
value a String with the value that will replace the current value of the specified header
throws
java.lang.IllegalArgumentException if there was a problem in the mime header name or the value being set
see
#getHeader(java.lang.String) getHeader(java.lang.String)


        boolean flag = false;

        if ((name == null) || name.equals("")) {
            throw new IllegalArgumentException(
                "Illegal MimeHeader name");
        }

        for (int i = 0; i < headers.size(); i++) {
            MimeHeader mimeheader = (MimeHeader) headers.elementAt(i);

            if (mimeheader.getName().equalsIgnoreCase(name)) {
                if (!flag) {
                    headers.setElementAt(new MimeHeader(mimeheader
                        .getName(), value), i);

                    flag = true;
                } else {
                    headers.removeElementAt(i--);
                }
            }
        }

        if (!flag) {
            addHeader(name, value);
        }