PageRenderTime 41ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 174 lines | 110 code | 27 blank | 37 comment | 24 complexity | f4be60559f0a22b42463b8b9ed5da075 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 com.microstar.xml.*;
  24. import java.io.*;
  25. import java.util.*;
  26. import org.gjt.sp.util.Log;
  27. class MirrorListHandler extends HandlerBase
  28. {
  29. //{{{ Constructor
  30. MirrorListHandler(MirrorList mirrors, String path)
  31. {
  32. this.mirrors = mirrors;
  33. this.path = path;
  34. stateStack = new Stack();
  35. } //}}}
  36. //{{{ resolveEntity() method
  37. public Object resolveEntity(String publicId, String systemId)
  38. {
  39. if("mirrors.dtd".equals(systemId))
  40. {
  41. // this will result in a slight speed up, since we
  42. // don't need to read the DTD anyway, as AElfred is
  43. // non-validating
  44. return new StringReader("<!-- -->");
  45. }
  46. return null;
  47. } //}}}
  48. //{{{ attribute() method
  49. public void attribute(String aname, String value, boolean isSpecified)
  50. {
  51. aname = (aname == null) ? null : aname.intern();
  52. value = (value == null) ? null : value.intern();
  53. if(aname == "ID")
  54. id = value;
  55. } //}}}
  56. //{{{ doctypeDecl() method
  57. public void doctypeDecl(String name, String publicId,
  58. String systemId) throws Exception
  59. {
  60. if("MIRRORS".equals(name))
  61. return;
  62. Log.log(Log.ERROR,this,path + ": DOCTYPE must be MIRRORS");
  63. } //}}}
  64. //{{{ charData() method
  65. public void charData(char[] c, int off, int len)
  66. {
  67. String tag = peekElement();
  68. String text = new String(c, off, len);
  69. if(tag == "DESCRIPTION")
  70. description = text;
  71. else if(tag == "LOCATION")
  72. location = text;
  73. else if(tag == "COUNTRY")
  74. country = text;
  75. else if(tag == "CONTINENT")
  76. continent = text;
  77. } //}}}
  78. //{{{ startElement() method
  79. public void startElement(String tag)
  80. {
  81. tag = pushElement(tag);
  82. if(tag == "MIRROR")
  83. mirror = new MirrorList.Mirror();
  84. } //}}}
  85. //{{{ endElement() method
  86. public void endElement(String tag)
  87. {
  88. if(tag == null)
  89. return;
  90. else
  91. tag = tag.intern();
  92. popElement();
  93. if(tag == "MIRROR")
  94. {
  95. mirror.id = id;
  96. mirror.description = description;
  97. mirror.location = location;
  98. mirror.country = country;
  99. mirror.continent = continent;
  100. mirrors.add(mirror);
  101. }
  102. } //}}}
  103. //{{{ startDocument() method
  104. public void startDocument()
  105. {
  106. try
  107. {
  108. pushElement(null);
  109. }
  110. catch (Exception e)
  111. {
  112. e.printStackTrace();
  113. }
  114. } //}}}
  115. //{{{ endDocument() method
  116. public void endDocument()
  117. {
  118. mirrors.finished();
  119. } //}}}
  120. //{{{ Private members
  121. //{{{ Variables
  122. private String id;
  123. private String description;
  124. private String location;
  125. private String country;
  126. private String continent;
  127. private MirrorList mirrors;
  128. private MirrorList.Mirror mirror;
  129. private Stack stateStack;
  130. private String path;
  131. //}}}
  132. private String pushElement(String name)
  133. {
  134. name = (name == null) ? null : name.intern();
  135. stateStack.push(name);
  136. return name;
  137. }
  138. private String peekElement()
  139. {
  140. return (String) stateStack.peek();
  141. }
  142. private String popElement()
  143. {
  144. return (String) stateStack.pop();
  145. }
  146. //}}}
  147. }