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


001:        package org.claros.intouch.contacts.services;
002:
003:        import java.io.BufferedReader;
004:        import java.io.File;
005:        import java.io.IOException;
006:        import java.io.InputStreamReader;
007:        import java.util.ArrayList;
008:        import java.util.HashMap;
009:        import java.util.Iterator;
010:        import java.util.List;
011:        import java.util.Locale;
012:        import java.util.StringTokenizer;
013:
014:        import javax.servlet.ServletException;
015:        import javax.servlet.http.HttpServletRequest;
016:        import javax.servlet.http.HttpServletResponse;
017:
018:        import org.apache.commons.fileupload.FileItem;
019:        import org.apache.commons.fileupload.disk.DiskFileItemFactory;
020:        import org.apache.commons.fileupload.servlet.ServletFileUpload;
021:        import org.claros.commons.auth.models.AuthProfile;
022:        import org.claros.intouch.common.exceptions.UnableToImportException;
023:        import org.claros.intouch.common.services.BaseService;
024:        import org.claros.intouch.common.utility.Constants;
025:        import org.claros.intouch.contacts.controllers.ImportExportController;
026:
027:        public class ImportContactsService extends BaseService {
028:            private static int MAX_MEM_SIZE = 1024 * 1024;
029:            private static int MAX_ATT_SIZE = 1024 * 1024 * Constants.maxAttSize;
030:            private static HashMap fields = new HashMap();
031:
032:            private static String tmpDir = Constants.tmpDir;
033:
034:            /**
035:             * 
036:             */
037:            private static final long serialVersionUID = 56265867864257045L;
038:
039:            /**
040:             * The doPost method of the servlet. <br>
041:             *
042:             * This method is called when a form has its tag value method equals to post.
043:             * 
044:             * @param request the request send by the client to the server
045:             * @param response the response send by the server to the client
046:             * @throws ServletException if an error occurred
047:             * @throws IOException if an error occurred
048:             */
049:            public void doPost(HttpServletRequest request,
050:                    HttpServletResponse response) throws ServletException,
051:                    IOException {
052:                response.setHeader("Expires", "-1");
053:                response.setHeader("Pragma", "no-cache");
054:                response.setHeader("Cache-control", "no-cache");
055:                response.setHeader("Content-Type", "text/html; charset=utf-8");
056:
057:                try {
058:                    // Create a factory for disk-based file items
059:                    DiskFileItemFactory factory = new DiskFileItemFactory();
060:
061:                    // Set factory constraints
062:                    factory.setSizeThreshold(MAX_MEM_SIZE);
063:                    factory.setRepository(new File(tmpDir));
064:
065:                    // Create a new file upload handler
066:                    ServletFileUpload upload = new ServletFileUpload(factory);
067:
068:                    // Set overall request size constraint
069:                    upload.setSizeMax(MAX_ATT_SIZE);
070:
071:                    // Parse the request
072:                    List items = upload.parseRequest(request);
073:                    // Process the uploaded items
074:                    Iterator iter = items.iterator();
075:
076:                    // we can parse the attachments now
077:                    iter = items.iterator();
078:
079:                    ArrayList columns = new ArrayList();
080:                    ArrayList data = new ArrayList();
081:                    int i = 0;
082:
083:                    while (iter.hasNext()) {
084:                        FileItem item = (FileItem) iter.next();
085:
086:                        if (!item.isFormField()) {
087:                            BufferedReader br = new BufferedReader(
088:                                    new InputStreamReader(item.getInputStream()));
089:                            String line = "";
090:                            String tmp = null;
091:                            try {
092:                                String charset = Constants.charset;
093:                                while ((line = br.readLine()) != null) {
094:                                    line = new String(line.getBytes(charset),
095:                                            "utf-8");
096:                                    try {
097:                                        line = org.claros.commons.utility.Utility
098:                                                .replaceAllOccurances(line,
099:                                                        ";;", "; ;");
100:                                        line = org.claros.commons.utility.Utility
101:                                                .replaceAllOccurances(line,
102:                                                        ";;", "; ;");
103:                                        StringTokenizer token = new StringTokenizer(
104:                                                line, ";");
105:                                        if (i == 0) {
106:                                            // the first line tells about what the fields stand for.
107:                                            String fieldName = null;
108:                                            while (token.hasMoreTokens()) {
109:                                                tmp = token.nextToken()
110:                                                        .toUpperCase(
111:                                                                new Locale(
112:                                                                        "en",
113:                                                                        "US"));
114:                                                fieldName = (String) fields
115:                                                        .get(tmp);
116:                                                if (fieldName == null) {
117:                                                    throw new UnableToImportException(
118:                                                            "Field "
119:                                                                    + tmp
120:                                                                    + " is an invalid column name");
121:                                                }
122:                                                columns.add(fieldName);
123:                                            }
124:                                        } else {
125:                                            // these are the data to be processed.
126:                                            ArrayList row = new ArrayList();
127:                                            while (token.hasMoreTokens()) {
128:                                                tmp = token.nextToken();
129:                                                row.add(tmp);
130:                                            }
131:                                            data.add(row);
132:                                        }
133:                                    } catch (UnableToImportException ue) {
134:                                        throw ue;
135:                                    } catch (Exception e) {
136:                                        // do nothing sier
137:                                    }
138:                                    i++;
139:                                }
140:                            } catch (Exception e) {
141:                                response
142:                                        .sendRedirect("../import_ok.jsp?result=1");
143:                            }
144:                        }
145:                    }
146:
147:                    AuthProfile auth = getAuthProfile(request);
148:                    int success = ImportExportController.importContacts(auth,
149:                            columns, data);
150:                    int fail = i - success - 1;
151:
152:                    response.sendRedirect("../import_ok.jsp?result=0&success="
153:                            + success + "&fail=" + fail);
154:                } catch (Exception e) {
155:                    response.sendRedirect("../import_ok.jsp?result=1");
156:                }
157:            }
158:
159:            static {
160:                fields.put("FIRST NAME", "FIRST_NAME");
161:                fields.put("MIDDLE NAME", "MIDDLE_NAME");
162:                fields.put("LAST NAME", "LAST_NAME");
163:                fields.put("FIRSTNAME", "FIRST_NAME");
164:                fields.put("MIDDLENAME", "MIDDLE_NAME");
165:                fields.put("LASTNAME", "LAST_NAME");
166:                fields.put("TITLE", "TITLE");
167:                fields.put("SEX", "SEX");
168:                fields.put("GSM PRIMARY", "GSM_NO_PRIMARY");
169:                fields.put("GSM ALTERNATE", "GSM_NO_ALTERNATE");
170:                fields.put("PRIMARY GSM", "GSM_NO_PRIMARY");
171:                fields.put("ALTERNATE GSM", "GSM_NO_ALTERNATE");
172:                fields.put("EMAIL PRIMARY", "EMAIL_PRIMARY");
173:                fields.put("EMAIL ALTERNATE", "EMAIL_ALTERNATE");
174:                fields.put("PRIMARY EMAIL", "EMAIL_PRIMARY");
175:                fields.put("ALTERNATE EMAIL", "EMAIL_ALTERNATE");
176:                fields.put("WEB PAGE", "WEB_PAGE");
177:                fields.put("URL", "WEB_PAGE");
178:                fields.put("WEBSITE", "WEB_PAGE");
179:                fields.put("WEBPAGE", "WEB_PAGE");
180:                fields.put("PERSONAL NOTE", "PERSONAL_NOTE");
181:                fields.put("NOTE", "PERSONAL_NOTE");
182:                fields.put("SPOUSE NAME", "SPOUSE_NAME");
183:                fields.put("NICKNAME", "NICKNAME");
184:                fields.put("NICK NAME", "NICKNAME");
185:                fields.put("BIRTHDAY", "BIRTHDAY");
186:                fields.put("BIRTHMONTH", "BIRTHMONTH");
187:                fields.put("ANNIVERSARYDAY", "ANNIVERSARYDAY");
188:                fields.put("ANNIVERSARYMONTH", "ANNIVERSARYMONTH");
189:                fields.put("HOME ADDRESS", "HOME_ADDRESS");
190:                fields.put("HOME CITY", "HOME_CITY");
191:                fields.put("HOME PROVINCE", "HOME_PROVINCE");
192:                fields.put("HOME ZIP", "HOME_ZIP");
193:                fields.put("HOME COUNTRY", "HOME_COUNTRY");
194:                fields.put("HOME PHONE", "HOME_PHONE");
195:                fields.put("HOME FAX", "HOME_FAKS");
196:                fields.put("COMPANY", "WORK_COMPANY");
197:                fields.put("JOB TITLE", "WORK_JOB_TITLE");
198:                fields.put("DEPARTMENT", "WORK_DEPARTMENT");
199:                fields.put("OFFICE", "WORK_OFFICE");
200:                fields.put("PROFESSION", "WORK_PROFESSION");
201:                fields.put("MANAGER NAME", "WORK_MANAGER_NAME");
202:                fields.put("ASSISTANT NAME", "WORK_ASSISTANT_NAME");
203:                fields.put("WORK ADDRESS", "WORK_ADDRESS");
204:                fields.put("WORK CITY", "WORK_CITY");
205:                fields.put("WORK PROVINCE", "WORK_PROVINCE");
206:                fields.put("WORK ZIP", "WORK_ZIP");
207:                fields.put("WORK COUNTRY", "WORK_COUNTRY");
208:                fields.put("WORK PHONE", "WORK_PHONE");
209:                fields.put("WORK FAX", "WORK_FAKS");
210:            }
211:
212:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.