PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

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

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