Source Code Cross Referenced for JwmaMessagePartImpl.java in  » Web-Mail » Jwma » dtw » webmail » model » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Mail » Jwma » dtw.webmail.model 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /***
002:         * jwma Java WebMail
003:         * Copyright (c) 2000-2003 jwma team
004:         *
005:         * jwma is free software; you can distribute and use this source
006:         * under the terms of the BSD-style license received along with
007:         * the distribution.
008:         ***/package dtw.webmail.model;
009:
010:        import java.util.*;
011:        import java.io.InputStream;
012:        import java.io.ByteArrayOutputStream;
013:        import javax.mail.*;
014:
015:        import org.apache.log4j.Logger;
016:
017:        //import dtw.webmail.JwmaKernel;
018:
019:        /**
020:         * Class implementing the JwmaMessagePart model.
021:         *
022:         * @author Dieter Wimberger
023:         * @version 0.9.7 07/02/2003
024:         */
025:        public class JwmaMessagePartImpl implements  JwmaMessagePart {
026:
027:            //logging
028:            private static Logger log = Logger
029:                    .getLogger(JwmaMessagePartImpl.class);
030:
031:            //instance attributes
032:            private String m_ContentType;
033:            private String m_Description;
034:            private String m_Name;
035:            private String m_TextContent = "";
036:            private int m_Number;
037:            private int m_Size;
038:            private Part m_Part;
039:
040:            /**
041:             * Private empty constructor, to prevent construction.
042:             */
043:            private JwmaMessagePartImpl() {
044:            }//constructor
045:
046:            /**
047:             * Constructs a <tt>JwmaMessagePartImpl</tt> with a
048:             * given part and number.
049:             *
050:             * @param part the part that is wrapped.
051:             * @param number an <tt>int</tt> that represents the part number.
052:             */
053:            private JwmaMessagePartImpl(Part p, int number) {
054:                m_Part = p;
055:                m_Number = number;
056:            }//constructor
057:
058:            /**
059:             * Constructs a <tt>JwmaMessagePartImpl</tt> with a
060:             * given part number.
061:             *
062:             * @param number an <tt>int</tt> that represents the part number.
063:             */
064:            private JwmaMessagePartImpl(int number) {
065:                m_Number = number;
066:            }//constructor
067:
068:            public int getPartNumber() {
069:                return m_Number;
070:            }//getNumber
071:
072:            public boolean isMimeType(String type) {
073:                if (m_Part != null) {
074:                    try {
075:                        return m_Part.isMimeType(type);
076:                    } catch (MessagingException mex) {
077:                        log.error("isMimeType()", mex);
078:                    }
079:                }
080:                //FIX: probably evaluate based on m_ContentType otherwise
081:                return false;
082:
083:            }//isMimeType
084:
085:            public String getContentType() {
086:                return m_ContentType;
087:            }//getContentType
088:
089:            /**
090:             * Gets the <tt>javax.mail.Part</tt> wrapped by this instance.
091:             *
092:             * @return the wrapped part instance.
093:             */
094:            public Part getPart() {
095:                return m_Part;
096:            }//getPart
097:
098:            public String getTextContent() {
099:                return m_TextContent;
100:            }//getTextContent
101:
102:            private void setTextContent(String text) {
103:                m_TextContent = text;
104:            }//setTextContent
105:
106:            /**
107:             * Sets the content-type (mime) of this <tt>JwmaMessagePart</tt>.
108:             *
109:             * @param type the content type of this <tt>JwmaMessagePart</tt>
110:             *        as <tt>String</tt>.
111:             */
112:            public void setContentType(String type) {
113:                m_ContentType = type;
114:            }//setContentType
115:
116:            public int getSize() {
117:                return m_Size;
118:            }//getSize
119:
120:            /**
121:             * Sets the size of this <tt>JwmaMessagePart</tt>.
122:             *
123:             * @param size of this <tt>JwmaMessagePart</tt> in bytes.
124:             */
125:            private void setSize(int size) {
126:                m_Size = size;
127:            }//setSize
128:
129:            public String getName() {
130:                return m_Name;
131:            }//getName
132:
133:            /**
134:             * Sets the name of this <tt>JwmaMessagePart</tt>.
135:             *
136:             * @param name the name of this <tt>JwmaMessagePart</tt>
137:             *        as <tt>String</tt>.
138:             */
139:            public void setName(String name) {
140:                m_Name = name;
141:            }//setName
142:
143:            public String getDescription() {
144:                return m_Description;
145:            }//getDescription
146:
147:            /**
148:             * Sets the description of this <tt>JwmaMessagePart</tt>.
149:             *
150:             * @param description of this <tt>JwmaMessagePart</tt>
151:             *        as <tt>String</tt>.
152:             */
153:            public void setDescription(String description) {
154:                m_Description = description;
155:            }//setDescription
156:
157:            /**
158:             * Creates a <tt>JwmaMessagePartImpl</tt> instance from a given
159:             * <tt>javax.mail.Part</tt> instance.
160:             *
161:             * @param part a <tt>javax.mail.Part</tt> instance.
162:             * @param number the number of the part as <tt>int</tt>.
163:             *
164:             * @return the newly created instance.
165:             * @throws JwmaException if it fails to create the new instance.
166:             */
167:            public static JwmaMessagePartImpl createJwmaMessagePartImpl(
168:                    Part part, int number) throws JwmaException {
169:                JwmaMessagePartImpl partinfo = new JwmaMessagePartImpl(part,
170:                        number);
171:
172:                //content type
173:                try {
174:                    partinfo.setContentType(part.getContentType());
175:
176:                    //size
177:                    int size = part.getSize();
178:                    //JwmaKernel.getReference().debugLog().write("Part size="+size);
179:
180:                    //correct size of encoded parts
181:                    String[] encoding = part
182:                            .getHeader("Content-Transfer-Encoding");
183:                    if (encoding != null
184:                            && encoding.length > 0
185:                            && (encoding[0].equalsIgnoreCase("base64") || encoding[0]
186:                                    .equalsIgnoreCase("uuencode"))) {
187:
188:                        //an encoded file is about 35% smaller in reality,
189:                        //so correct the size
190:                        size = (int) (size * 0.65);
191:                    }
192:
193:                    partinfo.setSize(size);
194:                    //description
195:                    partinfo.setDescription(part.getDescription());
196:
197:                    //filename
198:                    partinfo.setName(part.getFileName());
199:
200:                    //textcontent
201:                    if (partinfo.isMimeType("text/*")) {
202:                        Object content = part.getContent();
203:                        if (content instanceof  String) {
204:                            partinfo.setTextContent((String) content);
205:                        } else if (content instanceof  InputStream) {
206:                            InputStream in = (InputStream) content;
207:                            ByteArrayOutputStream bout = new ByteArrayOutputStream();
208:                            byte[] buffer = new byte[8192];
209:                            int amount = 0;
210:                            while ((amount = in.read(buffer)) >= 0) {
211:                                bout.write(buffer, 0, amount);
212:                            }
213:                            partinfo
214:                                    .setTextContent(new String(bout.toString()));
215:                        }
216:                    }
217:                } catch (Exception mex) {
218:                    throw new JwmaException("jwma.messagepart.failedcreation",
219:                            true).setException(mex);
220:                }
221:                return partinfo;
222:            }//createJwmaMessagePartImpl
223:
224:            /**
225:             * Creates a <tt>JwmaMessagePartImpl</tt> instance with a given
226:             * part number.
227:             *
228:             * @param number the number of the part as <tt>int</tt>.
229:             *
230:             * @return the newly created instance.
231:             */
232:            public static JwmaMessagePartImpl createJwmaMessagePartImpl(
233:                    int number) {
234:                return new JwmaMessagePartImpl(number);
235:            }//createMessagePartImpl
236:
237:        }//class JwmaMessagePartImpl
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.