PageRenderTime 56ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-1-pre5/org/gjt/sp/jedit/ActionListHandler.java

#
Java | 199 lines | 115 code | 30 blank | 54 comment | 27 complexity | ffdadc542ee1f0da64612f2edc19917a 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. * ActionListHandler.java - XML handler for action files
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2000, 2001 Slava Pestov
  7. * Portions copyright (C) 1999 mike dillon
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. */
  23. package org.gjt.sp.jedit;
  24. //{{{ Imports
  25. import com.microstar.xml.*;
  26. import java.io.*;
  27. import java.util.Stack;
  28. import org.gjt.sp.util.Log;
  29. //}}}
  30. class ActionListHandler extends HandlerBase
  31. {
  32. //{{{ ActionListHandler constructor
  33. ActionListHandler(String path, ActionSet actionSet)
  34. {
  35. this.path = path;
  36. this.actionSet = actionSet;
  37. stateStack = new Stack();
  38. } //}}}
  39. //{{{ resolveEntity() method
  40. public Object resolveEntity(String publicId, String systemId)
  41. {
  42. if("actions.dtd".equals(systemId))
  43. {
  44. // this will result in a slight speed up, since we
  45. // don't need to read the DTD anyway, as AElfred is
  46. // non-validating
  47. return new StringReader("<!-- -->");
  48. /* try
  49. {
  50. return new BufferedReader(new InputStreamReader(
  51. getClass().getResourceAsStream("actions.dtd")));
  52. }
  53. catch(Exception e)
  54. {
  55. Log.log(Log.ERROR,this,"Error while opening"
  56. + " actions.dtd:");
  57. Log.log(Log.ERROR,this,e);
  58. } */
  59. }
  60. return null;
  61. } //}}}
  62. //{{{ attribute() method
  63. public void attribute(String aname, String value, boolean isSpecified)
  64. {
  65. aname = (aname == null) ? null : aname.intern();
  66. value = (value == null) ? null : value.intern();
  67. if(aname == "NAME")
  68. actionName = value;
  69. else if(aname == "NO_REPEAT")
  70. noRepeat = (value == "TRUE");
  71. else if(aname == "NO_RECORD")
  72. noRecord = (value == "TRUE");
  73. } //}}}
  74. //{{{ doctypeDecl() method
  75. public void doctypeDecl(String name, String publicId,
  76. String systemId) throws Exception
  77. {
  78. if("ACTIONS".equals(name))
  79. return;
  80. Log.log(Log.ERROR,this,path + ": DOCTYPE must be ACTIONS");
  81. } //}}}
  82. //{{{ charData() method
  83. public void charData(char[] c, int off, int len)
  84. {
  85. String tag = peekElement();
  86. String text = new String(c, off, len);
  87. if (tag == "CODE")
  88. {
  89. code = text;
  90. }
  91. else if (tag == "IS_SELECTED")
  92. {
  93. isSelected = text;
  94. }
  95. } //}}}
  96. //{{{ startElement() method
  97. public void startElement(String tag)
  98. {
  99. tag = pushElement(tag);
  100. if (tag == "ACTION")
  101. {
  102. code = null;
  103. isSelected = null;
  104. }
  105. } //}}}
  106. //{{{ endElement() method
  107. public void endElement(String name)
  108. {
  109. if(name == null)
  110. return;
  111. String tag = peekElement();
  112. if(name.equals(tag))
  113. {
  114. if(tag == "ACTION")
  115. {
  116. actionSet.addAction(new BeanShellAction(actionName,
  117. code,isSelected,noRepeat,noRecord));
  118. noRepeat = noRecord = false;
  119. }
  120. popElement();
  121. }
  122. else
  123. {
  124. // can't happen
  125. throw new InternalError();
  126. }
  127. } //}}}
  128. //{{{ startDocument() method
  129. public void startDocument()
  130. {
  131. try
  132. {
  133. pushElement(null);
  134. }
  135. catch (Exception e)
  136. {
  137. e.printStackTrace();
  138. }
  139. } //}}}
  140. //{{{ Private members
  141. //{{{ Instance variables
  142. private String path;
  143. private ActionSet actionSet;
  144. private String actionName;
  145. private String code;
  146. private String isSelected;
  147. private boolean noRepeat;
  148. private boolean noRecord;
  149. private Stack stateStack;
  150. //}}}
  151. //{{{ pushElement() method
  152. private String pushElement(String name)
  153. {
  154. name = (name == null) ? null : name.intern();
  155. stateStack.push(name);
  156. return name;
  157. } //}}}
  158. //{{{ peekElement() method
  159. private String peekElement()
  160. {
  161. return (String) stateStack.peek();
  162. } //}}}
  163. //{{{ popElement() method
  164. private String popElement()
  165. {
  166. return (String) stateStack.pop();
  167. } //}}}
  168. //}}}
  169. }