1. /*
  2. * @(#)Entity.java 1.5 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.swing.text.html.parser;
  8. import java.util.Hashtable;
  9. import java.io.IOException;
  10. import java.io.InputStream;
  11. import java.io.InputStreamReader;
  12. import java.io.Reader;
  13. import java.io.CharArrayReader;
  14. import java.net.URL;
  15. /**
  16. * An entity in as described in a DTD using the ENTITY construct.
  17. * It defines the type and value of the the entity.
  18. *
  19. * @see DTD
  20. * @version 1.5, 11/29/01
  21. * @author Arthur van Hoff
  22. */
  23. public final
  24. class Entity implements DTDConstants {
  25. public String name;
  26. public int type;
  27. public char data[];
  28. /**
  29. * Create an entity.
  30. */
  31. public Entity(String name, int type, char data[]) {
  32. this.name = name;
  33. this.type = type;
  34. this.data = data;
  35. }
  36. /**
  37. * Get the name of the entity.
  38. */
  39. public String getName() {
  40. return name;
  41. }
  42. /**
  43. * Get the type of the entity.
  44. */
  45. public int getType() {
  46. return type & 0xFFFF;
  47. }
  48. /**
  49. * Return true if it is a parameter entity.
  50. */
  51. public boolean isParameter() {
  52. return (type & PARAMETER) != 0;
  53. }
  54. /**
  55. * Return true if it is a parameter entity.
  56. */
  57. public boolean isGeneral() {
  58. return (type & GENERAL) != 0;
  59. }
  60. /**
  61. * Return the data.
  62. */
  63. public char getData()[] {
  64. return data;
  65. }
  66. /**
  67. * Return the data as a string.
  68. */
  69. public String getString() {
  70. return new String(data, 0, data.length);
  71. }
  72. static Hashtable entityTypes = new Hashtable();
  73. static {
  74. entityTypes.put("PUBLIC", new Integer(PUBLIC));
  75. entityTypes.put("CDATA", new Integer(CDATA));
  76. entityTypes.put("SDATA", new Integer(SDATA));
  77. entityTypes.put("PI", new Integer(PI));
  78. entityTypes.put("STARTTAG", new Integer(STARTTAG));
  79. entityTypes.put("ENDTAG", new Integer(ENDTAG));
  80. entityTypes.put("MS", new Integer(MS));
  81. entityTypes.put("MD", new Integer(MD));
  82. entityTypes.put("SYSTEM", new Integer(SYSTEM));
  83. }
  84. public static int name2type(String nm) {
  85. Integer i = (Integer)entityTypes.get(nm);
  86. return (i == null) ? CDATA : i.intValue();
  87. }
  88. }