Source Code Cross Referenced for SuiteDownloadInfo.java in  » 6.0-JDK-Modules » j2me » com » sun » midp » installer » 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 » 6.0 JDK Modules » j2me » com.sun.midp.installer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *   
003:         *
004:         * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006:         * 
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License version
009:         * 2 only, as published by the Free Software Foundation.
010:         * 
011:         * This program is distributed in the hope that it will be useful, but
012:         * WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014:         * General Public License version 2 for more details (a copy is
015:         * included at /legal/license.txt).
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * version 2 along with this work; if not, write to the Free Software
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA
021:         * 
022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023:         * Clara, CA 95054 or visit www.sun.com if you need additional
024:         * information or have any questions.
025:         */
026:
027:        package com.sun.midp.installer;
028:
029:        import java.util.Vector;
030:
031:        import java.io.InputStreamReader;
032:        import java.io.IOException;
033:
034:        /**
035:         * This class represents the Information need to download a MIDlet suite and
036:         * display it to a user, in a list.
037:         */
038:        class SuiteDownloadInfo {
039:            /** URL for the JAD of this suite */
040:            String url;
041:            /** label to display to the User for this suite */
042:            String label;
043:
044:            /**
045:             * Read a HTML page and pickout the links for MIDlet suites.
046:             * A MIDlet suite links end with .jad
047:             *
048:             * @param page HTML page to be read
049:             *
050:             * @return vector of URL/Label pairs
051:             *
052:             * @exception IOException is thrown if any error prevents the 
053:             *   download of the HTML page.
054:             */
055:            static Vector getDownloadInfoFromPage(InputStreamReader page)
056:                    throws IOException {
057:                Vector suites = new Vector();
058:                SuiteDownloadInfo info;
059:
060:                info = getNextJadLink(page);
061:                while (info != null) {
062:                    if (info.url.endsWith(".jad") || info.url.endsWith(".jar")) {
063:                        suites.addElement(info);
064:                    }
065:
066:                    info = getNextJadLink(page);
067:                }
068:
069:                return suites;
070:            }
071:
072:            /**
073:             * Read a HTML page and pickout next link.
074:             *
075:             * @param page HTML page to be read
076:             *
077:             * @return URL/Label pair
078:             *
079:             * @exception IOException is thrown if any error prevents the 
080:             *   download of the HTML page.
081:             */
082:            private static SuiteDownloadInfo getNextJadLink(
083:                    InputStreamReader page) throws IOException {
084:                String url;
085:                String label;
086:
087:                url = getNextUrl(page);
088:                if (url == null) {
089:                    return null;
090:                }
091:
092:                label = getNextLabel(page);
093:                if (label == null) {
094:                    label = url;
095:                }
096:
097:                return new SuiteDownloadInfo(url, label);
098:            }
099:
100:            /**
101:             * Read a HTML page and pickout next href.
102:             *
103:             * @param page HTML page to be read
104:             *
105:             * @return URL
106:             *
107:             * @exception IOException is thrown if any error prevents the 
108:             *   download of the HTML page.
109:             */
110:            private static String getNextUrl(InputStreamReader page)
111:                    throws IOException {
112:                int currentChar;
113:                StringBuffer url;
114:
115:                if (!findString(page, "href=\"")) {
116:                    return null;
117:                }
118:
119:                url = new StringBuffer();
120:
121:                currentChar = page.read();
122:                while (currentChar != '"') {
123:                    if (currentChar == -1) {
124:                        return null;
125:                    }
126:
127:                    url.append((char) currentChar);
128:                    currentChar = page.read();
129:                }
130:
131:                if (url.length() == 0) {
132:                    return null;
133:                }
134:
135:                return url.toString();
136:            }
137:
138:            /**
139:             * Read a HTML page and pickout the text after the beginning anchor.
140:             *
141:             * @param page HTML page to be read
142:             *
143:             * @return label
144:             *
145:             * @exception IOException is thrown if any error prevents the 
146:             *   download of the HTML page.
147:             */
148:            private static String getNextLabel(InputStreamReader page)
149:                    throws IOException {
150:                int currentChar;
151:                StringBuffer label;
152:
153:                if (!findChar(page, '>')) {
154:                    return null;
155:                }
156:
157:                label = new StringBuffer();
158:
159:                currentChar = page.read();
160:                while (currentChar != '<') {
161:                    if (currentChar == -1) {
162:                        return null;
163:                    }
164:
165:                    label.append((char) currentChar);
166:                    currentChar = page.read();
167:                }
168:
169:                if (label.length() == 0) {
170:                    return null;
171:                }
172:
173:                return label.toString();
174:            }
175:
176:            /**
177:             * Find the next given string in an HTML page move past it.
178:             *
179:             * @param page HTML page to be read
180:             * @param targetString string to move past
181:             *
182:             * @return true if string found, else false
183:             *
184:             * @exception IOException is thrown if any error prevents the 
185:             *   download of the HTML page.
186:             */
187:            private static boolean findString(InputStreamReader page,
188:                    String targetString) throws IOException {
189:                for (int i = 0; i < targetString.length(); i++) {
190:                    if (!findChar(page, targetString.charAt(i))) {
191:                        return false;
192:                    }
193:                }
194:
195:                return true;
196:            }
197:
198:            /**
199:             * Find the next given char in an HTML page move past it.
200:             *
201:             * @param page HTML page to be read
202:             * @param targetChar char to move past
203:             *
204:             * @return true if string found, else false
205:             *
206:             * @exception IOException is thrown if any error prevents the 
207:             *   download of the HTML page.
208:             */
209:            private static boolean findChar(InputStreamReader page,
210:                    char targetChar) throws IOException {
211:                int currentChar;
212:
213:                currentChar = page.read();
214:                while (Character.toLowerCase((char) currentChar) != targetChar) {
215:                    if (currentChar == -1) {
216:                        return false;
217:                    }
218:
219:                    currentChar = page.read();
220:                }
221:
222:                return true;
223:            }
224:
225:            /**
226:             * Constructs a SuiteDownloadInfo.
227:             *
228:             * @param theUrl URL for this suite
229:             * @param theLabel label for this suite
230:             */
231:            SuiteDownloadInfo(String theUrl, String theLabel) {
232:                url = theUrl;
233:                label = theLabel;
234:            }
235:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.