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


001:        package org.claros.commons.utility;
002:
003:        import java.net.URLDecoder;
004:        import java.util.Locale;
005:
006:        public class Utility {
007:
008:            private final static char trChars[] = { '\u0131', '\u0130',
009:                    '\u015F', '\u015E', '\u011F', '\u011E', '\u00fd', '\u00dd',
010:                    '\u00fe', '\u00de', '\u00f0', '\u00d0', '\u00E7', '\u00C7',
011:                    '\u00FC', '\u00DC', '\u00F6', '\u00D6' };
012:            private final static char enChars[] = { 'i', 'I', 's', 'S', 'g',
013:                    'G', 'i', 'I', 's', 'S', 'g', 'G', 'c', 'C', 'u', 'U', 'o',
014:                    'O' };
015:            private final static char enLowerCaseChars[] = { 'i', 'i', 's',
016:                    's', 'g', 'g', 'i', 'i', 's', 's', 'g', 'g', 'c', 'c', 'u',
017:                    'u', 'o', 'o' };
018:            private final static String trUnicodes[] = { "ı", "İ",
019:                    "ş", "Ş", "ğ", "Ğ", "ı", "İ",
020:                    "ş", "Ş", "ğ", "Ğ", "ç", "Ç",
021:                    "ü", "Ü", "ö", "Ö" };
022:
023:            private final static char trDirtyChars[] = { '\u00fd', '\u00dd',
024:                    '\u00fe', '\u00de', '\u00f0', '\u00d0' };
025:            private final static char trCleanChars[] = { '\u0131', '\u0130',
026:                    '\u015F', '\u015E', '\u011F', '\u011E' };
027:
028:            /**
029:             * 
030:             * @param str
031:             * @param from
032:             * @param to
033:             * @return
034:             */
035:            public static String replaceAllOccurances(String str, String from,
036:                    String to) {
037:                if (str == null || str.length() == 0) {
038:                    return str;
039:                } else if (str.length() == 1 && str.equals(from)) {
040:                    return to;
041:                } else if (str.length() == 1 && !str.equals(from)) {
042:                    return str;
043:                }
044:                int j = -1;
045:                while ((j = str.indexOf(from)) >= 0) {
046:                    str = str.substring(0, j) + (char) 5
047:                            + str.substring(j + from.length());
048:                }
049:
050:                int i = -1;
051:                while ((i = str.indexOf((char) 5)) >= 0) {
052:                    str = str.substring(0, i) + to + str.substring(i + 1);
053:                }
054:
055:                return str;
056:            }
057:
058:            /**
059:             * 
060:             * @param str
061:             * @param trimStr
062:             * @return
063:             */
064:            public static String extendedTrim(String str, String trimStr) {
065:                if (str == null || str.length() == 0)
066:                    return str;
067:                for (str = str.trim(); str.startsWith(trimStr); str = str
068:                        .substring(trimStr.length()).trim())
069:                    ;
070:                for (; str.endsWith(trimStr); str = str.substring(0,
071:                        str.length() - trimStr.length()).trim())
072:                    ;
073:                return str;
074:            }
075:
076:            /**
077:             * 
078:             * @param number
079:             * @return
080:             */
081:            public static Object checkDecimalFormat(Object number) {
082:                String str = "-";
083:                try {
084:                    str = number.toString();
085:                    int posDot = str.indexOf(".");
086:                    int posComma = str.indexOf(",");
087:
088:                    if (posComma > posDot) {
089:                        str = Utility.replaceAllOccurances(str, ".", "");
090:                        str = Utility.replaceAllOccurances(str, ",", ".");
091:                    } else if (posComma == -1 && posDot > 0) {
092:                        int lastPosDot = str.lastIndexOf(".");
093:                        if (posDot != lastPosDot) {
094:                            str = Utility.replaceAllOccurances(str, ".", "");
095:                        }
096:                    }
097:                } catch (Exception e) {
098:                    str = "-";
099:                }
100:                return str;
101:            }
102:
103:            /**
104:             * 
105:             * @param str
106:             * @return
107:             */
108:            public static String doCharsetCorrections(String str) {
109:                if (str == null)
110:                    return "";
111:
112:                String extraChars[] = { "\u00FD", "\u00DD", "\u00FE", "\u00DE",
113:                        "\u00F0", "\u00D0" };
114:                String unicode[] = { "\u0131", "\u0130", "\u015F", "\u015E",
115:                        "\u011F", "\u011E" };
116:                for (int i = 0; i < extraChars.length; i++) {
117:                    while (str.indexOf(extraChars[i]) != -1) {
118:                        String tmp = str;
119:                        str = tmp.substring(0, tmp.indexOf(extraChars[i]))
120:                                + unicode[i]
121:                                + tmp.substring(tmp.indexOf(extraChars[i]) + 1,
122:                                        tmp.length());
123:                    }
124:                }
125:                return str;
126:            }
127:
128:            /**
129:             * 
130:             * @param input
131:             * @return
132:             */
133:            public static String htmlSpecialChars(String input) {
134:                StringBuffer filtered;
135:                try {
136:                    filtered = new StringBuffer(input.length());
137:                    char c;
138:                    for (int i = 0; i < input.length(); i++) {
139:                        c = input.charAt(i);
140:                        if (c == '<') {
141:                            filtered.append("&lt;");
142:                        } else if (c == '>') {
143:                            filtered.append("&gt;");
144:                        } else if (c == '"') {
145:                            filtered.append("&quot;");
146:                        } else if (c == '&') {
147:                            filtered.append("&amp;");
148:                        } else {
149:                            filtered.append(c);
150:                        }
151:                    }
152:                } catch (Exception e) {
153:                    return input;
154:                }
155:                return (filtered.toString());
156:            }
157:
158:            /**
159:             * 
160:             * @param a
161:             * @return
162:             */
163:            public static String convertTRCharsToHtmlSafe(String str) {
164:                if ((str == null) || (str.length() == 0))
165:                    return "";
166:
167:                int pos = -1;
168:                for (int i = 0; i < trChars.length; i++) {
169:                    while ((pos = str.indexOf(trChars[i])) != -1) {
170:                        str = str.substring(0, pos) + trUnicodes[i]
171:                                + str.substring(pos + 1, str.length());
172:                    }
173:                }
174:                return str;
175:            }
176:
177:            /**
178:             * 
179:             * @param a
180:             * @return
181:             */
182:            public static String updateTRChars(String str) {
183:                if ((str == null) || (str.length() == 0))
184:                    return "";
185:                String ret = "";
186:                try {
187:                    ret = javax.mail.internet.MimeUtility.decodeText(str);
188:                } catch (Exception e) {
189:                }
190:                String strLowerCase = ret.toLowerCase(new Locale("en", "US"));
191:                if (strLowerCase.startsWith("=?iso-8859-9?q?")) {
192:                    ret = ret.substring(15);
193:                    if (strLowerCase.endsWith("?=")) {
194:                        ret = ret.substring(0, ret.length() - 2);
195:                    } else {
196:                        int pos = -1;
197:                        while ((pos = ret.indexOf("?=")) != -1) {
198:                            ret = ret.substring(0, pos)
199:                                    + ret.substring(pos + 2, ret.length());
200:                        }
201:                    }
202:                    try {
203:                        ret = ret.replace('=', '%');
204:                        ret = URLDecoder.decode(ret, "iso-8859-9");
205:                    } catch (Exception ex) {
206:                    }
207:                }
208:                for (int i = 0; i < trDirtyChars.length; i++) {
209:                    int pos = -1;
210:                    while ((pos = ret.indexOf(trDirtyChars[i])) != -1) {
211:                        ret = ret.substring(0, pos) + trCleanChars[i]
212:                                + ret.substring(pos + 1, ret.length());
213:                    }
214:                }
215:                return ret;
216:            }
217:
218:            /**
219:             * 
220:             * @param a
221:             * @return
222:             */
223:            public static String convertTRCharsToENChars(String str) {
224:                if ((str == null) || (str.length() == 0))
225:                    return "";
226:
227:                int pos = -1;
228:                for (int i = 0; i < trChars.length; i++) {
229:                    while ((pos = str.indexOf(trChars[i])) != -1) {
230:                        str = str.substring(0, pos) + enChars[i]
231:                                + str.substring(pos + 1, str.length());
232:                    }
233:                }
234:                return str;
235:            }
236:
237:            /**
238:             * 
239:             * @param a
240:             * @return
241:             */
242:            public static String convertTRCharsToENLowerCaseChars(String str) {
243:                if ((str == null) || (str.length() == 0))
244:                    return "";
245:
246:                int pos = -1;
247:                for (int i = 0; i < trChars.length; i++) {
248:                    while ((pos = str.indexOf(trChars[i])) != -1) {
249:                        str = str.substring(0, pos) + enLowerCaseChars[i]
250:                                + str.substring(pos + 1, str.length());
251:                    }
252:                }
253:                return str;
254:            }
255:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.