/plugins/XML/branches/buffertagparser/xml/parser/AntXmlTag.java

# · Java · 91 lines · 76 code · 14 blank · 1 comment · 10 complexity · 550a059387de700e7d8ba2b11c596470 MD5 · raw file

  1. package xml.parser;
  2. import java.util.*;
  3. import javax.swing.Icon;
  4. import javax.swing.text.Position;
  5. import org.xml.sax.Attributes;
  6. import eclipseicons.EclipseIconsPlugin;
  7. public class AntXmlTag extends XmlTag {
  8. // TODO: figure out which is the default target and use the target_default.png icon.
  9. String originalName = null;
  10. public AntXmlTag(String name, String namespace, Position start, Attributes attributes) {
  11. super(name, namespace, start, attributes);
  12. originalName = name;
  13. String idName = null;
  14. String idValue = null;
  15. Map<String, String> attrs = new LinkedHashMap<String, String>();
  16. for (int i = 0; i < attributes.getLength(); i++) {
  17. String aname = attributes.getQName(i);
  18. String value = attributes.getValue(i);
  19. attrs.put(aname, value);
  20. if (attributes.getLocalName(i).equalsIgnoreCase("id") || attributes.getType(i).equals("ID")) {
  21. idName = aname;
  22. idValue = value;
  23. }
  24. }
  25. StringBuffer buf = new StringBuffer();
  26. buf.append(name).append(' ');
  27. String realName = attrs.get("name");
  28. if (realName != null) {
  29. buf.append("name=\"");
  30. buf.append(realName);
  31. buf.append("\" ");
  32. }
  33. for (String key : attrs.keySet()) {
  34. if ("name".equals(key)) {
  35. continue;
  36. }
  37. String value = attrs.get(key);
  38. buf.append(key);
  39. buf.append("=\"");
  40. buf.append(value);
  41. buf.append("\" ");
  42. }
  43. attributeString = buf.toString();
  44. if (idName == null) {
  45. idAttributeString = name;
  46. } else {
  47. idAttributeString = name + ' ' + idName + "=\"" + idValue + '"';
  48. }
  49. }
  50. public String getOriginalName() {
  51. return originalName;
  52. }
  53. public Icon getIcon() {
  54. if ("project".equals(originalName)) {
  55. return EclipseIconsPlugin.getIcon("ant.gif");
  56. }
  57. if ("target".equals(originalName)) {
  58. return EclipseIconsPlugin.getIcon("targetpublic_obj.gif");
  59. }
  60. if ("property".equals(originalName)) {
  61. return EclipseIconsPlugin.getIcon("ant_property.png");
  62. }
  63. if ("import".equals(originalName)) {
  64. return EclipseIconsPlugin.getIcon("ant_import.png");
  65. }
  66. if ("macrodef".equals(originalName)) {
  67. return EclipseIconsPlugin.getIcon("ant_macrodef.png");
  68. }
  69. if ("taskdef".equals(originalName)) {
  70. return EclipseIconsPlugin.getIcon("ant_taskdef.png");
  71. }
  72. return EclipseIconsPlugin.getIcon("ant_task.png");
  73. }
  74. }