PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/bundles/plugins-trunk/XML/xml/completion/CompletionInfoHandler.java

#
Java | 162 lines | 115 code | 17 blank | 30 comment | 19 complexity | 5387f65e8ae270974eb1d280279aa71f 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. * CompletionInfoHandler.java
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2001, 2003 Slava Pestov
  7. *
  8. * The XML plugin is licensed under the GNU General Public License, with
  9. * the following exception:
  10. *
  11. * "Permission is granted to link this code with software released under
  12. * the Apache license version 1.1, for example used by the Xerces XML
  13. * parser package."
  14. */
  15. package xml.completion;
  16. //{{{ Imports
  17. import java.util.*;
  18. import org.gjt.sp.jedit.jEdit;
  19. import org.xml.sax.ext.DefaultHandler2;
  20. import org.xml.sax.*;
  21. import xml.*;
  22. //}}}
  23. public class CompletionInfoHandler extends DefaultHandler2
  24. {
  25. //{{{ CompletionInfoHandler constructor
  26. public CompletionInfoHandler()
  27. {
  28. completionInfo = new CompletionInfo();
  29. /* This is redundant - already done in completionInfo ctor
  30. addEntity(new EntityDecl(EntityDecl.INTERNAL,"lt","<"));
  31. addEntity(new EntityDecl(EntityDecl.INTERNAL,"gt",">"));
  32. addEntity(new EntityDecl(EntityDecl.INTERNAL,"amp","&"));
  33. addEntity(new EntityDecl(EntityDecl.INTERNAL,"quot","\""));
  34. addEntity(new EntityDecl(EntityDecl.INTERNAL,"apos","'")); */
  35. } //}}}
  36. //{{{ getCompletionInfo() method
  37. public CompletionInfo getCompletionInfo()
  38. {
  39. return completionInfo;
  40. } //}}}
  41. //{{{ setDocumentLocator() method
  42. public void setDocumentLocator(Locator loc)
  43. {
  44. this.loc = loc;
  45. } //}}}
  46. //{{{ resolveEntity() method
  47. public InputSource resolveEntity(String name, String publicId, String baseURI, String systemId)
  48. throws SAXException
  49. {
  50. try
  51. {
  52. return Resolver.instance().resolveEntity(
  53. name,//name
  54. publicId,
  55. /*loc.getSystemId()*/baseURI, //current
  56. systemId);
  57. }
  58. catch(Exception e)
  59. {
  60. throw new SAXException(e);
  61. }
  62. } //}}}
  63. //{{{ startElement() method
  64. public void startElement(String namespaceURI,
  65. String sName, // simple name
  66. String qName, // qualified name
  67. Attributes attrs) throws SAXException
  68. {
  69. if(sName.equals("dtd"))
  70. {
  71. String extend = attrs.getValue("extend");
  72. if(extend != null)
  73. {
  74. String infoURI = jEdit.getProperty(
  75. "mode." + extend
  76. + ".xml.completion-info");
  77. if(infoURI != null)
  78. {
  79. CompletionInfo extendInfo = CompletionInfo
  80. .getCompletionInfoFromResource(infoURI);
  81. if(extendInfo != null)
  82. completionInfo = (CompletionInfo)extendInfo.clone();
  83. }
  84. }
  85. }
  86. else if(sName.equals("entity"))
  87. {
  88. addEntity(new EntityDecl(
  89. EntityDecl.INTERNAL,
  90. attrs.getValue("name"),
  91. attrs.getValue("value")));
  92. }
  93. else if(sName.equals("element"))
  94. {
  95. element = new ElementDecl(
  96. completionInfo,
  97. attrs.getValue("name"),
  98. attrs.getValue("content"));
  99. completionInfo.elements.add(element);
  100. completionInfo.elementHash.put(element.name,element);
  101. if("true".equals(attrs.getValue("anywhere")))
  102. completionInfo.elementsAllowedAnywhere.add(element);
  103. }
  104. else if(sName.equals("attribute"))
  105. {
  106. String name = attrs.getValue("name");
  107. String value = attrs.getValue("value");
  108. String type = attrs.getValue("type");
  109. ArrayList values;
  110. if(type.startsWith("("))
  111. {
  112. values = new ArrayList();
  113. StringTokenizer st = new StringTokenizer(
  114. type.substring(1,type.length() - 1),"|");
  115. while(st.hasMoreTokens())
  116. {
  117. values.add(st.nextToken());
  118. }
  119. }
  120. else
  121. values = null;
  122. boolean required = "true".equals(attrs.getValue("required"));
  123. element.addAttribute(new ElementDecl.AttributeDecl(
  124. name,null,value,values,type,required));
  125. }
  126. } //}}}
  127. //{{{ Private members
  128. private CompletionInfo completionInfo;
  129. private Locator loc;
  130. private ElementDecl element;
  131. //{{{ addEntity() method
  132. private void addEntity(EntityDecl entity)
  133. {
  134. completionInfo.entities.add(entity);
  135. if(entity.type == EntityDecl.INTERNAL
  136. && entity.value.length() == 1)
  137. {
  138. Character ch = new Character(
  139. entity.value.charAt(0));
  140. completionInfo.entityHash.put(entity.name,ch);
  141. completionInfo.entityHash.put(ch,entity.name);
  142. }
  143. } //}}}
  144. //}}}
  145. }