PageRenderTime 42ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/pluginmgr/MirrorListHandler.java

#
Java | 155 lines | 98 code | 22 blank | 35 comment | 14 complexity | 63f3f6bf8337b024446753cdfb6e4a40 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. * MirrorListHandler.java - XML handler for the mirrors list
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2002 Kris Kopicki (parts copied from Slava Pestov :) )
  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 java.util.*;
  24. import org.xml.sax.Attributes;
  25. import org.xml.sax.InputSource;
  26. import org.xml.sax.helpers.DefaultHandler;
  27. import org.gjt.sp.util.XMLUtilities;
  28. import org.gjt.sp.util.Log;
  29. import org.gjt.sp.jedit.options.PluginOptions;
  30. /**
  31. * @version $Id: MirrorListHandler.java 12504 2008-04-22 23:12:43Z ezust $
  32. */
  33. class MirrorListHandler extends DefaultHandler
  34. {
  35. //{{{ Constructor
  36. MirrorListHandler(MirrorList mirrors, String path)
  37. {
  38. this.mirrors = mirrors;
  39. this.path = path;
  40. } //}}}
  41. //{{{ resolveEntity() method
  42. public InputSource resolveEntity(String publicId, String systemId)
  43. {
  44. return XMLUtilities.findEntity(systemId, "mirrors.dtd",
  45. PluginOptions.class);
  46. } //}}}
  47. //{{{ characters() method
  48. public void characters(char[] c, int off, int len)
  49. {
  50. String tag = peekElement();
  51. if(tag == "DESCRIPTION")
  52. description.append(c, off, len);
  53. else if(tag == "LOCATION")
  54. location.append(c, off, len);
  55. else if(tag == "COUNTRY")
  56. country.append(c, off, len);
  57. else if(tag == "CONTINENT")
  58. continent.append(c, off, len);
  59. } //}}}
  60. //{{{ startElement() method
  61. public void startElement(String uri, String localName,
  62. String tag, Attributes attrs)
  63. {
  64. tag = pushElement(tag);
  65. if (tag.equals("MIRROR"))
  66. {
  67. mirror = new MirrorList.Mirror();
  68. id = attrs.getValue("ID");
  69. }
  70. } //}}}
  71. //{{{ endElement() method
  72. public void endElement(String uri, String localName, String tag)
  73. {
  74. popElement();
  75. if(tag.equals("MIRROR"))
  76. {
  77. mirror.id = id;
  78. mirror.description = description.toString();
  79. mirror.location = location.toString();
  80. mirror.country = country.toString();
  81. mirror.continent = continent.toString();
  82. mirrors.add(mirror);
  83. description.setLength(0);
  84. location.setLength(0);
  85. country.setLength(0);
  86. continent.setLength(0);
  87. }
  88. } //}}}
  89. //{{{ startDocument() method
  90. public void startDocument()
  91. {
  92. try
  93. {
  94. pushElement(null);
  95. }
  96. catch (Exception e)
  97. {
  98. Log.log(Log.ERROR, this, e);
  99. }
  100. } //}}}
  101. //{{{ endDocument() method
  102. public void endDocument()
  103. {
  104. mirrors.finished();
  105. } //}}}
  106. //{{{ Private members
  107. //{{{ Variables
  108. private String id;
  109. private final StringBuilder description = new StringBuilder();
  110. private final StringBuilder location = new StringBuilder();
  111. private final StringBuilder country = new StringBuilder();
  112. private final StringBuilder continent = new StringBuilder();
  113. private final MirrorList mirrors;
  114. private MirrorList.Mirror mirror;
  115. private final Stack<String> stateStack = new Stack<String>();
  116. private final String path;
  117. //}}}
  118. private String pushElement(String name)
  119. {
  120. name = name == null ? null : name.intern();
  121. stateStack.push(name);
  122. return name;
  123. }
  124. private String peekElement()
  125. {
  126. return stateStack.peek();
  127. }
  128. private void popElement()
  129. {
  130. stateStack.pop();
  131. }
  132. //}}}
  133. }