PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Java | 199 lines | 110 code | 29 blank | 60 comment | 13 complexity | f5a5e56ac8b3edeed40522369145b3c5 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. * ServiceManager.java - Handles services.xml files in plugins
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2003 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;
  23. //{{{ Imports
  24. import com.microstar.xml.*;
  25. import java.io.*;
  26. import java.net.URL;
  27. import java.util.*;
  28. import org.gjt.sp.util.Log;
  29. //}}}
  30. /**
  31. * @since jEdit 4.2pre1
  32. * @author Slava Pestov
  33. * @version $Id: ServiceListHandler.java 4667 2003-04-30 21:22:41Z spestov $
  34. */
  35. class ServiceListHandler extends HandlerBase
  36. {
  37. //{{{ ServiceListHandler constructor
  38. ServiceListHandler(PluginJAR plugin, URL uri)
  39. {
  40. this.plugin = plugin;
  41. this.uri = uri;
  42. stateStack = new Stack();
  43. cachedServices = new LinkedList();
  44. } //}}}
  45. //{{{ resolveEntity() method
  46. public Object resolveEntity(String publicId, String systemId)
  47. {
  48. if("services.dtd".equals(systemId))
  49. {
  50. // this will result in a slight speed up, since we
  51. // don't need to read the DTD anyway, as AElfred is
  52. // non-validating
  53. return new StringReader("<!-- -->");
  54. /* try
  55. {
  56. return new BufferedReader(new InputStreamReader(
  57. getClass().getResourceAsStream
  58. ("/org/gjt/sp/jedit/services.dtd")));
  59. }
  60. catch(Exception e)
  61. {
  62. Log.log(Log.ERROR,this,"Error while opening"
  63. + " dockables.dtd:");
  64. Log.log(Log.ERROR,this,e);
  65. } */
  66. }
  67. return null;
  68. } //}}}
  69. //{{{ attribute() method
  70. public void attribute(String aname, String value, boolean isSpecified)
  71. {
  72. if(aname.equals("NAME"))
  73. serviceName = value;
  74. else if(aname.equals("CLASS"))
  75. serviceClass = value;
  76. } //}}}
  77. //{{{ doctypeDecl() method
  78. public void doctypeDecl(String name, String publicId,
  79. String systemId) throws Exception
  80. {
  81. if("SERVICES".equals(name))
  82. return;
  83. Log.log(Log.ERROR,this,uri + ": DOCTYPE must be SERVICES");
  84. } //}}}
  85. //{{{ charData() method
  86. public void charData(char[] c, int off, int len)
  87. {
  88. String tag = peekElement();
  89. String text = new String(c, off, len);
  90. if (tag == "SERVICE")
  91. {
  92. code = text;
  93. }
  94. } //}}}
  95. //{{{ startElement() method
  96. public void startElement(String tag)
  97. {
  98. tag = pushElement(tag);
  99. } //}}}
  100. //{{{ endElement() method
  101. public void endElement(String name)
  102. {
  103. if(name == null)
  104. return;
  105. String tag = peekElement();
  106. if(name.equals(tag))
  107. {
  108. if(tag == "SERVICE")
  109. {
  110. ServiceManager.Descriptor d =
  111. new ServiceManager.Descriptor(
  112. serviceClass,serviceName,code,plugin);
  113. ServiceManager.registerService(d);
  114. cachedServices.add(d);
  115. }
  116. popElement();
  117. }
  118. else
  119. {
  120. // can't happen
  121. throw new InternalError();
  122. }
  123. } //}}}
  124. //{{{ startDocument() method
  125. public void startDocument()
  126. {
  127. try
  128. {
  129. pushElement(null);
  130. }
  131. catch (Exception e)
  132. {
  133. e.printStackTrace();
  134. }
  135. } //}}}
  136. //{{{ getCachedServices() method
  137. public ServiceManager.Descriptor[] getCachedServices()
  138. {
  139. return (ServiceManager.Descriptor[])cachedServices.toArray(
  140. new ServiceManager.Descriptor[cachedServices.size()]);
  141. } //}}}
  142. //{{{ Private members
  143. //{{{ Instance variables
  144. private PluginJAR plugin;
  145. private URL uri;
  146. private String serviceName;
  147. private String serviceClass;
  148. private String code;
  149. private Stack stateStack;
  150. private List cachedServices;
  151. //}}}
  152. //{{{ pushElement() method
  153. private String pushElement(String name)
  154. {
  155. name = (name == null) ? null : name.intern();
  156. stateStack.push(name);
  157. return name;
  158. } //}}}
  159. //{{{ peekElement() method
  160. private String peekElement()
  161. {
  162. return (String) stateStack.peek();
  163. } //}}}
  164. //{{{ popElement() method
  165. private String popElement()
  166. {
  167. return (String) stateStack.pop();
  168. } //}}}
  169. //}}}
  170. }