PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 115 lines | 67 code | 18 blank | 30 comment | 6 complexity | 5f77611f3516f2130fde4f2a97f11960 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  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. package org.gjt.sp.jedit.pluginmgr;
  23. import com.microstar.xml.*;
  24. import java.io.*;
  25. import java.net.*;
  26. import java.util.*;
  27. import org.gjt.sp.jedit.*;
  28. public class MirrorList
  29. {
  30. public ArrayList mirrors;
  31. //{{{ MirrorList constructor
  32. public MirrorList() throws Exception
  33. {
  34. mirrors = new ArrayList();
  35. Mirror none = new Mirror();
  36. none.id = Mirror.NONE;
  37. none.description = none.location = none.country = none.continent = "";
  38. mirrors.add(none);
  39. String path = jEdit.getProperty("plugin-manager.mirror-url");
  40. MirrorListHandler handler = new MirrorListHandler(this,path);
  41. XmlParser parser = new XmlParser();
  42. parser.setHandler(handler);
  43. Reader in = new BufferedReader(new InputStreamReader(
  44. new URL(path).openStream()));
  45. try
  46. {
  47. parser.parse(null,null,in);
  48. }
  49. finally
  50. {
  51. in.close();
  52. }
  53. } //}}}
  54. //{{{ Private members
  55. //{{{ add() method
  56. void add(Mirror mirror)
  57. {
  58. mirrors.add(mirror);
  59. } //}}}
  60. //{{{ finished() method
  61. void finished()
  62. {
  63. Collections.sort(mirrors,new MirrorCompare());
  64. } //}}}
  65. //}}}
  66. //{{{ Inner classes
  67. //{{{ Mirror class
  68. public static class Mirror
  69. {
  70. public static final String NONE = "NONE";
  71. public String id;
  72. public String description;
  73. public String location;
  74. public String country;
  75. public String continent;
  76. } //}}}
  77. //{{{ MirrorCompare class
  78. class MirrorCompare implements Comparator
  79. {
  80. public int compare(Object o1,Object o2)
  81. {
  82. Mirror m1 = (Mirror)o1;
  83. Mirror m2 = (Mirror)o2;
  84. int result;
  85. if ((result = m1.continent.compareToIgnoreCase(m2.continent)) == 0)
  86. if ((result = m1.country.compareToIgnoreCase(m2.country)) == 0)
  87. if ((result = m1.location.compareToIgnoreCase(m2.location)) == 0)
  88. return m1.description.compareToIgnoreCase(m2.description);
  89. return result;
  90. }
  91. public boolean equals(Object obj)
  92. {
  93. return (obj instanceof MirrorCompare);
  94. }
  95. } //}}}
  96. //}}}
  97. }