Source Code Cross Referenced for VCardParser.java in  » Search-Engine » Lius-0.4 » de » teamskill » util » 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 » Search Engine » Lius 0.4 » de.teamskill.util.parser 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Project: LIUS Package: de.teamskill.util.parser
003:         * 
004:         * Copyright (c) 2004 by Jens Fendler <jf@teamskill.de>
005:         * 
006:         * This program is a free software; you can redistribute it and/or modify it
007:         * under the terms of the GNU General Public License as published by the Free
008:         * Software Foundation; either version 2 of the License, or (at your option) any
009:         * later version. This program is distributed in the hope that it will be
010:         * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
012:         * Public License for more details. You should have received a copy of the GNU
013:         * General Public License along with this program; if not, write to the Free
014:         * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
015:         * USA
016:         */
017:
018:        package de.teamskill.util.parser;
019:
020:        import java.io.BufferedReader;
021:        import java.io.File;
022:        import java.io.FileInputStream;
023:        import java.io.IOException;
024:        import java.io.InputStream;
025:        import java.io.InputStreamReader;
026:        import java.util.List;
027:        import java.util.Vector;
028:
029:        import de.teamskill.util.VCard;
030:
031:        /**
032:         * Class: VCardParser <br>
033:         * 
034:         * Changelog:
035:         * <ul>
036:         * <li>02.06.2005: Initial implementation (jf)</li>
037:         * <li>03.06.2005: Fixed card detection code (no reg-ex anymore) (jf)</li>
038:         * </ul>
039:         * 
040:         * @author <a href="mailto:jf@teamskill.de">Jens Fendler </a>
041:         */
042:        public class VCardParser {
043:
044:            private static final String lineSep = System
045:                    .getProperty("line.separator");
046:
047:            private static final String BEGIN_PATTERN = "BEGIN:VCARD";
048:
049:            private static final String END_PATTERN = "END:VCARD";
050:
051:            private InputStream stream = null;
052:
053:            private List cards = new Vector();
054:
055:            public VCardParser(InputStream stream) throws IOException {
056:                // setup the input stream and parse it into the cards List
057:                this .stream = stream;
058:                parse(stream);
059:            }
060:
061:            public VCardParser(File file) throws IOException {
062:                this (new FileInputStream(file));
063:            }
064:
065:            public VCardParser(String filename) throws IOException {
066:                this (new File(filename));
067:            }
068:
069:            /**
070:             * parse
071:             * 
072:             * @param stream2
073:             * @throws IOException
074:             */
075:            private void parse(InputStream stream) throws IOException {
076:                BufferedReader br = new BufferedReader(new InputStreamReader(
077:                        stream));
078:                StringBuffer sb = new StringBuffer();
079:                String line = null;
080:                while ((line = br.readLine()) != null) {
081:                    if (line.startsWith(BEGIN_PATTERN)) {
082:                        StringBuffer cardBuffer = new StringBuffer();
083:                        // new VCard begins
084:                        cardBuffer.append(line).append(lineSep);
085:                        // finish reading of card content..
086:                        String cardString = finishCard(br, cardBuffer);
087:                        // add the new card to our container as a new VCard object
088:                        cards.add(new VCard(cardString));
089:                    }
090:                }
091:            }
092:
093:            /**
094:             * finishCard
095:             * 
096:             * @param br
097:             * @param cardBuffer
098:             * @return
099:             * @throws IOException
100:             */
101:            private String finishCard(BufferedReader br, StringBuffer cardBuffer)
102:                    throws IOException {
103:                String line = null;
104:                // simply loop until EOF is reached. if a valid card end marker is found
105:                // earlier we'll
106:                // return directly from within the loop..
107:                while ((line = br.readLine()) != null) {
108:                    // adjust for (invalid) short lines (e.g. containing only CR/LF)
109:                    if (line.length() > 2)
110:                        cardBuffer.append(line).append(lineSep);
111:
112:                    if (line.startsWith(END_PATTERN)) {
113:                        return cardBuffer.toString().trim();
114:                    }
115:                }
116:                // if a card is not correctly ending, fix it and return what we have so
117:                // far
118:                cardBuffer.append(END_PATTERN);
119:                return cardBuffer.toString();
120:            }
121:
122:            public List getCards() {
123:                return cards;
124:            }
125:
126:            public void setCards(List cards) {
127:                this .cards = cards;
128:            }
129:
130:            public InputStream getStream() {
131:                return stream;
132:            }
133:
134:            public void setStream(InputStream stream) {
135:                this.stream = stream;
136:            }
137:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.