001    /****************************************************************
002     * Licensed to the Apache Software Foundation (ASF) under one   *
003     * or more contributor license agreements.  See the NOTICE file *
004     * distributed with this work for additional information        *
005     * regarding copyright ownership.  The ASF licenses this file   *
006     * to you under the Apache License, Version 2.0 (the            *
007     * "License"); you may not use this file except in compliance   *
008     * with the License.  You may obtain a copy of the License at   *
009     *                                                              *
010     *   http://www.apache.org/licenses/LICENSE-2.0                 *
011     *                                                              *
012     * Unless required by applicable law or agreed to in writing,   *
013     * software distributed under the License is distributed on an  *
014     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
015     * KIND, either express or implied.  See the License for the    *
016     * specific language governing permissions and limitations      *
017     * under the License.                                           *
018     ****************************************************************/
019    
020    package org.apache.hupa.shared.data;
021    
022    import java.io.Serializable;
023    import java.util.ArrayList;
024    import java.util.HashMap;
025    import java.util.List;
026    import java.util.Map;
027    
028    import org.apache.hupa.shared.SConsts;
029    
030    public class MessageDetails implements Serializable{
031        /**
032             * 
033             */
034            private static final long serialVersionUID = 1L;
035    
036            private String text;
037        private ArrayList<MessageAttachment> aList;
038        private long uid;
039        private String raw;
040        private Map<String, List<String>> headers = new HashMap<String, List<String>>();
041    
042        
043        public String toString() {
044            return "uid=" + String.valueOf(getUid()) +
045            " text.length=" + (text != null ? text.length() : 0) + 
046            " raw.length=" + (raw != null ? raw.length() : 0) + 
047            " attachments=" + (aList != null ? aList.size() : 0) + 
048            " headers=" + (headers != null ? headers.size() : 0); 
049        }
050        
051        
052        public long getUid() {
053            return uid;
054        }
055    
056        public void setUid(long uid) {
057            this.uid = uid;
058        }
059        
060        /**
061         * Set a raw String representation of the header
062         * 
063         * @param raw
064         */
065        public void setRawHeader(String raw) {
066            this.raw = raw;
067        }
068    
069        /**
070         * Return a raw String representation of the header
071         * 
072         * @return raw
073         */
074        public String getRawHeader() {
075            return raw;
076        }
077        
078        public Map<String, List<String>> getHeaders() {
079                    return headers;
080            }
081        
082        public void addHeader(String name, String value) {
083            List<String> list = headers.get(name);
084            if (list == null) {
085                    list = new ArrayList<String>();
086                    headers.put(name, list);
087            }
088            list.add(value);
089        }
090        
091        
092        
093        /**
094         * Set the body text of the content
095         * 
096         * @param text
097         */
098        public void setText(String text) {
099            this.text = text;
100        }
101    
102        /**
103         * Return the body text of the content
104         * @return The text
105         */
106        public String getText() {
107            return text;
108        }
109    
110        /**
111         * Set the attachments 
112         * 
113         * @param aList
114         */
115        public void setMessageAttachments(ArrayList<MessageAttachment> aList) {
116            this.aList = aList;
117        }
118    
119        /**
120         * 
121         * @return the In-Reply-To header field.
122         */
123        public String getInReplyTo() {
124            return getHeaderValue(SConsts.HEADER_IN_REPLY_TO);
125        }
126    
127        public String getHeaderValue(String key) {
128            List<String> h = headers.get(key);
129            return h != null && !h.isEmpty() ? h.get(0) : null;
130        }
131    
132        /**
133         * 
134         * @return the References header field.
135         */
136        public String getReferences() {
137            return getHeaderValue(SConsts.HEADER_REFERENCES);
138        }
139    
140        public String getMessageId() {
141            return getHeaderValue(SConsts.HEADER_MESSAGE_ID);
142        }    
143        
144        /**
145         * Return the attachments 
146         * 
147         * @return aList
148         */
149        public ArrayList<MessageAttachment> getMessageAttachments() {
150            return aList;
151        }
152    
153    
154        public boolean equals(Object obj) {
155            if (obj instanceof MessageDetails) {
156                if (((MessageDetails)obj).getUid() == getUid()) {
157                    return true;
158                }
159            }
160            return false;
161        }
162        
163        public int hashCode() {
164            Long l = Long.valueOf(getUid());
165            return l.intValue() * 16;
166        }
167    }