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


001:        // The contents of this file are subject to the Mozilla Public License Version
002:        // 1.1
003:        //(the "License"); you may not use this file except in compliance with the
004:        //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005:        //
006:        //Software distributed under the License is distributed on an "AS IS" basis,
007:        //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008:        //for the specific language governing rights and
009:        //limitations under the License.
010:        //
011:        //The Original Code is "The Columba Project"
012:        //
013:        //The Initial Developers of the Original Code are Frederik Dietz and Timo
014:        // Stich.
015:        //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016:        //
017:        //All Rights Reserved.
018:        package org.columba.mail.parser;
019:
020:        import java.util.Iterator;
021:        import java.util.List;
022:        import java.util.Vector;
023:
024:        /**
025:         * Provides parsers for creating String representations from List objects and
026:         * vice versa.
027:         * 
028:         * @author fdietz
029:         */
030:        public class ListParser {
031:
032:            public final static char SEPARATOR_CHAR = ',';
033:
034:            public final static String SEPARATOR_STRING = ",";
035:
036:            public ListParser() {
037:            }
038:
039:            /**
040:             * Create list from String containing semicolon-separated email addresses.
041:             * 
042:             * @param str
043:             *            semicolon separated email address list
044:             * 
045:             * @return list list of email addresses, never <code>null</code>
046:             */
047:            public static List<String> createListFromString(String str) {
048:                if (str == null)
049:                    throw new IllegalArgumentException("str == null");
050:
051:                List<String> result = new Vector<String>();
052:                if (str.length() == 0)
053:                    return result;
054:
055:                int pos = 0;
056:                boolean bracket = false;
057:
058:                // Remove the ending separator and whitespace, if any exist
059:                str = str.trim();
060:                if (str.endsWith(SEPARATOR_STRING))
061:                    str = str.substring(0, str.length() - 1);
062:
063:                StringBuffer buf = new StringBuffer();
064:                while (pos < str.length()) {
065:                    char ch = str.charAt(pos);
066:
067:                    if ((ch == SEPARATOR_CHAR) && (bracket == false)) {
068:                        // found new message
069:                        String address = buf.toString().trim();
070:                        result.add(address);
071:
072:                        buf = new StringBuffer();
073:                    } else if (ch == '"') {
074:                        // Remove the double-quote characters from around the addresses in the string 
075:                        bracket = !bracket;
076:                    } else {
077:                        buf.append(ch);
078:                    }
079:                    pos++;
080:                }
081:
082:                String address = buf.toString().trim();
083:                // remove whitespaces
084:                address = address.trim();
085:                result.add(address);
086:
087:                return result;
088:            }
089:
090:            /**
091:             * Create list from String containing semicolon-separated email addresses.
092:             * 
093:             * @param str
094:             *            semicolon separated email address list
095:             * 
096:             * @return list list of email addresses, never <code>null</code>
097:            public static List<String> createListFromString(String str) {
098:            	if (str == null)
099:            		throw new IllegalArgumentException("str == null");
100:
101:            	List<String> result = new Vector<String>();
102:            	if (str.length() == 0)
103:            		return result;
104:
105:            	int pos = 0;
106:            	boolean bracket = false;
107:            	StringBuffer buf = new StringBuffer();
108:            	int listLength = str.length();
109:
110:            	while (pos < listLength) {
111:            		char ch = str.charAt(pos);
112:
113:            		if ((ch == SEPARATOR_CHAR) && (bracket == false)) {
114:            			// found new message
115:            			String address = buf.toString();
116:            			result.add(address);
117:
118:            			buf = new StringBuffer();
119:            			pos++;
120:            		} else if (ch == '"') {
121:            			buf.append(ch);
122:
123:            			pos++;
124:
125:            			bracket = !bracket;
126:            		} else {
127:            			buf.append(ch);
128:
129:            			pos++;
130:            		}
131:            	}
132:
133:            	String address = buf.toString();
134:            	// remove whitespaces
135:            	address = address.trim();
136:            	result.add(address);
137:
138:            	return result;
139:            }
140:             */
141:
142:            /**
143:             * Create comma-separated String representation of a list of String objects.
144:             * 
145:             * @param list
146:             *            list containing String objects
147:             * @return String representation, never <code>null</code
148:             */
149:            public static String createStringFromList(List<String> list,
150:                    String separator) {
151:                if (list == null)
152:                    throw new IllegalArgumentException("list == null");
153:                if (separator == null)
154:                    throw new IllegalArgumentException("separator == null");
155:
156:                StringBuffer output = new StringBuffer();
157:
158:                for (Iterator it = list.iterator(); it.hasNext();) {
159:                    String address = (String) it.next();
160:                    if (address == null) {
161:                        continue;
162:                    }
163:
164:                    // Remote double-quotes
165:                    StringBuffer addrSB = new StringBuffer(address);
166:                    while (true) {
167:                        int doubleQuote = addrSB.indexOf("\"");
168:                        if (doubleQuote >= 0)
169:                            addrSB.deleteCharAt(doubleQuote);
170:                        else
171:                            break;
172:                    }
173:
174:                    // If address contains a comma, enclose the display name portion in double-quotes
175:                    int comma = addrSB.indexOf(",");
176:                    int endDoubleQuote = addrSB.length();
177:                    if (comma >= 0) {
178:                        int addrStart = addrSB.indexOf(" <");
179:                        if (addrStart >= 0)
180:                            endDoubleQuote = addrStart;
181:                        addrSB.insert(endDoubleQuote, '"');
182:                        addrSB.insert(0, '"');
183:                    }
184:
185:                    address = addrSB.toString();
186:
187:                    output.append(address);
188:                    output.append(separator);
189:                    output.append(" ");
190:                }
191:
192:                /*
193:                if (output.length() > 0) {
194:                	output.deleteCharAt(output.length() - 1);
195:                }
196:                 */
197:
198:                return output.toString();
199:            }
200:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.