Source Code Cross Referenced for Utility.java in  » Web-Mail » claros-intouch2-2.2-beta » org » claros » commons » mail » utility » 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 » claros intouch2 2.2 beta » org.claros.commons.mail.utility 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.claros.commons.mail.utility;
002:
003:        import java.io.UnsupportedEncodingException;
004:        import java.util.StringTokenizer;
005:
006:        import javax.mail.Address;
007:        import javax.mail.internet.AddressException;
008:        import javax.mail.internet.InternetAddress;
009:
010:        import org.claros.commons.configuration.PropertyFile;
011:
012:        /**
013:         * @author Umut Gokbayrak
014:         *
015:         */
016:        public class Utility {
017:            private Utility() {
018:                super ();
019:            }
020:
021:            /**
022:             * 
023:             * @param addr
024:             * @return
025:             */
026:            public static String[] addressArrToStringArr(Address[] addr) {
027:                if (addr != null && addr.length > 0) {
028:                    String[] str = new String[addr.length];
029:                    for (int j = 0; j < addr.length; j++) {
030:                        InternetAddress add = (InternetAddress) addr[j];
031:                        String personal = org.claros.commons.utility.Utility
032:                                .doCharsetCorrections(add.getPersonal());
033:                        String address = org.claros.commons.utility.Utility
034:                                .doCharsetCorrections(add.getAddress());
035:
036:                        if (personal != null && personal.length() > 0) {
037:                            if (address != null && address.length() > 0) {
038:                                str[j] = personal + " <" + address + ">";
039:                            } else {
040:                                str[j] = personal;
041:                            }
042:                        } else {
043:                            if (address != null && address.length() > 0) {
044:                                str[j] = address;
045:                            } else {
046:                                str[j] = "";
047:                            }
048:                        }
049:                    }
050:                    return str;
051:                }
052:                return null;
053:            }
054:
055:            /**
056:             * 
057:             * @param addr
058:             * @return
059:             */
060:            public static String addressArrToString(Address[] addr) {
061:                String addrStr = "";
062:                String str[] = addressArrToStringArr(addr);
063:                if (str != null && str.length > 0) {
064:                    addrStr = "";
065:                    for (int i = 0; i < str.length; i++) {
066:                        addrStr += str[i] + ", ";
067:                    }
068:                }
069:                String msg = org.claros.commons.utility.Utility.extendedTrim(
070:                        addrStr, ",");
071:                return org.claros.commons.utility.Utility
072:                        .doCharsetCorrections(msg);
073:            }
074:
075:            /**
076:             * 
077:             * @param addr
078:             * @return
079:             */
080:            public static String[] addressArrToStringArrShort(Address[] addr) {
081:                if (addr != null && addr.length > 0) {
082:                    String[] str = new String[addr.length];
083:                    for (int j = 0; j < addr.length; j++) {
084:                        InternetAddress add = (InternetAddress) addr[j];
085:                        String personal = org.claros.commons.utility.Utility
086:                                .doCharsetCorrections(add.getPersonal());
087:                        String address = org.claros.commons.utility.Utility
088:                                .doCharsetCorrections(add.getAddress());
089:
090:                        if (personal != null && personal.length() > 0) {
091:                            str[j] = personal;
092:                        } else if (address != null && address.length() > 0) {
093:                            str[j] = address;
094:                        } else {
095:                            str[j] = "Unknown";
096:                        }
097:                    }
098:                    return str;
099:                }
100:                return null;
101:            }
102:
103:            /**
104:             * 
105:             * @param addr
106:             * @return
107:             */
108:            public static String addressArrToStringShort(Address[] addr) {
109:                String addrStr = "";
110:                String str[] = addressArrToStringArrShort(addr);
111:                if (str != null && str.length > 0) {
112:                    addrStr = "";
113:                    for (int i = 0; i < str.length; i++) {
114:                        addrStr += str[i] + ", ";
115:                    }
116:                }
117:                String msg = org.claros.commons.utility.Utility.extendedTrim(
118:                        addrStr, ",");
119:                msg = org.claros.commons.utility.Utility
120:                        .doCharsetCorrections(msg);
121:                return msg;
122:            }
123:
124:            /**
125:             * 
126:             * @param str
127:             * @return
128:             * @throws Exception
129:             */
130:            public static Address[] stringToAddressArray(String str)
131:                    throws Exception {
132:                if (str == null)
133:                    return null;
134:
135:                str = org.claros.commons.utility.Utility.extendedTrim(str, ",");
136:                StringTokenizer token = new StringTokenizer(str, ",");
137:                if (token.countTokens() != 0) {
138:                    Address[] outAddr = new Address[token.countTokens()];
139:                    int counter = 0;
140:                    while (token.hasMoreTokens()) {
141:                        String addr = token.nextToken().trim();
142:                        addr = org.claros.commons.utility.Utility
143:                                .replaceAllOccurances(addr, "&lt;", "<");
144:                        addr = org.claros.commons.utility.Utility
145:                                .replaceAllOccurances(addr, "&gt;", ">");
146:                        String fullname = "";
147:                        String email = "";
148:                        int j;
149:                        try {
150:                            if ((j = addr.indexOf("<")) > 0) {
151:                                fullname = org.claros.commons.utility.Utility
152:                                        .extendedTrim(addr.substring(0, j)
153:                                                .trim(), "\"");
154:                                email = org.claros.commons.utility.Utility
155:                                        .extendedTrim(
156:                                                org.claros.commons.utility.Utility
157:                                                        .extendedTrim(
158:                                                                addr
159:                                                                        .substring(j + 1),
160:                                                                ">"), "\"")
161:                                        .trim();
162:                                String charset = PropertyFile.getConfiguration(
163:                                        "/config/config.xml").getString(
164:                                        "common-params.charset");
165:                                outAddr[counter] = new InternetAddress(email,
166:                                        fullname, charset);
167:                            } else {
168:                                outAddr[counter] = new InternetAddress(addr);
169:                            }
170:                        } catch (UnsupportedEncodingException e) {
171:                            e.printStackTrace();
172:                        } catch (AddressException e) {
173:                            e.printStackTrace();
174:                        }
175:                        counter++;
176:                    }
177:                    return outAddr;
178:                } else {
179:                    return null;
180:                }
181:            }
182:
183:            /**
184:             * 
185:             * @param size
186:             * @return
187:             */
188:            public static String sizeToHumanReadable(long size) {
189:                String out = Math.round(size / 1024) + "K";
190:                if (out.equals("0K")) {
191:                    out = size + "B";
192:                }
193:                return out;
194:            }
195:
196:            /**
197:             * 
198:             * @param message
199:             * @return
200:             */
201:            public static String stripHTMLTags(String message) {
202:                StringBuffer returnMessage = new StringBuffer(message);
203:                try {
204:                    int startPosition = message.indexOf("<"); // encountered the first opening brace
205:                    int endPosition = message.indexOf(">"); // encountered the first closing braces
206:                    while (startPosition != -1) {
207:                        returnMessage.delete(startPosition, endPosition + 1); // remove the tag
208:                        returnMessage.insert(startPosition, " ");
209:                        startPosition = (returnMessage.toString()).indexOf("<"); // look for the next opening brace
210:                        endPosition = (returnMessage.toString()).indexOf(">"); // look for the next closing brace
211:                    }
212:                } catch (Throwable e) {
213:                    // do nothing sier
214:                }
215:                return returnMessage.toString();
216:            }
217:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.