Source Code Cross Referenced for MirrorList.java in  » Swing-Library » jEdit » org » gjt » sp » jedit » pluginmgr » 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 » Swing Library » jEdit » org.gjt.sp.jedit.pluginmgr 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * MirrorList.java - Mirrors list
003:         * :tabSize=8:indentSize=8:noTabs=false:
004:         * :folding=explicit:collapseFolds=1:
005:         *
006:         * Copyright (C) 2002 Kris Kopicki
007:         *
008:         * This program is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU General Public License
010:         * as published by the Free Software Foundation; either version 2
011:         * of the License, or any later version.
012:         *
013:         * This program is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016:         * GNU General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU General Public License
019:         * along with this program; if not, write to the Free Software
020:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
021:         */
022:
023:        package org.gjt.sp.jedit.pluginmgr;
024:
025:        import java.io.*;
026:        import java.net.*;
027:        import java.util.*;
028:
029:        import org.xml.sax.XMLReader;
030:        import org.xml.sax.InputSource;
031:        import org.xml.sax.helpers.XMLReaderFactory;
032:
033:        import org.gjt.sp.jedit.*;
034:        import org.gjt.sp.util.IOUtilities;
035:        import org.gjt.sp.util.ProgressObserver;
036:        import org.gjt.sp.util.Log;
037:
038:        /**
039:         * @version $Id: MirrorList.java 7062 2006-09-18 09:55:39Z kpouer $
040:         */
041:        public class MirrorList {
042:            public List<Mirror> mirrors;
043:            /** The xml mirror list. */
044:            public String xml;
045:
046:            //{{{ MirrorList constructor
047:            public MirrorList(boolean download, ProgressObserver observer)
048:                    throws Exception {
049:                mirrors = new ArrayList<Mirror>();
050:
051:                Mirror none = new Mirror();
052:                none.id = Mirror.NONE;
053:                none.description = none.location = none.country = none.continent = "";
054:                mirrors.add(none);
055:
056:                String path = jEdit.getProperty("plugin-manager.mirror-url");
057:                MirrorListHandler handler = new MirrorListHandler(this , path);
058:                if (download) {
059:                    Log.log(Log.NOTICE, this ,
060:                            "Loading mirror list from internet");
061:                    downloadXml(path);
062:                } else {
063:                    Log.log(Log.NOTICE, this , "Loading mirror list from cache");
064:                    readXml();
065:                }
066:                observer.setValue(1);
067:                Reader in = new BufferedReader(new StringReader(xml));
068:
069:                InputSource isrc = new InputSource(in);
070:                isrc.setSystemId("jedit.jar");
071:                XMLReader parser = XMLReaderFactory.createXMLReader();
072:                parser.setContentHandler(handler);
073:                parser.setDTDHandler(handler);
074:                parser.setEntityResolver(handler);
075:                parser.setErrorHandler(handler);
076:                parser.parse(isrc);
077:                observer.setValue(2);
078:            } //}}}
079:
080:            //{{{ Private members
081:
082:            //{{{ readXml() method
083:            /**
084:             * Read and store the mirror list xml.
085:             * @throws IOException exception if it was not possible to read the
086:             * xml or if the url was invalid
087:             */
088:            private void readXml() throws IOException {
089:                String settingsDirectory = jEdit.getSettingsDirectory();
090:                if (settingsDirectory == null)
091:                    return;
092:
093:                File mirrorList = new File(MiscUtilities.constructPath(
094:                        settingsDirectory, "mirrorList.xml"));
095:                if (!mirrorList.exists())
096:                    return;
097:                InputStream inputStream = null;
098:                try {
099:                    inputStream = new BufferedInputStream(new FileInputStream(
100:                            mirrorList));
101:
102:                    ByteArrayOutputStream out = new ByteArrayOutputStream();
103:                    IOUtilities.copyStream(null, inputStream, out, false);
104:                    xml = out.toString();
105:                } finally {
106:                    IOUtilities.closeQuietly(inputStream);
107:                }
108:            } //}}}
109:
110:            //{{{ downloadXml() method
111:            /**
112:             * Read and store the mirror list xml.
113:             *
114:             * @param path the url
115:             * @throws IOException exception if it was not possible to read the
116:             * xml or if the url was invalid
117:             */
118:            private void downloadXml(String path) throws IOException {
119:                InputStream inputStream = null;
120:                try {
121:                    inputStream = new URL(path).openStream();
122:
123:                    ByteArrayOutputStream out = new ByteArrayOutputStream();
124:                    IOUtilities.copyStream(null, inputStream, out, false);
125:                    xml = out.toString();
126:                } finally {
127:                    IOUtilities.closeQuietly(inputStream);
128:                }
129:            } //}}}
130:
131:            //{{{ add() method
132:            void add(Mirror mirror) {
133:                mirrors.add(mirror);
134:            } //}}}
135:
136:            //{{{ finished() method
137:            void finished() {
138:                Collections.sort(mirrors, new MirrorCompare());
139:            } //}}}
140:
141:            //}}}
142:
143:            //{{{ Inner classes
144:
145:            //{{{ Mirror class
146:            public static class Mirror {
147:                public static final String NONE = "NONE";
148:
149:                public String id;
150:                public String description;
151:                public String location;
152:                public String country;
153:                public String continent;
154:            } //}}}
155:
156:            //{{{ MirrorCompare class
157:            private class MirrorCompare implements  Comparator<Mirror> {
158:                public int compare(Mirror m1, Mirror m2) {
159:                    int result;
160:                    if ((result = m1.continent
161:                            .compareToIgnoreCase(m2.continent)) == 0)
162:                        if ((result = m1.country
163:                                .compareToIgnoreCase(m2.country)) == 0)
164:                            if ((result = m1.location
165:                                    .compareToIgnoreCase(m2.location)) == 0)
166:                                return m1.description
167:                                        .compareToIgnoreCase(m2.description);
168:                    return result;
169:                }
170:
171:                public boolean equals(Object obj) {
172:                    return obj instanceof  MirrorCompare;
173:                }
174:            } //}}}
175:
176:            //}}}
177:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.