< prev index next >

src/java.desktop/share/classes/javax/swing/text/html/parser/Entity.java

Print this page


   1 /*
   2  * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  38  * It defines the type and value of the entity.
  39  *
  40  * @see DTD
  41  * @author Arthur van Hoff
  42  */
  43 public final
  44 class Entity implements DTDConstants {
  45     /**
  46      * The name of the entity.
  47      */
  48     public String name;
  49 
  50     /**
  51      * The type of the entity.
  52      */
  53     public int type;
  54 
  55     /**
  56      * The char array of data.
  57      */
  58     public char data[];
  59 
  60     /**
  61      * Creates an entity.
  62      * @param name the name of the entity
  63      * @param type the type of the entity
  64      * @param data the char array of data
  65      */
  66     public Entity(String name, int type, char data[]) {
  67         this.name = name;
  68         this.type = type;
  69         this.data = data;
  70     }
  71 
  72     /**
  73      * Gets the name of the entity.
  74      * @return the name of the entity, as a <code>String</code>
  75      */
  76     public String getName() {
  77         return name;
  78     }
  79 
  80     /**
  81      * Gets the type of the entity.
  82      * @return the type of the entity
  83      */
  84     public int getType() {
  85         return type & 0xFFFF;
  86     }


  88     /**
  89      * Returns <code>true</code> if it is a parameter entity.
  90      * @return <code>true</code> if it is a parameter entity
  91      */
  92     public boolean isParameter() {
  93         return (type & PARAMETER) != 0;
  94     }
  95 
  96     /**
  97      * Returns <code>true</code> if it is a general entity.
  98      * @return <code>true</code> if it is a general entity
  99      */
 100     public boolean isGeneral() {
 101         return (type & GENERAL) != 0;
 102     }
 103 
 104     /**
 105      * Returns the <code>data</code>.
 106      * @return the <code>data</code>
 107      */
 108     public char getData()[] {
 109         return data;
 110     }
 111 
 112     /**
 113      * Returns the data as a <code>String</code>.
 114      * @return the data as a <code>String</code>
 115      */
 116     public String getString() {
 117         return new String(data, 0, data.length);
 118     }
 119 
 120 
 121     static Hashtable<String, Integer> entityTypes = new Hashtable<String, Integer>();
 122 
 123     static {
 124         entityTypes.put("PUBLIC", Integer.valueOf(PUBLIC));
 125         entityTypes.put("CDATA", Integer.valueOf(CDATA));
 126         entityTypes.put("SDATA", Integer.valueOf(SDATA));
 127         entityTypes.put("PI", Integer.valueOf(PI));
 128         entityTypes.put("STARTTAG", Integer.valueOf(STARTTAG));


   1 /*
   2  * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  38  * It defines the type and value of the entity.
  39  *
  40  * @see DTD
  41  * @author Arthur van Hoff
  42  */
  43 public final
  44 class Entity implements DTDConstants {
  45     /**
  46      * The name of the entity.
  47      */
  48     public String name;
  49 
  50     /**
  51      * The type of the entity.
  52      */
  53     public int type;
  54 
  55     /**
  56      * The char array of data.
  57      */
  58     public char[] data;
  59 
  60     /**
  61      * Creates an entity.
  62      * @param name the name of the entity
  63      * @param type the type of the entity
  64      * @param data the char array of data
  65      */
  66     public Entity(String name, int type, char[] data) {
  67         this.name = name;
  68         this.type = type;
  69         this.data = data;
  70     }
  71 
  72     /**
  73      * Gets the name of the entity.
  74      * @return the name of the entity, as a <code>String</code>
  75      */
  76     public String getName() {
  77         return name;
  78     }
  79 
  80     /**
  81      * Gets the type of the entity.
  82      * @return the type of the entity
  83      */
  84     public int getType() {
  85         return type & 0xFFFF;
  86     }


  88     /**
  89      * Returns <code>true</code> if it is a parameter entity.
  90      * @return <code>true</code> if it is a parameter entity
  91      */
  92     public boolean isParameter() {
  93         return (type & PARAMETER) != 0;
  94     }
  95 
  96     /**
  97      * Returns <code>true</code> if it is a general entity.
  98      * @return <code>true</code> if it is a general entity
  99      */
 100     public boolean isGeneral() {
 101         return (type & GENERAL) != 0;
 102     }
 103 
 104     /**
 105      * Returns the <code>data</code>.
 106      * @return the <code>data</code>
 107      */
 108     public char[] getData() {
 109         return data;
 110     }
 111 
 112     /**
 113      * Returns the data as a <code>String</code>.
 114      * @return the data as a <code>String</code>
 115      */
 116     public String getString() {
 117         return new String(data, 0, data.length);
 118     }
 119 
 120 
 121     static Hashtable<String, Integer> entityTypes = new Hashtable<String, Integer>();
 122 
 123     static {
 124         entityTypes.put("PUBLIC", Integer.valueOf(PUBLIC));
 125         entityTypes.put("CDATA", Integer.valueOf(CDATA));
 126         entityTypes.put("SDATA", Integer.valueOf(SDATA));
 127         entityTypes.put("PI", Integer.valueOf(PI));
 128         entityTypes.put("STARTTAG", Integer.valueOf(STARTTAG));


< prev index next >