PageRenderTime 25ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 203 lines | 119 code | 30 blank | 54 comment | 31 complexity | 443be686462b7450b15c0a724e288405 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. else if(aname == "NO_REMEMBER_LAST")
  74. noRememberLast = (value == "TRUE");
  75. } //}}}
  76. //{{{ doctypeDecl() method
  77. public void doctypeDecl(String name, String publicId,
  78. String systemId) throws Exception
  79. {
  80. if("ACTIONS".equals(name))
  81. return;
  82. Log.log(Log.ERROR,this,path + ": DOCTYPE must be ACTIONS");
  83. } //}}}
  84. //{{{ charData() method
  85. public void charData(char[] c, int off, int len)
  86. {
  87. String tag = peekElement();
  88. String text = new String(c, off, len);
  89. if (tag == "CODE")
  90. {
  91. code = text;
  92. }
  93. else if (tag == "IS_SELECTED")
  94. {
  95. isSelected = text;
  96. }
  97. } //}}}
  98. //{{{ startElement() method
  99. public void startElement(String tag)
  100. {
  101. tag = pushElement(tag);
  102. if (tag == "ACTION")
  103. {
  104. code = null;
  105. isSelected = null;
  106. }
  107. } //}}}
  108. //{{{ endElement() method
  109. public void endElement(String name)
  110. {
  111. if(name == null)
  112. return;
  113. String tag = peekElement();
  114. if(name.equals(tag))
  115. {
  116. if(tag == "ACTION")
  117. {
  118. actionSet.addAction(new BeanShellAction(actionName,
  119. code,isSelected,noRepeat,noRecord,
  120. noRememberLast));
  121. noRepeat = noRecord = noRememberLast = false;
  122. }
  123. popElement();
  124. }
  125. else
  126. {
  127. // can't happen
  128. throw new InternalError();
  129. }
  130. } //}}}
  131. //{{{ startDocument() method
  132. public void startDocument()
  133. {
  134. try
  135. {
  136. pushElement(null);
  137. }
  138. catch (Exception e)
  139. {
  140. e.printStackTrace();
  141. }
  142. } //}}}
  143. //{{{ Private members
  144. //{{{ Instance variables
  145. private String path;
  146. private ActionSet actionSet;
  147. private String actionName;
  148. private String code;
  149. private String isSelected;
  150. private boolean noRepeat;
  151. private boolean noRecord;
  152. private boolean noRememberLast;
  153. private Stack stateStack;
  154. //}}}
  155. //{{{ pushElement() method
  156. private String pushElement(String name)
  157. {
  158. name = (name == null) ? null : name.intern();
  159. stateStack.push(name);
  160. return name;
  161. } //}}}
  162. //{{{ peekElement() method
  163. private String peekElement()
  164. {
  165. return (String) stateStack.peek();
  166. } //}}}
  167. //{{{ popElement() method
  168. private String popElement()
  169. {
  170. return (String) stateStack.pop();
  171. } //}}}
  172. //}}}
  173. }