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