PageRenderTime 83ms CodeModel.GetById 65ms app.highlight 7ms RepoModel.GetById 9ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre4/org/gjt/sp/jedit/pluginmgr/MirrorList.java

#
Java | 115 lines | 67 code | 18 blank | 30 comment | 6 complexity | 5f77611f3516f2130fde4f2a97f11960 MD5 | raw file
  1/*
  2 * MirrorList.java - Mirrors list
  3 * :tabSize=8:indentSize=8:noTabs=false:
  4 * :folding=explicit:collapseFolds=1:
  5 *
  6 * Copyright (C) 2002 Kris Kopicki
  7 *
  8 * This program is free software; you can redistribute it and/or
  9 * modify it under the terms of the GNU General Public License
 10 * as published by the Free Software Foundation; either version 2
 11 * of the License, or any later version.
 12 *
 13 * This program is distributed in the hope that it will be useful,
 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16 * GNU General Public License for more details.
 17 *
 18 * You should have received a copy of the GNU General Public License
 19 * along with this program; if not, write to the Free Software
 20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 21 */
 22
 23package org.gjt.sp.jedit.pluginmgr;
 24
 25import com.microstar.xml.*;
 26import java.io.*;
 27import java.net.*;
 28import java.util.*;
 29import org.gjt.sp.jedit.*;
 30
 31public class MirrorList
 32{
 33	public ArrayList mirrors;
 34
 35	//{{{ MirrorList constructor
 36	public MirrorList() throws Exception
 37	{
 38		mirrors = new ArrayList();
 39
 40		Mirror none = new Mirror();
 41		none.id = Mirror.NONE;
 42		none.description = none.location = none.country = none.continent = "";
 43		mirrors.add(none);
 44
 45		String path = jEdit.getProperty("plugin-manager.mirror-url");
 46		MirrorListHandler handler = new MirrorListHandler(this,path);
 47		XmlParser parser = new XmlParser();
 48		parser.setHandler(handler);
 49
 50		Reader in = new BufferedReader(new InputStreamReader(
 51			new URL(path).openStream()));
 52		try
 53		{
 54			parser.parse(null,null,in);
 55		}
 56		finally
 57		{
 58			in.close();
 59		}
 60	} //}}}
 61
 62	//{{{ Private members
 63
 64	//{{{ add() method
 65	void add(Mirror mirror)
 66	{
 67		mirrors.add(mirror);
 68	} //}}}
 69
 70	//{{{ finished() method
 71	void finished()
 72	{
 73		Collections.sort(mirrors,new MirrorCompare());
 74	} //}}}
 75
 76	//}}}
 77
 78	//{{{ Inner classes
 79
 80	//{{{ Mirror class
 81	public static class Mirror
 82	{
 83		public static final String NONE = "NONE";
 84
 85		public String id;
 86		public String description;
 87		public String location;
 88		public String country;
 89		public String continent;
 90	} //}}}
 91
 92	//{{{ MirrorCompare class
 93	class MirrorCompare implements Comparator
 94	{
 95		public int compare(Object o1,Object o2)
 96		{
 97			Mirror m1 = (Mirror)o1;
 98			Mirror m2 = (Mirror)o2;
 99
100			int result;
101			if ((result = m1.continent.compareToIgnoreCase(m2.continent)) == 0)
102				if ((result = m1.country.compareToIgnoreCase(m2.country)) == 0)
103					if ((result = m1.location.compareToIgnoreCase(m2.location)) == 0)
104						return m1.description.compareToIgnoreCase(m2.description);
105			return result;
106		}
107
108		public boolean equals(Object obj)
109		{
110			return (obj instanceof MirrorCompare);
111		}
112	} //}}}
113
114	//}}}
115}