Source Code Cross Referenced for MessageParser.java in  » Mail-Clients » columba-1.4 » org » columba » mail » gui » message » viewer » 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 » Mail Clients » columba 1.4 » org.columba.mail.gui.message.viewer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.columba.mail.gui.message.viewer;
002:
003:        import java.io.InputStream;
004:        import java.nio.charset.Charset;
005:        import java.nio.charset.IllegalCharsetNameException;
006:        import java.nio.charset.UnsupportedCharsetException;
007:
008:        import org.columba.mail.gui.message.util.DocumentParser;
009:        import org.columba.mail.parser.text.HtmlParser;
010:        import org.columba.ristretto.coder.Base64DecoderInputStream;
011:        import org.columba.ristretto.coder.QuotedPrintableDecoderInputStream;
012:        import org.columba.ristretto.message.MimeHeader;
013:        import org.columba.ristretto.message.MimePart;
014:
015:        /**
016:         * Provides text processing helper methods for the text viewer component.
017:         *  
018:         * @author fdietz
019:         */
020:        public class MessageParser {
021:
022:            private static DocumentParser parser = new DocumentParser();
023:
024:            /**
025:             * @param bodyText
026:             * @throws Exception
027:             */
028:            public static String transformTextToHTML(String bodyText,
029:                    String css, boolean enableSmilies) throws Exception {
030:                String body = null;
031:
032:                // substitute special characters like:
033:                // <,>,&,\t,\n
034:                body = HtmlParser.substituteSpecialCharacters(bodyText);
035:
036:                // parse for urls and substite with HTML-code
037:                body = HtmlParser.substituteURL(body);
038:
039:                // parse for email addresses and substite with HTML-code
040:                body = HtmlParser.substituteEmailAddress(body);
041:
042:                // parse for quotings and color the darkgray
043:                body = DocumentParser.markQuotings(body);
044:
045:                // add smilies
046:                if (enableSmilies == true) {
047:                    body = DocumentParser.addSmilies(body);
048:                }
049:
050:                // encapsulate bodytext in html-code
051:                body = transformToHTML(new StringBuffer(body), css);
052:
053:                return body;
054:            }
055:
056:            /*
057:             * 
058:             * encapsulate bodytext in HTML code
059:             * 
060:             */
061:            private static String transformToHTML(StringBuffer buf, String css) {
062:                // prepend
063:                buf.insert(0, "<HTML><HEAD>" + css
064:                        + "</HEAD><BODY class=\"bodytext\"><P>");
065:
066:                // append
067:                buf.append("</P></BODY></HTML>");
068:
069:                return buf.toString();
070:            }
071:
072:            /**
073:             * @param bodyPart
074:             * @param bodyStream
075:             * @return
076:             */
077:            public static InputStream decodeBodyStream(MimePart bodyPart,
078:                    InputStream bodyStream) throws Exception {
079:
080:                // default encoding is plain
081:                int encoding = MimeHeader.PLAIN;
082:
083:                if (bodyPart != null) {
084:                    encoding = bodyPart.getHeader()
085:                            .getContentTransferEncoding();
086:                }
087:
088:                switch (encoding) {
089:                case MimeHeader.QUOTED_PRINTABLE: {
090:                    bodyStream = new QuotedPrintableDecoderInputStream(
091:                            bodyStream);
092:
093:                    break;
094:                }
095:
096:                case MimeHeader.BASE64: {
097:                    bodyStream = new Base64DecoderInputStream(bodyStream);
098:
099:                    break;
100:                }
101:                }
102:
103:                return bodyStream;
104:            }
105:
106:            /**
107:             * @param mediator
108:             * @param bodyPart
109:             * @return
110:             */
111:            public static Charset extractCharset(Charset charset,
112:                    MimePart bodyPart) {
113:
114:                // no charset specified -> automatic mode
115:                // -> try to determine charset based on content parameter
116:                if (charset == null) {
117:                    String charsetName = null;
118:
119:                    if (bodyPart != null) {
120:                        charsetName = bodyPart.getHeader().getContentParameter(
121:                                "charset");
122:                    }
123:
124:                    if (charsetName == null) {
125:                        // There is no charset info -> the default system charset is
126:                        // used
127:                        charsetName = System.getProperty("file.encoding");
128:                        charset = Charset.forName(charsetName);
129:                    } else {
130:                        try {
131:                            charset = Charset.forName(charsetName);
132:                        } catch (UnsupportedCharsetException e) {
133:                            charsetName = System.getProperty("file.encoding");
134:                            charset = Charset.forName(charsetName);
135:                        } catch (IllegalCharsetNameException e) {
136:                            charsetName = System.getProperty("file.encoding");
137:                            charset = Charset.forName(charsetName);
138:                        }
139:                    }
140:
141:                    // ((CharsetOwnerInterface) mediator).setCharset(charset);
142:
143:                }
144:                return charset;
145:            }
146:
147:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.